2
0

keymap.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. #include QMK_KEYBOARD_H
  2. #include "keymap.h"
  3. enum marianas_layers {
  4. QWERTY,
  5. /*
  6. COLEMAK,
  7. DVORAK,
  8. */
  9. NAV_CLUSTER,
  10. GAMING,
  11. SQLMACROS,
  12. SQLNAMES,
  13. FN_LAYER
  14. };
  15. enum sql_macros {
  16. S_LFTJN = SAFE_RANGE, // L
  17. S_INRJN, // I
  18. S_SLCT, // S
  19. S_FROM, // F
  20. S_DSNCT, // D
  21. S_ORDER, // O
  22. S_WHERE, // W
  23. S_ALTER, // Esc
  24. S_ASTRK, // *
  25. TD_A,
  26. TD_B,
  27. TD_C, // Corp, Corporation, Company
  28. TD_D, // Distribution, Dist, Distributor
  29. TD_E,
  30. TD_F,
  31. TD_G, // GlobalLookup
  32. TD_H,
  33. TD_I, // Instance, Item
  34. TD_J,
  35. TD_K,
  36. TD_L,
  37. TD_M,
  38. TD_N, // NadRate
  39. TD_O,
  40. TD_P, // Product, Person,
  41. TD_Q, // Darden
  42. TD_R,
  43. TD_S, // Supplier, Step
  44. TD_T, // Task, Type
  45. TD_U,
  46. TD_V,
  47. TD_W, // Workflow,
  48. TD_X,
  49. TD_Y,
  50. TD_Z,
  51. TD_BSPC,
  52. TD_ENT,
  53. TD_ESC
  54. };
  55. uint16_t *macroTaps = 0;
  56. char *tableNameList = 0;
  57. uint8_t *charCount = 0;
  58. uint8_t countPointer = 0;
  59. bool shifted = false;
  60. bool sendAbbr = false;
  61. void initStringData(void)
  62. {
  63. if (macroTaps == 0)
  64. {
  65. macroTaps = malloc(macroTapsLen*sizeof(uint16_t));
  66. for(int i = 0; i < macroTapsLen; i++)
  67. {
  68. macroTaps[i] = 0;
  69. }
  70. }
  71. if (tableNameList == 0)
  72. {
  73. tableNameList = malloc(tableNameListLen*sizeof(char));
  74. for(int i = 0; i < tableNameListLen; i++)
  75. {
  76. tableNameList[i] = 0;
  77. }
  78. }
  79. if (charCount == 0)
  80. {
  81. charCount = malloc(charCountLen*sizeof(uint8_t));
  82. for (int i = 0; i < charCountLen; i++)
  83. {
  84. charCount[i] = 0;
  85. }
  86. }
  87. }
  88. uint32_t layer_state_set_user(uint32_t state)
  89. {
  90. switch (biton32(state))
  91. {
  92. case QWERTY:
  93. rgblight_mode(9);
  94. break;
  95. case NAV_CLUSTER:
  96. rgblight_mode(29);
  97. break;
  98. case GAMING:
  99. rgblight_mode(26);
  100. break;
  101. case SQLMACROS:
  102. rgblight_mode(1);
  103. rgblight_setrgb(0x00, 0xFF, 0x80);
  104. break;
  105. case SQLNAMES:
  106. rgblight_mode(1);
  107. rgblight_setrgb(0x80, 0xFF, 0x00);
  108. break;
  109. case FN_LAYER:
  110. rgblight_mode(1);
  111. rgblight_setrgb(0x00, 0x80, 0xFF);
  112. break;
  113. }
  114. return state;
  115. }
  116. bool containsCode(uint16_t kc)
  117. {
  118. for (int i = 0; i < macroTapsLen && macroTaps[i] > 0; i++)
  119. {
  120. if (macroTaps[i] == kc) return true;
  121. }
  122. return false;
  123. }
  124. bool lastCodeIs(uint16_t kc)
  125. {
  126. for (int i = 0; i < macroTapsLen-1 && macroTaps[i] > 0; i++)
  127. {
  128. if (macroTaps[i] == kc && macroTaps[i+1] == 0) return true;
  129. }
  130. return false;
  131. }
  132. bool last2CodeAre(uint16_t kc)
  133. {
  134. for (int i = 0; i < macroTapsLen-2 && macroTaps[i] > 0; i++)
  135. {
  136. if (macroTaps[i] == kc && macroTaps[i+1] == kc && macroTaps[i+2] == 0) return true;
  137. }
  138. return false;
  139. }
  140. bool last2CodesAre(uint16_t kc, uint16_t kc2)
  141. {
  142. for (int i = 0; i < macroTapsLen-2 && macroTaps[i] > 0; i++)
  143. {
  144. if (macroTaps[i] == kc && macroTaps[i+1] == kc2 && macroTaps[i+2] == 0) return true;
  145. }
  146. return false;
  147. }
  148. void addKeyCode(uint16_t kc)
  149. {
  150. int i = 0;
  151. while (i < macroTapsLen-2 && macroTaps[i] > 0) i++;
  152. if (macroTaps[i] == 0)
  153. {
  154. macroTaps[i] = kc;
  155. macroTaps[i+1] = 0;
  156. }
  157. }
  158. void eraseKeyCodes(void)
  159. {
  160. int i = 0;
  161. while (i < macroTapsLen && macroTaps[i] > 0) macroTaps[i++] = 0;
  162. }
  163. void eraseCharCounts(void)
  164. {
  165. int i = 0;
  166. while (i < charCountLen)
  167. {
  168. charCount[i] = 0;
  169. }
  170. }
  171. void printTableAbbreviation(void)
  172. {
  173. initStringData();
  174. if (tableNameList[0] == 0)
  175. {
  176. return;
  177. }
  178. send_char(0x20);
  179. int i = 0;
  180. for (i = 0; i < tableNameListLen && tableNameList[i] > 0; i++)
  181. {
  182. if (tableNameList[i] >= 65 && tableNameList[i] <= 90)
  183. {
  184. send_char(tableNameList[i]+32);
  185. }
  186. else
  187. {
  188. send_char(tableNameList[i]);
  189. }
  190. }
  191. send_char(0x20);
  192. }
  193. void eraseTableAbbreviation(void)
  194. {
  195. initStringData();
  196. for (int i = 0; i < tableNameListLen && tableNameList[i] > 0; i++)
  197. {
  198. tableNameList[i] = '\0';
  199. }
  200. }
  201. void printString(char* str)
  202. {
  203. if (str[0] != '\0')
  204. {
  205. int i = 0;
  206. while (true)
  207. {
  208. if (str[i] == 0)
  209. {
  210. break;
  211. }
  212. send_char(str[i++]);
  213. charCount[countPointer]++;
  214. }
  215. }
  216. }
  217. void printStringAndQueueChar(char* str)
  218. {
  219. initStringData();
  220. if (charCount[countPointer] != 0)
  221. {
  222. countPointer++;
  223. }
  224. sendAbbr = true;
  225. if (str[0] != '\0')
  226. {
  227. printString(str);
  228. for (int i = 0; i < tableNameListLen-1; i++)
  229. {
  230. if (tableNameList[i] == '\0')
  231. {
  232. tableNameList[i] = str[0];
  233. tableNameList[i+1] = '\0';
  234. break;
  235. }
  236. else if (i == tableNameListLen-2)
  237. {
  238. printTableAbbreviation();
  239. break;
  240. }
  241. }
  242. //for (i = 0; i < tableNameListLen && tableNameList[i] > 0; i++)
  243. //{
  244. // send_char(tableNameList[i]);
  245. //}
  246. //send_string_P("Darden");
  247. //send_string_P(&myarray);
  248. //send_string_P(str);
  249. }
  250. }
  251. void ReplaceString(char *orig, char *repl)
  252. {
  253. int i = 0;
  254. while((orig[i] != 0x0 && repl[i] != 0x0) && orig[i] == repl[i])
  255. i++;
  256. if(orig[i] != 0x0)
  257. {
  258. int o = i;
  259. while (orig[o++] != 0x0) {
  260. charCount[countPointer]--;
  261. register_code(KC_BSPC);
  262. unregister_code(KC_BSPC);
  263. }
  264. }
  265. printString(repl+i);
  266. }
  267. void deletePrev(void)
  268. {
  269. for (int i = 0; i < charCount[countPointer]; i++)
  270. {
  271. register_code(KC_BSPC);
  272. unregister_code(KC_BSPC);
  273. }
  274. charCount[countPointer] = 0;
  275. countPointer--;
  276. int i = 1;
  277. for (;i < tableNameListLen-1; i++)
  278. {
  279. if (tableNameList[i] == 0x0)
  280. {
  281. break;
  282. }
  283. }
  284. tableNameList[i-1] = 0x0;
  285. }
  286. void processSmartMacroTap(uint16_t kc)
  287. {
  288. initStringData();
  289. switch(kc)
  290. {
  291. case TD_C:
  292. if (containsCode(TD_D))
  293. {
  294. printString("ribution");
  295. printStringAndQueueChar("Center");
  296. }
  297. else if (last2CodeAre(TD_C))
  298. {
  299. ReplaceString("Corporation", "Contact");
  300. }
  301. else if(lastCodeIs(TD_C))
  302. {
  303. printString("oration");
  304. }
  305. else
  306. {
  307. printStringAndQueueChar("Corp");
  308. }
  309. break;
  310. case TD_D:
  311. if (last2CodeAre(TD_D))
  312. {
  313. ReplaceString("Distribution", "Distributor");
  314. }
  315. else if(lastCodeIs(TD_D))
  316. {
  317. printString("ribution");
  318. }
  319. else
  320. {
  321. printStringAndQueueChar("Dist");
  322. }
  323. break;
  324. case TD_G:
  325. printStringAndQueueChar("Global");
  326. printStringAndQueueChar("Lookup");
  327. break;
  328. case TD_I:
  329. if (containsCode(TD_W))
  330. printStringAndQueueChar("Instance");
  331. else
  332. printStringAndQueueChar("Item");
  333. break;
  334. case TD_N:
  335. printStringAndQueueChar("NadRate");
  336. break;
  337. case TD_P:
  338. if (last2CodesAre(TD_D, TD_C))
  339. {
  340. ReplaceString("DistributionCenter", "DistCenter");
  341. printStringAndQueueChar("Pricing");
  342. }
  343. else if (last2CodeAre(TD_P))
  344. {
  345. }
  346. else if(lastCodeIs(TD_P))
  347. {
  348. ReplaceString("Product", "Person");
  349. }
  350. else
  351. {
  352. printStringAndQueueChar("Product");
  353. }
  354. break;
  355. case TD_Q:
  356. printStringAndQueueChar("Darden");
  357. break;
  358. case TD_S:
  359. if (containsCode(TD_W))
  360. if (containsCode(TD_S) || containsCode(TD_D))
  361. printStringAndQueueChar("Step");
  362. else
  363. printStringAndQueueChar("Session");
  364. else
  365. printStringAndQueueChar("Supplier");
  366. break;
  367. case TD_T:
  368. if (containsCode(TD_W))
  369. printStringAndQueueChar("Task");
  370. else
  371. printStringAndQueueChar("Type");
  372. break;
  373. case TD_W:
  374. printStringAndQueueChar("Workflow");
  375. break;
  376. }
  377. addKeyCode(kc);
  378. }
  379. bool process_record_user(uint16_t keycode, keyrecord_t *record)
  380. {
  381. if (record->event.pressed)
  382. {
  383. switch (keycode)
  384. {
  385. case KC_LSPO:
  386. case KC_RSPC:
  387. shifted = true;
  388. return true;
  389. case S_LFTJN: SEND_STRING("LEFT JOIN"); return false;
  390. case S_INRJN: SEND_STRING("INNER JOIN "); return false;
  391. case S_SLCT: SEND_STRING("SELECT "); return false;
  392. case S_FROM: SEND_STRING("FROM "); return false;
  393. case S_DSNCT: SEND_STRING("DISTINCT "); return false;
  394. case S_ORDER: SEND_STRING("ORDER "); return false;
  395. case S_WHERE: SEND_STRING("WHERE "); return false;
  396. case S_ALTER: SEND_STRING("ALTER SESSION SET CURRENT_SCHEMA = "); return false;
  397. case S_ASTRK: SEND_STRING("* "); return false;
  398. case KC_BSLS:
  399. initStringData();
  400. layer_on(SQLNAMES);
  401. return false;
  402. case TD_BSPC:
  403. if (!shifted){
  404. deletePrev();
  405. }
  406. else {
  407. register_code(KC_BSPC);
  408. unregister_code(KC_BSPC);
  409. }
  410. return false;
  411. case TD_A:
  412. case TD_B:
  413. case TD_C:
  414. case TD_D:
  415. case TD_E:
  416. case TD_F:
  417. case TD_G:
  418. case TD_H:
  419. case TD_I:
  420. case TD_J:
  421. case TD_K:
  422. case TD_L:
  423. case TD_M:
  424. case TD_N:
  425. case TD_O:
  426. case TD_P:
  427. case TD_Q:
  428. case TD_R:
  429. case TD_S:
  430. case TD_T:
  431. case TD_U:
  432. case TD_V:
  433. case TD_W:
  434. case TD_X:
  435. case TD_Y:
  436. case TD_Z:
  437. processSmartMacroTap(keycode);
  438. return false;
  439. case TD_ENT:
  440. printTableAbbreviation();
  441. case TD_ESC:
  442. eraseKeyCodes();
  443. eraseTableAbbreviation();
  444. layer_off(SQLNAMES);
  445. return true;
  446. }
  447. }
  448. else
  449. {
  450. switch (keycode)
  451. {
  452. case KC_BSLS:
  453. if (macroTaps[0] == 0)
  454. {
  455. SEND_STRING("\\");
  456. layer_off(SQLNAMES);
  457. }
  458. return true;
  459. case KC_LSPO:
  460. case KC_RSPC:
  461. shifted = false;
  462. return true;
  463. }
  464. }
  465. return true;
  466. };
  467. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  468. [QWERTY]=
  469. LAYOUT_60_ansi(
  470. ESCAP, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, MNUS, EQUL, BACKSPC,
  471. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, LBRC, RBRC, BSLASH,
  472. MO_FNLR, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, COLN, QUOT, ENTER_OR_SQL,
  473. LEFTSHFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, CMMA, PRRD, SLSH, RIGHT_SHIFT__PAREN,
  474. CTLL, WINL, ALTL, SPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACE, ALTR, WINR, APPR, CTLR),
  475. [NAV_CLUSTER]=
  476. LAYOUT_60_ansi(
  477. _____, PSCR, SCRL, PAUS, NSRT, HOME, PGUP, NMLK, KSSH, STAR, KMIN, ____, ____, ______,
  478. ______, ____, ____, ____, DELT, END_, PGDN, KP_7, KP_8, KP_9, PLUS, ____, ____, _____,
  479. _______, ____, ____, ____, ____, UPUP, UPUP, KP_4, KP_5, KP_6, PLUS, ____, ___________,
  480. ________, ____, ____, ____, LEFT, D_WN, RGHT, KP_1, KP_2, KP_3, KNTR, _________________,
  481. ____, ____, ____, /*-----------------*/KC_KP_0/*-----------------*/, KDOT, KNTR, ____, ____),
  482. [GAMING]=
  483. LAYOUT_60_ansi(
  484. _____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ______,
  485. ______, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, _____,
  486. KCNO, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ___________,
  487. ________, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, _________________,
  488. ____, KCNO, ____, /*------------------*/_____/*------------------*/, ____, KCNO, ____, QWRTY),
  489. [SQLMACROS]=
  490. LAYOUT_60_ansi(
  491. S_ALTER, ____, ____, ____, ____, ____, ____, ____, S_ASTRK, ____, ____, ____, ____, ___________,
  492. ______, ____, S_WHERE, ____, ____, ____, ____, ____, S_INRJN, S_ORDER, ____, ____, ____, ______,
  493. _______, KC_LBRC, S_SLCT, KC_PAST,S_FROM, ____, ____, ____, ____, S_LFTJN, ____, RBRC, ___________,
  494. ________, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, _________________,
  495. ____, ____, ____, /*------------------*/_____/*------------------*/, ____, ____, ____, ____),
  496. [SQLNAMES]=
  497. LAYOUT_60_ansi(
  498. TD_ESC, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, TD_BSPC,
  499. ________, TD_Q, TD_W, TD_E, TD_R, TD_T, TD_Y, TD_U, TD_I, TD_O, TD_P, ____, ____, _____,
  500. ___________, TD_A, TD_S, TD_D, TD_F, TD_G, TD_H, TD_J, TD_K, TD_L, ____, ____, TD_ENT,
  501. ___________, TD_Z, TD_X, TD_C, TD_V, TD_B, TD_N, TD_M, ____, ____, ____, _________________,
  502. ____, ____, ____, /*----------------------*/TD_ENT/*-----------------------*/, ____, ____, ____, RESET),
  503. [FN_LAYER]=
  504. LAYOUT_60_ansi(
  505. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL,
  506. KC_CAPSLOCK, KC_MPRV, KC_MPLY, KC_MNXT, LWIN(KC_R), ____, KC_CALC, KC_PGUP, KC_UP, KC_PGDN, KC_PSCR, KC_SLCK, KC_BRK, ____,
  507. ____, KC_VOLD, KC_MUTE, KC_VOLU, ____, ____, KC_HOME, KC_LEFT, KC_DOWN, KC_RIGHT, KC_INS, KC_DEL, ____,
  508. ____, ____, ____, ____, ____, ____, KC_END, ____, QWRTY, NAVS, GAME, ____,
  509. ____, ____, ____, _________________, ____, KC_HYPR, KC_MEH, ____)
  510. };