Created
September 12, 2020 19:52
-
-
Save browserdotsys/008b8b1830208c8f485e1dd0f352af97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (C) 2017 Steve Benz <s8878992@hotmail.com> | |
This library is free software; you can redistribute it and/or | |
modify it under the terms of the GNU Lesser General Public | |
License as published by the Free Software Foundation; either | |
version 2.1 of the License, or (at your option) any later version. | |
This library is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
Lesser General Public License for more details. | |
You should have received a copy of the GNU Lesser General Public | |
License along with this library; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
USA | |
*/ | |
#include "ps2_Keyboard.h" | |
#include "ps2_NullDiagnostics.h" | |
#include "ps2_UsbTranslator.h" | |
// This sketch requires you to have the "HIDProject" Arduino library installed. | |
#include "HID-Project.h" | |
static ps2::NullDiagnostics diagnostics; | |
static ps2::UsbTranslator<ps2::NullDiagnostics> keyMapping(diagnostics); | |
static ps2::Keyboard<3,2,1, ps2::NullDiagnostics> ps2Keyboard(diagnostics); | |
static ps2::UsbKeyboardLeds ledValueLastSentToPs2 = ps2::UsbKeyboardLeds::none; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
ps2Keyboard.begin(); | |
//ps2Keyboard.awaitStartup(); | |
BootKeyboard.begin(); | |
} | |
void loop() { | |
ps2::UsbKeyboardLeds newLedState = (ps2::UsbKeyboardLeds)BootKeyboard.getLeds(); | |
if (newLedState != ledValueLastSentToPs2) | |
{ | |
ps2Keyboard.sendLedStatus(keyMapping.translateLeds(newLedState)); | |
ledValueLastSentToPs2 = newLedState; | |
} | |
ps2::KeyboardOutput scanCode = ps2Keyboard.readScanCode(); | |
if (scanCode != ps2::KeyboardOutput::none && scanCode != ps2::KeyboardOutput::garbled) | |
{ | |
ps2::UsbKeyAction action = keyMapping.translatePs2Keycode(scanCode); | |
KeyboardKeycode hidCode = (KeyboardKeycode)action.hidCode; | |
switch (action.gesture) { | |
case ps2::UsbKeyAction::KeyDown: | |
BootKeyboard.press(hidCode); | |
break; | |
case ps2::UsbKeyAction::KeyUp: | |
BootKeyboard.release(hidCode); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment