tominabox1.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #include "tominabox1.h"
  2. #ifdef KEYBOARD_lazydesigners_dimple
  3. #ifdef RGBLIGHT_ENABLE
  4. __attribute__ ((weak))
  5. void keyboard_post_init_keymap(void) {}
  6. void keyboard_post_init_user(void) { // sets the backlighting to come on upon successful load then turn off
  7. rgblight_enable_noeeprom();
  8. rgblight_sethsv_noeeprom(RGB_RED);
  9. rgblight_mode_noeeprom(0);
  10. wait_ms(700);
  11. rgblight_disable_noeeprom();
  12. }
  13. #endif // RGBLIGHT
  14. #endif // Dimple
  15. #ifdef RGB_MATRIX_ENABLE
  16. void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type);
  17. static bool is_suspended;
  18. static bool rgb_matrix_enabled;
  19. __attribute__ ((weak))
  20. void suspend_power_down_keymap(void) {}
  21. void suspend_power_down_user(void) {
  22. rgb_matrix_set_suspend_state(true);
  23. if (!is_suspended) {
  24. is_suspended = true;
  25. rgb_matrix_enabled = (bool)rgb_matrix_config.enable;
  26. rgb_matrix_disable_noeeprom();
  27. }
  28. }
  29. __attribute__ ((weak))
  30. void suspend_wakeup_init_keymap(void) {}
  31. void suspend_wakeup_init_user(void) {
  32. rgb_matrix_set_suspend_state(false);
  33. is_suspended = false;
  34. if (rgb_matrix_enabled) {
  35. rgb_matrix_enable_noeeprom();
  36. }
  37. }
  38. # include "lib/lib8tion/lib8tion.h"
  39. extern led_config_t g_led_config;
  40. void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type) {
  41. HSV hsv = {hue, sat, val};
  42. if (hsv.v > rgb_matrix_config.hsv.v) {
  43. hsv.v = rgb_matrix_config.hsv.v;
  44. }
  45. switch (mode) {
  46. case 1: // breathing
  47. {
  48. uint16_t time = scale16by8(g_rgb_counters.tick, speed / 8);
  49. hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
  50. RGB rgb = hsv_to_rgb(hsv);
  51. for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
  52. if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
  53. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  54. }
  55. }
  56. break;
  57. }
  58. default: // Solid Color
  59. {
  60. RGB rgb = hsv_to_rgb(hsv);
  61. for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
  62. if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
  63. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  64. }
  65. }
  66. break;
  67. }
  68. }
  69. }
  70. #endif //RGB_MATRIX_ENABLE
  71. void dance_cln_finished (qk_tap_dance_state_t *state, void *user_data) {
  72. if (state->count == 1) {
  73. register_code16(S(KC_2));
  74. } else {
  75. SEND_STRING("tom.campie@gmail.com");
  76. }
  77. }
  78. void dance_cln_reset (qk_tap_dance_state_t *state, void *user_data) {
  79. if (state->count == 1) {
  80. unregister_code16(S(KC_2));
  81. } else {
  82. }
  83. }
  84. qk_tap_dance_action_t tap_dance_actions[] = {
  85. [KC_EMAIL] = ACTION_TAP_DANCE_FN_ADVANCED (NULL, dance_cln_finished, dance_cln_reset),
  86. [TD_SFT_CPS] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS),
  87. };
  88. #define TAPPING_TERM 200
  89. #define IGNORE_MOD_TAP_INTERRUPT
  90. #ifdef KEYBOARD_crkbd_rev1
  91. #endif // CRKBD
  92. uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
  93. switch (keycode) {
  94. case LSFT_T(KC_CAPS):
  95. return 250;
  96. case KC_ENT_LOW:
  97. return 150;
  98. case KC_SPC_RSE:
  99. return(250);
  100. case LCTL_T(KC_TAB):
  101. return 300;
  102. default:
  103. return TAPPING_TERM;
  104. }
  105. };
  106. __attribute__ ((weak))
  107. layer_state_t layer_state_set_keymap (layer_state_t state) {
  108. return state;
  109. }
  110. layer_state_t layer_state_set_user(layer_state_t state) {
  111. state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  112. switch (get_highest_layer(state)) {
  113. case _LOWER:
  114. break;
  115. case _RAISE:
  116. break;
  117. case _ADJUST:
  118. break;
  119. default:
  120. break;
  121. }
  122. return state;
  123. }
  124. #ifdef KEYBOARD_crkbd_rev1
  125. __attribute__((weak))
  126. void matrix_scan_keymap(void) {}
  127. extern bool oled_initialized;
  128. void matrix_scan_user(void) {
  129. if(!oled_initialized) {
  130. wait_ms(200);
  131. oled_init(0);
  132. return;
  133. }
  134. matrix_scan_keymap();
  135. }
  136. extern uint8_t is_master;
  137. #endif // CRKBD
  138. uint16_t oled_timer;
  139. __attribute__ ((weak))
  140. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  141. return true;
  142. }
  143. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  144. #ifdef CONSOLE_ENABLE
  145. uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
  146. #endif
  147. if (record->event.pressed) {
  148. #ifdef OLED_ENABLE
  149. oled_timer = timer_read();
  150. oled_on();
  151. #endif // OLED_ENABLE
  152. switch (keycode) {
  153. case KC_BBB:
  154. if (record->event.pressed) {
  155. SEND_STRING(":b:");
  156. } else {}
  157. break;
  158. case KC_BEPIS:
  159. if (record->event.pressed) {
  160. SEND_STRING("BEPIS");
  161. } else {}
  162. break;
  163. }
  164. }
  165. return true;
  166. }
  167. #ifdef KEYBOARD_crkbd_rev1
  168. #ifdef OLED_ENABLE
  169. void render_logo(void) {
  170. static const char PROGMEM logo[] = {
  171. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
  172. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
  173. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
  174. 0};
  175. oled_write_P(logo, false);
  176. }
  177. void render_status_main(void) {
  178. // Host Keyboard USB Status
  179. oled_write_P(PSTR("USB: "), false);
  180. switch (USB_DeviceState) {
  181. case DEVICE_STATE_Unattached:
  182. oled_write_P(PSTR("Unattached\n"), false);
  183. break;
  184. case DEVICE_STATE_Suspended:
  185. oled_write_P(PSTR("Suspended\n"), false);
  186. break;
  187. case DEVICE_STATE_Configured:
  188. oled_write_P(PSTR("Connected\n"), false);
  189. break;
  190. case DEVICE_STATE_Powered:
  191. oled_write_P(PSTR("Powered\n"), false);
  192. break;
  193. case DEVICE_STATE_Default:
  194. oled_write_P(PSTR("Default\n"), false);
  195. break;
  196. case DEVICE_STATE_Addressed:
  197. oled_write_P(PSTR("Addressed\n"), false);
  198. break;
  199. default:
  200. oled_write_P(PSTR("Invalid\n"), false);
  201. }
  202. // Host Keyboard Layer Status
  203. oled_write_P(PSTR("Layer: "), false);
  204. switch (get_highest_layer(layer_state)) {
  205. case _BASE:
  206. oled_write_P(PSTR("Colemak\n"), false);
  207. break;
  208. case _RAISE:
  209. oled_write_P(PSTR("Numbers\n"), false);
  210. break;
  211. case _LOWER:
  212. oled_write_P(PSTR("Symbols\n"), false);
  213. break;
  214. case _ADJUST:
  215. oled_write_P(PSTR("Adjust\n"), false);
  216. break;
  217. case _ARROW:
  218. oled_write_P(PSTR("Navigation\n"), false);
  219. break;
  220. case _FKEY:
  221. oled_write_P(PSTR("Function\n"), false);
  222. break;
  223. default:
  224. // Or use the write_ln shortcut over adding '\n' to the end of your string
  225. oled_write_ln_P(PSTR("Undefined"), false);
  226. }
  227. // Host Keyboard LED Status
  228. oled_write_ln_P(IS_HOST_LED_ON(USB_LED_CAPS_LOCK) ? PSTR("Caps Lock\n") : PSTR(" \n"), false);
  229. }
  230. __attribute__ ((weak))
  231. void oled_task_keymap(void) {}
  232. bool oled_task_user(void) {
  233. if (timer_elapsed(oled_timer) > 20000) {
  234. oled_off();
  235. return;
  236. }
  237. if (is_master) {
  238. render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
  239. } else {
  240. render_logo();
  241. oled_scroll_left();
  242. }
  243. oled_task_keymap();
  244. return false;
  245. }
  246. #endif // OLED_Driver
  247. #endif // crkbd