7 #include "common/utils.h"
9 #include "drivers/time.h"
10 #include "drivers/lights_io.h"
14 #include "fc/config.h"
15 #include "fc/rc_controls.h"
16 #include "fc/rc_modes.h"
17 #include "fc/runtime_config.h"
19 #include "scheduler/scheduler.h"
21 #include "config/feature.h"
23 #include "config/parameter_group.h"
24 #include "config/parameter_group_ids.h"
26 #include "io/lights.h"
30 PG_REGISTER_WITH_RESET_TEMPLATE(lightsConfig_t
, lightsConfig
, PG_LIGHTS_CONFIG
, 0);
32 PG_RESET_TEMPLATE(lightsConfig_t
, lightsConfig
,
34 .enabled
= SETTING_FAILSAFE_LIGHTS_DEFAULT
,
35 .flash_period
= SETTING_FAILSAFE_LIGHTS_FLASH_PERIOD_DEFAULT
,
36 .flash_on_time
= SETTING_FAILSAFE_LIGHTS_FLASH_ON_TIME_DEFAULT
40 static bool lights_on
= false;
41 static timeUs_t last_status_change
= 0;
43 static void lightsSetStatus(bool status
, timeUs_t currentTimeUs
)
45 if (status
!= lights_on
) {
47 lightsHardwareSetStatus(status
);
48 last_status_change
= currentTimeUs
;
53 * Lights handler function to be called periodically in loop. Updates lights
54 * state via time schedule.
56 void lightsUpdate(timeUs_t currentTimeUs
)
58 UNUSED(currentTimeUs
);
59 if (lightsConfig()->failsafe
.enabled
&& FLIGHT_MODE(FAILSAFE_MODE
) && ARMING_FLAG(WAS_EVER_ARMED
)) {
60 if (lightsConfig()->failsafe
.flash_period
<= lightsConfig()->failsafe
.flash_on_time
) {
61 lightsSetStatus(true, currentTimeUs
);
64 if (currentTimeUs
- last_status_change
> lightsConfig()->failsafe
.flash_on_time
* 1000)
65 lightsSetStatus(false, currentTimeUs
);
67 if (currentTimeUs
- last_status_change
> (uint32_t)(lightsConfig()->failsafe
.flash_period
- lightsConfig()->failsafe
.flash_on_time
) * 1000)
68 lightsSetStatus(true, currentTimeUs
);
72 lightsSetStatus(IS_RC_MODE_ACTIVE(BOXLIGHTS
), currentTimeUs
);
80 #endif /* USE_LIGHTS */