From 5f9d4e33b3ca2416efb9aa9079a181a854762e82 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 22 Feb 2023 11:47:23 +0000 Subject: [PATCH] Interstate 75: Auto-detect board version. --- .../examples/interstate75/75W/buttons.py | 2 +- .../examples/interstate75/75W/cheerlights.py | 2 +- .../examples/interstate75/75W/clock.py | 2 +- micropython/modules_py/interstate75.md | 38 +++++++------------ micropython/modules_py/interstate75.py | 6 ++- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/micropython/examples/interstate75/75W/buttons.py b/micropython/examples/interstate75/75W/buttons.py index 7916dbc5..dd3c36b0 100644 --- a/micropython/examples/interstate75/75W/buttons.py +++ b/micropython/examples/interstate75/75W/buttons.py @@ -4,7 +4,7 @@ Push either switch A, switch B or the BOOT switch (in the case of the non-w vers ''' import interstate75 -i75 = interstate75.Interstate75(display=interstate75.DISPLAY_INTERSTATE75_32X32, interstate75w=True) +i75 = interstate75.Interstate75(display=interstate75.DISPLAY_INTERSTATE75_32X32) graphics = i75.display width = i75.width diff --git a/micropython/examples/interstate75/75W/cheerlights.py b/micropython/examples/interstate75/75W/cheerlights.py index 14aff563..79d41231 100644 --- a/micropython/examples/interstate75/75W/cheerlights.py +++ b/micropython/examples/interstate75/75W/cheerlights.py @@ -77,7 +77,7 @@ def update_leds(): print("LEDs updated!") -i75 = interstate75.Interstate75(display=interstate75.DISPLAY_INTERSTATE75_32X32, interstate75w=True) +i75 = interstate75.Interstate75(display=interstate75.DISPLAY_INTERSTATE75_32X32) graphics = i75.display width = i75.width diff --git a/micropython/examples/interstate75/75W/clock.py b/micropython/examples/interstate75/75W/clock.py index 7be075c0..c95ca905 100644 --- a/micropython/examples/interstate75/75W/clock.py +++ b/micropython/examples/interstate75/75W/clock.py @@ -14,7 +14,7 @@ import network import ntptime from interstate75 import Interstate75, DISPLAY_INTERSTATE75_32X32 -i75 = Interstate75(display=DISPLAY_INTERSTATE75_32X32, interstate75w=True) +i75 = Interstate75(display=DISPLAY_INTERSTATE75_32X32) graphics = i75.display width = i75.width diff --git a/micropython/modules_py/interstate75.md b/micropython/modules_py/interstate75.md index b83810b5..f54bcc6b 100644 --- a/micropython/modules_py/interstate75.md +++ b/micropython/modules_py/interstate75.md @@ -4,9 +4,10 @@ This library offers convenient functions for interacting with [Interstate75](htt ## Table of Content - [Table of Content](#table-of-content) -- [Interstate75 Module](#interstate75-class) +- [Interstate75 Class](#interstate75-class) - [Switches](#switches) - [RGB LED](#rgb-led) +- [Display](#display) @@ -14,7 +15,18 @@ This library offers convenient functions for interacting with [Interstate75](htt The `Interstate75` class deals with RGB LED and buttons on the Interstate75 and 75W. To create one, import the `interstate75` module, then define a new `board` variable. -This is where you define the HUB75 matrix display size that you wish to use by defining `display=` + +```python +import interstate75 + +display = interstate75.DISPLAY_INTERSTATE75_32X32 + +board = interstate75.Interstate75(display=display) +``` + +The version of Intersate75 you're using should be automatically detected. Check `board.interstate75w` to verify this. It should be `True` on a W and `False` on a non-W. + +You can choose the HUB75 matrix display size that you wish to use by defining `display=` as one of the following: ```python DISPLAY_INTERSTATE75_32X32 @@ -27,28 +39,6 @@ DISPLAY_INTERSTATE75_192X64 DISPLAY_INTERSTATE75_256X64 ``` -You are able to set which version of the Interstate75 that you are using with the `interstate75w=`. By default this value is set to `True` to use the Interstate75W button layout. By setting it to `False` the module will use the Interstate75 button layout. If you are using an Interstate75W it is important to set this value to interstate75w=True, otherwise this could disable the WiFi in your project - -```python -import interstate75 - -display = interstate75.DISPLAY_INTERSTATE75_32X32 - -board = interstate75.Interstate75(display=display) -``` - -Or for an Interstate75W. - -```python -import interstate75 - -display = interstate75.DISPLAY_INTERSTATE75_32X32 - -board = interstate75.Interstate75(display=display, interstate75w=False) # This is the setup to be able to access the both A and BOOT on the Interstate75 (non W) -``` - -From here, all features can be accessed by calling functions on `board`. In addition, when using Qwiic / Stemma QT devices, the I2C channel to use can be accessed with `board.i2c`. - ### Switches Interstate75 and 75W have two switches in the front of the board. To read one of the switches, call `.switch_pressed(switch)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`. This returns `True` when the specified switch is pressed, and `False` otherwise. diff --git a/micropython/modules_py/interstate75.py b/micropython/modules_py/interstate75.py index 2637377e..13f231e0 100644 --- a/micropython/modules_py/interstate75.py +++ b/micropython/modules_py/interstate75.py @@ -2,6 +2,7 @@ from pimoroni import RGBLED, Button from picographics import PicoGraphics, DISPLAY_INTERSTATE75_32X32, DISPLAY_INTERSTATE75_64X32, DISPLAY_INTERSTATE75_96X32, DISPLAY_INTERSTATE75_128X32, DISPLAY_INTERSTATE75_64X64, DISPLAY_INTERSTATE75_128X64, DISPLAY_INTERSTATE75_192X64, DISPLAY_INTERSTATE75_256X64 from pimoroni_i2c import PimoroniI2C import hub75 +import sys # Index Constants SWITCH_A = 0 @@ -40,12 +41,13 @@ class Interstate75: # Count Constants NUM_SWITCHES = 2 - def __init__(self, display, panel_type=hub75.PANEL_GENERIC, stb_invert=False, color_order=hub75.COLOR_ORDER_RGB, interstate75w=False): + def __init__(self, display, panel_type=hub75.PANEL_GENERIC, stb_invert=False, color_order=hub75.COLOR_ORDER_RGB): + self.interstate75w = "Pico W" in sys.implementation._machine self.display = PicoGraphics(display=display) self.width, self.height = self.display.get_bounds() self.hub75 = hub75.Hub75(self.width, self.height, panel_type=panel_type, stb_invert=stb_invert, color_order=color_order) self.hub75.start() - if interstate75w: + if self.interstate75w: self._switch_pins = self.SWITCH_PINS_W else: self._switch_pins = self.SWITCH_PINS