diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-07-27 15:07:24 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-07-27 15:07:24 +0200 |
| commit | e94d439286b867a658468d2326b022fad3478ec0 (patch) | |
| tree | 956351337fd6fa61f6b1193226f2abb0b284bc84 /usr/space_light/src/space_light.c | |
| parent | 6ab0289447ea4388124d2a5278d10bacb438472f (diff) | |
| download | wb3s-ble-nebula-galaxy-e94d439286b867a658468d2326b022fad3478ec0.tar.gz wb3s-ble-nebula-galaxy-e94d439286b867a658468d2326b022fad3478ec0.zip | |
space_light: fix timer
Diffstat (limited to 'usr/space_light/src/space_light.c')
| -rw-r--r-- | usr/space_light/src/space_light.c | 79 |
1 files changed, 18 insertions, 61 deletions
diff --git a/usr/space_light/src/space_light.c b/usr/space_light/src/space_light.c index 82e4e1f..85c5243 100644 --- a/usr/space_light/src/space_light.c +++ b/usr/space_light/src/space_light.c @@ -195,73 +195,30 @@ void set_rgbcw(struct RGBCW *rgbcw) { bk_pwm_update_param(WARM, pwm_period, m_period); } -static void oneShotTimerCallback(TimerHandle_t xTimer) { power_save_mode(); } +static void oneShotTimerCallback(TimerHandle_t xTimer) { + bk_printf("TIMER CALLBACK called\r\n"); + power_save_mode(); +} -void set_timer(uint16_t seconds) { - // FIXME: restructure the code - if (xOneShotTimer == NULL && seconds == 0) { - return; - } - if (seconds == 0) { - xTimerStop(xOneShotTimer, 0); +void set_timer(uint32_t seconds) { + bk_printf("seconds %u\r\n", seconds); + if (xOneShotTimer != NULL) { + bk_printf("Delete timer because we want to reconfigure it\r\n"); + xTimerDelete(xOneShotTimer, 0); + xOneShotTimer = NULL; } - if (xOneShotTimer == NULL) { - xOneShotTimer = xTimerCreate("OneShot", seconds * 1000, pdFALSE, 0, - oneShotTimerCallback); - } - if ((xOneShotTimer != NULL)) { - xTimerStart(xOneShotTimer, 0); + if (seconds == 0) { + return; } -} -// Complete hacky command which will be removed shortly -// this is just to shorten the developemnt cycle -void setPWM(uint8_t *values, size_t len) { - // at least try something ^^ + uint32_t ticks = pdMS_TO_TICKS(seconds * 1000); + bk_printf("timer to ticks: %u\r\n", ticks); + xOneShotTimer = + xTimerCreate("OneShotTimer", ticks, pdFALSE, 0, oneShotTimerCallback); - switch (values[0]) { - case 0x01: // initialzie - { - if (len < 6) { - return; - } - uint8_t pwm = values[1]; - uint16_t frequency = values[2] << 8 | values[3]; - uint16_t duty = values[4] << 8 | values[5]; - bk_pwm_initialize(pwm, frequency, duty); - break; - } - case 0x02: // start - { - if (len < 2) { - return; - } - uint8_t pwm = values[1]; - bk_pwm_start(pwm); - break; - } - case 0x03: // stop - { - if (len < 2) { - return; - } - uint8_t pwm = values[1]; - bk_pwm_stop(pwm); - break; - } - case 0x04: // update param - { - if (len < 6) { - return; - } - uint8_t pwm = values[1]; - uint16_t frequency = values[2] << 8 | values[3]; - uint16_t duty = values[4] << 8 | values[5]; - bk_pwm_update_param(pwm, frequency, duty); - } - default: - return; + if (xOneShotTimer != NULL) { + xTimerStart(xOneShotTimer, 0); } } |
