]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - keyboards/handwired/promethium/keymaps/priyadi/keymap.c
move GRV to ESC position
[qmk_firmware.git] / keyboards / handwired / promethium / keymaps / priyadi / keymap.c
index 1e5e497dfd1b4708c4f1e4263d2878c2c29e5ea3..68f79f5f76ee830da6b9764819ba1801af15d1a5 100644 (file)
@@ -10,6 +10,7 @@
 #include "ps2_mouse.h"
 #include "ps2.h"
 #include "outputselect.h"
+#include "led.h"
 #define COUNT(x) (sizeof (x) / sizeof (*(x)))
 
 // Fillers to make layering clearer
 #undef KC_RALT
 #define KC_RALT MT(MOD_RALT, KC_SLCK)
 
+bool capslock = false;
+#ifdef DOUBLESPACE_LAYER_ENABLE
+bool lspace_active = false;
+bool rspace_active = false;
+bool lspace_emitted = false;
+bool rspace_emitted = false;
+bool space_layer_entered = false;
+#endif
+
 // glow
 enum glow_modes {
   GLOW_NONE,
@@ -31,6 +41,7 @@ enum glow_modes {
 };
 uint8_t glow_mode = GLOW_MIN;
 
+void turn_off_capslock(void);
 extern keymap_config_t keymap_config;
 
 enum layers {
@@ -39,6 +50,7 @@ enum layers {
   _COLEMAK,
   _WORKMAN,
   _NORMAN,
+  _DEFAULT_LAYER_MAX = _NORMAN,
 
   _PUNC,
   _NUM,
@@ -52,6 +64,9 @@ enum layers {
   _SYS,
 };
 
+// double-space layer
+#define _SPACE _GUI
+
 enum planck_keycodes {
   // layouts
   QWERTY = SAFE_RANGE,
@@ -74,6 +89,8 @@ enum planck_keycodes {
   OSX,
 
   // others
+  LSPACE,
+  RSPACE,
   GLOW,
   AUDIO
 };
@@ -413,61 +430,43 @@ void led_reset(void) {
   }
 }
 
-void led_layer_normal(void) {
-  rgbsps_set(LED_IND_FUNC, 0, 0, 0);
-  rgbsps_set(LED_IND_NUM, 0, 0, 0);
-  rgbsps_set(LED_IND_EMOJI, 0, 0, 0);
-
-  led_reset();
-
-  rgbsps_send();
-}
-
-void led_layer_func(void) {
-  rgbsps_set(LED_IND_FUNC, 0, 15, 0);
-  rgbsps_set(LED_IND_NUM, 0, 0, 0);
-  rgbsps_set(LED_IND_EMOJI, 0, 0, 0);
-
-  led_reset();
-
-  rgbsps_send();
-}
-
-void led_layer_punc(void) {
-  rgbsps_set(LED_IND_FUNC, 0, 15, 0);
-  rgbsps_set(LED_IND_NUM, 0, 0, 15);
-  rgbsps_set(LED_IND_EMOJI, 0, 0, 0);
-
-  led_reset();
+void led_set_layer_indicator(void) {
+  static uint8_t oldlayer = 255;
 
-  rgbsps_send();
-}
-
-void led_layer_num(void) {
   rgbsps_set(LED_IND_FUNC, 0, 0, 0);
-  rgbsps_set(LED_IND_NUM, 0, 0, 15);
+  // rgbsps_set(LED_IND_NUM, 0, 0, 0);
   rgbsps_set(LED_IND_EMOJI, 0, 0, 0);
 
   led_reset();
 
-  rgbsps_send();
-}
+  uint8_t layer = biton32(layer_state);
+  if (oldlayer == layer) {
+    return;
+  }
 
-void led_layer_emoji(void) {
-  rgbsps_set(LED_IND_FUNC, 0, 0, 0);
-  rgbsps_set(LED_IND_NUM, 0, 0, 0);
-  rgbsps_set(LED_IND_EMOJI, 15, 15, 0);
+  oldlayer = layer;
 
-  rgbsps_set(LED_PUNC, 15, 15, 15);
-  rgbsps_set(LED_EMOJI, 15, 15, 15);
+  if (layer <= _DEFAULT_LAYER_MAX) {
+    rgbsps_send();
+    return;
+  }
 
-  rgbsps_send();
-}
+  switch(layer) {
+    case _FUNC:
+      rgbsps_set(LED_IND_FUNC, 15, 0, 0);
+      break;
+    // case _NUM:
+    //   rgbsps_set(LED_IND_NUM, 0, 0, 15);
+    //   break;
+    case _EMOJI:
+      rgbsps_set(LED_IND_EMOJI, 15, 15, 0);
+      break;
+    default:
+      rgbsps_set(LED_IND_FUNC, 3, 3, 3);
+      // rgbsps_set(LED_IND_NUM, 3, 3, 3);
+      rgbsps_set(LED_IND_EMOJI, 3, 3, 3);
+  }
 
-void led_layer_gui(void) {
-  rgbsps_set(LED_IND_FUNC, 15, 10, 15);
-  rgbsps_set(LED_IND_NUM, 15, 10, 15);
-  rgbsps_set(LED_IND_EMOJI, 15, 10, 15);
   rgbsps_send();
 }
 
@@ -497,8 +496,6 @@ void led_init(void) {
   rgbsps_set(LED_TRACKPOINT1, 15, 0, 0);
   rgbsps_set(LED_TRACKPOINT2, 0, 0, 15);
   rgbsps_set(LED_TRACKPOINT3, 15, 0, 0);
-
-  led_layer_normal();
 }
 
 
@@ -521,7 +518,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
   KC_TAB,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC,
   KC_ESC,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_QUOT, KC_ENT ,
   KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_RSFT,
-  KC_LCTL, KC_LALT, KC_LGUI, PUNC,    NUM,     KC_SPC,  KC_SPC,  FUNC,    GREEK,   KC_RGUI, KC_RALT, KC_RCTL
+  KC_LCTL, KC_LALT, KC_LGUI, PUNC,    NUM,     LSPACE,  RSPACE,  FUNC,    GREEK,   KC_RGUI, KC_RALT, KC_RCTL
 ),
 
 /* Dvorak
@@ -619,8 +616,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  * `-----------------------------------------------------------------------------------'
  */
 [_PUNC] = KEYMAP(
-  KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_GRV ,
-  XXXXXXX, KC_ASTR, KC_BSLS, KC_MINS,  KC_EQL, KC_SLSH, XXXXXXX, KC_LPRN, KC_RPRN, KC_LABK, KC_RABK, XXXXXXX,
+  KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
+  KC_GRV,  KC_ASTR, KC_BSLS, KC_MINS,  KC_EQL, KC_SLSH, XXXXXXX, KC_LPRN, KC_RPRN, KC_LABK, KC_RABK, _______,
   KC_AMPR, KC_CIRC, KC_PIPE, KC_UNDS, KC_PLUS, KC_QUES, XXXXXXX, KC_LBRC, KC_RBRC, KC_LCBR, KC_RCBR, KC_COLN,
   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
 ),
@@ -637,10 +634,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  * `-----------------------------------------------------------------------------------'
  */
 [_NUM] = KEYMAP(
-  KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, S(KC_A),    KC_7,    KC_8,    KC_9, S(KC_D), KC_GRV,
-  XXXXXXX, KC_ASTR, KC_BSLS, KC_MINS,  KC_EQL, KC_SLSH, S(KC_B),    KC_4,    KC_5,    KC_6, S(KC_E), _______,
+  KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, S(KC_A),    KC_7,    KC_8,    KC_9, S(KC_D), _______,
+  KC_GRV,  KC_ASTR, KC_BSLS, KC_MINS,  KC_EQL, KC_SLSH, S(KC_B),    KC_4,    KC_5,    KC_6, S(KC_E), _______,
   KC_AMPR, KC_CIRC, KC_PIPE, KC_UNDS, KC_PLUS, KC_QUES, S(KC_C),    KC_1,    KC_2,    KC_3, S(KC_F), KC_COLN,
-  _______, _______, _______, _______, _______, _______,    KC_X,    KC_0, KC_COMM,  KC_DOT, _______, _______
+  _______, _______, _______, _______, _______, _______, _______,    KC_0, KC_COMM,  KC_DOT, KC_X,    _______
 ),
 
 /* Func
@@ -712,7 +709,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
   X(HART2), X(CRY2),X(WEARY),X(EYERT),X(SMIRK), X(TJOY),X(RECYC),X(UNAMU),X(MUSIC),X(OKHND),X(PENSV), X(PHEW),
   X(THMUP), X(PRAY),X(SMILE),X(SMIL2),X(FLUSH), X(GRIN),X(HEART),  X(BYE), X(KISS),X(CELEB), X(COOL),X(NOEVS),
   X(THMDN),X(SLEEP), X(CLAP),  X(CRY),  X(VIC),X(BHART),  X(SUN),X(SMEYE), X(WINK), X(MOON),X(CONFU),X(NOEVH),
-    X(POO), X(EYES),X(HUNRD), _______,X(SKULL),X(HORNS), X(HALO), X(FEAR), _______,X(YUMMY),X(DISAP),X(NOEVK)
+    X(POO), X(EYES), _______,X(HUNRD), X(SKULL),X(HORNS), X(HALO), X(FEAR),X(YUMMY),_______,X(DISAP),X(NOEVK)
 ),
 
 /* GUI
@@ -729,13 +726,13 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 [_GUI] = KEYMAP(
   XXXXXXX, G(KC_1), G(KC_2), G(KC_3), G(KC_4), G(KC_5), G(KC_6), G(KC_7), G(KC_8), G(KC_9), G(KC_0), XXXXXXX,
   XXXXXXX, XXXXXXX, KC_VOLD, KC_MUTE, KC_VOLU, XXXXXXX, XXXXXXX, KC_WWWB, XXXXXXX, KC_WWWF, XXXXXXX, XXXXXXX,
-  XXXXXXX, XXXXXXX, KC_MPRV, KC_MPLY, KC_MNXT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+  XXXXXXX, XXXXXXX, KC_MPRV, KC_MPLY, KC_MNXT, KC_SPC,  KC_SPC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
   XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX
 ),
 
 /* Sys
  * ,-----------------------------------------------------------------------------------.
- * |      |Qwerty| Win  |      |      |      |      | USB  |      |      |      |      |
+ * |      |Qwerty| Win  |      |Reset |      |      | USB  |      |      |      |      |
  * |------+------+------+------+------+-------------+------+------+------+------+------|
  * |      |Audio |      |Dvorak|      | Glow |      |      |WorkMn|Linux |      |      |
  * |------+------+------+------+------+------+------+------+------+------+------+------|
@@ -745,7 +742,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  * `-----------------------------------------------------------------------------------'
  */
 [_SYS] = KEYMAP(
-  XXXXXXX, QWERTY,  WIN,     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OUT_USB, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+  XXXXXXX, QWERTY,  WIN,     XXXXXXX, RESET,   XXXXXXX, XXXXXXX, OUT_USB, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
   XXXXXXX, AUDIO,   XXXXXXX, DVORAK,  XXXXXXX, GLOW,    XXXXXXX, XXXXXXX, WORKMAN, LINUX,   XXXXXXX, XXXXXXX,
   XXXXXXX, XXXXXXX, XXXXXXX, COLEMAK, XXXXXXX, OUT_BLE, NORMAN,  OSX,     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
   _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______
@@ -758,12 +755,76 @@ void persistant_default_layer_set(uint16_t default_layer) {
   default_layer_set(default_layer);
 }
 
+#ifdef DOUBLESPACE_LAYER_ENABLE
+void process_doublespace(bool pressed, bool *isactive, bool *otheractive, bool *isemitted) {
+  if (pressed) {
+    *isactive = true;
+    if (*otheractive) {
+      layer_on(_SPACE);
+      space_layer_entered = true;
+    }
+  } else {
+    *isactive = false;
+    if (space_layer_entered) {
+      layer_off(_SPACE);
+      if (!*otheractive) {
+        space_layer_entered = false;
+      }
+    } else {
+      if (!*isemitted) {
+        register_code(KC_SPC);
+        unregister_code(KC_SPC);
+      }
+      *isemitted = false;
+    }
+  }
+}
+#endif
+
 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
   bool lshift = keyboard_report->mods & MOD_BIT(KC_LSFT);
   bool rshift = keyboard_report->mods & MOD_BIT(KC_RSFT);
 
+#ifdef DOUBLESPACE_LAYER_ENABLE
+  // double-space: send space immediately if any other key depressed before space is released
+  if ((lspace_active ^ rspace_active)
+      && keycode != LSPACE
+      && keycode != RSPACE
+      && record->event.pressed)
+  {
+    if (lspace_active) {
+      if (!lspace_emitted) {
+        register_code(KC_SPC);
+        unregister_code(KC_SPC);
+      }
+      lspace_emitted = true;
+    }
+    if (rspace_active) {
+      if (!rspace_emitted) {
+        register_code(KC_SPC);
+        unregister_code(KC_SPC);
+      }
+      rspace_emitted = true;
+    }
+  }
+#endif
+
   switch (keycode) {
+
+#ifdef DOUBLESPACE_LAYER_ENABLE
+    // double-space enter space layer
+    case LSPACE:
+      process_doublespace(record->event.pressed, &lspace_active, &rspace_active, &lspace_emitted);
+      return false;
+      break;
+    case RSPACE:
+      process_doublespace(record->event.pressed, &rspace_active, &lspace_active, &rspace_emitted);
+      return false;
+      break;
+#endif
+
     // handle greek layer shift
+    // handle both shift = capslock
     case KC_LSFT:
     case KC_RSFT:
       ;
@@ -778,6 +839,13 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
             layer_off(_GREEKU);
           }
         }
+      } else {
+        if (record->event.pressed) {
+          if (lshift ^ rshift) { // if only one shift was pressed
+            register_code(KC_CAPS);
+            unregister_code(KC_CAPS);
+          }
+        }
       }
       return true;
       break;
@@ -872,20 +940,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
     case PUNC:
       if (record->event.pressed) {
         layer_on(_PUNC);
-        update_tri_layer(_PUNC, _GREEKL, _GUI);
-        if (IS_LAYER_ON(_GUI)) {
-          led_layer_normal();
-        } else {
-          led_layer_punc();
-        }
+        update_tri_layer(_PUNC, _GREEKL, _EMOJI);
       } else {
         layer_off(_PUNC);
-        update_tri_layer(_PUNC, _GREEKL, _GUI);
-        if (IS_LAYER_ON(_GREEKL)) {
-          led_layer_normal();
-        } else {
-          led_layer_normal();
-        }
+        update_tri_layer(_PUNC, _GREEKL, _EMOJI);
       }
       return false;
       break;
@@ -898,33 +956,22 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
         } else {
           layer_on(_GREEKL);
           layer_off(_GREEKU);
-          update_tri_layer(_PUNC, _GREEKL, _GUI);
-          if (IS_LAYER_ON(_GUI)) {
-            led_layer_normal();
-          } else {
-            led_layer_normal();
-          }
+          update_tri_layer(_PUNC, _GREEKL, _EMOJI);
         }
       } else {
         layer_off(_GREEKU);
         layer_off(_GREEKL);
-        update_tri_layer(_PUNC, _GREEKL, _GUI);
-        if (IS_LAYER_ON(_PUNC)) {
-          led_layer_normal();
-        } else {
-          led_layer_normal();
-        }
+        update_tri_layer(_PUNC, _GREEKL, _EMOJI);
       }
       return false;
       break;
 
     case NUM:
       if (record->event.pressed) {
+        turn_off_capslock();
         layer_on(_NUM);
-        led_layer_num();
       } else {
         layer_off(_NUM);
-        led_layer_normal();
       }
       return false;
       break;
@@ -932,10 +979,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
     case FUNC:
       if (record->event.pressed) {
         layer_on(_FUNC);
-        led_layer_func();
       } else {
         layer_off(_FUNC);
-        led_layer_normal();
       }
       return false;
       break;
@@ -1003,32 +1048,55 @@ void matrix_init_user(void) {
   }
 }
 
-void battery_poll(float percentage) {
-  rgbsps_sethsv(LED_IND_BATTERY, percentage*120/100, 255, 15);
+void matrix_scan_user(void) {
+  led_set_layer_indicator();
+}
+
+void battery_poll(uint8_t level) {
+  rgbsps_sethsv(LED_IND_BATTERY, level * 120/255, 255, 15);
   rgbsps_send();
 }
 
+void led_set_user(uint8_t usb_led) {
+  bool new_capslock = usb_led & (1<<USB_LED_CAPS_LOCK);
+  if (new_capslock ^ capslock) { // capslock state is different
+    if ((capslock = new_capslock)) {
+      rgbsps_set(LED_IND_NUM, 15, 0, 0);
+    } else {
+      rgbsps_set(LED_IND_NUM, 0, 0, 0);
+    }
+    rgbsps_send();
+  }
+}
+
+void turn_off_capslock() {
+  if (capslock) {
+    register_code(KC_CAPS);
+    unregister_code(KC_CAPS);
+  }
+}
+
 void ps2_mouse_init_user() {
     uint8_t rcv;
 
     // set TrackPoint sensitivity
-    PS2_MOUSE_SEND(0xE2, "set trackpoint sensitivity: 0xE2");
-    PS2_MOUSE_SEND(0x81, "set trackpoint sensitivity: 0x81");
-    PS2_MOUSE_SEND(0x4A, "set trackpoint sensitivity: 0x4A");
-    PS2_MOUSE_SEND(0x49, "set trackpoint sensitivity: 0x59");
+    PS2_MOUSE_SEND(0xE2, "tpsens: 0xE2");
+    PS2_MOUSE_SEND(0x81, "tpsens: 0x81");
+    PS2_MOUSE_SEND(0x4A, "tpsens: 0x4A");
+    PS2_MOUSE_SEND(0x49, "tpsens: 0x59");
 
     // set TrackPoint Negative Inertia factor
-    PS2_MOUSE_SEND(0xE2, "set negative inertia factor: 0xE2");
-    PS2_MOUSE_SEND(0x81, "set negative inertia factor: 0x81");
-    PS2_MOUSE_SEND(0x4D, "set negative inertia factor: 0x4D");
-    PS2_MOUSE_SEND(0x06, "set negative inertia factor: 0x06");
+    PS2_MOUSE_SEND(0xE2, "tpnegin: 0xE2");
+    PS2_MOUSE_SEND(0x81, "tpnegin: 0x81");
+    PS2_MOUSE_SEND(0x4D, "tpnegin: 0x4D");
+    PS2_MOUSE_SEND(0x06, "tpnegin: 0x06");
 
     // set TrackPoint speed
     // (transfer function upper plateau speed)
-    PS2_MOUSE_SEND(0xE2, "set trackpoint speed: 0xE2");
-    PS2_MOUSE_SEND(0x81, "set trackpoint speed: 0x81");
-    PS2_MOUSE_SEND(0x60, "set trackpoint speed: 0x60");
-    PS2_MOUSE_SEND(0x61, "set trackpoint speed: 0x61");
+    PS2_MOUSE_SEND(0xE2, "tpsp: 0xE2");
+    PS2_MOUSE_SEND(0x81, "tpsp: 0x81");
+    PS2_MOUSE_SEND(0x60, "tpsp: 0x60");
+    PS2_MOUSE_SEND(0x61, "tpsp: 0x61");
 
     // inquire pts status
     rcv = ps2_host_send(0xE2);