Skip to content

Commit d93c838

Browse files
authored
Merge pull request #2 from kattni/update-display-class
Update display class.
2 parents fa1602f + ead4066 commit d93c838

File tree

5 files changed

+60
-44
lines changed

5 files changed

+60
-44
lines changed

adafruit_clue.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@
6161
import math
6262
import board
6363
import digitalio
64-
import audiobusio
65-
import audiopwmio
66-
import audiocore
67-
import gamepad
68-
import touchio
6964
import neopixel
7065
import adafruit_apds9960.apds9960
7166
import adafruit_bmp280
7267
import adafruit_lis3mdl
7368
import adafruit_lsm6ds
7469
import adafruit_sht31d
70+
import audiobusio
71+
import audiopwmio
72+
import audiocore
73+
import gamepad
74+
import touchio
7575

7676
__version__ = "0.0.0-auto.0"
7777
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CLUE.git"
7878

79-
class _DisplayClueData:
80-
"""Display sensor data."""
79+
class _ClueSimpleTextDisplay:
80+
"""Easily display lines of text on CLUE display."""
8181
def __init__(self, title="CLUE Sensor Data", title_color=0xFFFFFF, title_scale=1, # pylint: disable=too-many-arguments
82-
clue_data_scale=1, font=None, num_lines=1, colors=None):
82+
text_scale=1, font=None, num_lines=1, colors=None):
8383
import displayio
8484
import terminalio
8585
from adafruit_display_text import label
@@ -104,8 +104,8 @@ def __init__(self, title="CLUE Sensor Data", title_color=0xFFFFFF, title_scale=1
104104
title.y = 8
105105
self._y = title.y + 20
106106

107-
self.data_group = displayio.Group(max_size=20, scale=clue_data_scale)
108-
self.data_group.append(title)
107+
self.text_group = displayio.Group(max_size=20, scale=text_scale)
108+
self.text_group.append(title)
109109

110110
self._lines = []
111111
for num in range(num_lines):
@@ -117,17 +117,17 @@ def __getitem__(self, item):
117117

118118
def add_text_line(self, color=0xFFFFFF):
119119
"""Adds a line on the display of the specified color and returns the label object."""
120-
clue_data_label = self._label.Label(self._font, text="", max_glyphs=45, color=color)
121-
clue_data_label.x = 0
122-
clue_data_label.y = self._y
123-
self._y = clue_data_label.y + 13
124-
self.data_group.append(clue_data_label)
120+
text_label = self._label.Label(self._font, text="", max_glyphs=45, color=color)
121+
text_label.x = 0
122+
text_label.y = self._y
123+
self._y = text_label.y + 13
124+
self.text_group.append(text_label)
125125

126-
return clue_data_label
126+
return text_label
127127

128128
def show(self):
129129
"""Call show() to display the data list."""
130-
self._display.show(self.data_group)
130+
self._display.show(self.text_group)
131131

132132
def show_terminal(self):
133133
"""Revert to terminalio screen."""
@@ -794,9 +794,9 @@ def loud_sound(self, sound_threshold=200):
794794
return self.sound_level > sound_threshold
795795

796796
@staticmethod
797-
def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), title_scale=1, # pylint: disable=too-many-arguments
798-
num_lines=1, clue_data_scale=1, font=None, colors=None):
799-
"""Display CLUE data as lines of text.
797+
def simple_text_display(title="CLUE Sensor Data", title_color=(255, 255, 255), title_scale=1, # pylint: disable=too-many-arguments
798+
num_lines=1, text_scale=1, font=None, colors=None):
799+
"""Display lines of text on the CLUE display.
800800
801801
Setup occurs before the loop. For data to be dynamically updated on the display, you must
802802
include the data call in the loop by using ``.text =``. For example, if setup is saved as
@@ -808,7 +808,7 @@ def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), tit
808808
:param title_color: The color of the displayed title. Defaults to white 255, 255, 255).
809809
:param int title_scale: Scale the size of the title. Defaults to 1.
810810
:param int num_lines: The number of lines of data you intend to display. Defaults to 1.
811-
:param int clue_data_scale: Scale the size of the data lines. Scales the title as well.
811+
:param int text_scale: Scale the size of the data lines. Scales the title as well.
812812
Defaults to 1.
813813
:param str font: The font to use to display the title and data. Defaults to built in
814814
``terminalio.FONT``.
@@ -836,9 +836,9 @@ def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), tit
836836
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)
837837
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
838838
"""
839-
return _DisplayClueData(title=title, title_color=title_color, title_scale=title_scale,
840-
num_lines=num_lines, clue_data_scale=clue_data_scale, font=font,
841-
colors=colors)
839+
return _ClueSimpleTextDisplay(title=title, title_color=title_color, title_scale=title_scale,
840+
num_lines=num_lines, text_scale=text_scale, font=font,
841+
colors=colors)
842842

843843

844844
clue = Clue() # pylint: disable=invalid-name

examples/clue_display_sensor_data.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from adafruit_clue import clue
2+
3+
clue.sea_level_pressure = 1020
4+
5+
clue_data = clue.simple_text_display(title="CLUE Sensor Data!", title_scale=2, num_lines=15)
6+
7+
while True:
8+
clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*clue.acceleration)
9+
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f} dps".format(*clue.gyro)
10+
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*clue.magnetic)
11+
clue_data[3].text = "Pressure: {:.3f} hPa".format(clue.pressure)
12+
clue_data[4].text = "Altitude: {:.1f} m".format(clue.altitude)
13+
clue_data[5].text = "Temperature: {:.1f} C".format(clue.temperature)
14+
clue_data[6].text = "Humidity: {:.1f} %".format(clue.humidity)
15+
clue_data[7].text = "Proximity: {}".format(clue.proximity)
16+
clue_data[8].text = "Gesture: {}".format(clue.gesture)
17+
clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
18+
clue_data[10].text = "Button A: {}".format(clue.button_a)
19+
clue_data[11].text = "Button B: {}".format(clue.button_b)
20+
clue_data[12].text = "Touch 0: {}".format(clue.touch_0)
21+
clue_data[13].text = "Touch 1: {}".format(clue.touch_1)
22+
clue_data[14].text = "Touch 2: {}".format(clue.touch_2)
23+
clue_data.show()

examples/clue_simpletest.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
clue.sea_level_pressure = 1020
44

5-
clue_data = clue.display_clue_data(title="CLUE Sensor Data!", title_scale=2, num_lines=15)
6-
75
while True:
8-
clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)
9-
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)
10-
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
11-
clue_data[3].text = "Pressure: {:.3f}hPa".format(clue.pressure)
12-
clue_data[4].text = "Altitude: {:.1f}m".format(clue.altitude)
13-
clue_data[5].text = "Temperature: {:.1f}C".format(clue.temperature)
14-
clue_data[6].text = "Humidity: {:.1f}%".format(clue.humidity)
15-
clue_data[7].text = "Proximity: {}".format(clue.proximity)
16-
clue_data[8].text = "Gesture: {}".format(clue.gesture)
17-
clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
18-
clue_data[10].text = "Button A: {}".format(clue.button_a)
19-
clue_data[11].text = "Button B: {}".format(clue.button_b)
20-
clue_data[12].text = "Touch 0: {}".format(clue.touch_0)
21-
clue_data[13].text = "Touch 1: {}".format(clue.touch_1)
22-
clue_data[14].text = "Touch 2: {}".format(clue.touch_2)
23-
clue_data.show()
6+
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*clue.acceleration))
7+
print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*clue.gyro))
8+
print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*clue.magnetic))
9+
print("Pressure: {:.3f} hPa".format(clue.pressure))
10+
print("Altitude: {:.1f} m".format(clue.altitude))
11+
print("Temperature: {:.1f} C".format(clue.temperature))
12+
print("Humidity: {:.1f} %".format(clue.humidity))
13+
print("Proximity: {}".format(clue.proximity))
14+
print("Gesture: {}".format(clue.gesture))
15+
print("Color: R: {} G: {} B: {} C: {}".format(*clue.color))
16+
print("--------------------------------")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ adafruit-circuitpython-sht31d
66
adafruit-circuitpython-lsm6ds
77
adafruit-circuitpython-lis3mdl
88
adafruit-circuitpython-display-text
9-
adafuit-circuitpython-bmp280
9+
adafruit-circuitpython-bmp280
1010
adafruit-circuitpython-apds9960

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'adafruit-circuitpython-lsm6ds',
4343
'adafruit-circuitpython-lis3mdl',
4444
'adafruit-circuitpython-display-text',
45-
'adafuit-circuitpython-bmp280',
45+
'adafruit-circuitpython-bmp280',
4646
'adafruit-circuitpython-apds9960'
4747
],
4848

0 commit comments

Comments
 (0)