semf
arrowcontrol.cpp
Go to the documentation of this file.
1
11
12namespace semf::esh
13{
14ArrowControl::ArrowControl(Printer& printer, const int& count, bool echo)
15: m_printer(printer),
16 m_count(count),
17 m_echo(echo)
18{
19}
20
22{
23 if (m_busy)
24 {
25 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::Start_IsBusy)));
26 return;
27 }
28 m_busy = true;
29
30 m_printer.dataAvailable.connect(m_onSecondCharSlot);
31 m_printer.readCharacter();
32}
33
34void ArrowControl::onSecondChar(char c)
35{
36 m_printer.dataAvailable.disconnect(m_onSecondCharSlot);
37 if (c != '[')
38 {
39 m_busy = false;
40 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::OnSecondChar_UnexpectedChar)));
41 return;
42 }
43
44 m_printer.dataAvailable.connect(m_onThirdCharSlot);
45 m_printer.readCharacter();
46}
47
48void ArrowControl::onThirdChar(char c)
49{
50 m_printer.dataAvailable.disconnect(m_onThirdCharSlot);
51 if (c != 'A' && c != 'B')
52 {
53 m_busy = false;
54 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::OnThirdChar_UnexpectedChar)));
55 return;
56 }
57
58 m_c = c;
59 m_printer.dataWritten.connect(m_onCleared);
60 m_printer.print("\b \b", m_echo ? m_count : m_count + 4);
61}
62
63void ArrowControl::onCleared()
64{
65 m_printer.dataWritten.disconnect(m_onCleared);
66 m_busy = false;
67 if (m_c == 'A')
68 {
69 up();
70 }
71 else
72 {
73 down();
74 }
75}
76} // namespace semf::esh
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
void start()
Starts the reading process.
ArrowControl(Printer &printer, const int &count, bool echo)
Constructor.
Class for string related UART communication. Using this class outside of an esh-context can make sens...
Definition: printer.h:25
void print(char character, size_t count)
Prints a single character count times.
Definition: printer.cpp:20
void readCharacter()
Triggers a read cyle for reading a single character.
Definition: printer.cpp:58