diff options
Diffstat (limited to 'quantum/process_keycode/process_printer_bb.c')
| -rw-r--r-- | quantum/process_keycode/process_printer_bb.c | 276 |
1 files changed, 276 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c new file mode 100644 index 000000000..55d3b552b --- /dev/null +++ b/quantum/process_keycode/process_printer_bb.c | |||
| @@ -0,0 +1,276 @@ | |||
| 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 | #define SERIAL_PIN_DDR DDRD | ||
| 24 | #define SERIAL_PIN_PORT PORTD | ||
| 25 | #define SERIAL_PIN_MASK _BV(PD3) | ||
| 26 | #define SERIAL_DELAY 52 | ||
| 27 | |||
| 28 | inline static | ||
| 29 | void serial_delay(void) { | ||
| 30 | _delay_us(SERIAL_DELAY); | ||
| 31 | } | ||
| 32 | |||
| 33 | inline static | ||
| 34 | void serial_high(void) { | ||
| 35 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 36 | } | ||
| 37 | |||
| 38 | inline static | ||
| 39 | void serial_low(void) { | ||
| 40 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | ||
| 41 | } | ||
| 42 | |||
| 43 | inline static | ||
| 44 | void serial_output(void) { | ||
| 45 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | void enabled_printing() { | ||
| 50 | printing_enabled = true; | ||
| 51 | serial_output(); | ||
| 52 | serial_high(); | ||
| 53 | } | ||
| 54 | |||
| 55 | void disable_printing() { | ||
| 56 | printing_enabled = false; | ||
| 57 | } | ||
| 58 | |||
| 59 | uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; | ||
| 60 | |||
| 61 | // uint8_t keycode_to_ascii[0xFF][2]; | ||
| 62 | |||
| 63 | // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; | ||
| 64 | |||
| 65 | void print_char(char c) { | ||
| 66 | uint8_t b = 8; | ||
| 67 | serial_output(); | ||
| 68 | while( b-- ) { | ||
| 69 | if(c & (1 << b)) { | ||
| 70 | serial_high(); | ||
| 71 | } else { | ||
| 72 | serial_low(); | ||
| 73 | } | ||
| 74 | serial_delay(); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | void print_string(char c[]) { | ||
| 79 | for(uint8_t i = 0; i < strlen(c); i++) | ||
| 80 | print_char(c[i]); | ||
| 81 | } | ||
| 82 | |||
| 83 | bool process_printer(uint16_t keycode, keyrecord_t *record) { | ||
| 84 | if (keycode == PRINT_ON) { | ||
| 85 | enabled_printing(); | ||
| 86 | return false; | ||
| 87 | } | ||
| 88 | if (keycode == PRINT_OFF) { | ||
| 89 | disable_printing(); | ||
| 90 | return false; | ||
| 91 | } | ||
| 92 | |||
| 93 | if (printing_enabled) { | ||
| 94 | switch(keycode) { | ||
| 95 | case KC_EXLM ... KC_RPRN: | ||
| 96 | case KC_UNDS: | ||
| 97 | case KC_PLUS: | ||
| 98 | case KC_LCBR: | ||
| 99 | case KC_RCBR: | ||
| 100 | case KC_PIPE: | ||
| 101 | case KC_TILD: | ||
| 102 | keycode &= 0xFF; | ||
| 103 | case KC_LSFT: | ||
| 104 | case KC_RSFT: | ||
| 105 | if (record->event.pressed) { | ||
| 106 | character_shift++; | ||
| 107 | } else { | ||
| 108 | character_shift--; | ||
| 109 | } | ||
| 110 | return false; | ||
| 111 | break; | ||
| 112 | } | ||
| 113 | |||
| 114 | switch(keycode) { | ||
| 115 | case KC_F1: | ||
| 116 | if (record->event.pressed) { | ||
| 117 | print_string("This is a line of text!\n\n\n"); | ||
| 118 | } | ||
| 119 | return false; | ||
| 120 | case KC_ESC: | ||
| 121 | if (record->event.pressed) { | ||
| 122 | print_char(0x1B); | ||
| 123 | } | ||
| 124 | return false; | ||
| 125 | break; | ||
| 126 | case KC_SPC: | ||
| 127 | if (record->event.pressed) { | ||
| 128 | print_char(0x20); | ||
| 129 | } | ||
| 130 | return false; | ||
| 131 | break; | ||
| 132 | case KC_A ... KC_Z: | ||
| 133 | if (record->event.pressed) { | ||
| 134 | if (character_shift) { | ||
| 135 | print_char(0x41 + (keycode - KC_A)); | ||
| 136 | } else { | ||
| 137 | print_char(0x61 + (keycode - KC_A)); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | return false; | ||
| 141 | break; | ||
| 142 | case KC_1 ... KC_0: | ||
| 143 | if (record->event.pressed) { | ||
| 144 | if (character_shift) { | ||
| 145 | print_char(shifted_numbers[keycode - KC_1]); | ||
| 146 | } else { | ||
| 147 | print_char(0x30 + ((keycode - KC_1 + 1) % 10)); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | return false; | ||
| 151 | break; | ||
| 152 | case KC_ENT: | ||
| 153 | if (record->event.pressed) { | ||
| 154 | if (character_shift) { | ||
| 155 | print_char(0x0C); | ||
| 156 | } else { | ||
| 157 | print_char(0x0A); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return false; | ||
| 161 | break; | ||
| 162 | case KC_BSPC: | ||
| 163 | if (record->event.pressed) { | ||
| 164 | if (character_shift) { | ||
| 165 | print_char(0x18); | ||
| 166 | } else { | ||
| 167 | print_char(0x1A); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | return false; | ||
| 171 | break; | ||
| 172 | case KC_DOT: | ||
| 173 | if (record->event.pressed) { | ||
| 174 | if (character_shift) { | ||
| 175 | print_char(0x3E); | ||
| 176 | } else { | ||
| 177 | print_char(0x2E); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | return false; | ||
| 181 | break; | ||
| 182 | case KC_COMM: | ||
| 183 | if (record->event.pressed) { | ||
| 184 | if (character_shift) { | ||
| 185 | print_char(0x3C); | ||
| 186 | } else { | ||
| 187 | print_char(0x2C); | ||
| 188 | } | ||
| 189 | } | ||
| 190 | return false; | ||
| 191 | break; | ||
| 192 | case KC_SLSH: | ||
| 193 | if (record->event.pressed) { | ||
| 194 | if (character_shift) { | ||
| 195 | print_char(0x3F); | ||
| 196 | } else { | ||
| 197 | print_char(0x2F); | ||
| 198 | } | ||
| 199 | } | ||
| 200 | return false; | ||
| 201 | break; | ||
| 202 | case KC_QUOT: | ||
| 203 | if (record->event.pressed) { | ||
| 204 | if (character_shift) { | ||
| 205 | print_char(0x22); | ||
| 206 | } else { | ||
| 207 | print_char(0x27); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | return false; | ||
| 211 | break; | ||
| 212 | case KC_GRV: | ||
| 213 | if (record->event.pressed) { | ||
| 214 | if (character_shift) { | ||
| 215 | print_char(0x7E); | ||
| 216 | } else { | ||
| 217 | print_char(0x60); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | return false; | ||
| 221 | break; | ||
| 222 | case KC_MINS: | ||
| 223 | if (record->event.pressed) { | ||
| 224 | if (character_shift) { | ||
| 225 | print_char(0x5F); | ||
| 226 | } else { | ||
| 227 | print_char(0x2D); | ||
| 228 | } | ||
| 229 | } | ||
| 230 | return false; | ||
| 231 | break; | ||
| 232 | case KC_EQL: | ||
| 233 | if (record->event.pressed) { | ||
| 234 | if (character_shift) { | ||
| 235 | print_char(0x2B); | ||
| 236 | } else { | ||
| 237 | print_char(0x3D); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | return false; | ||
| 241 | break; | ||
| 242 | case KC_LBRC: | ||
| 243 | if (record->event.pressed) { | ||
| 244 | if (character_shift) { | ||
| 245 | print_char(0x7B); | ||
| 246 | } else { | ||
| 247 | print_char(0x5B); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | return false; | ||
| 251 | break; | ||
| 252 | case KC_RBRC: | ||
| 253 | if (record->event.pressed) { | ||
| 254 | if (character_shift) { | ||
| 255 | print_char(0x7D); | ||
| 256 | } else { | ||
| 257 | print_char(0x5D); | ||
| 258 | } | ||
| 259 | } | ||
| 260 | return false; | ||
| 261 | break; | ||
| 262 | case KC_BSLS: | ||
| 263 | if (record->event.pressed) { | ||
| 264 | if (character_shift) { | ||
| 265 | print_char(0x7C); | ||
| 266 | } else { | ||
| 267 | print_char(0x5C); | ||
| 268 | } | ||
| 269 | } | ||
| 270 | return false; | ||
| 271 | break; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | return true; | ||
| 275 | |||
| 276 | } | ||
