qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

common_oled.c (3684B)


      1 /*
      2  * ----------------------------------------------------------------------------
      3  * "THE BEER-WARE LICENSE" (Revision 42):
      4  * <https://github.com/Legonut> wrote this file.  As long as you retain this
      5  * notice you can do whatever you want with this stuff. If we meet some day, and
      6  * you think this stuff is worth it, you can buy me a beer in return. David Rauseo
      7  * ----------------------------------------------------------------------------
      8  */
      9 
     10 #include "common_oled.h"
     11 #include "oled_driver.h"
     12 #include "rgb_matrix.h"
     13 
     14 // for memcpy & snprintf
     15 #include <stdio.h>
     16 #include <string.h>
     17 #include <transactions.h>
     18 
     19 typedef struct {
     20     bool selecting;
     21     uint8_t selection;
     22 } kb_menu_status_t;
     23 
     24 static kb_menu_status_t rgb_menu = { false, 4 };
     25 static bool rgb_menu_changed = false;
     26 
     27 void render_logo(void) {
     28     static const char PROGMEM font_logo[] = {
     29         0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
     30         0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
     31         0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
     32     oled_write_P(font_logo, false);
     33 }
     34 
     35 void render_icon(void) {
     36     static const char PROGMEM font_icon[] = {
     37         0x9b,0x9c,0x9d,0x9e,0x9f,
     38         0xbb,0xbc,0xbd,0xbe,0xbf,
     39         0xdb,0xdc,0xdd,0xde,0xdf,0
     40     };
     41     oled_write_P(font_icon, false);
     42 }
     43 
     44 #define RGB_FUNCTION_COUNT 6
     45 typedef void (*rgb_matrix_f)(void);
     46 const rgb_matrix_f rgb_matrix_functions[RGB_FUNCTION_COUNT][2] = {
     47     { rgb_matrix_increase_hue,      rgb_matrix_decrease_hue     },
     48     { rgb_matrix_increase_sat,      rgb_matrix_decrease_sat     },
     49     { rgb_matrix_increase_val,      rgb_matrix_decrease_val     },
     50     { rgb_matrix_increase_speed,    rgb_matrix_decrease_speed   },
     51     { rgb_matrix_step,              rgb_matrix_step_reverse     },
     52     { rgb_matrix_toggle,            rgb_matrix_toggle           }
     53 };
     54 
     55 void render_rgb_menu(void) {
     56     static char buffer[63] = {0};
     57     snprintf(buffer, sizeof(buffer), "Hue    %3dSatrn  %3dValue  %3dSpeed  %3dMode   %3dEnbld  %3d", 
     58     rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_config.enable);
     59 
     60     if (rgb_menu.selecting) {
     61         buffer[5 + rgb_menu.selection * 10] = '*';
     62     }
     63     else {
     64         buffer[5 + rgb_menu.selection * 10] = '>';
     65     }
     66     oled_write(buffer, false);
     67 }
     68 
     69 void rgb_menu_selection(void) {
     70     if (!is_keyboard_master()) return;
     71     rgb_menu.selecting = !rgb_menu.selecting;
     72     rgb_menu_changed = true;
     73 }
     74 
     75 void rgb_menu_action(bool clockwise) {
     76     if (!is_keyboard_master()) return;
     77     if (rgb_menu.selecting)  {
     78         if (!clockwise) {
     79             rgb_menu.selection = (rgb_menu.selection - 1);
     80             if (rgb_menu.selection >= RGB_FUNCTION_COUNT)
     81                 rgb_menu.selection = RGB_FUNCTION_COUNT - 1;
     82         }
     83         else {
     84             rgb_menu.selection = (rgb_menu.selection + 1) % RGB_FUNCTION_COUNT;
     85         }
     86     }
     87     else {
     88         (*rgb_matrix_functions[rgb_menu.selection][clockwise])();
     89     }
     90     rgb_menu_changed = true;
     91 }
     92 
     93 void rgb_menu_update(int8_t transaction_id) {
     94     if (!is_keyboard_master()) return;
     95     if (!rgb_menu_changed) return;
     96     rgb_menu_changed = false;
     97     transaction_rpc_send(transaction_id, sizeof(kb_menu_status_t), &rgb_menu);
     98 }
     99 
    100 void rgb_menu_slave_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
    101     memcpy(&rgb_menu, initiator2target_buffer, sizeof(kb_menu_status_t));
    102 }