Skip to content

Feature/custom charset - #24

Open
Thokoop wants to merge 6 commits into
jhoff:mainfrom
Thokoop:feature/custom-charset
Open

Feature/custom charset#24
Thokoop wants to merge 6 commits into
jhoff:mainfrom
Thokoop:feature/custom-charset

Conversation

@Thokoop

@Thokoop Thokoop commented Apr 15, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@socquique

Copy link
Copy Markdown

Been running this branch on an 8 module display for a while — thanks for it, the custom charset is genuinely useful.

One thing I ran into that you may want to look at: the constructor derives the flap count from the length of the string, and never reads the charset setting it is handed.

if (len < 37) {
    charSetSize = numChars = 37;                       // charsetSize ignored
} else if (len >= 37) {
    charSetSize = numChars = (len >= 48) ? 48 : 37;    // charsetSize ignored
} else {
    // unreachable: len < 37 and len >= 37 already cover everything
}

Two consequences:

  • Selecting Standard (37) with a 48 character string in the box silently gives you a 48 flap drum, and vice versa.
  • More awkward, a typo that leaves the string at, say, 40 characters turns a 48 flap display into a 37 flap one. Every charPositions[] entry is then computed from the wrong divisor, so every character lands somewhere else on the drum. Nothing tells you why.

The settings page already validates that the string length equals charset — the red/green border and the n/48 counter — so the firmware and the UI disagree about which one is authoritative.

What worked for me is letting charset decide the geometry and treating custom_charset purely as the labels:

charSetSize = numChars = (charsetSize == 48) ? 48 : 37;

if ((int) charsetStr.length() == numChars) {
    usingCustomChars = true;
    for (int i = 0; i < numChars; i++) {
        customChars[i] = charsetStr[i];
    }
} else {
    usingCustomChars = false;
    const char *fallback = (numChars == 48) ? ExtendedChars : StandardChars;
    for (int i = 0; i < numChars; i++) {
        customChars[i] = fallback[i];
    }
    // ...and say so on serial, so a mismatch is diagnosable
}

customChars[numChars] = '\0';

A mismatched string then falls back to the built-in set for the size you actually selected, instead of quietly changing the size. Also drops the unreachable third branch.

Happy to open this as a PR against your branch if it's useful — didn't want to push at your work uninvited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants