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 void enable_printing(void) {
24 printing_enabled = true;
28 void disable_printing(void) {
29 printing_enabled = false;
32 uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
34 // uint8_t keycode_to_ascii[0xFF][2];
36 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
38 void print_char(char c) {
44 void print_string(char c[]) {
45 for(uint8_t i = 0; i < strlen(c); i++)
49 void print_box_string(const char text[]) {
50 size_t len = strlen(text);
51 char out[len * 3 + 8];
53 for (uint8_t i = 0; i < len; i++) {
60 for (uint8_t i = 0; i < len; i++) {
61 out[len + 4 + i] = text[i];
63 out[len * 2 + 4] = 0xB3;
64 out[len * 2 + 5] = '\n';
67 out[len * 2 + 6] = 0xC0;
68 for (uint8_t i = 0; i < len; i++) {
69 out[len * 2 + 7 + i] = 0xC4;
71 out[len * 3 + 7] = 0xD9;
72 out[len * 3 + 8] = '\n';
77 bool process_printer(uint16_t keycode, keyrecord_t *record) {
78 if (keycode == PRINT_ON) {
82 if (keycode == PRINT_OFF) {
87 if (printing_enabled) {
89 case KC_EXLM ... KC_RPRN:
99 if (record->event.pressed) {
110 if (record->event.pressed) {
111 print_box_string("This is a line of text!");
115 if (record->event.pressed) {
121 if (record->event.pressed) {
127 if (record->event.pressed) {
128 if (character_shift) {
129 print_char(0x41 + (keycode - KC_A));
131 print_char(0x61 + (keycode - KC_A));
137 if (record->event.pressed) {
138 if (character_shift) {
139 print_char(shifted_numbers[keycode - KC_1]);
141 print_char(0x30 + ((keycode - KC_1 + 1) % 10));
147 if (record->event.pressed) {
148 if (character_shift) {
157 if (record->event.pressed) {
158 if (character_shift) {
167 if (record->event.pressed) {
168 if (character_shift) {
177 if (record->event.pressed) {
178 if (character_shift) {
187 if (record->event.pressed) {
188 if (character_shift) {
197 if (record->event.pressed) {
198 if (character_shift) {
207 if (record->event.pressed) {
208 if (character_shift) {
217 if (record->event.pressed) {
218 if (character_shift) {
227 if (record->event.pressed) {
228 if (character_shift) {
237 if (record->event.pressed) {
238 if (character_shift) {
247 if (record->event.pressed) {
248 if (character_shift) {
257 if (record->event.pressed) {
258 if (character_shift) {