]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/visualizer/visualizer.c
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
[qmk_firmware.git] / quantum / visualizer / visualizer.c
index c240734055ed00feb0fd4d9779a584e12baab0a7..5826d909e45c1aad9282fc4971cd344724d19dd8 100644 (file)
@@ -29,9 +29,7 @@ SOFTWARE.
 #include "ch.h"
 #endif
 
-#ifdef LCD_ENABLE
 #include "gfx.h"
-#endif
 
 #ifdef LCD_BACKLIGHT_ENABLE
 #include "lcd_backlight.h"
@@ -45,7 +43,7 @@ SOFTWARE.
 #include "nodebug.h"
 #endif
 
-#ifdef USE_SERIAL_LINK
+#ifdef SERIAL_LINK_ENABLE
 #include "serial_link/protocol/transport.h"
 #include "serial_link/system/serial_link.h"
 #endif
@@ -55,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,
 };
@@ -66,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;
 }
@@ -75,7 +77,7 @@ static bool visualizer_enabled = false;
 #define MAX_SIMULTANEOUS_ANIMATIONS 4
 static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {};
 
-#ifdef USE_SERIAL_LINK
+#ifdef SERIAL_LINK_ENABLE
 MASTER_TO_ALL_SLAVES_OBJECT(current_status, visualizer_keyboard_status_t);
 
 static remote_object_t* remote_objects[] = {
@@ -309,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) {
@@ -352,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,
     };
@@ -458,15 +500,13 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
 }
 
 void visualizer_init(void) {
-#ifdef LCD_ENABLE
     gfxInit();
-#endif
 
 #ifdef LCD_BACKLIGHT_ENABLE
     lcd_backlight_init();
 #endif
 
-#ifdef USE_SERIAL_LINK
+#ifdef SERIAL_LINK_ENABLE
     add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
 #endif
 
@@ -490,7 +530,7 @@ void update_status(bool changed) {
             geventSendEvent(listener);
         }
     }
-#ifdef USE_SERIAL_LINK
+#ifdef SERIAL_LINK_ENABLE
     static systime_t last_update = 0;
     systime_t current_update = chVTGetSystemTimeX();
     systime_t delta = current_update - last_update;
@@ -503,14 +543,25 @@ 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.
     // Alternatively a mutex could be used instead of the volatile variables
 
     bool changed = false;
-#ifdef USE_SERIAL_LINK
+#ifdef SERIAL_LINK_ENABLE
     if (is_serial_link_connected ()) {
         visualizer_keyboard_status_t* new_status = read_current_status();
         if (new_status) {
@@ -527,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,
         };