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