Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seven segment character displays (single and multiple) #930

Merged
merged 29 commits into from Mar 11, 2021
Merged

Conversation

waveform80
Copy link
Member

The continuation of #488.

I re-worked the original PR to provide the character string assigned via the "display" method as the string value of the component, and added some logic to handle the reverse mapping (deriving the string state from the LED state).

This did raise a few complications; it's entirely possible, even likely, to have a n:1 mapping of strings to LED states (consider 5 and S, or 0 and O) in which case which reverse mapping should be selected, should it be stable, etc. etc. Then the question arose of how to deal with the decimal point LED given that it essentially applies to all states, and doubling the size of the mapping isn't particularly pleasant. Hence, I've dealt with that as an effectively distinct state (and thus character) in the value. Hence one can assign "A" to the display, or "A." and in the latter case it'll happily accept the trailing "." as an indication of the decimal-point's state, then using the remaining prefix to determine the state of the rest of the LEDs.

At that point I decided it would be quite nice if it could be made generic (for n-segment displays) so I added a mapping parser from a simple text format and moved the default mapping into a resource'd text file (see gpiozero/fonts/7seg.txt in the new PR, along with gpiozero/fonts/14seg.txt).

Initially, I'd decided that there wasn't time to deal with the myriad questions that a multi-character display generates (threading etc. etc.) so I'd started by excising that chunk of the PR, but then I wound up hacking on it over the weekend and getting further than expected so that's wound up back in this PR too. Given that the single character display now has a string type, it made obvious sense for the multi-character one to do likewise. This also generated a few issues regarding the multiple decimal points often available in these displays but the simple solution is to allow any sequence of strings, whether that's a multi-character string (with no decimal points) or a tuple of strings which can thus explicitly split at decimal points.

I've tweaked the threading stuff from the original quite extensively as well: the new code pre-calculates the LED transitions before starting the thread and knows how to activate multiple characters simultaneously if their LED states are equivalent.

Full coverage tests are included for all the new classes.

martinohanlon and others added 22 commits March 5, 2021 17:09
Out of scope for this cycle
Added a "font" attribute which maps *stuff* to the tuple of LED values
where *stuff* can be a string or basically anything that can key a dict.
This gets slightly complicated when a decimal-point is added as that
pretty much dictates that the value has to be a string (unless we want
to treat the DP *entirely* separately but that makes the value even
messier IMO).

Converted Martin's default 7-seg font to a text-based format and added a
parser for it to tools, then revised that parser to work generically for
any number of segments, and added a default 14-seg font for fun (though
I haven't actually got any hardware to test this :)
And add it to the export list
The group parameter's never used (not even implemented in the parent
class), and the name parameter's *almost* never used. Makes far more
sense to just have the target and args/kwargs first.
Add a _parse_state method which'll be useful in the multiplexed version,
and ensure common types in values of LEDCharFont
Yeah, we've got time :)

Added a semi-intelligent transition calculation so we don't bother with
a background thread where we don't need to (all visible chars the same)
and if the display includes multiple of the same char we just re-use
states for them.
Add docs for font and value properties, fix decl in api_boards.rst, add
decls for LEDCharFont, load_segment_font, load_font_7seg, and
load_font_14seg
Including API and an "advanced" recipe (this isn't in the basic section
as it will almost certainly require modification for the user's display
pinout which will probably require interpretation of the circuit
diagram)
Inkscape v1 has changed the command line parameters in a backwards
incompatible fashion. Query the installed version and modify the make
rules as necessary
Good ol' LaTeX isn't so good with Unicode whicch we've now got in
LEDCharDisplay. Switching to the XeTeX engine is now possible on
ReadTheDocs and handles Unicode much more easily, so this commit does
so. This introduces some extra dependencies (added to the development
instructions)
This was referenced Mar 10, 2021
waveform80 and others added 5 commits March 11, 2021 00:16
Need to call shell for shell functions!
Just as there's a tones module, the fonts parsing stuff really doesn't
belong in "tools".
@waveform80
Copy link
Member Author

Fonts split from tools into separate module (and docs chapter) as requested.

Copy link
Member

@bennuttall bennuttall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fixed a reference to tools.load_segment_font but otherwise LGTM

@waveform80 waveform80 merged commit a405689 into master Mar 11, 2021
@waveform80 waveform80 deleted the 7seg branch March 11, 2021 23:44
crs-k pushed a commit to crs-k/pwnagotchi-scoreboard that referenced this pull request Feb 17, 2024
Bumps [gpiozero](https://github.com/gpiozero/gpiozero) from 1.5.1 to
2.0.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/gpiozero/gpiozero/blob/master/docs/changelog.rst">gpiozero's
changelog</a>.</em></p>
<blockquote>
<h1>Release 2.0.1 (2024-02-15)</h1>
<ul>
<li>Fixed Python 3.12 compatibility, and clarify that 3.9 is the lowest
supported
version in our CI configuration
(<code>[#1113](https://github.com/gpiozero/gpiozero/issues/1113)</code>_)</li>
</ul>
<p>.. _<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/1113">#1113</a>:
<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/1113">gpiozero/gpiozero#1113</a></p>
<h1>Release 2.0 (2023-09-12)</h1>
<ul>
<li>Removed Python 2.x support; many thanks to Fangchen Li for a
substantial
amount of work on this!
(<code>[#799](https://github.com/gpiozero/gpiozero/issues/799)</code>_
<code>[#896](https://github.com/gpiozero/gpiozero/issues/896)</code>_)</li>
<li>Removed RPIO pin implementation</li>
<li>Made :class:<code>gpiozero.pins.lgpio.LGPIOFactory</code> the
default factory; the
former default,
:class:<code>gpiozero.pins.rpigpio.RPiGPIOFactory</code>, is now the
second place preference</li>
<li>Added :doc:<code>compat</code> chapter</li>
<li>Added :program:<code>pintest</code> utility</li>
<li>Added Raspberry Pi 5 board data</li>
</ul>
<p>.. _<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/799">#799</a>:
<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/799">gpiozero/gpiozero#799</a>
.. _<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/896">#896</a>:
<a
href="https://redirect.github.com/gpiozero/gpiozero/issues/896">gpiozero/gpiozero#896</a></p>
<h1>Release 1.6.2 (2021-03-18)</h1>
<ul>
<li>Correct docs referring to 1.6.0 as the last version supporting
Python 2</li>
</ul>
<p>.. warning::</p>
<pre><code>This is the last release to support Python 2
</code></pre>
<h1>Release 1.6.1 (2021-03-17)</h1>
<ul>
<li>Fix missing font files for 7-segment displays</li>
</ul>
<h1>Release 1.6.0 (2021-03-14)</h1>
<ul>
<li>Added :class:<code>RotaryEncoder</code> class (thanks to Paulo
Mateus)
(<code>[#482](https://github.com/gpiozero/gpiozero/issues/482)</code><em>,
<code>[#928](https://github.com/gpiozero/gpiozero/issues/928)</code></em>)</li>
<li>Added support for multi-segment character displays with
:class:<code>LEDCharDisplay</code> and
:class:<code>LEDMultiCharDisplay</code> along with &quot;font&quot;
support using :class:<code>LEDCharFont</code> (thanks to Martin
O'Hanlon)
(<code>[#357](https://github.com/gpiozero/gpiozero/issues/357)</code><em>,

<code>[#485](https://github.com/gpiozero/gpiozero/issues/485)</code></em>,
<code>[#488](https://github.com/gpiozero/gpiozero/issues/488)</code><em>,
<code>[#493](https://github.com/gpiozero/gpiozero/issues/493)</code></em>,
<code>[#930](https://github.com/gpiozero/gpiozero/issues/930)</code>_)</li>
<li>Added :class:<code>Pibrella</code> class (thanks to Carl Monk)
(<code>[#773](https://github.com/gpiozero/gpiozero/issues/773)</code><em>,
<code>[#798](https://github.com/gpiozero/gpiozero/issues/798)</code></em>)</li>
<li>Added :class:<code>TrafficpHat</code> class (thanks to Ryan
Walmsley)
(<code>[#845](https://github.com/gpiozero/gpiozero/issues/845)</code><em>,
<code>[#846](https://github.com/gpiozero/gpiozero/issues/846)</code></em>)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/a13848bd9701844c139709750cfa038c59b2ab5f"><code>a13848b</code></a>
Run copyrights script for release</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/3ee415cbfd5de07324696ceadd22ded92c48a517"><code>3ee415c</code></a>
Bump revision and add changelog for release</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/ebf8874bd71d353ebb5f83dcb1fdbc6be58b454d"><code>ebf8874</code></a>
Fix <a
href="https://redirect.github.com/gpiozero/gpiozero/issues/1113">#1113</a></li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/fa114311048c052ea1b6810c235cc0f858720f36"><code>fa11431</code></a>
Set 3.9 as base version, fix 3.12 compatibility</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/981e3f70b00853fd011baf8cd1cb17f241e4ab65"><code>981e3f7</code></a>
Merge pull request <a
href="https://redirect.github.com/gpiozero/gpiozero/issues/1104">#1104</a>
from lurch/patch-2</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/0f09a5a1d0c3b0055cdfe52de3009deea30f8654"><code>0f09a5a</code></a>
Small docs typo</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/e59c55c77bdd635a566ff31815e93a51d54907e8"><code>e59c55c</code></a>
Workaround rtd's ancient flag</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/025ba5bc2f0b7a0936afc792345a0615586f6b61"><code>025ba5b</code></a>
Would help if I specified the right requirement...</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/cba887aa60d3c844ea7e36f8c4d170fd9073d87c"><code>cba887a</code></a>
RTD builds &quot;old&quot; projects with sphinx 1.8</li>
<li><a
href="https://github.com/gpiozero/gpiozero/commit/390caf61ba73af65f39395551c25674631eca7d0"><code>390caf6</code></a>
The root doc default changed to 'contents'</li>
<li>Additional commits viewable in <a
href="https://github.com/gpiozero/gpiozero/compare/v1.5.1...v2.0.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gpiozero&package-manager=pip&previous-version=1.5.1&new-version=2.0.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

None yet

3 participants