1 /* Copyright 2016 Jack Humbert
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.
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.
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/>.
17 #include "process_printer.h"
18 #include "action_util.h"
20 bool printing_enabled = false;
21 uint8_t character_shift = 0;
23 #define SERIAL_PIN_DDR DDRD
24 #define SERIAL_PIN_PORT PORTD
25 #define SERIAL_PIN_MASK _BV(PD3)
26 #define SERIAL_DELAY 52
29 void serial_delay(void) {
30 _delay_us(SERIAL_DELAY);
34 void serial_high(void) {
35 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
39 void serial_low(void) {
40 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
44 void serial_output(void) {
45 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
49 void enabled_printing() {
50 printing_enabled = true;
55 void disable_printing() {
56 printing_enabled = false;
59 uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
61 // uint8_t keycode_to_ascii[0xFF][2];
63 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
65 void print_char(char c) {
78 void print_string(char c[]) {
79 for(uint8_t i = 0; i < strlen(c); i++)
83 bool process_printer(uint16_t keycode, keyrecord_t *record) {
84 if (keycode == PRINT_ON) {
88 if (keycode == PRINT_OFF) {
93 if (printing_enabled) {
95 case KC_EXLM ... KC_RPRN:
105 if (record->event.pressed) {
116 if (record->event.pressed) {
117 print_string("This is a line of text!\n\n\n");
121 if (record->event.pressed) {
127 if (record->event.pressed) {
133 if (record->event.pressed) {
134 if (character_shift) {
135 print_char(0x41 + (keycode - KC_A));
137 print_char(0x61 + (keycode - KC_A));
143 if (record->event.pressed) {
144 if (character_shift) {
145 print_char(shifted_numbers[keycode - KC_1]);
147 print_char(0x30 + ((keycode - KC_1 + 1) % 10));
153 if (record->event.pressed) {
154 if (character_shift) {
163 if (record->event.pressed) {
164 if (character_shift) {
173 if (record->event.pressed) {
174 if (character_shift) {
183 if (record->event.pressed) {
184 if (character_shift) {
193 if (record->event.pressed) {
194 if (character_shift) {
203 if (record->event.pressed) {
204 if (character_shift) {
213 if (record->event.pressed) {
214 if (character_shift) {
223 if (record->event.pressed) {
224 if (character_shift) {
233 if (record->event.pressed) {
234 if (character_shift) {
243 if (record->event.pressed) {
244 if (character_shift) {
253 if (record->event.pressed) {
254 if (character_shift) {
263 if (record->event.pressed) {
264 if (character_shift) {