/* * ws2812_effect.c * * Created on: Mar 25, 2026 * Author: ewars */ #include "ws2812_drv.h" #include "ws2812_effect.h" #include "clock.h" #include #include "ds1307.h" #define NV_COLOUR_HOURS_ADDR 0x08 #define NV_COLOUR_MINUTES_ADDR 0x09 #define NV_COLOUR_SECONDS_ADDR 0x0A #define NV_COLOUR_BACKGND_ADDR 0x0B typedef struct { uint8_t r; uint8_t g; uint8_t b; } colour_s; static colour_s colour_hours = {250, 0, 0}; static colour_s colour_minutes = {0, 250, 0}; static colour_s colour_seconds = {0, 0, 250}; static colour_s colour_background = {0, 0, 0}; void ws_effect_setDisplayColoursNV(void){ uint8_t rxBuf[3] = {0}; ds1307_read_user_RAM(NV_COLOUR_HOURS_ADDR, rxBuf, 3); colour_hours.r = rxBuf[0]; colour_hours.g = rxBuf[1]; colour_hours.b = rxBuf[2]; ds1307_read_user_RAM(NV_COLOUR_MINUTES_ADDR, rxBuf, 3); colour_minutes.r = rxBuf[0]; colour_minutes.g = rxBuf[1]; colour_minutes.b = rxBuf[2]; ds1307_read_user_RAM(NV_COLOUR_SECONDS_ADDR, rxBuf, 3); colour_seconds.r = rxBuf[0]; colour_seconds.g = rxBuf[1]; colour_seconds.b = rxBuf[2]; ds1307_read_user_RAM(NV_COLOUR_BACKGND_ADDR, rxBuf, 3); colour_background.r = rxBuf[0]; colour_background.g = rxBuf[1]; colour_background.b = rxBuf[2]; } void clock_setColourHours(uint8_t r, uint8_t g, uint8_t b){ colour_hours.r = r; colour_hours.g = g; colour_hours.b = b; } void clock_setColourMinutes(uint8_t r, uint8_t g, uint8_t b){ colour_minutes.r = r; colour_minutes.g = g; colour_minutes.b = b; } void clock_setColourSeconds(uint8_t r, uint8_t g, uint8_t b){ colour_seconds.r = r; colour_seconds.g = g; colour_seconds.b = b; } void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b){ colour_background.r = r; colour_background.g = g; colour_background.b = b; } void ws_Effect_RoudTheClock(void){ #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); for (uint8_t led = 0; led < 24; led++) { ws2812_reset(); ws2812_set_colour(led, r, g, b); ws2812_update(); HAL_Delay(20); } } void ws_Effect_RandRound(void){ #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); for (uint8_t led = 0; led < 24; led++) { ws2812_set_colour(led, r, g, b); ws2812_update(); HAL_Delay(20); } } void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second){ ws2812_reset(); //ws2812_resetColour(colour_background.r, colour_background.g, colour_background.b); ws2812_update(); ws2812_set_colour(hour, colour_hours.r, colour_hours.g, colour_hours.b); ws2812_update(); ws2812_set_colour(minute, colour_minutes.r, colour_minutes.g, colour_minutes.b); ws2812_update(); ws2812_set_colour(second, colour_seconds.r, colour_seconds.g, colour_seconds.b); ws2812_update(); } void ws_effect_display_hour(uint8_t hour){ ws2812_reset(); ws2812_set_colour(hour, colour_hours.r, colour_hours.g, colour_hours.b); } void ws_Effect_RandRand(void){ #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); #define RAND_MAX 24 uint8_t led = rand(); ws2812_set_colour(led, r, g, b); ws2812_update(); HAL_Delay(1); }