@@ -178,8 +178,6 @@ static void reconfigure(Data *d) {
178178static void configure (Data * d ) {
179179 state_set_disabled (& d -> state , d -> float_conf .disabled );
180180
181- lcm_configure (& d -> lcm , & d -> float_conf .leds );
182-
183181 // Loop time in microseconds
184182 d -> loop_time_us = 1e6 / d -> float_conf .hertz ;
185183
@@ -214,16 +212,18 @@ static void configure(Data *d) {
214212
215213 reconfigure (d );
216214
215+ lcm_configure (& d -> lcm , & d -> leds );
216+
217217 if (d -> state .state == STATE_DISABLED ) {
218218 beep_alert (d , 3 , false);
219219 } else if (d -> state .state != STATE_STARTUP ) {
220220 beep_alert (d , 1 , false);
221221 }
222222}
223223
224- static void leds_headlights_switch (CfgLeds * cfg_leds , LcmData * lcm , bool headlights_on ) {
225- cfg_leds -> headlights_on = headlights_on ;
226- lcm_configure (lcm , cfg_leds );
224+ static void leds_headlights_switch (Leds * leds , LcmData * lcm , bool headlights_on ) {
225+ leds_set_headlights_enabled ( leds , headlights_on ) ;
226+ lcm_configure (lcm , leds );
227227}
228228
229229static void reset_runtime_vars (Data * d ) {
@@ -964,14 +964,15 @@ static void refloat_thd(void *arg) {
964964 }
965965
966966 if (d -> float_conf .hardware .leds .mode != LED_MODE_OFF ) {
967- if (!d -> leds .cfg -> headlights_on &&
967+ const LedsRuntimeStatus * led_status = leds_get_runtime_status (& d -> leds );
968+ if (!led_status -> headlights_enabled &&
968969 konami_check (& d -> headlights_on_konami , & d -> leds , & d -> footpad , & d -> time )) {
969- leds_headlights_switch (& d -> float_conf . leds , & d -> lcm , true);
970+ leds_headlights_switch (& d -> leds , & d -> lcm , true);
970971 }
971972
972- if (d -> leds . cfg -> headlights_on &&
973+ if (led_status -> headlights_enabled &&
973974 konami_check (& d -> headlights_off_konami , & d -> leds , & d -> footpad , & d -> time )) {
974- leds_headlights_switch (& d -> float_conf . leds , & d -> lcm , false);
975+ leds_headlights_switch (& d -> leds , & d -> lcm , false);
975976 }
976977 }
977978
@@ -2028,7 +2029,7 @@ static void cmd_alerts_control(AlertTracker *at, uint8_t *buf, size_t len) {
20282029 }
20292030}
20302031
2031- static void lights_control_request (CfgLeds * leds , uint8_t * buffer , size_t len , LcmData * lcm ) {
2032+ static void lights_control_request (Leds * leds , uint8_t * buffer , size_t len , LcmData * lcm ) {
20322033 if (len < 5 ) {
20332034 return ;
20342035 }
@@ -2040,25 +2041,27 @@ static void lights_control_request(CfgLeds *leds, uint8_t *buffer, size_t len, L
20402041 uint8_t value = buffer [ind ++ ];
20412042
20422043 if (mask & 0x1 ) {
2043- leds -> on = value & 0x1 ;
2044+ leds_set_enabled ( leds , value & 0x1 ) ;
20442045 }
20452046
20462047 if (mask & 0x2 ) {
2047- leds -> headlights_on = value & 0x2 ;
2048+ leds_set_headlights_enabled ( leds , value & 0x2 ) ;
20482049 }
20492050
20502051 lcm_configure (lcm , leds );
20512052 }
20522053}
20532054
2054- static void lights_control_response (const CfgLeds * leds ) {
2055+ static void lights_control_response (const Leds * leds ) {
20552056 static const int bufsize = 3 ;
20562057 uint8_t buffer [bufsize ];
20572058 int32_t ind = 0 ;
20582059
20592060 buffer [ind ++ ] = 101 ; // Package ID
20602061 buffer [ind ++ ] = COMMAND_LIGHTS_CONTROL ;
2061- buffer [ind ++ ] = leds -> headlights_on << 1 | leds -> on ;
2062+
2063+ const LedsRuntimeStatus * status = leds_get_runtime_status (leds );
2064+ buffer [ind ++ ] = status -> headlights_enabled << 1 | status -> enabled ;
20622065
20632066 SEND_APP_DATA (buffer , bufsize , ind );
20642067}
@@ -2273,8 +2276,8 @@ static void on_command_received(unsigned char *buffer, unsigned int len) {
22732276 return ;
22742277 }
22752278 case COMMAND_LIGHTS_CONTROL : {
2276- lights_control_request (& d -> float_conf . leds , & buffer [2 ], len - 2 , & d -> lcm );
2277- lights_control_response (& d -> float_conf . leds );
2279+ lights_control_request (& d -> leds , & buffer [2 ], len - 2 , & d -> lcm );
2280+ lights_control_response (& d -> leds );
22782281 return ;
22792282 }
22802283 case COMMAND_DATA_RECORD_REQUEST : {
0 commit comments