Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "keyboard.h"
- #include <stdint.h>
- #include <stdbool.h>
- enum KEYCODE {
- NULL_KEY = 0,
- Q_PRESSED = 0x10,
- Q_RELEASED = 0x90,
- W_PRESSED = 0x11,
- W_RELEASED = 0x91,
- E_PRESSED = 0x12,
- E_RELEASED = 0x92,
- R_PRESSED = 0x13,
- R_RELEASED = 0x93,
- T_PRESSED = 0x14,
- T_RELEASED = 0x94,
- Y_PRESSED = 0x15,
- Y_RELEASED = 0x95,
- U_PRESSED = 0x16,
- U_RELEASED = 0x96,
- I_PRESSED = 0x17,
- I_RELEASED = 0x97,
- O_PRESSED = 0x18,
- O_RELEASED = 0x98,
- P_PRESSED = 0x19,
- P_RELEASED = 0x99,
- A_PRESSED = 0x1E,
- A_RELEASED = 0x9E,
- S_PRESSED = 0x1F,
- S_RELEASED = 0x9F,
- D_PRESSED = 0x20,
- D_RELEASED = 0xA0,
- F_PRESSED = 0x21,
- F_RELEASED = 0xA1,
- G_PRESSED = 0x22,
- G_RELEASED = 0xA2,
- H_PRESSED = 0x23,
- H_RELEASED = 0xA3,
- J_PRESSED = 0x24,
- J_RELEASED = 0xA4,
- K_PRESSED = 0x25,
- K_RELEASED = 0xA5,
- L_PRESSED = 0x26,
- L_RELEASED = 0xA6,
- Z_PRESSED = 0x2C,
- Z_RELEASED = 0xAC,
- X_PRESSED = 0x2D,
- X_RELEASED = 0xAD,
- C_PRESSED = 0x2E,
- C_RELEASED = 0xAE,
- V_PRESSED = 0x2F,
- V_RELEASED = 0xAF,
- B_PRESSED = 0x30,
- B_RELEASED = 0xB0,
- N_PRESSED = 0x31,
- N_RELEASED = 0xB1,
- M_PRESSED = 0x32,
- M_RELEASED = 0xB2,
- ZERO_PRESSED = 0x0B,
- ZERO_RELEASED = 0x8B,
- ONE_PRESSED = 0x2,
- ONE_RELEASED = 0x82,
- NINE_PRESSED = 0xA,
- NINE_RELEASED = 0x8A,
- POINT_PRESSED = 0x34,
- POINT_RELEASED = 0xB4,
- SLASH_RELEASED = 0xB5,
- BACKSPACE_PRESSED = 0xE,
- BACKSPACE_RELEASED = 0x8E,
- SPACE_PRESSED = 0x39,
- SPACE_RELEASED = 0xB9,
- ENTER_PRESSED = 0x1C,
- ENTER_RELEASED = 0x9C,
- LSHIFT_PRESSED = 0x2A,
- LSHIFT_RELEASED = 0xAA,
- RSHIFT_PRESSED = 0x36,
- RSHIFT_RELEASED = 0xB6,
- };
- bool shiftPressed = false;
- static char* _qwertzuiop = "qwertyuiop";
- static char* _asdfghjkl = "asdfghjkl";
- static char* _yxcvbnm = "zxcvbnm";
- static char* _num = "123456789";
- static char* _caps_qwertzuiop = "QWERTYUIOP";
- static char* _caps_asdfghjkl = "ASDFGHJKL";
- static char* _caps_yxcvbnm = "ZXCVBNM";
- uint8_t keyboard_to_ascii(uint8_t key) {
- if(key == ENTER_PRESSED) return '\n';
- if(key == SPACE_PRESSED) return ' ';
- if(key == ENTER_PRESSED) return '\r';
- if(key == POINT_RELEASED) return '.';
- if(key == SLASH_RELEASED) return '/';
- if(key == ZERO_PRESSED) return '0';
- if(key >= ONE_PRESSED && key <= NINE_PRESSED)
- return _num[key - ONE_PRESSED];
- if(key >= Q_PRESSED && key <= ENTER_PRESSED)
- {
- if (shiftPressed) {
- return _caps_qwertzuiop[key - Q_PRESSED];
- } else {
- return _qwertzuiop[key - Q_PRESSED];
- }
- } else if(key >= A_PRESSED && key <= L_PRESSED)
- {
- if (shiftPressed) {
- return _caps_asdfghjkl[key - A_PRESSED];
- } else {
- return _asdfghjkl[key - A_PRESSED];
- }
- } else if(key >= Z_PRESSED && key <= M_PRESSED)
- {
- if (shiftPressed) {
- return _caps_yxcvbnm[key - Z_PRESSED];
- } else {
- return _yxcvbnm[key - Z_PRESSED];
- }
- }
- if (key == LSHIFT_PRESSED || key == RSHIFT_PRESSED) {
- shiftPressed = true;
- } else {
- shiftPressed = false;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement