aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_music.c16
-rw-r--r--quantum/process_keycode/process_printer.c254
-rw-r--r--quantum/process_keycode/process_printer.h8
-rw-r--r--quantum/process_keycode/process_printer_bb.c260
-rw-r--r--quantum/process_keycode/process_unicode.c41
-rw-r--r--quantum/process_keycode/process_unicode.h1
6 files changed, 569 insertions, 11 deletions
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index 2d52e47a7..1e2648bff 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -1,8 +1,8 @@
1#include "process_music.h" 1#include "process_music.h"
2 2
3bool music_activated = false; 3bool music_activated = false;
4uint8_t starting_note = 0x0C; 4uint8_t music_starting_note = 0x0C;
5int offset = 7; 5int music_offset = 7;
6 6
7// music sequencer 7// music sequencer
8static bool music_sequence_recording = false; 8static bool music_sequence_recording = false;
@@ -114,8 +114,18 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
114 music_sequence_interval+=10; 114 music_sequence_interval+=10;
115 return false; 115 return false;
116 } 116 }
117 #define MUSIC_MODE_GUITAR
118
119 #ifdef MUSIC_MODE_CHROMATIC
120 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row));
121 #elif defined(MUSIC_MODE_GUITAR)
122 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 7)*5.0/12);
123 #elif defined(MUSIC_MODE_VIOLIN)
124 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 5)*7.0/12);
125 #else
126 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row));
127 #endif
117 128
118 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
119 if (record->event.pressed) { 129 if (record->event.pressed) {
120 play_note(freq, 0xF); 130 play_note(freq, 0xF);
121 if (music_sequence_recording) { 131 if (music_sequence_recording) {
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
4bool printing_enabled = false;
5uint8_t character_shift = 0;
6
7void enabled_printing() {
8 printing_enabled = true;
9 serial_init();
10}
11
12void disable_printing() {
13 printing_enabled = false;
14}
15
16uint8_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
22void print_char(char c) {
23 USB_Disable();
24 serial_send(c);
25 USB_Init();
26}
27
28void 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
56void print_string(char c[]) {
57 for(uint8_t i = 0; i < strlen(c); i++)
58 print_char(c[i]);
59}
60
61bool 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
4bool printing_enabled = false;
5uint8_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
12inline static
13void serial_delay(void) {
14 _delay_us(SERIAL_DELAY);
15}
16
17inline static
18void serial_high(void) {
19 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
20}
21
22inline static
23void serial_low(void) {
24 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
25}
26
27inline static
28void serial_output(void) {
29 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
30}
31
32
33void enabled_printing() {
34 printing_enabled = true;
35 serial_output();
36 serial_high();
37}
38
39void disable_printing() {
40 printing_enabled = false;
41}
42
43uint8_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
49void 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
62void print_string(char c[]) {
63 for(uint8_t i = 0; i < strlen(c); i++)
64 print_char(c[i]);
65}
66
67bool 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
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c
index cd3a610b4..a30e93ae3 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -1,6 +1,8 @@
1#include "process_unicode.h" 1#include "process_unicode.h"
2#include "action_util.h"
2 3
3static uint8_t input_mode; 4static uint8_t input_mode;
5uint8_t mods;
4 6
5__attribute__((weak)) 7__attribute__((weak))
6uint16_t hex_to_keycode(uint8_t hex) 8uint16_t hex_to_keycode(uint8_t hex)
@@ -25,6 +27,19 @@ uint8_t get_unicode_input_mode(void) {
25 27
26__attribute__((weak)) 28__attribute__((weak))
27void unicode_input_start (void) { 29void unicode_input_start (void) {
30 // save current mods
31 mods = keyboard_report->mods;
32
33 // unregister all mods to start from clean state
34 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
35 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
36 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
37 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
38 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
39 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
40 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
41 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
42
28 switch(input_mode) { 43 switch(input_mode) {
29 case UC_OSX: 44 case UC_OSX:
30 register_code(KC_LALT); 45 register_code(KC_LALT);
@@ -54,15 +69,25 @@ void unicode_input_start (void) {
54__attribute__((weak)) 69__attribute__((weak))
55void unicode_input_finish (void) { 70void unicode_input_finish (void) {
56 switch(input_mode) { 71 switch(input_mode) {
57 case UC_OSX: 72 case UC_OSX:
58 case UC_WIN: 73 case UC_WIN:
59 unregister_code(KC_LALT); 74 unregister_code(KC_LALT);
60 break; 75 break;
61 case UC_LNX: 76 case UC_LNX:
62 register_code(KC_SPC); 77 register_code(KC_SPC);
63 unregister_code(KC_SPC); 78 unregister_code(KC_SPC);
64 break; 79 break;
65 } 80 }
81
82 // reregister previously set mods
83 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
84 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
85 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
86 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
87 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
88 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
89 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
90 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
66} 91}
67 92
68void register_hex(uint16_t hex) { 93void register_hex(uint16_t hex) {
diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h
index 065eeb5f6..f17cfa6cf 100644
--- a/quantum/process_keycode/process_unicode.h
+++ b/quantum/process_keycode/process_unicode.h
@@ -22,6 +22,7 @@ void register_hex(uint16_t hex);
22bool process_unicode(uint16_t keycode, keyrecord_t *record); 22bool process_unicode(uint16_t keycode, keyrecord_t *record);
23 23
24#ifdef UNICODEMAP_ENABLE 24#ifdef UNICODEMAP_ENABLE
25void unicode_map_input_error(void);
25bool process_unicode_map(uint16_t keycode, keyrecord_t *record); 26bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
26#endif 27#endif
27 28