quantum/rgblight.c: add split-keyboard master side sync functions

add functions:
  uint8_t rgblight_get_change_flags(void);
  void rgblight_clear_change_flags(void);
  void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo);

change function:
  void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom);
This commit is contained in:
mtei 2019-03-20 06:23:43 +09:00
parent 3c1fc31f72
commit be6e022c0f
2 changed files with 39 additions and 25 deletions

View File

@ -724,34 +724,48 @@ void rgblight_set(void) {
#endif #endif
#ifdef RGBLIGHT_SPLIT #ifdef RGBLIGHT_SPLIT
/* for split keyboard master side */
uint8_t rgblight_get_change_flags(void) {
return rgblight_status.change_flags;
}
void rgblight_clear_change_flags(void) {
rgblight_status.change_flags = 0;
}
void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) {
syncinfo->config = rgblight_config;
syncinfo->status = rgblight_status;
}
/* for split keyboard slave side */ /* for split keyboard slave side */
void rgblight_update_sync(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom) { void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
if( status->change_flags & RGBLIGHT_STATUS_CHANGE_MODE ) { if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) {
if (config->enable) { if (syncinfo->config.enable) {
rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); rgblight_config.enable = 1; // == rgblight_enable_noeeprom();
rgblight_mode_noeeprom(config->mode); rgblight_mode_noeeprom(syncinfo->config.mode);
} else { } else {
rgblight_disable_noeeprom(); rgblight_disable_noeeprom();
} }
} }
if( status->change_flags & RGBLIGHT_STATUS_CHANGE_HSVS ) { if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_HSVS) {
rgblight_sethsv_eeprom_helper(config->hue, config->sat, config->val, false); rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, false);
// rgblight_config.speed = config->speed; // NEED??? // rgblight_config.speed = config->speed; // NEED???
} }
#ifdef RGBLIGHT_USE_TIMER #ifdef RGBLIGHT_USE_TIMER
if( status->change_flags & RGBLIGHT_STATUS_CHANGE_TIMER ) { if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) {
if (status->timer_enabled) { if (syncinfo->status.timer_enabled) {
rgblight_timer_enable(); rgblight_timer_enable();
} else { } else {
rgblight_timer_disable(); rgblight_timer_disable();
} }
} }
#ifdef RGBLIGHT_SPLIT_ANIMATION #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
if (status->change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) { if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) {
animation_status.restart = true; animation_status.restart = true;
} }
#endif #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
#endif #endif /* RGBLIGHT_USE_TIMER */
} }
#endif #endif
@ -891,7 +905,7 @@ void rgblight_task(void) {
animation_status.pos16 = 0; // restart signal to local each effect animation_status.pos16 = 0; // restart signal to local each effect
} }
if (timer_elapsed(animation_status.last_timer) >= interval_time) { if (timer_elapsed(animation_status.last_timer) >= interval_time) {
#ifdef RGBLIGHT_SPLIT_ANIMATION #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
static uint16_t report_last_timer = 0; static uint16_t report_last_timer = 0;
static bool tick_flag = false; static bool tick_flag = false;
uint16_t oldpos16; uint16_t oldpos16;
@ -909,7 +923,7 @@ void rgblight_task(void) {
#endif #endif
animation_status.last_timer += interval_time; animation_status.last_timer += interval_time;
effect_func(&animation_status); effect_func(&animation_status);
#ifdef RGBLIGHT_SPLIT_ANIMATION #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
//dprintf("pos16, oldpos16 = %d %d\n", //dprintf("pos16, oldpos16 = %d %d\n",
// animation_status.pos16,oldpos16); // animation_status.pos16,oldpos16);
if (animation_status.pos16 == 0 && oldpos16 != 0) { if (animation_status.pos16 == 0 && oldpos16 != 0) {
@ -1035,7 +1049,7 @@ void rgblight_effect_snake(animation_status_t *anim) {
increment = -1; increment = -1;
} }
#ifdef RGBLIGHT_SPLIT_ANIMATION #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
if (anim->pos == 0) { // restart signal if (anim->pos == 0) { // restart signal
if (increment == 1) { if (increment == 1) {
pos = RGBLED_NUM - 1; pos = RGBLED_NUM - 1;
@ -1089,7 +1103,7 @@ void rgblight_effect_knight(animation_status_t *anim) {
static int8_t increment = 1; static int8_t increment = 1;
uint8_t i, cur; uint8_t i, cur;
#ifdef RGBLIGHT_SPLIT_ANIMATION #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
if (anim->pos == 0) { // restart signal if (anim->pos == 0) { // restart signal
anim->pos = 1; anim->pos = 1;
low_bound = 0; low_bound = 0;

View File

@ -16,12 +16,6 @@
#ifndef RGBLIGHT_H #ifndef RGBLIGHT_H
#define RGBLIGHT_H #define RGBLIGHT_H
#ifdef RGBLIGHT_SPLIT_ANIMATION
#ifndef RGBLIGHT_SPLIT
#define RGBLIGHT_SPLIT
#endif
#endif
#include "rgblight_reconfig.h" #include "rgblight_reconfig.h"
/***** rgblight_mode(mode)/rgblight_mode_noeeprom(mode) **** /***** rgblight_mode(mode)/rgblight_mode_noeeprom(mode) ****
@ -189,11 +183,17 @@ typedef struct _rgblight_status_t {
#define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2) #define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2)
#define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3) #define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3)
extern rgblight_config_t rgblight_config; typedef struct _rgblight_syncinfo_t {
extern rgblight_status_t rgblight_status; rgblight_config_t config;
rgblight_status_t status;
} rgblight_syncinfo_t;
/* for split keyboard master side */
uint8_t rgblight_get_change_flags(void);
void rgblight_clear_change_flags(void);
void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo);
/* for split keyboard slave side */ /* for split keyboard slave side */
void rgblight_update_sync(rgblight_config_t *config, rgblight_status_t *status, bool write_to_eeprom); void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom);
#endif #endif
void rgblight_init(void); void rgblight_init(void);