MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
Command.h
Go to the documentation of this file.
1// Copyright 2020 Andreas Burnickl
2// SPDX-License-Identifier: GPL-3.0-or-later
3
12
13#ifndef MAXMATRIX_SRC_COMMAND_COMMAND_H_
14#define MAXMATRIX_SRC_COMMAND_COMMAND_H_
15
16#include "Arduino.h"
17#include "MaxMatrixAttributes.h"
18#include "MaxMatrixConfig.h"
19#include "MaxMatrixError.h"
21#include "Utility/array.h"
22#include "Utility/span.h"
23
24namespace max_matrix {
25
30enum class CommandState : uint8_t {
34};
35
36class Matrix;
37
75class Command {
76 private:
77 /*
78 * As internal::Text is, the class is handed the matrix by every call rather
79 * than keeping a reference to it.
80 */
83 uint8_t line_length_{0};
84 bool line_too_long_{false};
85
86 /*
87 * The commands find their parts by their position in line_, a byte, as the
88 * static_assert below holds the line to: walked by a span instead, as T-20
89 * would have it for a text of unknown length, SerialControl was larger. The
90 * line always ends with a null character, which Feed() puts there, so a
91 * position needs no check against its size.
92 */
93 static constexpr uint16_t kMaxLineLength{0xFF};
94 static_assert(MAXMATRIX_COMMAND_LINE_LENGTH <= kMaxLineLength,
95 "a position in the line has to fit into a byte");
97 Print& answer);
98 MAXMATRIX_NODISCARD uint8_t Find(uint8_t from, char c) const;
99 MAXMATRIX_NODISCARD Status ExecuteTextShift(Matrix& matrix, uint8_t value);
100 MAXMATRIX_NODISCARD Status ExecuteText(Matrix& matrix, uint8_t value) const;
101 MAXMATRIX_NODISCARD Status ExecuteDot(Matrix& matrix, uint8_t value);
102 MAXMATRIX_NODISCARD Status ExecuteSetting(Matrix& matrix,
103 uint8_t value) const;
104 static void AnswerPicture(Matrix& matrix, Print& answer);
105 MAXMATRIX_NODISCARD Result<uint16_t> ConvertToNumber(uint8_t text,
106 uint16_t maximum) const;
107 static char ConvertToHexDigit(uint8_t value);
108
109 public:
112
132 Result<CommandState> Feed(Matrix& matrix, char c, Print& answer);
133};
134
135} // namespace max_matrix
136
137#endif // MAXMATRIX_SRC_COMMAND_COMMAND_H_
CommandState
What Command::Feed() says about the char it was given, when the line did not fail; why it failed is t...
Definition Command.h:30
@ kDone
Definition Command.h:32
@ kPending
Definition Command.h:31
@ kAnswered
Definition Command.h:33
The attributes of a later standard, as macros, where the compiler has them.
#define MAXMATRIX_NODISCARD
Marks a function whose result must not be dropped: the compiler warns where it is.
Definition MaxMatrixAttributes.h:37
Configuration of the MaxMatrix library.
#define MAXMATRIX_COMMAND_LINE_LENGTH
The chars of a line Command takes; it costs twice as many bytes of RAM.
Definition MaxMatrixConfig.h:60
Why a call did not do what it was asked.
The values of a switch of the configuration, and the end of a text.
A C array that knows its size, as std::array, and make_array(), which takes the size from the values.
Command()
Makes a reader at the start of an empty line.
Result< CommandState > Feed(Matrix &matrix, char c, Print &answer)
Takes the next char of a command line, and carries the line out and answers it at its end.
The matrix a sketch draws on: a chain of 8x8 modules, in the coordinates the viewer sees.
Definition MaxMatrix.h:81
What a getter of a single value returns: the value, or why there is none.
Definition MaxMatrixError.h:141
What a function that can fail returns when it has no value to return.
Definition MaxMatrixError.h:73
Elements that lie elsewhere, reached by index within their size, as std::span.
A C array of N elements that knows its size.
Definition array.h:42