Skip to content

Commit

Permalink
add rgblight_update_hook()
Browse files Browse the repository at this point in the history
  • Loading branch information
mtei committed Jan 31, 2019
1 parent 5f6ef1b commit 432b74c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
40 changes: 34 additions & 6 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ 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 };

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;
Expand Down Expand Up @@ -123,6 +123,27 @@ void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
(*led1).b = b;
}

#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)
Expand Down Expand Up @@ -328,6 +349,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();
}
Expand All @@ -338,6 +360,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();
}
Expand Down Expand Up @@ -512,6 +535,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);
Expand Down Expand Up @@ -611,18 +635,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");
}

Expand All @@ -633,7 +661,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
}
Expand Down
12 changes: 12 additions & 0 deletions quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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);
Expand Down

0 comments on commit 432b74c

Please sign in to comment.