-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_prompt.c
executable file
·46 lines (39 loc) · 1 KB
/
serial_prompt.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
#include <stdbool.h>
#include <ctype.h>
#include "hw_types.h"
#include "consoleUtils.h"
#include "serial.h"
#include "serial_prompt.h"
static promptActions_t s_actions;
static volatile uint8_t s_rxByte = 0;
static void serialRxIsrCallback(uint8_t rxByte);
void SerialPrompt_init(promptActions_t actions)
{
Serial_init();
Serial_setRxIsrCallback(serialRxIsrCallback);
s_actions = actions;
}
static void serialRxIsrCallback(uint8_t rxByte)
{
s_rxByte = rxByte;
}
void SerialPrompt_doBackgroundWork(void)
{
if (s_rxByte != 0) {
uint8_t normalizedCommand = tolower(s_rxByte);
if (normalizedCommand == '?') {
s_actions.helpAction();
} else if (normalizedCommand == 'a') {
s_actions.aAction();
} else if (normalizedCommand == 'b') {
s_actions.bAction();
} else if (normalizedCommand == 'x') {
s_actions.xAction();
} else if ('0' <= normalizedCommand && normalizedCommand <= '9') {
s_actions.numberAction(normalizedCommand - '0');
} else {
s_actions.errorAction();
}
s_rxByte = 0;
}
}