summaryrefslogtreecommitdiff
path: root/quantum/visualizer
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-04-02 01:31:04 +0300
committerFred Sundvik <fsundvik@gmail.com>2017-04-09 18:34:59 +0300
commit39385144e7dc3337e623cdc8147b4a441f22fd62 (patch)
treec553b85bbd7c0754296f999e83647ac7b779a22d /quantum/visualizer
parent9a4ce28683b667ab67d48d92196bab7e277d4800 (diff)
Emulate Ergodox EZ leds by LCD colors
Diffstat (limited to 'quantum/visualizer')
-rw-r--r--quantum/visualizer/visualizer.c25
-rw-r--r--quantum/visualizer/visualizer.h8
2 files changed, 32 insertions, 1 deletions
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 62ebebceed..bff0df4947 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -64,6 +64,9 @@ static visualizer_keyboard_status_t current_status = {
.mods = 0xFF,
.leds = 0xFFFFFFFF,
.suspended = false,
+#ifdef VISUALIZER_USER_DATA_SIZE
+ .user_data = {0}
+#endif
};
static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
@@ -71,11 +74,19 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
status1->default_layer == status2->default_layer &&
status1->mods == status2->mods &&
status1->leds == status2->leds &&
- status1->suspended == status2->suspended;
+ status1->suspended == status2->suspended
+#ifdef VISUALIZER_USER_DATA_SIZE
+ && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
+#endif
+ ;
}
static bool visualizer_enabled = false;
+#ifdef VISUALIZER_USER_DATA_SIZE
+static uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
+#endif
+
#define MAX_SIMULTANEOUS_ANIMATIONS 4
static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {};
@@ -431,6 +442,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
.mods = 0xFF,
.leds = 0xFFFFFFFF,
.suspended = false,
+#ifdef VISUALIZER_USER_DATA_SIZE
+ .user_data = {0},
+#endif
};
visualizer_state_t state = {
@@ -590,6 +604,12 @@ uint8_t visualizer_get_mods() {
return mods;
}
+#ifdef VISUALIZER_USER_DATA_SIZE
+void visualizer_set_user_data(void* u) {
+ memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE);
+}
+#endif
+
void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) {
// Note that there's a small race condition here, the thread could read
// a state where one of these are set but not the other. But this should
@@ -618,6 +638,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin
.leds = leds,
.suspended = current_status.suspended,
};
+#ifdef VISUALIZER_USER_DATA_SIZE
+ memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE);
+#endif
if (!same_status(&current_status, &new_status)) {
changed = true;
current_status = new_status;
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index 2c81cb9f71..beb8f2ab41 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -68,6 +68,9 @@ typedef struct {
uint8_t mods;
uint32_t leds; // See led.h for available statuses
bool suspended;
+#ifdef VISUALIZER_USER_DATA_SIZE
+ uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
+#endif
} visualizer_keyboard_status_t;
// The state struct is used by the various keyframe functions
@@ -146,6 +149,11 @@ bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualiz
// directly from the initalize_user_visualizer function (the animation can be null)
bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state);
+// The master can set userdata which will be transferred to the slave
+#ifdef VISUALIZER_USER_DATA_SIZE
+void visualizer_set_user_data(void* user_data);
+#endif
+
// These functions have to be implemented by the user
void initialize_user_visualizer(visualizer_state_t* state);
void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status);