diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-07-27 16:30:16 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-07-27 16:30:16 +0200 |
| commit | dbda1f93a828303dc20c686f40ce7e460100639b (patch) | |
| tree | a9cf40df0d097ad686e6a49a83271727d4bfc9bc /usr | |
| parent | 68cf01e3db805d87500f97399ea07c59f5569e99 (diff) | |
| download | wb3s-ble-nebula-galaxy-dbda1f93a828303dc20c686f40ce7e460100639b.tar.gz wb3s-ble-nebula-galaxy-dbda1f93a828303dc20c686f40ce7e460100639b.zip | |
Diffstat (limited to 'usr')
| -rw-r--r-- | usr/space_light/src/space_light.c | 89 |
1 files changed, 74 insertions, 15 deletions
diff --git a/usr/space_light/src/space_light.c b/usr/space_light/src/space_light.c index 85c5243..498885e 100644 --- a/usr/space_light/src/space_light.c +++ b/usr/space_light/src/space_light.c @@ -33,6 +33,7 @@ #include "task.h" #include "timers.h" +#include "BkDriverGpio.h" #include "BkDriverPwm.h" #define WARM BK_PWM_0 @@ -42,22 +43,16 @@ #define BLUE BK_PWM_5 TimerHandle_t xOneShotTimer = NULL; +TimerHandle_t xPollGPIOTimer = NULL; -void power_save_mode() { - // Turn your lights down low - // And pull your window curtain (yeah) - // Couldn't resitst ^^ - bk_pwm_initialize(RED, 26000, 26000); - bk_pwm_start(RED); - bk_pwm_initialize(GREEN, 26000, 26000); - bk_pwm_start(GREEN); - bk_pwm_initialize(BLUE, 26000, 26000); - bk_pwm_start(BLUE); - bk_pwm_initialize(COLD, 26000, 26000); - bk_pwm_start(COLD); - bk_pwm_initialize(WARM, 26000, 0); - bk_pwm_start(WARM); -} +typedef enum { + POWER_SAVE = 0, + STARTS_I_LIKE = 1, +} STARS_STATE; + +STARS_STATE stars_state = POWER_SAVE; + +void power_save_mode(); /* * As the following took me longer then expected @@ -222,7 +217,71 @@ void set_timer(uint32_t seconds) { } } +static void stars_i_like() { + bk_printf("stars_i_like\r\n"); + struct RGBCW rgbcw = {0, 0, 37, 9, 15}; + set_rgbcw(&rgbcw); + set_timer(3600); + stars_state = STARTS_I_LIKE; +} + +void power_save_mode() { + bk_printf("power_save_mode\r\n"); + // Turn your lights down low + // And pull your window curtain (yeah) + // Couldn't resitst ^^ + bk_pwm_initialize(RED, 26000, 26000); + bk_pwm_start(RED); + bk_pwm_initialize(GREEN, 26000, 26000); + bk_pwm_start(GREEN); + bk_pwm_initialize(BLUE, 26000, 26000); + bk_pwm_start(BLUE); + bk_pwm_initialize(COLD, 26000, 26000); + bk_pwm_start(COLD); + bk_pwm_initialize(WARM, 26000, 0); + bk_pwm_start(WARM); + set_timer(0); + stars_state = POWER_SAVE; +} + +static void pollGPIOTimerCallback(TimerHandle_t xTimer) { + if (BkGpioInputGet(GPIO14) == 0) { + switch (stars_state) { + case POWER_SAVE: + stars_i_like(); + break; + case STARTS_I_LIKE: + power_save_mode(); + break; + default: + bk_printf("Unexpected state %i\r\n", stars_state); + } + } +} + +bool init_ctrl_button() { return BkGpioInitialize(GPIO14, INPUT_NORMAL); } + +void init_ctrl_button_poller() { + bk_printf("set_gpio_timer\r\n"); + if (xPollGPIOTimer != NULL) { + bk_printf("Delete timer because we want to reconfigure it\r\n"); + xTimerDelete(xPollGPIOTimer, 0); + xPollGPIOTimer = NULL; + } + + uint32_t ticks = pdMS_TO_TICKS(500); + bk_printf("timer to ticks: %u\r\n", ticks); + xPollGPIOTimer = + xTimerCreate("PollGPIOTimer", ticks, pdTRUE, 0, pollGPIOTimerCallback); + + if (xPollGPIOTimer != NULL) { + xTimerStart(xPollGPIOTimer, 0); + } +} + void init_led_thread(void *arg) { + init_ctrl_button(); + init_ctrl_button_poller(); power_save_mode(); rtos_delete_thread(NULL); } |
