diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2024-12-29 21:42:44 +0100 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2024-12-29 21:42:44 +0100 |
| commit | b917dc4fa5a400141c75c81164f442dd43b23a28 (patch) | |
| tree | 3dd3833416380508d724b3a6684a7e70ff3aeda5 /usr/space_light/src/device.c | |
| parent | 45c9ca9eb3c0f858cbb2324ae290d39809c80cce (diff) | |
| download | wb3s-ble-nebula-galaxy-b917dc4fa5a400141c75c81164f442dd43b23a28.tar.gz wb3s-ble-nebula-galaxy-b917dc4fa5a400141c75c81164f442dd43b23a28.zip | |
space_light: add hacky timer
Diffstat (limited to 'usr/space_light/src/device.c')
| -rw-r--r-- | usr/space_light/src/device.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/usr/space_light/src/device.c b/usr/space_light/src/device.c index 32ac281..30bcf9e 100644 --- a/usr/space_light/src/device.c +++ b/usr/space_light/src/device.c @@ -20,6 +20,10 @@ #include "mcu_ps_pub.h" #include "start_type_pub.h" +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" + #include "space_light.h" #define ATT_DB_LENGTH 5 @@ -69,6 +73,10 @@ bk_attm_desc_t btl_att_db[ATT_DB_LENGTH] = { beken_semaphore_t app_sema = NULL; beken_semaphore_t ext_init_sema = NULL; +TimerHandle_t xOneShotTimer; + +static void oneShotTimerCallback(TimerHandle_t xTimer) { power_save_mode(); } + static void ble_event_callback(ble_event_t event, void *param) { switch (event) { case BLE_STACK_OK: @@ -155,11 +163,32 @@ static void ble_event_callback(ble_event_t event, void *param) { #define CMD_RGBCW 0x1 static void ble_write_callback(write_req_t *write_req) { - struct RGBCW rgbcw = { - write_req->value[1], write_req->value[2], write_req->value[3], - write_req->value[4], write_req->value[5], - }; - setRGBCW(&rgbcw); + switch (write_req->value[0]) { + case 0x1: { + struct RGBCW rgbcw = { + write_req->value[1], write_req->value[2], write_req->value[3], + write_req->value[4], write_req->value[5], + }; + setRGBCW(&rgbcw); + break; + } + case 0x2: + if (write_req->len != 3) { + return; + } + uint16_t seconds = write_req->value[1] << 8 | write_req->value[2]; + xOneShotTimer = xTimerCreate("OneShot", seconds * 1000, pdFALSE, 0, + oneShotTimerCallback); + if ((xOneShotTimer != NULL)) { + xTimerStart(xOneShotTimer, 0); + } + break; + case 0xFF: + setPWM(&write_req->value[1], write_req->len - 1); + break; + default: + break; + } } static unsigned char ble_read_callback(read_req_t *read_req) { |
