// Hook function invoked for key presses when we are in // magic mode. void magic_key_press(uint8_t k) { if (is_magic_key(k)) { magic_mode = 0; } if (layout[k].value == KEY_X) { ll_key_press(KEY_X); ll_key_release(KEY_X); ll_key_press(KEY_X); ll_key_release(KEY_X); } // Replay recorded keypresses: if (layout[k].value == KEY_R) { magic_mode = 0; replay_keypresses(); } // Activate bootloader: if (layout[k].value == KEY_B) { jump_bootloader(); } }
//Key Execute function //Decodes a keycode, and executes depending on codetype void key_execute(keycode aKey, uint8_t down) { print("inside key_execute\n"); phex(aKey.type); print("<-Type:Code->"); phex(aKey.code); print("\n"); switch(aKey.type) { case TYPE_KEY: //Check for type, and call functions if(down) add_key(aKey.code); else del_key(aKey.code); break; case TYPE_MOD: //Check for type, and call functions if(down) add_mod(aKey.code); else del_mod(aKey.code); break; case TYPE_MEDIA: case TYPE_MOUSE: //Placeholder if mouse and media keys implemented break; case TYPE_MOMENTARY: //For mementary layer changes clear_keyboard(); //Clear all current plessed keys, because they may not exist in new layer if(down) set_current_layer(aKey.code); else set_current_layer(0); //Return to default layer break; case TYPE_TOGGLE: //For toggleing layer changes if(down && (aKey.code ^ get_current_layer()) ) { clear_keyboard(); set_current_layer(aKey.code); } break; case TYPE_MISC: //Miscelaneous functions need special treatment switch(aKey.code) { case CODE_JMP_BOOT: //Jump to boot loader if(down) //Only want to activate on key-down { jump_bootloader(); } break; case CODE_BR_UP: //Raise brightness of LEDS //In steps of 24 if(down) //Only want to activate on key-down { if(OCR4D < 0xF0) OCR4D += 0x20; } break; case CODE_BR_DOWN: //Lower brightness of LEDS //In steps of 24 if(down) //Only want to activate on key-down { if(OCR4D > 0x10) OCR4D -= 0x20; } break; } break; default: //Default case: Unknown Keytype //Print error and do nothing print("Unknown Key Type: "); phex(aKey.type); pchar('\n'); } }
/** Called when command mode is active. * * First pressed key is mapped to first layer defined and evaluated. Use only a-z and 0-9 for commands, others exit this mode. * * @todo: leave automatically on unknown command or timeout, or signal mode through leds. * */ void handleCommand(void) { if(!commandMode()) return; if(activeKeys.keycnt==0) return; struct Key k=activeKeys.keys[0]; uint8_t hid = getKeyCode(k.row, k.col, 0); if(subcmd) { handleSubCmd(k); return; } clearActiveKeys(); clearRowData(); // Char with Meaning: // A:ASCIIPrint, B:BootL, C:PrintConfig, G:GeoArea, H:HardwarePC/Mac, L: SwitchLayout, M:Macro, P:PrintLayout, Q:QuitCommand, T: Trackpoint // Char without Meaning: // O:MouseMode, R:PrintKeyHID switch(hid) { #ifdef PINKYDROP case HID_D: g_pinkydrop = g_pinkydrop ? 0 : 1; printf("\nPinkydrop %d", g_pinkydrop); eeprom_write_byte(&ee_pinkyDrop, g_pinkydrop); setCommandMode(false); break; #endif case HID_V: printf("\nAdNW %s", FW_VERSION); setCommandMode(false); break; case HID_Q: case HID_ESC: printf("\nLeaving command mode::"); setCommandMode(false); break; case HID_B: printf("\nBootloader::"); jump_bootloader(); break; /* case HID_P: // Print Layout: one layer per press on key 'p' printLayout(layer); layer=(layer+1)%LAYERS; if(layer==0) setCommandMode(false); break; */ #ifdef MOUSE_HAS_SCROLL_WHEELS case HID_T: printf("\nTrackpoint:"); tp_id(); setCommandMode(false); break; #endif case HID_L: g_alternateLayer = g_alternateLayer ? 0 : 1; eeprom_write_byte(&ee_alternateLayer,g_alternateLayer); printf("\nAlternate layer %s", g_alternateLayer ? "selected." : "off."); setCommandMode(false); break; #ifdef PS2MOUSE case HID_M: g_mouse_enabled = g_mouse_enabled > 0 ? 0 : 1; printf("\nMouse %sabled", g_mouse_enabled ? "en" : "dis"); setCommandMode(false); break; #endif case HID_X: subcmd=SUB_MACRO; printf("Macro mode true\n"); break; case HID_R: printf("Macro recording\n"); subcmd=SUB_MACRO_REC; break; case HID_H: subcmd=SUB_PASSHASH; break; default: printf("\nUnknown command."); break; } }
/** Called when command mode is active. * * First pressed key is mapped to first layer defined and evaluated. Use only a-z and 0-9 for commands, others exit this mode. * * @todo: leave automatically on unknown command or timeout, or signal mode through leds. * */ void handleCommand(void) { if(!commandMode()) return; if(activeKeys.keycnt==0) return; struct Key k=activeKeys.keys[0]; uint8_t hid = getKeyCode(k.row, k.col, 0); if(subcmd) { handleSubCmd(k); return; } clearActiveKeys(); clearRowData(); // Char with Meaning: // A:ASCIIPrint, B:BootL, C:PrintConfig, G:GeoArea, H:HardwarePC/Mac, L: SwitchLayout, M:Macro, P:PrintLayout, Q:QuitCommand, T: Trackpoint // Char without Meaning: // O:MouseMode, R:PrintKeyHID switch(hid) { case HID_D: g_pinkydrop = !g_pinkydrop; printf("\nPinkydrop %d", g_pinkydrop); setCommandMode(false); break; case HID_V: printf("\nAdNW %s", FW_VERSION); setCommandMode(false); break; case HID_C: PrintConfiguration(); break; case HID_G: // G:GeoArea umschalten printf("\nG:GeoArea::"); subcmd=SUB_GEOAREA; break; case HID_H: // HardwarePC/Mac umschalten printf("\nHardwarePC/Mac::"); subcmd=SUB_PC_MAC; break; case HID_Q: case HID_ESC: printf("\nLeaving command mode::"); setCommandMode(false); break; case HID_B: printf("\nBootloader::"); jump_bootloader(); break; case HID_P: // Print Layout: one layer per press on key 'p' printLayout(layer); layer=(layer+1)%LAYERS; if(layer==0) setCommandMode(false); break; #ifdef MOUSE_HAS_SCROLL_WHEELS case HID_T: printf("\nTrackpoint:"); tp_id(); setCommandMode(false); break; #endif case HID_L: g_alternateLayer=!g_alternateLayer; printf("\nAlternate layer %s", g_alternateLayer ? "selected." : "off."); setCommandMode(false); /* // Layout umschalten printf("\nSwitch layout::"); subcmd=SUB_LAYOUT; */ break; case HID_A: for(uint8_t i=32; i<255; ++i) { if(i%16==0) printf("\n %03d", i); printf("%c ", (char)(i)); if(i==127) i+=33; } setCommandMode(false); break; case HID_M: g_mouse_enabled = g_mouse_enabled > 0 ? 0 : 1; printf("\nMouse %sabled", g_mouse_enabled ? "en" : "dis"); setCommandMode(false); break; case HID_R: // print HID code of pressed key printf("\nHID code read active."); subcmd=SUB_READ; idx=0; break; case HID_X: subcmd=SUB_MACRO; printf("Macro mode true\n"); break; default: printf("\nUnknown command."); break; } }