Skip to content

Update display class. #2

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

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions adafruit_clue.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@
import math
import board
import digitalio
import audiobusio
import audiopwmio
import audiocore
import gamepad
import touchio
import neopixel
import adafruit_apds9960.apds9960
import adafruit_bmp280
import adafruit_lis3mdl
import adafruit_lsm6ds
import adafruit_sht31d
import audiobusio
import audiopwmio
import audiocore
import gamepad
import touchio

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

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

self.data_group = displayio.Group(max_size=20, scale=clue_data_scale)
self.data_group.append(title)
self.text_group = displayio.Group(max_size=20, scale=text_scale)
self.text_group.append(title)

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

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

return clue_data_label
return text_label

def show(self):
"""Call show() to display the data list."""
self._display.show(self.data_group)
self._display.show(self.text_group)

def show_terminal(self):
"""Revert to terminalio screen."""
Expand Down Expand Up @@ -794,9 +794,9 @@ def loud_sound(self, sound_threshold=200):
return self.sound_level > sound_threshold

@staticmethod
def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), title_scale=1, # pylint: disable=too-many-arguments
num_lines=1, clue_data_scale=1, font=None, colors=None):
"""Display CLUE data as lines of text.
def simple_text_display(title="CLUE Sensor Data", title_color=(255, 255, 255), title_scale=1, # pylint: disable=too-many-arguments
num_lines=1, text_scale=1, font=None, colors=None):
"""Display lines of text on the CLUE display.

Setup occurs before the loop. For data to be dynamically updated on the display, you must
include the data call in the loop by using ``.text =``. For example, if setup is saved as
Expand All @@ -808,7 +808,7 @@ def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), tit
:param title_color: The color of the displayed title. Defaults to white 255, 255, 255).
:param int title_scale: Scale the size of the title. Defaults to 1.
:param int num_lines: The number of lines of data you intend to display. Defaults to 1.
:param int clue_data_scale: Scale the size of the data lines. Scales the title as well.
:param int text_scale: Scale the size of the data lines. Scales the title as well.
Defaults to 1.
:param str font: The font to use to display the title and data. Defaults to built in
``terminalio.FONT``.
Expand Down Expand Up @@ -836,9 +836,9 @@ def display_clue_data(title="CLUE Sensor Data", title_color=(255, 255, 255), tit
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
"""
return _DisplayClueData(title=title, title_color=title_color, title_scale=title_scale,
num_lines=num_lines, clue_data_scale=clue_data_scale, font=font,
colors=colors)
return _ClueSimpleTextDisplay(title=title, title_color=title_color, title_scale=title_scale,
num_lines=num_lines, text_scale=text_scale, font=font,
colors=colors)


clue = Clue() # pylint: disable=invalid-name
Expand Down
23 changes: 23 additions & 0 deletions examples/clue_display_sensor_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from adafruit_clue import clue

clue.sea_level_pressure = 1020

clue_data = clue.simple_text_display(title="CLUE Sensor Data!", title_scale=2, num_lines=15)

while True:
clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*clue.acceleration)
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f} dps".format(*clue.gyro)
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*clue.magnetic)
clue_data[3].text = "Pressure: {:.3f} hPa".format(clue.pressure)
clue_data[4].text = "Altitude: {:.1f} m".format(clue.altitude)
clue_data[5].text = "Temperature: {:.1f} C".format(clue.temperature)
clue_data[6].text = "Humidity: {:.1f} %".format(clue.humidity)
clue_data[7].text = "Proximity: {}".format(clue.proximity)
clue_data[8].text = "Gesture: {}".format(clue.gesture)
clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
clue_data[10].text = "Button A: {}".format(clue.button_a)
clue_data[11].text = "Button B: {}".format(clue.button_b)
clue_data[12].text = "Touch 0: {}".format(clue.touch_0)
clue_data[13].text = "Touch 1: {}".format(clue.touch_1)
clue_data[14].text = "Touch 2: {}".format(clue.touch_2)
clue_data.show()
29 changes: 11 additions & 18 deletions examples/clue_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

clue.sea_level_pressure = 1020

clue_data = clue.display_clue_data(title="CLUE Sensor Data!", title_scale=2, num_lines=15)

while True:
clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
clue_data[3].text = "Pressure: {:.3f}hPa".format(clue.pressure)
clue_data[4].text = "Altitude: {:.1f}m".format(clue.altitude)
clue_data[5].text = "Temperature: {:.1f}C".format(clue.temperature)
clue_data[6].text = "Humidity: {:.1f}%".format(clue.humidity)
clue_data[7].text = "Proximity: {}".format(clue.proximity)
clue_data[8].text = "Gesture: {}".format(clue.gesture)
clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
clue_data[10].text = "Button A: {}".format(clue.button_a)
clue_data[11].text = "Button B: {}".format(clue.button_b)
clue_data[12].text = "Touch 0: {}".format(clue.touch_0)
clue_data[13].text = "Touch 1: {}".format(clue.touch_1)
clue_data[14].text = "Touch 2: {}".format(clue.touch_2)
clue_data.show()
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*clue.acceleration))
print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*clue.gyro))
print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*clue.magnetic))
print("Pressure: {:.3f} hPa".format(clue.pressure))
print("Altitude: {:.1f} m".format(clue.altitude))
print("Temperature: {:.1f} C".format(clue.temperature))
print("Humidity: {:.1f} %".format(clue.humidity))
print("Proximity: {}".format(clue.proximity))
print("Gesture: {}".format(clue.gesture))
print("Color: R: {} G: {} B: {} C: {}".format(*clue.color))
print("--------------------------------")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ adafruit-circuitpython-sht31d
adafruit-circuitpython-lsm6ds
adafruit-circuitpython-lis3mdl
adafruit-circuitpython-display-text
adafuit-circuitpython-bmp280
adafruit-circuitpython-bmp280
adafruit-circuitpython-apds9960
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'adafruit-circuitpython-lsm6ds',
'adafruit-circuitpython-lis3mdl',
'adafruit-circuitpython-display-text',
'adafuit-circuitpython-bmp280',
'adafruit-circuitpython-bmp280',
'adafruit-circuitpython-apds9960'
],

Expand Down