Fix led lua code so the buffer do not include device specific magic values

This commit is contained in:
Paul Dino Jones 2025-03-23 18:05:58 -04:00
parent 1e6bde9da1
commit 8c764358b7
2 changed files with 37 additions and 34 deletions

View File

@ -216,6 +216,7 @@ int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata)
int total_leds = serialdevice->numleds;
size_t bufsize = (total_leds * 3) + 14;
char ledbytes[total_leds * 3];
char bytes[bufsize];
for(int j = 0; j < bufsize; j++)
@ -241,7 +242,7 @@ int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata)
lua_State* L = serialdevice->m.L;
lua_pushstring(L, "buff");
lua_pushlightuserdata(L, &bytes);
lua_pushlightuserdata(L, &ledbytes);
lua_settable(L, LUA_REGISTRYINDEX);
simdata_to_lua(L, simdata);
@ -273,14 +274,16 @@ int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata)
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
}
for(int i = 0; i < total_leds; i++)
{
bytes[11 + (i * 3) + 0] = ledbytes[(i * 3) + 0];
bytes[11 + (i * 3) + 1] = ledbytes[(i * 3) + 1];
bytes[11 + (i * 3) + 2] = ledbytes[(i * 3) + 2];
}
size_t size = sizeof(bytes);
arduino_update(serialdevice, &bytes, size);
// move to free
return result;
}

View File

@ -175,9 +175,9 @@ int set_led_range_to_color(lua_State *L)
for( int i = range_start; i < range_end; i++)
{
bytes[(i * 3) + 11 + 0] = color0;
bytes[(i * 3) + 11 + 1] = color1;
bytes[(i * 3) + 11 + 2] = color2;
bytes[(i * 3) + 0] = color0;
bytes[(i * 3) + 1] = color1;
bytes[(i * 3) + 2] = color2;
}
}
@ -232,9 +232,9 @@ int set_led_range_to_rgb_color(lua_State *L)
for( int i = range_start; i < range_end; i++)
{
bytes[(i * 3) + 11 + 0] = color0;
bytes[(i * 3) + 11 + 1] = color1;
bytes[(i * 3) + 11 + 2] = color2;
bytes[(i * 3) + 0] = color0;
bytes[(i * 3) + 1] = color1;
bytes[(i * 3) + 2] = color2;
}
}
@ -274,9 +274,9 @@ int set_led_to_color(lua_State *L)
uint8_t color1 = get_color_rgb_value(color, 1);
uint8_t color2 = get_color_rgb_value(color, 2);
bytes[(led * 3) + 11 + 0] = color0;
bytes[(led * 3) + 11 + 1] = color1;
bytes[(led * 3) + 11 + 2] = color2;
bytes[(led * 3) + 0] = color0;
bytes[(led * 3) + 1] = color1;
bytes[(led * 3) + 2] = color2;
}
@ -318,9 +318,9 @@ int set_led_to_rgb_color(lua_State *L)
slogt("tenth byte of buff is x%02x", bytes[10]);
bytes[(led * 3) + 11 + 0] = color0;
bytes[(led * 3) + 11 + 1] = color1;
bytes[(led * 3) + 11 + 2] = color2;
bytes[(led * 3) + 0] = color0;
bytes[(led * 3) + 1] = color1;
bytes[(led * 3) + 2] = color2;
}
@ -346,9 +346,9 @@ int led_clear_all(lua_State *L)
for( int i = 0; i < numlights; i++)
{
bytes[(i * 3) + 11 + 0] = 0x00;
bytes[(i * 3) + 11 + 1] = 0x00;
bytes[(i * 3) + 11 + 2] = 0x00;
bytes[(i * 3) + 0] = 0x00;
bytes[(i * 3) + 1] = 0x00;
bytes[(i * 3) + 2] = 0x00;
}
}