summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjB <steve@sagacity.ca>2017-01-17 21:47:07 -0500
committerSjB <steve@sagacity.ca>2017-01-17 21:57:32 -0500
commit9eb8d05246fba4f46c04b8fa1884b8f2d2ee0664 (patch)
treeb423092318863773fe81beb6bf5c9c6317ae0ab6
parent3d264adfc5e4538b57315cb8d3d429b9ed310f25 (diff)
added mods status bit to visualizer.
Since we can't read the real_mods and oneshot_mods static variable directly within the update_user_visualizer_state function (Threading and serial link). We are know storing the mods states in the visualizer_keyboard_status_t structure. We can now display the status of the modifier keys on the LCD display.
-rw-r--r--quantum/visualizer/visualizer.c58
-rw-r--r--quantum/visualizer/visualizer.h9
-rw-r--r--tmk_core/common/keyboard.c2
3 files changed, 66 insertions, 3 deletions
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 54f6faaa42..5826d909e4 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -53,10 +53,13 @@ SOFTWARE.
#define "Visualizer thread priority not defined"
#endif
+// mods status
+#include "action_util.h"
static visualizer_keyboard_status_t current_status = {
.layer = 0xFFFFFFFF,
.default_layer = 0xFFFFFFFF,
+ .mods = 0xFF,
.leds = 0xFFFFFFFF,
.suspended = false,
};
@@ -64,6 +67,7 @@ static visualizer_keyboard_status_t current_status = {
static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
return status1->layer == status2->layer &&
status1->default_layer == status2->default_layer &&
+ status1->mods == status2->mods &&
status1->leds == status2->leds &&
status1->suspended == status2->suspended;
}
@@ -307,6 +311,45 @@ bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_s
gdispFlush();
return false;
}
+
+static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
+ *buffer = ' ';
+ ++buffer;
+
+ for (int i = 0; i<8; i++)
+ {
+ uint32_t mask = (1u << i);
+ if (mods & mask) {
+ *buffer = '1';
+ } else {
+ *buffer = '0';
+ }
+ ++buffer;
+
+ if (i==3) {
+ *buffer = ' ';
+ ++buffer;
+ }
+ }
+ *buffer = 0;
+}
+
+bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
+ (void)animation;
+
+ const char* title = "Modifier states";
+ const char* mods_header = " CSAG CSAG ";
+ char status_buffer[12];
+
+ gdispClear(White);
+ gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
+ gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
+ format_mods_bitmap_string(state->status.mods, status_buffer);
+ gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
+
+ gdispFlush();
+ return false;
+}
#endif // LCD_ENABLE
bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
@@ -350,6 +393,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
visualizer_keyboard_status_t initial_status = {
.default_layer = 0xFFFFFFFF,
.layer = 0xFFFFFFFF,
+ .mods = 0xFF,
.leds = 0xFFFFFFFF,
.suspended = false,
};
@@ -499,7 +543,18 @@ void update_status(bool changed) {
#endif
}
-void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds) {
+uint8_t visualizer_get_mods() {
+ uint8_t mods = get_mods();
+
+#ifndef NO_ACTION_ONESHOT
+ if (!has_oneshot_mods_timed_out()) {
+ mods |= get_oneshot_mods();
+ }
+#endif
+ return mods;
+}
+
+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
// not really matter as it will be fixed during the next loop step.
@@ -523,6 +578,7 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds) {
visualizer_keyboard_status_t new_status = {
.layer = state,
.default_layer = default_state,
+ .mods = mods,
.leds = leds,
.suspended = current_status.suspended,
};
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index 53e250725c..315af50228 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -34,10 +34,14 @@ SOFTWARE.
#include "lcd_backlight.h"
#endif
+// use this function to merget both real_mods and oneshot_mods in a uint16_t
+uint8_t visualizer_get_mods(void);
+
// This need to be called once at the start
void visualizer_init(void);
// This should be called at every matrix scan
-void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds);
+void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds);
+
// This should be called when the keyboard goes to suspend state
void visualizer_suspend(void);
// This should be called when the keyboard wakes up from suspend state
@@ -61,6 +65,7 @@ struct keyframe_animation_t;
typedef struct {
uint32_t layer;
uint32_t default_layer;
+ uint8_t mods;
uint32_t leds; // See led.h for available statuses
bool suspended;
} visualizer_keyboard_status_t;
@@ -129,6 +134,8 @@ bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_st
bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
// Displays a bitmap (0/1) of all the currently active layers
bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
+// Displays a bitmap (0/1) of all the currently active mods
+bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 371d93f3e5..7653507928 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -188,7 +188,7 @@ MATRIX_LOOP_END:
#endif
#ifdef VISUALIZER_ENABLE
- visualizer_update(default_layer_state, layer_state, host_keyboard_leds());
+ visualizer_update(default_layer_state, layer_state, visualizer_get_mods(), host_keyboard_leds());
#endif
// update LED