qmk

QMK Firmware
git clone git://git.z3bra.org/qmk.git
Log | Files | Refs | Submodules | LICENSE

satisfaction_oled.c (8530B)


      1 #include "satisfaction75.h"
      2 #include "micro_oled.h"
      3 
      4 __attribute__ ((weak))
      5 void draw_ui() {
      6 #ifdef QWIIC_MICRO_OLED_ENABLE
      7   clear_buffer();
      8   last_flush = timer_read();
      9   send_command(DISPLAYON);
     10   if(clock_set_mode){
     11     draw_clock();
     12     return;
     13   }
     14   switch (oled_mode){
     15     default:
     16     case OLED_DEFAULT:
     17       draw_default();
     18       break;
     19     case OLED_TIME:
     20       draw_clock();
     21       break;
     22     case OLED_OFF:
     23       send_command(DISPLAYOFF);
     24       break;
     25   }
     26 #endif
     27 }
     28 
     29 void draw_encoder(int8_t startX, int8_t startY, bool show_legend){
     30   if(show_legend){
     31     draw_string(startX + 1, startY + 2, "ENC", PIXEL_ON, NORM, 0);
     32   } else {
     33     startX -= 22;
     34   }
     35   draw_rect_filled_soft(startX + 22, startY + 1, 3 + (3 * 6), 9, PIXEL_ON, NORM);
     36   char* mode_string = "";
     37   switch(encoder_mode){
     38     default:
     39     case ENC_MODE_VOLUME:
     40       mode_string = "VOL";
     41       break;
     42     case ENC_MODE_MEDIA:
     43       mode_string = "MED";
     44       break;
     45     case ENC_MODE_SCROLL:
     46       mode_string = "SCR";
     47       break;
     48     case ENC_MODE_BRIGHTNESS:
     49       mode_string = "BRT";
     50       break;
     51     case ENC_MODE_BACKLIGHT:
     52       mode_string = "BKL";
     53       break;
     54     case ENC_MODE_CLOCK_SET:
     55       mode_string = "CLK";
     56       break;
     57     case ENC_MODE_CUSTOM0:
     58       mode_string = "CS0";
     59       break;
     60     case ENC_MODE_CUSTOM1:
     61       mode_string = "CS1";
     62       break;
     63     case ENC_MODE_CUSTOM2:
     64       mode_string = "CS2";
     65       break;
     66   }
     67   draw_string(startX + 24, startY + 2, mode_string, PIXEL_ON, XOR, 0);
     68 }
     69 
     70 void draw_layer_section(int8_t startX, int8_t startY, bool show_legend){
     71   if(show_legend){
     72     draw_string(startX + 1, startY + 2, "LAYER", PIXEL_ON, NORM, 0);
     73   } else {
     74     startX -= 32;
     75   }
     76   draw_rect_filled_soft(startX + 32, startY + 1, 9, 9, PIXEL_ON, NORM);
     77   draw_char(startX + 34, startY + 2, layer + 0x30, PIXEL_ON, XOR, 0);
     78 }
     79 
     80 void draw_default(){
     81   uint8_t hour = last_minute / 60;
     82   uint16_t minute = last_minute % 60;
     83 
     84   if(encoder_mode == ENC_MODE_CLOCK_SET){
     85     hour = hour_config;
     86     minute = minute_config;
     87   }
     88 
     89   bool is_pm = (hour / 12) > 0;
     90   hour = hour % 12;
     91   if (hour == 0){
     92     hour = 12;
     93   }
     94   char hour_str[2] = "";
     95   char min_str[2] = "";
     96 
     97   sprintf(hour_str, "%02d", hour);
     98   sprintf(min_str, "%02d", minute);
     99 
    100   uint8_t mods = get_mods();
    101 
    102 /* Layer indicator is 41 x 10 pixels */
    103   draw_layer_section(0,0,true);
    104 
    105 #define ENCODER_INDICATOR_X 45
    106 #define ENCODER_INDICATOR_Y 0
    107   draw_encoder(ENCODER_INDICATOR_X, ENCODER_INDICATOR_Y, true);
    108 /* Matrix display is 19 x 9 pixels */
    109 #define MATRIX_DISPLAY_X 0
    110 #define MATRIX_DISPLAY_Y 18
    111 
    112   for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
    113     for (uint8_t y = 0; y < MATRIX_COLS; y++) {
    114       draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
    115     }
    116   }
    117   draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
    118   /* hadron oled location on thumbnail */
    119   draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
    120 
    121 /* Mod display is 41 x 16 pixels */
    122 #define MOD_DISPLAY_X 30
    123 #define MOD_DISPLAY_Y 18
    124 
    125   if (mods & MOD_LSFT) {
    126     draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
    127     draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
    128   } else {
    129     draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
    130   }
    131   if (mods & MOD_LCTL) {
    132     draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
    133     draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
    134   } else {
    135     draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
    136   }
    137   if (mods & MOD_LALT) {
    138     draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
    139     draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
    140   } else {
    141     draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
    142   }
    143   if (mods & MOD_LGUI) {
    144     draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
    145     draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
    146   } else {
    147     draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
    148   }
    149 
    150 /* Lock display is 23 x 21 */
    151 #define LOCK_DISPLAY_X 100
    152 #define LOCK_DISPLAY_Y 0
    153 
    154   if (led_capslock == true) {
    155     draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
    156     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y +1, "CAP", PIXEL_OFF, NORM, 0);
    157   } else if (led_capslock == false) {
    158     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y +1, "CAP", PIXEL_ON, NORM, 0);
    159   }
    160 
    161   if (led_scrolllock == true) {
    162     draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
    163     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "SCR", PIXEL_OFF, NORM, 0);
    164   } else if (led_scrolllock == false) {
    165     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "SCR", PIXEL_ON, NORM, 0);
    166   }
    167 
    168 #define TIME_DISPLAY_X 82
    169 #define TIME_DISPLAY_Y 22
    170   draw_string(TIME_DISPLAY_X, TIME_DISPLAY_Y, hour_str, PIXEL_ON, NORM, 0);
    171   draw_string(TIME_DISPLAY_X + 11, TIME_DISPLAY_Y, ":", PIXEL_ON, NORM, 0);
    172   draw_string(TIME_DISPLAY_X + 15, TIME_DISPLAY_Y, min_str, PIXEL_ON, NORM, 0);
    173   if(is_pm){
    174     draw_string(TIME_DISPLAY_X + 27, TIME_DISPLAY_Y, "pm", PIXEL_ON, NORM, 0);
    175   } else{
    176     draw_string(TIME_DISPLAY_X + 27, TIME_DISPLAY_Y, "am", PIXEL_ON, NORM, 0);
    177   }
    178 
    179   send_buffer();
    180 }
    181 
    182 void draw_clock(){
    183   int8_t hour = last_minute / 60;
    184   int16_t minute = last_minute % 60;
    185   int16_t year = last_timespec.year + 1980;
    186   int8_t month = last_timespec.month;
    187   int8_t day = last_timespec.day;
    188 
    189   if(encoder_mode == ENC_MODE_CLOCK_SET){
    190     hour = hour_config;
    191     minute = minute_config;
    192     year = year_config + 1980;
    193     month = month_config;
    194     day = day_config;
    195   }
    196 
    197   bool is_pm = (hour / 12) > 0;
    198   hour = hour % 12;
    199   if (hour == 0){
    200     hour = 12;
    201   }
    202   char hour_str[2] = "";
    203   char min_str[2] = "";
    204   char year_str[4] = "";
    205   char month_str[2] = "";
    206   char day_str[2] = "";
    207 
    208   sprintf(hour_str, "%02d", hour);
    209   sprintf(min_str, "%02d", minute);
    210   sprintf(year_str, "%d", year);
    211   sprintf(month_str, "%02d", month);
    212   sprintf(day_str, "%02d", day);
    213 
    214 
    215 #define DATE_DISPLAY_X 6
    216 #define DATE_DISPLAY_Y 0
    217   draw_string(DATE_DISPLAY_X, DATE_DISPLAY_Y, year_str, PIXEL_ON, NORM, 0);
    218   draw_string(DATE_DISPLAY_X + 25, DATE_DISPLAY_Y, "-", PIXEL_ON, NORM, 0);
    219   draw_string(DATE_DISPLAY_X + 31, DATE_DISPLAY_Y, month_str, PIXEL_ON, NORM, 0);
    220   draw_string(DATE_DISPLAY_X + 44, DATE_DISPLAY_Y, "-", PIXEL_ON, NORM, 0);
    221   draw_string(DATE_DISPLAY_X + 50, DATE_DISPLAY_Y, day_str, PIXEL_ON, NORM, 0);
    222 
    223 #define CLOCK_DISPLAY_X 6
    224 #define CLOCK_DISPLAY_Y 14
    225   draw_string(CLOCK_DISPLAY_X, CLOCK_DISPLAY_Y, hour_str, PIXEL_ON, NORM, 1);
    226   draw_string(CLOCK_DISPLAY_X + 17, CLOCK_DISPLAY_Y, ":", PIXEL_ON, NORM, 1);
    227   draw_string(CLOCK_DISPLAY_X + 25, CLOCK_DISPLAY_Y, min_str, PIXEL_ON, NORM, 1);
    228   if(is_pm){
    229     draw_string(CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y, "pm", PIXEL_ON, NORM, 1);
    230   } else{
    231     draw_string(CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y, "am", PIXEL_ON, NORM, 1);
    232   }
    233 
    234   if(clock_set_mode){
    235     switch(time_config_idx){
    236       case 0: // hour
    237       default:
    238         draw_line(CLOCK_DISPLAY_X, CLOCK_DISPLAY_Y + 17, CLOCK_DISPLAY_X + 16, CLOCK_DISPLAY_Y + 17, PIXEL_ON, NORM);
    239         break;
    240       case 1: // minute
    241         draw_line(CLOCK_DISPLAY_X + 25, CLOCK_DISPLAY_Y + 17, CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y + 17, PIXEL_ON, NORM);
    242         break;
    243       case 2: // year
    244         draw_line(DATE_DISPLAY_X, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 23, DATE_DISPLAY_Y + 9, PIXEL_ON, NORM);
    245         break;
    246       case 3: // month
    247         draw_line(DATE_DISPLAY_X + 31, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 43, DATE_DISPLAY_Y + 9, PIXEL_ON, NORM);
    248         break;
    249       case 4: //day
    250         draw_line(DATE_DISPLAY_X + 50, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 61, DATE_DISPLAY_Y + 9,PIXEL_ON, NORM);
    251         break;
    252     }
    253   }
    254 
    255   draw_encoder(80, 0, true);
    256   draw_layer_section(80, 11, true);
    257 
    258 #define CAPS_DISPLAY_X 86
    259 #define CAPS_DISPLAY_Y 22
    260 
    261   if (led_capslock == true) {
    262     draw_rect_filled_soft(CAPS_DISPLAY_X, CAPS_DISPLAY_Y, 5 + (4 * 6), 9, PIXEL_ON, NORM);
    263     draw_string(CAPS_DISPLAY_X + 3, CAPS_DISPLAY_Y +1, "CAPS", PIXEL_OFF, NORM, 0);
    264   } else if (led_capslock == false) {
    265     draw_string(CAPS_DISPLAY_X + 3, CAPS_DISPLAY_Y +1, "CAPS", PIXEL_ON, NORM, 0);
    266   }
    267 
    268 
    269   send_buffer();
    270 
    271 }