-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.c
100 lines (87 loc) · 2.25 KB
/
cmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* File: cmd.c
* Author: [email protected]
*
* Created on 18. April 2023, 21:18
*/
#include <string.h>
#include <stdlib.h>
#include "cmd.h"
#include "usart.h"
#include "eink.h"
#include "display.h"
#include "font.h"
#include "unifont.h"
#include "dejavu.h"
#include "bitmaps.h"
/**
* Sets the frame buffer to black (0xff) or white (0x00).
* @param data
*/
static void clear(char *data) {
strtok(data, " ");
char *end;
uint8_t color = strtol(strtok(NULL, " "), &end, 16);
setFrame(color);
}
/**
* Writes one line of text in the given font to the given row and column.
* @param data
*/
static void text(char *data) {
strtok(data, " ");
char *end;
uint16_t row = strtol(strtok(NULL, " "), &end, 10);
uint16_t col = strtol(strtok(NULL, " "), &end, 10);
char *font = strtok(NULL, " ");
char *text = strtok(NULL, "\0");
const __flash Font *unifont = &unifontFont;
const __flash Font *dejavu = &dejaVuFont;
switch(*font) {
case FONT_UNIFONT: writeString(row, col, unifont, text); break;
case FONT_DEJAVU: writeString(row, col, dejavu, text); break;
default: break;
}
}
/**
* Writes the bitmap with the given index to the given row and column.
* @param data
*/
static void bitmap(char *data) {
strtok(data, " ");
char *end;
uint16_t row = strtol(strtok(NULL, " "), &end, 10);
uint16_t col = strtol(strtok(NULL, " "), &end, 10);
uint8_t index = strtol(strtok(NULL, " "), &end, 10);
writeBitmap(row, col, index);
}
/**
* Updates the display with either fast or full update mode.
* @param data
*/
static void update(char *data) {
strtok(data, " ");
char *end;
uint8_t fast = strtol(strtok(NULL, " "), &end, 10);
display(fast);
}
/**
* Writes the Unifont demo in fast update mode.
*/
static void demo(void) {
setFrame(0x00);
writeBitmap(1, 198, TUX);
unifontDemo();
display(true);
}
void handleCmd(char *data) {
printString("\r\n");
switch(*data) {
case CMD_CLEAR: clear(data); break;
case CMD_TEXT: text(data); break;
case CMD_BITMAP: bitmap(data); break;
case CMD_DEMO: demo(); break;
case CMD_UPDATE: update(data); break;
default: break;
}
}