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