Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion OIL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Status: `open`, `in progress`, `done`, `dropped` (with the reason in the item).
| 38 | Results that must not be ignored | 36 | done | #94 |
| 39 | MC/DC coverage | 34 | done | #95, #96 |
| 40 | Braced initialization checked | 34 | done | #93 |
| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107, #113, #115, #116, #117, #118, #121, #122, #124, #125, #126, #127, #128 |
| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107, #113, #115, #116, #117, #118, #121, #122, #124, #125, #126, #127, #128, #129 |
| 42 | A newer avr-gcc as a cross-check | 41 | done | |
| 43 | Bit operations in one class, from the template | 41 | done | #109 |

Expand Down Expand Up @@ -1207,6 +1207,18 @@ column and row of `ControlDotPanel`, which `ControlCommandTest` and the order of
digits)` is left too: `SimulatorTest` pins the call that escapes a char, the frame log of the page
only the eye.

As reviewed for the chapter Types on 2026-11-17, its review parts T-1, T-8, T-13, T-14, T-18, T-19
and T-23, T-17 being done above. As built for the library: a char is stored and the length counted
in two statements (T-14); `internal::Panel::ChangeMapping()` walks its pairs of modules by one
counter rather than two in one declaration (T-13, T-14); the header of a font is read by one
function into a struct, where `CheckFont()` and `GetGlyph()` each assigned four variables declared
ahead, which also takes a copy the chapter Functions missed (T-13, FN-13); `Command` passes a
command with a value on in a function of its own, where its status was declared ahead (T-13); a
condition of three parts in `CheckFont()` and a sum in that of `CharShiftTask()` are named steps
(T-18); and the `auto` of a port register says why the type cannot be written (T-8). On the Uno,
in every variant, every example 8 bytes of flash smaller, Shutdown 12 and SerialControl 22; the
same RAM.

### 42 A newer avr-gcc as a cross-check

`max_matrix::Byte` (41) made the examples 30 to 50 bytes of flash larger on the Uno at first,
Expand Down
52 changes: 29 additions & 23 deletions src/Command/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Result<CommandState> Command::Feed(Matrix& matrix, char c, Print& answer) {
}
if (c != kLineEnd) {
if (line_length_ < MAXMATRIX_COMMAND_LINE_LENGTH) {
line_[line_length_++] = c;
line_[line_length_] = c;
line_length_++;
} else {
line_too_long_ = true;
}
Expand Down Expand Up @@ -103,36 +104,41 @@ Result<CommandState> Command::Feed(Matrix& matrix, char c, Print& answer) {
// with the end of the name, and passes it on by name.
Result<CommandState> Command::Execute(Matrix& matrix, Print& answer) {
uint8_t const separator{Find(0, kValueSeparator)};
Status status{Error::kOk};

if (line_[separator] == internal::kNullCharacter) {
if (0 == strcmp_P(line_.data(), PSTR("picture"))) {
AnswerPicture(matrix, answer);
return CommandState::kAnswered;
}
if (0 != strcmp_P(line_.data(), PSTR("clear"))) {
return Error::kUnknownCommand;
}
matrix.Clear();
} else {
if (line_[separator] != internal::kNullCharacter) {
line_[separator] = internal::kNullCharacter;
auto const value{static_cast<uint8_t>(separator + 1)};
if (0 == strcmp_P(line_.data(), PSTR("text"))) {
status = ExecuteText(matrix, value);
} else if (0 == strcmp_P(line_.data(), PSTR("textShift"))) {
status = ExecuteTextShift(matrix, value);
} else if (0 == strcmp_P(line_.data(), PSTR("setDot"))) {
status = ExecuteDot(matrix, value);
} else {
status = ExecuteSetting(matrix, value);
Status const status{
ExecuteWithValue(matrix, static_cast<uint8_t>(separator + 1))};
if (!status.IsOk()) {
return status.GetError();
}
return CommandState::kDone;
}
if (0 == strcmp_P(line_.data(), PSTR("picture"))) {
AnswerPicture(matrix, answer);
return CommandState::kAnswered;
}
if (!status.IsOk()) {
return status.GetError();
if (0 != strcmp_P(line_.data(), PSTR("clear"))) {
return Error::kUnknownCommand;
}
matrix.Clear();
return CommandState::kDone;
}

// Passes a command NAME=VALUE on by its name, which ends where `value` starts.
Status Command::ExecuteWithValue(Matrix& matrix, uint8_t value) {
if (0 == strcmp_P(line_.data(), PSTR("text"))) {
return ExecuteText(matrix, value);
}
if (0 == strcmp_P(line_.data(), PSTR("textShift"))) {
return ExecuteTextShift(matrix, value);
}
if (0 == strcmp_P(line_.data(), PSTR("setDot"))) {
return ExecuteDot(matrix, value);
}
return ExecuteSetting(matrix, value);
}

// Returns the position of the first `c` in the line from `from` on, or that of
// the line's null character if there is none. The line always ends with one,
// as Feed() puts it there.
Expand Down
1 change: 1 addition & 0 deletions src/Command/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Command {
MAXMATRIX_NODISCARD Result<CommandState> Execute(Matrix& matrix,
Print& answer);
MAXMATRIX_NODISCARD uint8_t Find(uint8_t from, char c) const;
MAXMATRIX_NODISCARD Status ExecuteWithValue(Matrix& matrix, uint8_t value);
MAXMATRIX_NODISCARD Status ExecuteTextShift(Matrix& matrix, uint8_t value);
MAXMATRIX_NODISCARD Status ExecuteText(Matrix& matrix, uint8_t value) const;
MAXMATRIX_NODISCARD Status ExecuteDot(Matrix& matrix, uint8_t value);
Expand Down
77 changes: 39 additions & 38 deletions src/Font/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ uint8_t ReadByte(span<uint8_t const> font, size_t position) {
return pgm_read_byte(&font[position]);
}

/* what the header of a font says: its first and last code, the height of its
* chars, and where the width of its first char lies */
struct FontHeader {
uint16_t first;
uint16_t last;
uint8_t height;
size_t offset;
};

// Reads the header of `font`; one that is not of version 1 is read as one of
// version 2, as CheckFont() takes no other.
FontHeader ReadHeader(span<uint8_t const> font) {
if (ReadByte(font, kVersionPosition) == kVersion1) {
return FontHeader{ReadByte(font, kFirstPosition),
ReadByte(font, kLastPosition1),
ReadByte(font, kHeightPosition1), kHeaderLength1};
}
return FontHeader{ReadNumber(font, kFirstPosition),
ReadNumber(font, kLastPosition2),
ReadByte(font, kHeightPosition2), kHeaderLength2};
}

} // namespace

/*
Expand Down Expand Up @@ -205,35 +227,28 @@ Status Font::CheckFont(span<uint8_t const> font) {
}

uint8_t const version{ReadByte(font, kVersionPosition)};
uint16_t first{0};
uint16_t last{0};
uint8_t height{0};
size_t offset{0};

if (version == kVersion1) {
first = ReadByte(font, kFirstPosition);
last = ReadByte(font, kLastPosition1);
height = ReadByte(font, kHeightPosition1);
offset = kHeaderLength1;
} else if ((version == kVersion2) && (font.size() >= kHeaderLength2)) {
first = ReadNumber(font, kFirstPosition);
last = ReadNumber(font, kLastPosition2);
height = ReadByte(font, kHeightPosition2);
offset = kHeaderLength2;
} else {
bool const header_whole{
(version == kVersion1) ||
((version == kVersion2) && (font.size() >= kHeaderLength2))};
if (!header_whole) {
return Error::kNotAFont;
}
if ((first > last) || (height < 1) || (height > kRowNumberOfModule)) {
FontHeader const header{ReadHeader(font)};
bool const has_chars{header.first <= header.last};
bool const height_fits{(header.height >= 1) &&
(header.height <= kRowNumberOfModule)};
if (!has_chars || !height_fits) {
return Error::kNotAFont;
}
size_t offset{header.offset};
/* the loop ends at the last char rather than past it, as a last char of
* 0xFFFF has no next */
for (uint16_t code{first};; code++) {
for (uint16_t code{header.first};; code++) {
if (offset >= font.size()) {
return Error::kNotAFont;
}
offset += ReadByte(font, offset) + 1u;
if (code == last) {
if (code == header.last) {
break;
}
}
Expand All @@ -246,35 +261,21 @@ Status Font::CheckFont(span<uint8_t const> font) {
* five bytes from flash cost less than the RAM to keep them.
*/
Result<Glyph> Font::GetGlyph(span<uint8_t const> font, char c) {
bool const version_1{ReadByte(font, kVersionPosition) == kVersion1};
FontHeader const header{ReadHeader(font)};
uint16_t const code{static_cast<uint8_t>(c)};
uint16_t first{0};
uint16_t last{0};
uint8_t height{0};
size_t offset{0};

if (version_1) {
first = ReadByte(font, kFirstPosition);
last = ReadByte(font, kLastPosition1);
height = ReadByte(font, kHeightPosition1);
offset = kHeaderLength1;
} else {
first = ReadNumber(font, kFirstPosition);
last = ReadNumber(font, kLastPosition2);
height = ReadByte(font, kHeightPosition2);
offset = kHeaderLength2;
}
if ((code < first) || (code > last)) {
if ((code < header.first) || (code > header.last)) {
return Error::kUnknownChar;
}
for (uint16_t skipped{first}; skipped < code; skipped++) {
size_t offset{header.offset};
for (uint16_t skipped{header.first}; skipped < code; skipped++) {
offset += ReadByte(font, offset) + 1u;
}
uint8_t const width{ReadByte(font, offset)};
if (width == 0) {
return Error::kUnknownChar;
}
return Glyph{font.subspan(offset + 1).first(width), height};
return Glyph{font.subspan(offset + 1).first(width), header.height};
}

DecodedChar Font::DecodeChar(span<char const> text) {
Expand Down
8 changes: 6 additions & 2 deletions src/Matrix/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,12 @@ void Panel::ChangeMapping(MatrixOrientation matrix_orientation,
MatrixOrientation const old_matrix_orientation{matrix_orientation_};
ModuleType const old_module_type{module_type_};

for (int16_t left{0}, right{static_cast<int16_t>(GetNumberOfModules() - 1)};
left <= right; left++, right--) {
uint8_t const modules{GetNumberOfModules()};
// a module in the middle of an odd chain pairs with itself
auto const pairs{static_cast<uint8_t>((modules + 1) / 2)};

for (uint8_t left{0}; left < pairs; left++) {
auto const right{static_cast<uint8_t>(modules - 1 - left)};
uint8_t const left_column{
static_cast<uint8_t>(left * kColumnNumberOfModule)};
uint8_t const right_column{
Expand Down
3 changes: 2 additions & 1 deletion src/Max7219/Chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ void Chain::ShiftOut(uint8_t value) {
* The core's portOutputRegister() makes the register's address, a number read
* from flash, a pointer, and SREG is the status register at its fixed
* address: clang-tidy reports both on the Uno, where there is no other way to
* a port.
* a port. T-8: auto, as the register is a volatile uint8_t on the board and
* the mock's object of its own on the host.
*/
auto* const data_in_register{portOutputRegister(
data_in_.port)}; /* NOLINT(performance-no-int-to-ptr) */
Expand Down
8 changes: 5 additions & 3 deletions src/Text/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@ bool Text::CharShiftTask(Panel& panel) {
panel.ShiftLeft(Byte{});
sprite_shift_counter_++;

/* the step after the char and the spaces behind it have come in */
auto const done{
static_cast<uint16_t>(glyph_.columns.size() + space_between_chars_ + 1)};

/* if sprite is completed set only spaces */
if (sprite_shift_counter_ <= glyph_.columns.size()) {
X const left{static_cast<int16_t>(panel.GetNumberOfColumns() -
sprite_shift_counter_)};
SetGlyph(panel, Point{left, Y{0}}, glyph_);
} else if (sprite_shift_counter_ ==
static_cast<uint16_t>(glyph_.columns.size() +
space_between_chars_ + 1)) {
} else if (sprite_shift_counter_ == done) {
/* if sprite and spaces are completed task has finished */
sprite_shift_counter_ = kShiftIdle;
return false;
Expand Down