From 1c22b94101a970ad91444e621e51fbaed69c8993 Mon Sep 17 00:00:00 2001 From: virskl Date: Wed, 18 Nov 2026 17:38:33 +0100 Subject: [PATCH 1/2] A shift brings one column per step and ends with the space behind its char The reference promises that a shifting char or text comes in until its last char stands at the right edge, and gives the shift interval as the time per column. The first step of a char brought two of its columns at once, the step that ended a char one more empty column, and the end of a text another: "Hi" stopped with three empty columns at the right edge, a single char with two. As decided, every char now comes in one column per step with the space behind it and no more, so that chars shifted one after another keep their distance; a text ends once the space behind its last char has come in, in a call that shifts nothing. The reference says so. Reading the next char in the step that ends a char instead ended a text without that call, but avr-gcc kept the reading out of line for its second caller, 46 to 64 bytes of flash; as built, the examples that shift text are 14 to 20 bytes smaller. The tests that pinned the old steps follow, the pace of a shift among them, and the panels of ScrollText and Messages at their time in simavr, each the same text one column behind. RightEdge() and ShiftUntilReady() moved into the test support, as the tests of the text use them too. --- OIL.md | 12 ++++++++ simulator/Expected/Messages.txt | 14 ++++----- simulator/Expected/ScrollText.txt | 14 ++++----- src/MaxMatrix.h | 21 ++++++------- src/Text/Text.cpp | 50 +++++++++++++++---------------- src/Text/Text.h | 4 +-- test/Font/FontTest.cpp | 2 +- test/MaxMatrixTest.cpp | 40 ++++++++++--------------- test/MaxMatrixTestSupport.cpp | 19 ++++++++++++ test/MaxMatrixTestSupport.h | 8 +++++ test/Text/TextTest.cpp | 36 +++++++++++++++++++++- 11 files changed, 142 insertions(+), 78 deletions(-) diff --git a/OIL.md b/OIL.md index 7ad7f68..012814f 100644 --- a/OIL.md +++ b/OIL.md @@ -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, diff --git a/simulator/Expected/Messages.txt b/simulator/Expected/Messages.txt index 9e0c7a6..49c672f 100644 --- a/simulator/Expected/Messages.txt +++ b/simulator/Expected/Messages.txt @@ -1,8 +1,8 @@ -.............##................. -............#..#.......##....... -............#....#.##.#..#.###.. -............#.##.##...#..#.#..#. -............#..#.#....#..#.#..#. -............#..#.#....#..#.#..#. -.............###.#.....###.#..#. +..............##................ +.............#..#.......##...... +.............#....#.##.#..#.###. +.............#.##.##...#..#.#..# +.............#..#.#....#..#.#..# +.............#..#.#....#..#.#..# +..............###.#.....###.#..# ................................ diff --git a/simulator/Expected/ScrollText.txt b/simulator/Expected/ScrollText.txt index eeb26a4..70f430e 100644 --- a/simulator/Expected/ScrollText.txt +++ b/simulator/Expected/ScrollText.txt @@ -1,8 +1,8 @@ -.##..##...........#...#......... -..#...#...........#...#......... -..#...#...##......#...#..##..#.# -..#...#..#..#.....#.#.#.#..#.##. -..#...#..#..#.....#.#.#.#..#.#.. -..#...#..#..#.....#.#.#.#..#.#.. -.###.###..##.......#.#...##..#.. +..##..##...........#...#........ +...#...#...........#...#........ +...#...#...##......#...#..##..#. +#..#...#..#..#.....#.#.#.#..#.## +#..#...#..#..#.....#.#.#.#..#.#. +...#...#..#..#.....#.#.#.#..#.#. +..###.###..##.......#.#...##..#. ................................ diff --git a/src/MaxMatrix.h b/src/MaxMatrix.h index 98931b7..97e6f1d 100644 --- a/src/MaxMatrix.h +++ b/src/MaxMatrix.h @@ -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 @@ -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(). diff --git a/src/Text/Text.cpp b/src/Text/Text.cpp index 31e4190..4af8594 100644 --- a/src/Text/Text.cpp +++ b/src/Text/Text.cpp @@ -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(glyph_.columns.size())}; - /* the step after the char and the spaces behind it have come in */ - auto const done{ - static_cast(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(panel.GetNumberOfColumns() - - sprite_shift_counter_)}; + if (step <= width) { + X const left{static_cast(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(width + space_between_chars_)}; + bool const going_on{step < last_step}; + sprite_shift_counter_ = + going_on ? static_cast(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; } /* diff --git a/src/Text/Text.h b/src/Text/Text.h index c6bdc58..b348659 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -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}; diff --git a/test/Font/FontTest.cpp b/test/Font/FontTest.cpp index 9b49479..0434a03 100644 --- a/test/Font/FontTest.cpp +++ b/test/Font/FontTest.cpp @@ -222,7 +222,7 @@ TEST_F(MaxMatrixTest, CharWiderThanASpriteIsDrawnWhole) { for (uint8_t column{0}; column < 8; column++) { EXPECT_EQ( matrix_ - .GetColumn(X{static_cast(kNumberOfColumns - 10 + column)}) + .GetColumn(X{static_cast(kNumberOfColumns - 9 + column)}) .GetValue() .ToInteger(), Bit::ToMask(column)) diff --git a/test/MaxMatrixTest.cpp b/test/MaxMatrixTest.cpp index 3fd100c..3df2321 100644 --- a/test/MaxMatrixTest.cpp +++ b/test/MaxMatrixTest.cpp @@ -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 RightEdge(Matrix const& matrix, uint8_t width = 3) { - std::vector columns; - for (auto x{static_cast(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: @@ -187,7 +177,7 @@ TEST_F(ShiftPaceTest, FirstStepComesAtOnce) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x00, 0x14})); } TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassed) { @@ -197,7 +187,7 @@ TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassed) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x00, 0x14})); } TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassed) { @@ -207,7 +197,7 @@ TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassed) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x14, 0x3E, 0x14})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); } /* a call after loop() was held up takes one step, not the ones it missed */ @@ -219,7 +209,7 @@ TEST_F(ShiftPaceTest, LateCallTakesOneStep) { matrix_.ShiftTask(); matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x14, 0x3E, 0x14})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); } /* the interval counts from a late step, not from when it was due */ @@ -232,7 +222,7 @@ TEST_F(ShiftPaceTest, NoStepAnIntervalAfterTheMissedOne) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x14, 0x3E, 0x14})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); } TEST_F(ShiftPaceTest, StepAnIntervalAfterTheLateOne) { @@ -244,7 +234,7 @@ TEST_F(ShiftPaceTest, StepAnIntervalAfterTheLateOne) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x3E, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x14, 0x3E, 0x14})); } TEST_F(ShiftPaceTest, IntervalZeroStepsOnEveryCall) { @@ -255,11 +245,11 @@ TEST_F(ShiftPaceTest, IntervalZeroStepsOnEveryCall) { matrix_.ShiftTask(); matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x3E, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{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(); @@ -268,7 +258,7 @@ TEST_F(ShiftPaceTest, NewShiftStartsAtOnce) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_, 2), (std::vector{0x08, 0x08})); + EXPECT_EQ(RightEdge(matrix_, 2), (std::vector{0x14, 0x08})); } /* the interval is counted across the overflow of millis() after 49.7 days: a @@ -281,7 +271,7 @@ TEST_F(ShiftPaceTest, NoStepJustBeforeTheClockWraps) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x00, 0x14})); } TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassedAcrossTheWrap) { @@ -291,7 +281,7 @@ TEST_F(ShiftPaceTest, NoStepBeforeTheIntervalHasPassedAcrossTheWrap) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x00, 0x14})); } TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassedAcrossTheWrap) { @@ -301,7 +291,7 @@ TEST_F(ShiftPaceTest, StepOnceTheIntervalHasPassedAcrossTheWrap) { matrix_.ShiftTask(); - EXPECT_EQ(RightEdge(matrix_), (std::vector{0x14, 0x3E, 0x14})); + EXPECT_EQ(RightEdge(matrix_), (std::vector{0x00, 0x14, 0x3E})); } TEST_F(MaxMatrixTest, ShutdownDarkensEveryModule) { diff --git a/test/MaxMatrixTestSupport.cpp b/test/MaxMatrixTestSupport.cpp index 4f83c5a..0f4d5a3 100644 --- a/test/MaxMatrixTestSupport.cpp +++ b/test/MaxMatrixTestSupport.cpp @@ -120,6 +120,25 @@ std::vector ShownPicture(Matrix& matrix) { matrix.GetNumberOfColumns()); } +std::vector RightEdge(max_matrix::Matrix const& matrix, + uint8_t width) { + std::vector columns; + int16_t const right{matrix.GetNumberOfColumns()}; + for (auto x{static_cast(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++) { diff --git a/test/MaxMatrixTestSupport.h b/test/MaxMatrixTestSupport.h index d771eca..10d60ae 100644 --- a/test/MaxMatrixTestSupport.h +++ b/test/MaxMatrixTestSupport.h @@ -205,6 +205,14 @@ std::vector Picture(DotType dot, /* the picture as the library reports it, through GetDot */ std::vector 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 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); diff --git a/test/Text/TextTest.cpp b/test/Text/TextTest.cpp index 318f528..23ed662 100644 --- a/test/Text/TextTest.cpp +++ b/test/Text/TextTest.cpp @@ -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> pictures; @@ -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{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{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{0x7F, 0x08, 0x08, 0x7F, 0x00, 0x44, 0x7D, + 0x40, 0x00})); +} + } // namespace } // namespace max_matrix From b2dea4f1e2da2277e6ebe279d4425725c0627270 Mon Sep 17 00:00:00 2001 From: virskl Date: Wed, 18 Nov 2026 17:38:42 +0100 Subject: [PATCH 2/2] OIL.md: 41 is #151 as well --- OIL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OIL.md b/OIL.md index 012814f..6119fdd 100644 --- a/OIL.md +++ b/OIL.md @@ -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 |