17#ifndef MAXMATRIX_SRC_MAXMATRIX_H_
18#define MAXMATRIX_SRC_MAXMATRIX_H_
86 bool auto_update_{
true};
88 uint32_t last_shift_{0};
101 void StartShift(
State shift_state);
125 Matrix(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin,
139 return panel_.GetNumberOfModules();
144 return panel_.GetNumberOfColumns();
158 return shift_interval_;
163 return panel_.GetWired().GetChain().GetDataInPin();
168 return panel_.GetWired().GetChain().GetChipSelectPin();
173 return panel_.GetWired().GetChain().GetClockPin();
179 return panel_.GetModuleType();
185 return panel_.GetMatrixOrientation();
190 return text_.GetSpaceBetweenChars();
201 panel_.GetColumn(module, column));
234 return text_.GetFont();
243 panel_.GetWired().GetChain().SetDataInPin(data_in_pin);
252 panel_.GetWired().GetChain().SetChipSelectPin(chip_select_pin);
261 panel_.GetWired().GetChain().SetClockPin(clock_pin);
283 shift_interval_ = shift_interval;
326 panel_.SetColumn(column, value);
332 panel_.SetColumn(module, column, value);
347 panel_.SetRow(row, values);
353 panel_.SetRow(module, row, value);
358 void SetDot(int16_t column, int16_t row,
bool value) {
359 panel_.SetDot(column, row, value);
366 int16_t x0, int16_t y0, int16_t x1, int16_t y1,
bool value) {
367 panel_.DrawLine(x0, y0, x1, y1, value);
374 int16_t x, int16_t y, int16_t width, int16_t height,
bool value) {
375 panel_.DrawRect(x, y, width, height, value);
382 int16_t x, int16_t y, int16_t width, int16_t height,
bool value) {
383 panel_.FillRect(x, y, width, height, value);
388 void DrawCircle(int16_t x, int16_t y, int16_t radius,
bool value) {
389 panel_.DrawCircle(x, y, radius, value);
418 panel_.DrawBitmap(x, y, height, bitmap);
501 text_.SetSpaceBetweenChars(space_between_chars);
550 panel_.SetModuleType(module_type);
557 panel_.SetMatrixOrientation(matrix_orientation);
589 void Update() { panel_.GetWired().Send(); }
593 panel_.GetWired().Clear();
605 panel_.GetWired().GetChain().WriteRegisterAll(
606 register_address, register_value, panel_.GetNumberOfModules());
611 panel_.ShiftLeft(fill);
617 Byte const shifted_out{panel_.ShiftLeft(shifted_in)};
624 panel_.ShiftRight(fill);
630 Byte const shifted_out{panel_.ShiftRight(shifted_in)};
637 panel_.ShiftUp(fill);
643 panel_.ShiftDown(fill);
673 bool previous_auto_update_;
682 : matrix_{matrix}, previous_auto_update_{matrix.GetAutoUpdate()} {
688 ~Batch() { matrix_.get().SetAutoUpdate(previous_auto_update_); }
707template <u
int8_t NumberOfModules>
733template <u
int8_t NumberOfModules>
736 "a chain has 1 to kMaxNumberOfModules modules");
748 MatrixOf(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin)
749 : internal::Buffer<NumberOfModules>{},
750 Matrix{data_in_pin, chip_select_pin, clock_pin, this->
buffer_} {}
A byte of raw data, as a column of dots, which is no number.
Transfer to the chain of MAX7219.
Commands for the matrix, one per line of text.
The font of the MaxMatrix library.
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_SHIFT_INTERVAL_INIT_VALUE
The milliseconds per column of a shifting text, until Matrix::SetShiftInterval(); 0 for a step on eve...
Definition MaxMatrixConfig.h:69
constexpr uint8_t kMaxNumberOfModules
The most modules a chain may have: a column is counted in a byte throughout, as an index into the buf...
Definition MaxMatrixConfig.h:92
constexpr size_t BufferSize(size_t modules)
The bytes of the buffer of a chain, one per column.
Definition MaxMatrixConfig.h:100
constexpr uint8_t kRowNumberOfModule
The rows of one module, and of the matrix.
Definition MaxMatrixConfig.h:85
Why a call did not do what it was asked.
#define MAXMATRIX_REPORT_ERROR(Api, Call)
Passes on what Call returns, after reporting its error, if it has one, under Api.
Definition MaxMatrixError.h:40
The values of a switch of the configuration, and the end of a text.
State
What a Matrix is doing, as Matrix::GetState() tells it.
Definition MaxMatrix.h:40
@ kReady
Definition MaxMatrix.h:44
@ kNone
Definition MaxMatrix.h:41
@ kCharShift
Definition MaxMatrix.h:48
@ kInit
Definition MaxMatrix.h:42
@ kStringShift
Definition MaxMatrix.h:46
The matrix as the viewer sees it.
ModuleType
How the LEDs of a module are wired to its MAX7219, named as MD_MAX72XX names its hardware types.
Definition Panel.h:57
ShiftFill
What comes in at the edge a shift leaves empty.
Definition Panel.h:78
@ kZero
Definition Panel.h:79
MatrixOrientation
How the whole matrix is turned: by 180 degrees for a board mounted upside down.
Definition Panel.h:28
A C array that knows its size, as std::array, and make_array(), which takes the size from the values.
Batch(Batch const &)=delete
Not copyable: a copy would put auto update back twice.
~Batch()
Puts auto update back as it was, which sends the picture if it was on.
Definition MaxMatrix.h:688
Batch & operator=(Batch const &)=delete
Not assignable, as it is not copyable.
Batch(Matrix &matrix)
Turns auto update of matrix off until the end of the block.
Definition MaxMatrix.h:681
A byte of raw data: eight dots of a column or a row, or the value of a register of the MAX7219.
Definition Byte.h:45
MatrixOf(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin)
Makes the matrix on the chain at these pins.
Definition MaxMatrix.h:748
The matrix a sketch draws on: a chain of 8x8 modules, in the coordinates the viewer sees.
Definition MaxMatrix.h:81
void DrawBitmap(int16_t x, int16_t y, uint8_t height, span< uint8_t const > bitmap)
Draws a picture from flash with its top left corner at x, y.
Definition MaxMatrix.h:416
MAXMATRIX_NODISCARD Status GetRow(int16_t row, span< Byte > values)
Gives a row of the matrix, one byte per module.
Definition MaxMatrix.h:218
Matrix & operator=(Matrix const &)=delete
Not assignable, as it is not copyable.
void ShiftDown(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one row down.
Definition MaxMatrix.h:642
Status SetCharWithShift(char c)
Starts shifting a char in from the right, until it stands at the right edge.
void SetDot(int16_t column, int16_t row, bool value)
Lights a dot or turns it off.
Definition MaxMatrix.h:358
MAXMATRIX_NODISCARD uint8_t GetNumberOfColumns() const
Returns the columns of the matrix, eight per module.
Definition MaxMatrix.h:143
void ShiftTask()
Shifts a text or a char one column further, if the shift interval has passed.
Status SetTextWithShift(span< char const > text, bool repeat=false)
Starts shifting a text in from the right, until its last char stands at the right edge,...
void SetSprite(int16_t x, int16_t y, Sprite const &sprite)
Draws a sprite with its top left corner at x, y.
Definition MaxMatrix.h:543
void DrawBitmap(int16_t x, int16_t y, span< uint8_t const > bitmap)
Draws a picture from flash, 8 rows high, with its top left corner at x, y.
Definition MaxMatrix.h:410
void SetDataInPin(uint8_t data_in_pin)
Sets the pin DIN of the chain is connected to.
Definition MaxMatrix.h:242
Byte ShiftLeft(Byte shifted_in)
Shifts the whole picture one column to the left, with a column of the sketch coming in at the right.
Definition MaxMatrix.h:616
void SetMatrixOrientation(MatrixOrientation matrix_orientation)
Sets how the whole matrix is turned.
Definition MaxMatrix.h:556
void SetAutoUpdate(bool auto_update)
Sets whether what is drawn is sent at once.
Status SetIntensity(uint8_t intensity)
Sets how bright every LED is lit.
MAXMATRIX_NODISCARD Result< Byte > GetColumn(uint8_t module, uint8_t column)
Returns a column of a module.
Definition MaxMatrix.h:199
void SetShiftInterval(uint16_t shift_interval)
Sets the milliseconds per column of a shifting text.
Definition MaxMatrix.h:282
void ShiftLeft(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one column to the left.
Definition MaxMatrix.h:610
Matrix(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin, span< Byte > buffer)
Makes a matrix on the chain at these pins, in the buffer given, and empties it.
void SetDisplayTest(bool display_test)
Lights every LED at full brightness, or shows the picture again.
void SetSpaceBetweenChars(uint8_t space_between_chars)
Sets the empty columns between two chars of a text.
Definition MaxMatrix.h:500
MAXMATRIX_NODISCARD uint16_t GetShiftInterval() const
Returns the milliseconds per column of a shifting text; see SetShiftInterval().
Definition MaxMatrix.h:157
MAXMATRIX_NODISCARD bool GetAutoUpdate() const
Returns whether every function that draws sends its result at once; see SetAutoUpdate().
Definition MaxMatrix.h:153
void ShiftRight(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one column to the right.
Definition MaxMatrix.h:623
MAXMATRIX_NODISCARD uint8_t GetChipSelectPin() const
Returns the pin CS of the chain is connected to.
Definition MaxMatrix.h:167
void SetRow(uint8_t module, uint8_t row, Byte value)
Sets a row of a module.
Definition MaxMatrix.h:352
void SetShutdown(bool shutdown)
Turns the LEDs of every MAX7219 off, or on again.
Byte ShiftRight(Byte shifted_in)
Shifts the whole picture one column to the right, with a column of the sketch coming in at the left.
Definition MaxMatrix.h:629
MAXMATRIX_NODISCARD uint8_t GetSpaceBetweenChars() const
Returns the empty columns between two chars of a text.
Definition MaxMatrix.h:189
void SetChipSelectPin(uint8_t chip_select_pin)
Sets the pin CS of the chain is connected to.
Definition MaxMatrix.h:251
~Matrix()=default
Leaves the LEDs as they are.
MAXMATRIX_NODISCARD Result< Byte > GetRow(uint8_t module, uint8_t row)
Returns a row of a module.
Definition MaxMatrix.h:223
void Clear()
Turns every LED off.
Definition MaxMatrix.h:592
void ShiftUp(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one row up.
Definition MaxMatrix.h:636
void Update()
Sends what was drawn since the last update.
Definition MaxMatrix.h:589
void DrawCircle(int16_t x, int16_t y, int16_t radius, bool value)
Draws the outline of a circle.
Definition MaxMatrix.h:388
Status SetText(span< char const > text)
Draws a text from the left edge, as far as it fits.
Definition MaxMatrix.h:463
MAXMATRIX_NODISCARD State GetState() const
Returns what the matrix is doing; State::kReady once a shifted text is complete.
Definition MaxMatrix.h:149
void FillRect(int16_t x, int16_t y, int16_t width, int16_t height, bool value)
Draws a rectangle with its inside.
Definition MaxMatrix.h:381
Status SetFont(span< uint8_t const > font)
Sets the font every char is drawn in from now on.
Definition MaxMatrix.h:530
Status SetChar(int16_t x, int16_t y, char c)
Draws a char with its top left corner at x, y.
Definition MaxMatrix.h:433
void SetClockPin(uint8_t clock_pin)
Sets the pin CLK of the chain is connected to.
Definition MaxMatrix.h:260
MAXMATRIX_NODISCARD span< uint8_t const > GetFont() const
Returns the font every char is drawn in.
Definition MaxMatrix.h:233
MAXMATRIX_NODISCARD uint8_t GetNumberOfModules() const
Returns the modules of the chain.
Definition MaxMatrix.h:138
void SetColumn(uint8_t module, uint8_t column, Byte value)
Sets a column of a module.
Definition MaxMatrix.h:331
MAXMATRIX_NODISCARD MatrixOrientation GetMatrixOrientation() const
Returns how the whole matrix is turned; see SetMatrixOrientation().
Definition MaxMatrix.h:184
void StopShift()
Stops a shifting text or char where it is.
MAXMATRIX_NODISCARD Result< Byte > GetColumn(int16_t column)
Returns a column of the matrix.
Definition MaxMatrix.h:194
MAXMATRIX_NODISCARD Result< bool > GetDot(int16_t column, int16_t row)
Returns whether a dot is lit.
Definition MaxMatrix.h:228
Matrix(Matrix const &)=delete
Not copyable: the copy would draw into the same buffer.
void DrawRect(int16_t x, int16_t y, int16_t width, int16_t height, bool value)
Draws the outline of a rectangle.
Definition MaxMatrix.h:373
void SetColumn(int16_t column, Byte value)
Sets a column of the matrix.
Definition MaxMatrix.h:325
void Init()
Sets the chain up: the pins, every register of every MAX7219, and every LED off.
void RegisterWrite(uint8_t register_address, uint8_t register_value)
Writes one register of every MAX7219 in the chain, at once.
Definition MaxMatrix.h:604
void SetModuleType(ModuleType module_type)
Sets how the LEDs of every module are wired.
Definition MaxMatrix.h:549
MAXMATRIX_NODISCARD ModuleType GetModuleType() const
Returns how the LEDs of every module are wired; see SetModuleType().
Definition MaxMatrix.h:178
void SetRow(int16_t row, span< Byte const > values)
Sets a row of the matrix, one byte per module.
Definition MaxMatrix.h:346
MAXMATRIX_NODISCARD uint8_t GetClockPin() const
Returns the pin CLK of the chain is connected to.
Definition MaxMatrix.h:172
void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, bool value)
Draws a straight line from one dot to another, both ends included.
Definition MaxMatrix.h:365
MAXMATRIX_NODISCARD uint8_t GetDataInPin() const
Returns the pin DIN of the chain is connected to.
Definition MaxMatrix.h:162
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
The buffer of a MatrixOf.
Definition MaxMatrix.h:708
array< Byte, BufferSize(NumberOfModules)> buffer_
One byte per column.
Definition MaxMatrix.h:711
The matrix as the viewer sees it: columns, rows and dots in the viewer's coordinates.
Definition Panel.h:94
Text on the matrix: chars and strings in the font, standing or shifting in.
Definition Text.h:33
static void SetSprite(Panel &panel, int16_t x, int16_t y, Sprite const &sprite)
Draws a sprite with its top left corner at x, y.
A reference to a T that is never null and owns nothing.
Definition reference_wrapper.h:43
A view of size() elements that another owns: a font, a bitmap, a text or a buffer.
Definition span.h:64
A reference that copies, as std::reference_wrapper, for gnu++11 without the standard library.
Elements that lie elsewhere, reached by index within their size, as std::span.
A sprite of your own: its width, its height and up to five columns.
Definition Font.h:38
A C array of N elements that knows its size.
Definition array.h:42