diff options
Diffstat (limited to 'quantum/process_keycode/process_printer.c')
| -rw-r--r-- | quantum/process_keycode/process_printer.c | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c new file mode 100644 index 000000000..807f7a0b9 --- /dev/null +++ b/quantum/process_keycode/process_printer.c | |||
| @@ -0,0 +1,270 @@ | |||
| 1 | /* Copyright 2016 Jack Humbert | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "process_printer.h" | ||
| 18 | #include "action_util.h" | ||
| 19 | |||
| 20 | bool printing_enabled = false; | ||
| 21 | uint8_t character_shift = 0; | ||
| 22 | |||
| 23 | void enabled_printing() { | ||
| 24 | printing_enabled = true; | ||
| 25 | serial_init(); | ||
| 26 | } | ||
| 27 | |||
| 28 | void disable_printing() { | ||
| 29 | printing_enabled = false; | ||
| 30 | } | ||
| 31 | |||
| 32 | uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; | ||
| 33 | |||
| 34 | // uint8_t keycode_to_ascii[0xFF][2]; | ||
| 35 | |||
| 36 | // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; | ||
| 37 | |||
| 38 | void print_char(char c) { | ||
| 39 | USB_Disable(); | ||
| 40 | serial_send(c); | ||
| 41 | USB_Init(); | ||
| 42 | } | ||
| 43 | |||
| 44 | void print_box_string(uint8_t text[]) { | ||
| 45 | uint8_t len = strlen(text); | ||
| 46 | uint8_t out[len * 3 + 8]; | ||
| 47 | out[0] = 0xDA; | ||
| 48 | for (uint8_t i = 0; i < len; i++) { | ||
| 49 | out[i+1] = 0xC4; | ||
| 50 | } | ||
| 51 | out[len + 1] = 0xBF; | ||
| 52 | out[len + 2] = '\n'; | ||
| 53 | |||
| 54 | out[len + 3] = 0xB3; | ||
| 55 | for (uint8_t i = 0; i < len; i++) { | ||
| 56 | out[len + 4 + i] = text[i]; | ||
| 57 | } | ||
| 58 | out[len * 2 + 4] = 0xB3; | ||
| 59 | out[len * 2 + 5] = '\n'; | ||
| 60 | |||
| 61 | |||
| 62 | out[len * 2 + 6] = 0xC0; | ||
| 63 | for (uint8_t i = 0; i < len; i++) { | ||
| 64 | out[len * 2 + 7 + i] = 0xC4; | ||
| 65 | } | ||
| 66 | out[len * 3 + 7] = 0xD9; | ||
| 67 | out[len * 3 + 8] = '\n'; | ||
| 68 | |||
| 69 | print_string(out); | ||
| 70 | } | ||
| 71 | |||
| 72 | void print_string(char c[]) { | ||
| 73 | for(uint8_t i = 0; i < strlen(c); i++) | ||
| 74 | print_char(c[i]); | ||
| 75 | } | ||
| 76 | |||
| 77 | bool process_printer(uint16_t keycode, keyrecord_t *record) { | ||
| 78 | if (keycode == PRINT_ON) { | ||
| 79 | enabled_printing(); | ||
| 80 | return false; | ||
| 81 | } | ||
| 82 | if (keycode == PRINT_OFF) { | ||
| 83 | disable_printing(); | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (printing_enabled) { | ||
| 88 | switch(keycode) { | ||
| 89 | case KC_EXLM ... KC_RPRN: | ||
| 90 | case KC_UNDS: | ||
| 91 | case KC_PLUS: | ||
| 92 | case KC_LCBR: | ||
| 93 | case KC_RCBR: | ||
| 94 | case KC_PIPE: | ||
| 95 | case KC_TILD: | ||
| 96 | keycode &= 0xFF; | ||
| 97 | case KC_LSFT: | ||
| 98 | case KC_RSFT: | ||
| 99 | if (record->event.pressed) { | ||
| 100 | character_shift++; | ||
| 101 | } else { | ||
| 102 | character_shift--; | ||
| 103 | } | ||
| 104 | return false; | ||
| 105 | break; | ||
| 106 | } | ||
| 107 | |||
| 108 | switch(keycode) { | ||
| 109 | case KC_F1: | ||
| 110 | if (record->event.pressed) { | ||
| 111 | print_box_string("This is a line of text!"); | ||
| 112 | } | ||
| 113 | return false; | ||
| 114 | case KC_ESC: | ||
| 115 | if (record->event.pressed) { | ||
| 116 | print_char(0x1B); | ||
| 117 | } | ||
| 118 | return false; | ||
| 119 | break; | ||
| 120 | case KC_SPC: | ||
| 121 | if (record->event.pressed) { | ||
| 122 | print_char(0x20); | ||
| 123 | } | ||
| 124 | return false; | ||
| 125 | break; | ||
| 126 | case KC_A ... KC_Z: | ||
| 127 | if (record->event.pressed) { | ||
| 128 | if (character_shift) { | ||
| 129 | print_char(0x41 + (keycode - KC_A)); | ||
| 130 | } else { | ||
| 131 | print_char(0x61 + (keycode - KC_A)); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | return false; | ||
| 135 | break; | ||
| 136 | case KC_1 ... KC_0: | ||
| 137 | if (record->event.pressed) { | ||
| 138 | if (character_shift) { | ||
| 139 | print_char(shifted_numbers[keycode - KC_1]); | ||
| 140 | } else { | ||
| 141 | print_char(0x30 + ((keycode - KC_1 + 1) % 10)); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | return false; | ||
| 145 | break; | ||
| 146 | case KC_ENT: | ||
| 147 | if (record->event.pressed) { | ||
| 148 | if (character_shift) { | ||
| 149 | print_char(0x0C); | ||
| 150 | } else { | ||
| 151 | print_char(0x0A); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | return false; | ||
| 155 | break; | ||
| 156 | case KC_BSPC: | ||
| 157 | if (record->event.pressed) { | ||
| 158 | if (character_shift) { | ||
| 159 | print_char(0x18); | ||
| 160 | } else { | ||
| 161 | print_char(0x1A); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | return false; | ||
| 165 | break; | ||
| 166 | case KC_DOT: | ||
| 167 | if (record->event.pressed) { | ||
| 168 | if (character_shift) { | ||
| 169 | print_char(0x3E); | ||
| 170 | } else { | ||
| 171 | print_char(0x2E); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | return false; | ||
| 175 | break; | ||
| 176 | case KC_COMM: | ||
| 177 | if (record->event.pressed) { | ||
| 178 | if (character_shift) { | ||
| 179 | print_char(0x3C); | ||
| 180 | } else { | ||
| 181 | print_char(0x2C); | ||
| 182 | } | ||
| 183 | } | ||
| 184 | return false; | ||
| 185 | break; | ||
| 186 | case KC_SLSH: | ||
| 187 | if (record->event.pressed) { | ||
| 188 | if (character_shift) { | ||
| 189 | print_char(0x3F); | ||
| 190 | } else { | ||
| 191 | print_char(0x2F); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | return false; | ||
| 195 | break; | ||
| 196 | case KC_QUOT: | ||
| 197 | if (record->event.pressed) { | ||
| 198 | if (character_shift) { | ||
| 199 | print_char(0x22); | ||
| 200 | } else { | ||
| 201 | print_char(0x27); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | return false; | ||
| 205 | break; | ||
| 206 | case KC_GRV: | ||
| 207 | if (record->event.pressed) { | ||
| 208 | if (character_shift) { | ||
| 209 | print_char(0x7E); | ||
| 210 | } else { | ||
| 211 | print_char(0x60); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | return false; | ||
| 215 | break; | ||
| 216 | case KC_MINS: | ||
| 217 | if (record->event.pressed) { | ||
| 218 | if (character_shift) { | ||
| 219 | print_char(0x5F); | ||
| 220 | } else { | ||
| 221 | print_char(0x2D); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | return false; | ||
| 225 | break; | ||
| 226 | case KC_EQL: | ||
| 227 | if (record->event.pressed) { | ||
| 228 | if (character_shift) { | ||
| 229 | print_char(0x2B); | ||
| 230 | } else { | ||
| 231 | print_char(0x3D); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | return false; | ||
| 235 | break; | ||
| 236 | case KC_LBRC: | ||
| 237 | if (record->event.pressed) { | ||
| 238 | if (character_shift) { | ||
| 239 | print_char(0x7B); | ||
| 240 | } else { | ||
| 241 | print_char(0x5B); | ||
| 242 | } | ||
| 243 | } | ||
| 244 | return false; | ||
| 245 | break; | ||
| 246 | case KC_RBRC: | ||
| 247 | if (record->event.pressed) { | ||
| 248 | if (character_shift) { | ||
| 249 | print_char(0x7D); | ||
| 250 | } else { | ||
| 251 | print_char(0x5D); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | return false; | ||
| 255 | break; | ||
| 256 | case KC_BSLS: | ||
| 257 | if (record->event.pressed) { | ||
| 258 | if (character_shift) { | ||
| 259 | print_char(0x7C); | ||
| 260 | } else { | ||
| 261 | print_char(0x5C); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | return false; | ||
| 265 | break; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | return true; | ||
| 269 | |||
| 270 | } | ||
