summaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_printer.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_printer.c')
-rw-r--r--quantum/process_keycode/process_printer.c269
1 files changed, 0 insertions, 269 deletions
diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c
deleted file mode 100644
index 6dd1f28c9b..0000000000
--- a/quantum/process_keycode/process_printer.c
+++ /dev/null
@@ -1,269 +0,0 @@
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#include "uart.h"
20
21bool printing_enabled = false;
22uint8_t character_shift = 0;
23
24void enable_printing(void) {
25 printing_enabled = true;
26 uart_init(19200);
27}
28
29void disable_printing(void) {
30 printing_enabled = false;
31}
32
33uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
34
35// uint8_t keycode_to_ascii[0xFF][2];
36
37// keycode_to_ascii[KC_MINUS] = {0x2D, 0x5F};
38
39void print_char(char c) {
40 USB_Disable();
41 uart_write(c);
42 USB_Init();
43}
44
45void print_string(char c[]) {
46 for (uint8_t i = 0; i < strlen(c); i++)
47 print_char(c[i]);
48}
49
50void print_box_string(const char text[]) {
51 size_t len = strlen(text);
52 char out[len * 3 + 8];
53 out[0] = 0xDA;
54 for (uint8_t i = 0; i < len; i++) {
55 out[i + 1] = 0xC4;
56 }
57 out[len + 1] = 0xBF;
58 out[len + 2] = '\n';
59
60 out[len + 3] = 0xB3;
61 for (uint8_t i = 0; i < len; i++) {
62 out[len + 4 + i] = text[i];
63 }
64 out[len * 2 + 4] = 0xB3;
65 out[len * 2 + 5] = '\n';
66
67 out[len * 2 + 6] = 0xC0;
68 for (uint8_t i = 0; i < len; i++) {
69 out[len * 2 + 7 + i] = 0xC4;
70 }
71 out[len * 3 + 7] = 0xD9;
72 out[len * 3 + 8] = '\n';
73
74 print_string(out);
75}
76
77bool process_printer(uint16_t keycode, keyrecord_t *record) {
78 if (keycode == PRINT_ON) {
79 enable_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_LEFT_SHIFT:
98 case KC_RIGHT_SHIFT:
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_ESCAPE:
115 if (record->event.pressed) {
116 print_char(0x1B);
117 }
118 return false;
119 break;
120 case KC_SPACE:
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_ENTER:
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_BACKSPACE:
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_COMMA:
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_SLASH:
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_QUOTE:
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_GRAVE:
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_MINUS:
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_EQUAL:
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_LEFT_BRACKET:
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_RIGHT_BRACKET:
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_BACKSLASH:
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}