semf
printer.h
Go to the documentation of this file.
1
10#ifndef SEMF_COMMUNICATION_ESH_PRINTER_H_
11#define SEMF_COMMUNICATION_ESH_PRINTER_H_
12
17#include <string_view>
18
19namespace semf::esh
20{
25{
26public:
30 enum class ErrorCode : uint8_t
31 {
32 Print_IsBusy = 0
33 };
38 explicit Printer(semf::UartHardware& uart);
39 Printer(const Printer& other) = delete;
40 virtual ~Printer() = default;
47 void print(char character, size_t count);
54 void print(std::string_view text, size_t count = 1);
58 void readCharacter();
63 bool isBusy() const;
65 SEMF_SIGNAL(dataWritten);
67 SEMF_SIGNAL(dataAvailable, char);
70
71private:
73 void onCharWritten();
75 void onStringWritten();
77 void onDataAvailable();
79 void onDataWritten();
80
82 semf::UartHardware& m_uart;
84 char m_char;
86 std::string_view m_string;
88 size_t m_count = 0;
90 bool m_busy = false;
92 uint8_t m_availableChar;
94 SEMF_SLOT(m_onDataAvailableSlot, Printer, *this, onDataAvailable);
96 SEMF_SLOT(m_onCharWrittenSlot, Printer, *this, onCharWritten);
98 SEMF_SLOT(m_onStringWrittenSlot, Printer, *this, onStringWritten);
100 SEMF_SLOT(m_uartErrorSlot, Signal<Error>, error, emitSignal, Error);
102 static constexpr Error::ClassID kSemfClassId = Error::ClassID::Printer;
103};
104} // namespace semf::esh
105#endif // SEMF_COMMUNICATION_ESH_PRINTER_H_
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
ClassID
Semf class IDs.
Definition: error.h:28
Signal for lightweight signal/slot implementation. One signal can be connected to multiple slots and ...
Definition: signal.h:41
Class for using UART hardware.
Definition: uarthardware.h:22
Class for string related UART communication. Using this class outside of an esh-context can make sens...
Definition: printer.h:25
ErrorCode
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring...
Definition: printer.h:31
void print(char character, size_t count)
Prints a single character count times.
Definition: printer.cpp:20
Printer(const Printer &other)=delete
Printer(semf::UartHardware &uart)
Constructor.
Definition: printer.cpp:14
SEMF_SIGNAL(error, Error)
SEMF_SIGNAL(dataAvailable, char)
bool isBusy() const
Indicates wether the printer is busy.
Definition: printer.cpp:64
void readCharacter()
Triggers a read cyle for reading a single character.
Definition: printer.cpp:58
SEMF_SIGNAL(dataWritten)
virtual ~Printer()=default