From f69e57f1b6a55f341d789a1c0c7346a83b31902c Mon Sep 17 00:00:00 2001 From: mtei <2170248+mtei@users.noreply.github.com> Date: Tue, 26 Feb 2019 19:37:31 +0900 Subject: [PATCH] implement rgblight_update_hook() --- quantum/rgblight.c | 23 +++++++++++++++++++++-- quantum/rgblight.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b403317f5f..72bb4ac252 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -158,6 +158,25 @@ void rgblight_check_config(void) { /* Overwrite with individual code of keyboard. */ __attribute__ ((weak)) void rgblight_update_hook(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom) { + static rgblight_config_t config_old = {}; + rgblight_status_t status_old = {}; + + if( config != NULL ) { + if( config_old.enable != config->enable || config_old.mode != config->mode ) { + rgblight_status.change_mode = 1; + } + if( config_old.hue != config->hue || config_old.sat != config->sat || + config_old.val != config->val || config_old.speed != config->speed ) { + rgblight_status.change_hsvs = 1; + } + config_old = *config; + } + if( status != NULL ) { + if( status_old.timer_enabled != status->timer_enabled ) { + rgblight_status.change_mode = 1; + } + status_old.timer_enabled = status->timer_enabled; + } } /* for split keyboard slave side */ @@ -510,13 +529,13 @@ void rgblight_decrease_val(void) { } void rgblight_increase_speed(void) { rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); - rgblight_update_hook(NULL, &rgblight_status, false); + rgblight_update_hook(&rgblight_config, NULL, true); eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } void rgblight_decrease_speed(void) { rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); - rgblight_update_hook(NULL, &rgblight_status, false); + rgblight_update_hook(&rgblight_config, NULL, true); eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 827bbef472..0228ae4131 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -165,6 +165,8 @@ typedef union { typedef struct _rgblight_status_t { bool timer_enabled; + bool change_mode; // change mode or enable + bool change_hsvs; // change hue, sat, val or speed // TODO: add animation syncronizing // (with integrate timer processing.) } rgblight_status_t;