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, #129, #130, #132, #133, #134, #135, #136, #139, #140, #141, #142, #143, #144, #145, #146, #147, #148, #149, #150 |
| 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, #130, #132, #133, #134, #135, #136, #139, #140, #141, #142, #143, #144, #145, #146, #147, #148, #149, #150, #151 |
| 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 @@ -1402,6 +1402,18 @@ looped over; the tests of a matrix not set up share a fixture of their own rathe
one beside the fixture's; and a test that leaves the LEDs other than the buffer, as one in
shutdown, puts them back at its end, with the reason.

As built for the end of a shift (TS-4), as decided on 2026-11-19: a shifting char brings one
column per step, its glyph and the space behind it, and no more, and a text ends once the space
behind its last char has come in, in a call that shifts nothing, as one more caller of the
function that reads the next char made avr-gcc keep it out of line, 46 to 64 bytes of flash; as
built, the examples that shift text are 14 to 20 bytes smaller instead. The first step of a char
had brought two of its columns at once, against the interval the reference gives per column, the
step that ended a char one more empty column, and the end of a text another; the reference had
promised that the last char stands at the right edge. The test of the chain lengths found it, as
it was the first to write the end of a shift down rather than see that something was lit. The
tests that pinned the old steps, the pace of a shift among them, and the panels of `ScrollText`
and `Messages` at their time in simavr, each one column behind, follow.

### 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
14 changes: 7 additions & 7 deletions simulator/Expected/Messages.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.............##.................
............#..#.......##.......
............#....#.##.#..#.###..
............#.##.##...#..#.#..#.
............#..#.#....#..#.#..#.
............#..#.#....#..#.#..#.
.............###.#.....###.#..#.
..............##................
.............#..#.......##......
.............#....#.##.#..#.###.
.............#.##.##...#..#.#..#
.............#..#.#....#..#.#..#
.............#..#.#....#..#.#..#
..............###.#.....###.#..#
................................
14 changes: 7 additions & 7 deletions simulator/Expected/ScrollText.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.##..##...........#...#.........
..#...#...........#...#.........
..#...#...##......#...#..##..#.#
..#...#..#..#.....#.#.#.#..#.##.
..#...#..#..#.....#.#.#.#..#.#..
..#...#..#..#.....#.#.#.#..#.#..
.###.###..##.......#.#...##..#..
..##..##...........#...#........
...#...#...........#...#........
...#...#...##......#...#..##..#.
#..#...#..#..#.....#.#.#.#..#.##
#..#...#..#..#.....#.#.#.#..#.#.
...#...#..#..#.....#.#.#.#..#.#.
..###.###..##.......#.#...##..#.
................................
21 changes: 11 additions & 10 deletions src/MaxMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ class Matrix {
}

/*!
* \brief Starts shifting a char in from the right, until it stands at the
* right edge.
* \brief Starts shifting a char in from the right, until it and the space
* behind it have come in.
*
* ShiftTask() takes the steps; GetState() is State::kCharShift until
* the char stands.
* ShiftTask() takes the steps, one column each; GetState() is
* State::kCharShift until the char stands, the space behind it at the
* right edge, so that a char shifted in after it keeps its distance.
*
* \param[in] c The char, latin-1.
* \return Error::kOk; Error::kNotSetUp before an Init() has succeeded; or
Expand All @@ -436,13 +437,13 @@ class Matrix {
}

/*!
* \brief Starts shifting a text in from the right, until its last char stands
* at the right edge, or over and over.
* \brief Starts shifting a text in from the right, until its last char and
* the space behind it have come in, or over and over.
*
* ShiftTask() takes the steps; GetState() is State::kStringShift
* until the text stands. A text that repeats goes on with its first char
* right after its last, so a few spaces at its end keep the two apart; it
* shifts until StopShift() or the next shift starts.
* ShiftTask() takes the steps, one column each; GetState() is
* State::kStringShift until the text stands. A text that repeats goes on with
* its first char right after its last, so a few spaces at its end keep the
* two apart; it shifts until StopShift() or the next shift starts.
*
* \param[in] text The text, UTF-8 or latin-1, up to its terminating null
* character or the end of the span, as for SetText().
Expand Down
50 changes: 25 additions & 25 deletions src/Text/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,40 +123,40 @@ bool Text::CharShiftTask(Panel& panel) {
// An empty column comes in, by the column rather than ShiftFill, so
// that a sketch that only shifts text does not link the other fills.
panel.ShiftLeft(Byte{});
sprite_shift_counter_++;
uint16_t const step{sprite_shift_counter_};
auto const width{static_cast<uint16_t>(glyph_.columns.size())};

/* 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_)};
if (step <= width) {
X const left{static_cast<int16_t>(panel.GetNumberOfColumns() - step)};
SetGlyph(panel, Point{left, Y{0}}, glyph_);
} else if (sprite_shift_counter_ == done) {
/* if sprite and spaces are completed task has finished */
sprite_shift_counter_ = kShiftIdle;
return false;
}
return true;
// Done with the step that brings the last column of its space: one more
// brought an empty column no char asked for.
auto const last_step{static_cast<uint16_t>(width + space_between_chars_)};
bool const going_on{step < last_step};
sprite_shift_counter_ =
going_on ? static_cast<uint16_t>(step + 1u) : kShiftIdle;
return going_on;
}

/*
* The next char is read once the one before has come in, in the call after the
* step that brought its space; at the end of the text that call shifts
* nothing. Read in the step that ends a char instead, the text ended without
* that call, but avr-gcc kept ReadNextChar() out of line for its second caller,
* 46 to 64 bytes of flash in the examples that shift text.
*/
bool Text::StringShiftTask(Panel& panel) {
/* has char shift task finished shifting sprite or char */
if (sprite_shift_counter_ == kShiftIdle) {
ReadNextChar();
if (sprite_shift_counter_ == kShiftStart) {
CharShiftTask(panel);
} else { /* end of string reached, task has finished */
panel.ShiftLeft(Byte{});
return false;
}
} else {
/* go on shifting Sprite; the end of a char is not the end of the string */
CharShiftTask(panel);
}
return true;
bool const going_on{sprite_shift_counter_ != kShiftIdle};
if (going_on) {
// Whether the char has come in shows in the counter, which the next
// call reads.
Discard(CharShiftTask(panel));
}
return going_on;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Text.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class Text {
*/

/*
* The columns of a char shifted in so far, its space included: kShiftIdle
* while no char is shifting, and kShiftStart when one begins. A count rather
* The step of a char under way, from kShiftStart, one per column of the char
* and of its space: kShiftIdle while no char is shifting. A count rather
* than a state, so the two values are constants, not an enum.
*/
static constexpr uint16_t kShiftIdle{0};
Expand Down
2 changes: 1 addition & 1 deletion test/Font/FontTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ TEST_F(MaxMatrixTest, CharWiderThanASpriteIsDrawnWhole) {
for (uint8_t column{0}; column < 8; column++) {
EXPECT_EQ(
matrix_
.GetColumn(X{static_cast<int16_t>(kNumberOfColumns - 10 + column)})
.GetColumn(X{static_cast<int16_t>(kNumberOfColumns - 9 + column)})
.GetValue()
.ToInteger(),
Bit<uint8_t>::ToMask(column))
Expand Down
40 changes: 15 additions & 25 deletions test/MaxMatrixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,9 @@ TEST_F(MaxMatrixTest, AutoUpdateOnSendsWhatWasDrawn) {
}

/* The tests below tell the steps of a shifting char by the three columns at
* the right edge of the panel, where '#' brings 0x14, 0x3E, 0x14 and 0x3E, the
* first when the shift starts and one more per step, and hold the clock, so
* that a step 50 ms on does not depend on how fast the host is. Up to three
* steps, each leaves the edge another picture. */
std::vector<uint8_t> RightEdge(Matrix const& matrix, uint8_t width = 3) {
std::vector<uint8_t> columns;
for (auto x{static_cast<int16_t>(kNumberOfColumns - width)};
x < kNumberOfColumns; x++) {
columns.push_back(matrix.GetColumn(X{x}).GetValue().ToInteger());
}
return columns;
}

* the right edge of the panel, where '#' brings 0x14, 0x3E and 0x14, one per
* step, and hold the clock, so that a step 50 ms on does not depend on how
* fast the host is. Up to three steps, each leaves the edge another picture. */
/* a char shifting in at 50 ms per step, its shift started at `start` */
class ShiftPaceTest : public MaxMatrixTest {
protected:
Expand All @@ -187,7 +177,7 @@ TEST_F(ShiftPaceTest, FirstStepComesAtOnce) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x00, 0x14}));
}

TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassed) {
Expand All @@ -197,7 +187,7 @@ TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassed) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x00, 0x14}));
}

TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassed) {
Expand All @@ -207,7 +197,7 @@ TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassed) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
}

/* a call after loop() was held up takes one step, not the ones it missed */
Expand All @@ -219,7 +209,7 @@ TEST_F(ShiftPaceTest, LateCallTakesOneStep) {
matrix_.ShiftTask();
matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
}

/* the interval counts from a late step, not from when it was due */
Expand All @@ -232,7 +222,7 @@ TEST_F(ShiftPaceTest, NoStepAnIntervalAfterTheMissedOne) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
}

TEST_F(ShiftPaceTest, StepAnIntervalAfterTheLateOne) {
Expand All @@ -244,7 +234,7 @@ TEST_F(ShiftPaceTest, StepAnIntervalAfterTheLateOne) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x3E, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
}

TEST_F(ShiftPaceTest, IntervalZeroStepsOnEveryCall) {
Expand All @@ -255,11 +245,11 @@ TEST_F(ShiftPaceTest, IntervalZeroStepsOnEveryCall) {
matrix_.ShiftTask();
matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x3E, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
}

/* a new char or text starts at once, however recently the one before took a
* step: '+' brings 0x08, 0x08 and 0x3E */
* step: '+' brings 0x08 first, beside the 0x14 of '#' */
TEST_F(ShiftPaceTest, NewShiftStartsAtOnce) {
StartShift(1000);
matrix_.ShiftTask();
Expand All @@ -268,7 +258,7 @@ TEST_F(ShiftPaceTest, NewShiftStartsAtOnce) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_, 2), (std::vector<uint8_t>{0x08, 0x08}));
EXPECT_EQ(RightEdge(matrix_, 2), (std::vector<uint8_t>{0x14, 0x08}));
}

/* the interval is counted across the overflow of millis() after 49.7 days: a
Expand All @@ -281,7 +271,7 @@ TEST_F(ShiftPaceTest, NoStepJustBeforeTheClockWraps) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x00, 0x14}));
}

TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassedAcrossTheWrap) {
Expand All @@ -291,7 +281,7 @@ TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassedAcrossTheWrap) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x00, 0x14}));
}

TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassedAcrossTheWrap) {
Expand All @@ -301,7 +291,7 @@ TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassedAcrossTheWrap) {

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x14, 0x3E, 0x14}));
EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x14, 0x3E}));
}

TEST_F(MaxMatrixTest, ShutdownDarkensEveryModule) {
Expand Down
19 changes: 19 additions & 0 deletions test/MaxMatrixTestSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ std::vector<std::string> ShownPicture(Matrix& matrix) {
matrix.GetNumberOfColumns());
}

std::vector<uint8_t> RightEdge(max_matrix::Matrix const& matrix,
uint8_t width) {
std::vector<uint8_t> columns;
int16_t const right{matrix.GetNumberOfColumns()};
for (auto x{static_cast<int16_t>(right - width)}; x < right; x++) {
columns.push_back(
matrix.GetColumn(max_matrix::X{x}).GetValue().ToInteger());
}
return columns;
}

void ShiftUntilReady(max_matrix::Matrix& matrix) {
for (uint16_t step{0};
(step < 1000) && (matrix.GetState() != max_matrix::State::kReady);
step++) {
matrix.ShiftTask();
}
}

void DrawPattern(Matrix& matrix) {
for (uint8_t x{0}; x < matrix.GetNumberOfColumns(); x++) {
for (uint8_t y{0}; y < max_matrix::kRowNumberOfModule; y++) {
Expand Down
8 changes: 8 additions & 0 deletions test/MaxMatrixTestSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ std::vector<std::string> Picture(DotType dot,
/* the picture as the library reports it, through GetDot */
std::vector<std::string> ShownPicture(max_matrix::Matrix& matrix);

/* the columns at the right edge of the panel, as numbers, where a char that
* shifts in shows what it has brought so far */
std::vector<uint8_t> RightEdge(max_matrix::Matrix const& matrix,
uint8_t width = 3);

/* steps the shift running now until it is done, at most 1000 steps */
void ShiftUntilReady(max_matrix::Matrix& matrix);

/* draws Pattern() on the whole panel, dot by dot */
void DrawPattern(max_matrix::Matrix& matrix);

Expand Down
36 changes: 35 additions & 1 deletion test/Text/TextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_F(MaxMatrixTest, TextShiftFinishes) {
* item 31): once the picture before it has left the panel, every picture comes
* again one pass of the text later, with no column between its end and its
* start, and the shift does not end. A pass is what the text takes when it does
* not repeat, less the last step, which only shifts the panel once more. */
* not repeat, less the last call, which only finds its end. */
TEST_F(MaxMatrixTest, RepeatingTextStartsOver) {
char const text[] = "Hi \xC4\x01 ";
std::vector<std::vector<std::string>> pictures;
Expand Down Expand Up @@ -235,5 +235,39 @@ TEST_F(MaxMatrixTest, NoSpaceBetweenCharsSetsThemSideBySide) {
}));
}

/* the first step of a char brought two of its columns at once, though the
* interval is the time per column: '#' brings 0x14 first */
TEST_F(MaxMatrixTest, CharShiftBringsOneColumnPerStep) {
ASSERT_EQ(matrix_.SetCharWithShift('#').GetError(), Error::kOk);

matrix_.ShiftTask();

EXPECT_EQ(RightEdge(matrix_), (std::vector<uint8_t>{0x00, 0x00, 0x14}));
}

/* a char shifts in with the space behind it, and no more: each char brought
* one more empty column, as the step that ended it shifted as well; '#' is
* 0x14, 0x3E, 0x14, 0x3E, 0x14 */
TEST_F(MaxMatrixTest, CharShiftEndsWithTheSpaceBehindIt) {
ASSERT_EQ(matrix_.SetCharWithShift('#').GetError(), Error::kOk);

ShiftUntilReady(matrix_);

EXPECT_EQ(RightEdge(matrix_, 6),
(std::vector<uint8_t>{0x14, 0x3E, 0x14, 0x3E, 0x14, 0x00}));
}

/* a text ends with the space behind its last char: the end of a text brought
* one more empty column; "Hi" is 7F 08 08 7F, the space, 44 7D 40 */
TEST_F(MaxMatrixTest, TextShiftEndsWithTheSpaceBehindItsLastChar) {
ASSERT_EQ(matrix_.SetTextWithShift("Hi").GetError(), Error::kOk);

ShiftUntilReady(matrix_);

EXPECT_EQ(RightEdge(matrix_, 9),
(std::vector<uint8_t>{0x7F, 0x08, 0x08, 0x7F, 0x00, 0x44, 0x7D,
0x40, 0x00}));
}

} // namespace
} // namespace max_matrix
Loading