Interstate 75: Auto-detect board version.

patch/i75-userbutton
Phil Howard 2023-02-22 11:47:23 +00:00
rodzic 552339a49e
commit 5f9d4e33b3
5 zmienionych plików z 21 dodań i 29 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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.

Wyświetl plik

@ -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