Skip to content

Commit 2ef3b8c

Browse files
committed
adding more comments everywhere and usage stubs for the properties
1 parent 9e83b89 commit 2ef3b8c

File tree

1 file changed

+74
-12
lines changed

1 file changed

+74
-12
lines changed

Diff for: adafruit_monsterm4sk.py

+74-12
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@
4242
__version__ = "0.0.0-auto.0"
4343
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MonsterM4sk.git"
4444

45-
SS_LIGHTSENSOR_PIN = 2
45+
# Seesaw pin numbers
46+
SS_LIGHTSENSOR_PIN = 2 # "through-hole" light sensor near left eye
4647
SS_VCCSENSOR_PIN = 3
47-
SS_BACKLIGHT_PIN = 5
48-
SS_TFTRESET_PIN = 8
48+
SS_BACKLIGHT_PIN = 5 # left screen backlight
49+
SS_TFTRESET_PIN = 8 # left screen reset
50+
51+
# buttons above left eye. Match silkscreen :)
4952
SS_SWITCH1_PIN = 9
5053
SS_SWITCH2_PIN = 10
5154
SS_SWITCH3_PIN = 11
@@ -60,19 +63,27 @@ class MonsterM4sk:
6063
"""
6164

6265
def __init__(self, i2c=None):
66+
"""
67+
:param i2c: The I2C bus to use, will try board.I2C()
68+
if not supplied
69+
"""
6370
displayio.release_displays()
6471

6572
if i2c is None:
6673
i2c = board.I2C()
6774

6875
# set up on-board seesaw
6976
self._ss = Seesaw(i2c)
70-
# left screen
71-
self._ss.pin_mode(SS_TFTRESET_PIN, self._ss.OUTPUT)
77+
78+
# set up seesaw pins
79+
self._ss.pin_mode(SS_TFTRESET_PIN, self._ss.OUTPUT) # left sceen reset
80+
81+
# buttons abolve left eye
7282
self._ss.pin_mode(SS_SWITCH1_PIN, self._ss.INPUT_PULLUP)
7383
self._ss.pin_mode(SS_SWITCH2_PIN, self._ss.INPUT_PULLUP)
7484
self._ss.pin_mode(SS_SWITCH3_PIN, self._ss.INPUT_PULLUP)
7585

86+
# light sensor near left eye
7687
self._ss.pin_mode(SS_LIGHTSENSOR_PIN, self._ss.INPUT)
7788

7889
# Manual reset for left screen
@@ -92,17 +103,19 @@ def __init__(self, i2c=None):
92103
left_tft_dc = board.LEFT_TFT_DC
93104

94105
left_display_bus = displayio.FourWire(
95-
left_spi, command=left_tft_dc, chip_select=left_tft_cs
106+
left_spi, command=left_tft_dc, chip_select=left_tft_cs # Reset on Seesaw
96107
)
97108

98109
self.left_display = ST7789(left_display_bus, width=240, height=240, rowstart=80)
99110

111+
# right backlight on board
100112
self.right_backlight = pulseio.PWMOut(
101113
board.RIGHT_TFT_LITE, frequency=5000, duty_cycle=0
102114
)
115+
# full brightness
103116
self.right_backlight.duty_cycle = 65535
104117

105-
# right display
118+
# right display spi bus
106119
right_spi = busio.SPI(board.RIGHT_TFT_SCK, MOSI=board.RIGHT_TFT_MOSI)
107120
right_tft_cs = board.RIGHT_TFT_CS
108121
right_tft_dc = board.RIGHT_TFT_DC
@@ -111,13 +124,14 @@ def __init__(self, i2c=None):
111124
right_spi,
112125
command=right_tft_dc,
113126
chip_select=right_tft_cs,
114-
reset=board.RIGHT_TFT_RST,
127+
reset=board.RIGHT_TFT_RST, # reset on board
115128
)
116129

117130
self.right_display = ST7789(
118131
right_display_bus, width=240, height=240, rowstart=80
119132
)
120133

134+
# setup accelerometer
121135
if i2c is not None:
122136
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
123137
try:
@@ -127,12 +141,25 @@ def __init__(self, i2c=None):
127141
except ValueError:
128142
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
129143

144+
# touchio on nose
130145
self.nose = touchio.TouchIn(board.NOSE)
146+
147+
# can be iffy, depending on environment and person.
148+
# User code can tweak if needed.
131149
self.nose.threshold = 180
132150

133151
@property
134152
def acceleration(self):
135-
"""Accelerometer data, +/- 2G sensitivity."""
153+
"""Accelerometer data, +/- 2G sensitivity.
154+
155+
This example initializes the mask and prints the accelerometer data.
156+
157+
.. code-block:: python
158+
import adafruit_monsterm4sk
159+
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
160+
print(mask.acceleration)
161+
162+
"""
136163
return (
137164
self._accelerometer.acceleration
138165
if self._accelerometer is not None
@@ -141,12 +168,34 @@ def acceleration(self):
141168

142169
@property
143170
def light(self):
144-
"""Light sensor data."""
171+
"""Light sensor data.
172+
173+
This example initializes the mask and prints the light sensor data.
174+
175+
.. code-block:: python
176+
import adafruit_monsterm4sk
177+
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
178+
print(mask.light)
179+
180+
"""
145181
return self._ss.analog_read(SS_LIGHTSENSOR_PIN)
146182

147183
@property
148184
def buttons(self):
149-
"""Buttons dictionary."""
185+
"""Buttons dictionary.
186+
187+
This example initializes the mask and prints when the S9 button
188+
is pressed down.
189+
190+
.. code-block:: python
191+
import adafruit_monsterm4sk
192+
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
193+
194+
while True:
195+
if mask.buttons["S9"]:
196+
print("Button S9 pressed!")
197+
198+
"""
150199

151200
return {
152201
"S9": self._ss.digital_read(SS_SWITCH1_PIN) is False,
@@ -156,5 +205,18 @@ def buttons(self):
156205

157206
@property
158207
def boop(self):
159-
"""Nose touch sense."""
208+
"""Nose touch sense.
209+
210+
This example initializes the mask and prints when the nose touch pad
211+
is being touched.
212+
213+
.. code-block:: python
214+
import adafruit_monsterm4sk
215+
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
216+
217+
while True:
218+
if mask.boop:
219+
print("Nose touched!")
220+
221+
"""
160222
return self.nose.value

0 commit comments

Comments
 (0)