diff --git a/conf/rpms_and_radar.lua b/conf/rpms_and_radar.lua index 4337c51..142db56 100644 --- a/conf/rpms_and_radar.lua +++ b/conf/rpms_and_radar.lua @@ -58,11 +58,11 @@ while(i <= proxcars and leftsideset == false) do i = i + 1 end - +rpm_leds = 6 -- rpm stuff if simdata.rpm > 0 and simdata.maxrpm > 0 then rpmmargin = .05*simdata.maxrpm; - rpminterval = (simdata.maxrpm-rpmmargin) / 6; + rpminterval = (simdata.maxrpm-rpmmargin) / rpm_leds; litleds = 0 for i = 1,6 do @@ -72,18 +72,18 @@ if simdata.rpm > 0 and simdata.maxrpm > 0 then end color = GREEN - if litleds > 3 and litleds < 6 then + if litleds > rpm_leds/2 and litleds < rpm_leds then color = YELLOW end - if litleds >= 6 then + if litleds >= rpm_leds then color = RED end - if litleds >= 6 then + if litleds >= rpm_leds then if simdata.mtick % 2 == 0 then set_led_range_to_color(1, litleds, color) else - led_clear_all() + led_clear_range(1, rpm_leds) end else set_led_range_to_color(1, litleds, color) diff --git a/src/monocoque/devices/serial/arduino.c b/src/monocoque/devices/serial/arduino.c index 765ff74..0d05cc6 100644 --- a/src/monocoque/devices/serial/arduino.c +++ b/src/monocoque/devices/serial/arduino.c @@ -313,6 +313,7 @@ int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata) lua_register(L, "set_led_to_rgb_color", set_led_to_rgb_color); lua_register(L, "set_led_range_to_rgb_color", set_led_range_to_rgb_color); lua_register(L, "led_clear_all", led_clear_all); + lua_register(L, "led_clear_range", led_clear_all); lua_pushinteger(L, LUALEDCOLOR_RED); lua_setglobal(L, "RED"); diff --git a/src/monocoque/devices/serial/arduinoledlua.c b/src/monocoque/devices/serial/arduinoledlua.c index 76b7b97..f2082f8 100644 --- a/src/monocoque/devices/serial/arduinoledlua.c +++ b/src/monocoque/devices/serial/arduinoledlua.c @@ -340,3 +340,49 @@ int led_clear_all(lua_State *L) } } + +int led_clear_range(lua_State *L) +{ + + slogt("lua called c function led_clear_range"); + + int range_start = lua_tonumber(L, 1); + int range_end = lua_tonumber(L, 2); + + slogd("lua range start is %i", range_start); + slogd("lua range end is %i", range_end); + + range_start = range_start - 1; + + lua_getglobal(L, "TotalLeds"); + int numlights = 0; + if (lua_isnumber(L, -1)) + { + numlights = lua_tonumber(L, -1); + } + slogd("num leds is %i", numlights); + + if(range_end > numlights) + { + range_end = numlights; + } + + if(range_end == 0) + { + return 1; + } + + lua_pushstring(L, "buff"); + lua_gettable(L, LUA_REGISTRYINDEX); + char* bytes = lua_touserdata(L, -1); + + slogt("first byte of buff is x%02x", bytes[0]); + + for( int i = 0; i < numlights; i++) + { + bytes[(i * 3) + 0] = 0x00; + bytes[(i * 3) + 1] = 0x00; + bytes[(i * 3) + 2] = 0x00; + } + +} diff --git a/src/monocoque/devices/serial/arduinoledlua.h b/src/monocoque/devices/serial/arduinoledlua.h index 65d027b..99c413a 100644 --- a/src/monocoque/devices/serial/arduinoledlua.h +++ b/src/monocoque/devices/serial/arduinoledlua.h @@ -21,5 +21,6 @@ int set_led_to_color(lua_State *L); int set_led_range_to_rgb_color(lua_State *L); int set_led_to_rgb_color(lua_State *L); int led_clear_all(lua_State *L); +int led_clear_range(lua_State *L); #endif