diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2024-12-25 00:34:42 +0100 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2024-12-29 19:54:53 +0100 |
| commit | 1762c56956bafd6fc0636516b494dfa935ff8aec (patch) | |
| tree | 5b693c0c70400b71c982401fd9693a48991d3c23 /usr/space_light/src/space_light.c | |
| parent | 40404fb81dfad3f5c5cf567bb053796a9135165e (diff) | |
| download | wb3s-ble-nebula-galaxy-1762c56956bafd6fc0636516b494dfa935ff8aec.tar.gz wb3s-ble-nebula-galaxy-1762c56956bafd6fc0636516b494dfa935ff8aec.zip | |
space_light: first version
TODO: pwm initialization is currently best guess
could be wrong active low|high
TODO: implement pairing
TODO: implement timer
TODO: use the button for something
TODO: implement a better client
Diffstat (limited to 'usr/space_light/src/space_light.c')
| -rw-r--r-- | usr/space_light/src/space_light.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/usr/space_light/src/space_light.c b/usr/space_light/src/space_light.c new file mode 100644 index 0000000..f1a0373 --- /dev/null +++ b/usr/space_light/src/space_light.c @@ -0,0 +1,110 @@ +#include "comm.h" +#include "comm_task.h" +#include <math.h> +#include <space_light.h> +#include <stdint.h> + +#include "BkDriverPwm.h" + +#define WARM BK_PWM_0 +#define COLD BK_PWM_2 +#define RED BK_PWM_3 +#define GREEN BK_PWM_4 +#define BLUE BK_PWM_5 + +static const float max_freq = 1000.0f; + +// FIXME: consider creating a lookup table +static inline uint16_t get_led_frequency(const uint8_t value, + const float gamma) { + return (uint16_t)pow((float)value / 255.0f, gamma) * max_freq + 0.5; +} + +void setRGBCW(struct RGBCW *rgbcw) { + if (rgbcw->r) { + bk_pwm_initialize(RED, get_led_frequency(rgbcw->r, 2.8), 10); + bk_pwm_start(RED); + } else { + // FIXME: same as in the init ^^ should be stop + bk_pwm_initialize(RED, 100, 10); + bk_pwm_start(RED); + } + + if (rgbcw->g) { + bk_pwm_initialize(GREEN, get_led_frequency(rgbcw->g, 2.8), 10); + bk_pwm_start(GREEN); + } else { + // FIXME: same as in the init ^^ should be stop + bk_pwm_initialize(GREEN, 100, 10); + bk_pwm_start(GREEN); + } + + if (rgbcw->b) { + bk_pwm_initialize(BLUE, get_led_frequency(rgbcw->b, 2.8), 10); + bk_pwm_start(BLUE); + } else { + // FIXME: same as in the init ^^ should be stop + bk_pwm_initialize(BLUE, 100, 10); + bk_pwm_start(BLUE); + } + + if (rgbcw->c) { + uint16_t value = rgbcw->c; + if (value > 100) { + value = 100; + } + value = value * 10; + bk_pwm_initialize(COLD, value, 50); + bk_pwm_start(COLD); + } else { + bk_pwm_initialize(COLD, 0, 50); + bk_pwm_stop(COLD); + } + + if (rgbcw->w) { + uint16_t value = rgbcw->w; + if (value > 100) { + value = 100; + } + value = value * 10; + value = 1000 - value; // the motor is inverted 1000 is the slowest value + bk_pwm_initialize(WARM, value, 10); + bk_pwm_start(WARM); + } else { + bk_pwm_initialize(WARM, 0, 10); + bk_pwm_stop(WARM); + } +} + +void init_led_thread(void *arg) { + // FIXME: this is as it is stupid and bad but it works this way.. + // TODO: figure out how to just disable pwm without setting defaults first ^^ + // TODO: update pwm also is not working like it should + bk_pwm_stop(RED); + bk_pwm_stop(GREEN); + bk_pwm_stop(BLUE); + bk_pwm_stop(COLD); + bk_pwm_stop(WARM); + + bk_pwm_initialize(RED, 100, 50); + bk_pwm_start(RED); + bk_pwm_initialize(GREEN, 100, 50); + bk_pwm_start(GREEN); + bk_pwm_initialize(BLUE, 100, 50); + bk_pwm_start(BLUE); + // FIXME: laser is still a puzzle to me + bk_pwm_initialize(COLD, 100, 50); + bk_pwm_start(COLD); + bk_pwm_initialize(WARM, 1000, 50); + bk_pwm_start(WARM); + + // FIXME: doing this will start all leds to full color ^^ + // TODO: figgure out how to reverse the level in the configuration of each PWM + // bk_pwm_stop(RED); + // bk_pwm_stop(GREEN); + // bk_pwm_stop(BLUE); + // bk_pwm_stop(COLD); + // bk_pwm_stop(WARM); + + rtos_delete_thread(NULL); +} |
