add rgblight_update_hook()

pull/5020/head
mtei 6 years ago
parent 67bcd0db55
commit 24fb695922

@ -57,10 +57,10 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
#endif
rgblight_config_t rgblight_config;
rgblight_status_t rgblight_status = { .timer_enabled = false };
bool is_rgblight_initialized = false;
LED_TYPE led[RGBLED_NUM];
bool rgblight_timer_enabled = false;
void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
uint8_t r = 0, g = 0, b = 0, base, color;
@ -153,6 +153,29 @@ void rgblight_check_config(void) {
}
#ifdef RGBLIGHT_SPLIT
/* for split keyboard master side */
/* Overwrite with individual code of keyboard. */
__attribute__ ((weak))
void rgblight_update_hook(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom) {
}
/* for split keyboard slave side */
/* Call from keyboard individual code. */
void rgblight_update_sync(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom) {
// TODO: not yet implemented
// if (config != NULL) {
// do sync
// }
// if (status != NULL) {
// do sync
// }
}
#else
#define rgblight_update_hook(dummy1,dummy2,dummy3)
#endif
uint32_t eeconfig_read_rgblight(void) {
#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
return eeprom_read_dword(EECONFIG_RGBLIGHT);
@ -369,6 +392,7 @@ void rgblight_disable(void) {
#ifdef RGBLIGHT_USE_TIMER
rgblight_timer_disable();
#endif
rgblight_update_hook(&rgblight_config, NULL, true);
wait_ms(50);
rgblight_set();
}
@ -379,6 +403,7 @@ void rgblight_disable_noeeprom(void) {
#ifdef RGBLIGHT_USE_TIMER
rgblight_timer_disable();
#endif
rgblight_update_hook(&rgblight_config, NULL, false);
wait_ms(50);
rgblight_set();
}
@ -553,6 +578,7 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool
rgblight_config.hue = hue;
rgblight_config.sat = sat;
rgblight_config.val = val;
rgblight_update_hook(&rgblight_config, NULL, write_to_eeprom);
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
@ -701,18 +727,22 @@ void rgblight_timer_init(void) {
// OCR3AL = RGBLED_TIMER_TOP & 0xff;
// SREG = sreg;
rgblight_timer_enabled = true;
rgblight_status.timer_enabled = true;
rgblight_update_hook(NULL, &rgblight_status, false);
}
void rgblight_timer_enable(void) {
rgblight_timer_enabled = true;
rgblight_status.timer_enabled = true;
rgblight_update_hook(NULL, &rgblight_status, false);
dprintf("TIMER3 enabled.\n");
}
void rgblight_timer_disable(void) {
rgblight_timer_enabled = false;
rgblight_status.timer_enabled = false;
rgblight_update_hook(NULL, &rgblight_status, false);
dprintf("TIMER3 disabled.\n");
}
void rgblight_timer_toggle(void) {
rgblight_timer_enabled ^= rgblight_timer_enabled;
rgblight_status.timer_enabled ^= rgblight_status.timer_enabled;
rgblight_update_hook(NULL, &rgblight_status, false);
dprintf("TIMER3 toggled.\n");
}
@ -724,7 +754,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
void rgblight_task(void) {
if (rgblight_timer_enabled) {
if (rgblight_status.timer_enabled) {
// static light mode, do nothing here
if ( 1 == 0 ) { //dummy
}

@ -163,6 +163,18 @@ typedef union {
};
} rgblight_config_t;
typedef struct _rgblight_status_t {
bool timer_enabled;
// TODO: add animation syncronizing
} rgblight_status_t;
#ifdef RGBLIGHT_SPLIT
/* for split keyboard master side */
void rgblight_update_hook(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom);
/* for split keyboard slave side */
void rgblight_update_sync(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom);
#endif
void rgblight_init(void);
void rgblight_increase(void);
void rgblight_decrease(void);

Loading…
Cancel
Save