-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.h
152 lines (136 loc) · 3.63 KB
/
interface.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Dependencies.
*/
#include <stdarg.h>
#ifdef ARDUINO
#include <Arduino_LED_Matrix.h>
#else
#include <stdio.h>
#include <stdint.h>
#endif
/*
Constants.
*/
#define PIN_PUSHBUTTON 2
/*
Types.
*/
#ifndef ARDUINO
typedef uint8_t byte;
#endif
/*
Globals.
*/
#ifdef ARDUINO
ArduinoLEDMatrix ledMatrix;
#endif
#define M 1
#define _ 0
byte bitmapIdle[8][12] = {
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, _, _, _, _, _, _, _ },
{ _, _, M, _, _, _, _, _, _, _, _, _ },
{ _, _, M, _, _, _, _, _, _, _, _, _ },
{ _, _, M, _, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
};
byte bitmapScanning[8][12] = {
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, _, _, _, _, _, _, _ },
{ _, M, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, _, _, _, _, _, _, _ },
{ _, _, _, M, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, M, _, M, _, M, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
};
byte bitmapResetting[8][12] = {
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, _, _, _, _, _, _, _, _, _ },
{ _, M, _, M, _, _, _, _, _, _, _, _ },
{ _, M, M, _, _, _, _, _, _, _, _, _ },
{ _, M, _, M, _, _, _, _, _, _, _, _ },
{ _, M, _, M, _, M, _, M, _, M, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
};
byte bitmapFailSD[8][12] = {
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, M, _, M, M, _, _, M, _, _ },
{ _, M, _, _, _, M, _, M, _, M, _, _ },
{ _, M, M, M, _, M, _, M, _, M, _, _ },
{ _, _, _, M, _, M, _, M, _, _, _, _ },
{ _, M, M, M, _, M, M, _, _, M, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
};
byte bitmapFailSensor[8][12] = {
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, M, M, _, _, M, M, M, _, M, _, _ },
{ _, M, _, M, _, M, _, _, _, M, _, _ },
{ _, M, _, M, _, M, M, M, _, M, _, _ },
{ _, M, _, M, _, _, _, M, _, _, _, _ },
{ _, M, M, _, _, M, M, M, _, M, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, _, _, _, _, _, _, _, _ },
};
#undef M
#undef _
/*
Functions.
*/
void log(const char *format, ...)
{
char message[256];
va_list args;
va_start(args, format);
vsnprintf(message, sizeof(message) / sizeof(*message), format, args);
va_end(args);
#ifdef ARDUINO
Serial.print(message);
#else
fprintf(stderr, "%s", message);
#endif
}
void showState()
{
byte (*bitmap)[12] = bitmapIdle;
switch (state) {
case IDLE: bitmap = bitmapIdle; break;
case SCANNING: bitmap = bitmapScanning; break;
case RESETTING: bitmap = bitmapResetting; break;
case FAIL_SD: bitmap = bitmapFailSD; break;
case FAIL_SENSOR: bitmap = bitmapFailSensor; break;
}
#ifdef ARDUINO
ledMatrix.renderBitmap(bitmap, 8, 12);
#else
log("\n");
for (int i = 0; i < sizeof(bitmapIdle) / sizeof(*bitmapIdle); ++i) {
for (int j = 0; j < sizeof(*bitmapIdle) / sizeof(**bitmapIdle); ++j) {
log("\033[48;5;25m\033[38;5;%dm◢◤\033[0m", bitmap[i][j] ? 210 : 252);
}
log("\n");
}
#endif
}
void toggleState()
{
switch (state) {
case IDLE: state = SCANNING; break;
case SCANNING: state = RESETTING; break;
default: break;
}
// TODO: Use a new setState function here that encompasses showState?
}
void setupInterface()
{
#ifdef ARDUINO
pinMode(PIN_PUSHBUTTON, INPUT);
attachInterrupt(digitalPinToInterrupt(PIN_PUSHBUTTON), toggleState, FALLING);
Serial.begin(115200);
ledMatrix.begin();
#endif
}