43
43
import board
44
44
45
45
from plotter import Plotter
46
- from plot_source import PlotSource , TemperaturePlotSource , PressurePlotSource , \
47
- HumidityPlotSource , ColorPlotSource , ProximityPlotSource , \
48
- IlluminatedColorPlotSource , VolumePlotSource , \
49
- AccelerometerPlotSource , GyroPlotSource , \
50
- MagnetometerPlotSource , PinPlotSource
46
+ from plot_source import (
47
+ TemperaturePlotSource ,
48
+ PressurePlotSource ,
49
+ HumidityPlotSource ,
50
+ ColorPlotSource ,
51
+ ProximityPlotSource ,
52
+ IlluminatedColorPlotSource ,
53
+ VolumePlotSource ,
54
+ AccelerometerPlotSource ,
55
+ GyroPlotSource ,
56
+ MagnetometerPlotSource ,
57
+ PinPlotSource ,
58
+ )
51
59
from adafruit_clue import clue
52
60
53
-
54
61
debug = 1
55
62
56
-
57
63
# A list of all the data sources for plotting
58
- sources = [TemperaturePlotSource (clue , mode = "Celsius" ),
59
- TemperaturePlotSource (clue , mode = "Fahrenheit" ),
60
- PressurePlotSource (clue , mode = "Metric" ),
61
- PressurePlotSource (clue , mode = "Imperial" ),
62
- HumidityPlotSource (clue ),
63
- ColorPlotSource (clue ),
64
- ProximityPlotSource (clue ),
65
- IlluminatedColorPlotSource (clue , mode = "Red" ),
66
- IlluminatedColorPlotSource (clue , mode = "Green" ),
67
- IlluminatedColorPlotSource (clue , mode = "Blue" ),
68
- IlluminatedColorPlotSource (clue , mode = "Clear" ),
69
- VolumePlotSource (clue ),
70
- AccelerometerPlotSource (clue ),
71
- GyroPlotSource (clue ),
72
- MagnetometerPlotSource (clue ),
73
- PinPlotSource ([board .P0 , board .P1 , board .P2 ])
74
- ]
64
+ # NOTE: Due to memory contraints, the total number of data sources
65
+ # is limited. Can try adding more until a memory limit is hit. At that
66
+ # point, decide what to keep and what to toss. Can comment/uncomment lines
67
+ # below as desired.
68
+ sources = [
69
+ TemperaturePlotSource (clue , mode = "Celsius" ),
70
+ # TemperaturePlotSource(clue, mode="Fahrenheit"),
71
+ PressurePlotSource (clue , mode = "Metric" ),
72
+ # PressurePlotSource(clue, mode="Imperial"),
73
+ HumidityPlotSource (clue ),
74
+ ColorPlotSource (clue ),
75
+ ProximityPlotSource (clue ),
76
+ # IlluminatedColorPlotSource(clue, mode="Red"),
77
+ # IlluminatedColorPlotSource(clue, mode="Green"),
78
+ # IlluminatedColorPlotSource(clue, mode="Blue"),
79
+ # IlluminatedColorPlotSource(clue, mode="Clear"),
80
+ # VolumePlotSource(clue),
81
+ AccelerometerPlotSource (clue ),
82
+ # GyroPlotSource(clue),
83
+ # MagnetometerPlotSource(clue),
84
+ # PinPlotSource([board.P0, board.P1, board.P2])
85
+ ]
75
86
# The first source to select when plotting starts
76
87
current_source_idx = 0
77
88
78
89
# The various plotting styles - scroll is currently a jump scroll
79
- stylemodes = (("lines" , "scroll" ), # draws lines between points
80
- ("lines" , "wrap" ),
81
- ("dots" , "scroll" ), # just points - slightly quicker
82
- ("dots" , "wrap" )
83
- )
90
+ stylemodes = (
91
+ ("lines" , "scroll" ), # draws lines between points
92
+ ("lines" , "wrap" ),
93
+ ("dots" , "scroll" ), # just points - slightly quicker
94
+ ("dots" , "wrap" ),
95
+ )
84
96
current_sm_idx = 0
85
97
86
98
@@ -94,7 +106,7 @@ def d_print(level, *args, **kwargs):
94
106
95
107
def select_colors (plttr , src , def_palette ):
96
108
"""Choose the colours based on the particular PlotSource
97
- or forcing use of default palette."""
109
+ or forcing use of default palette."""
98
110
# otherwise use defaults
99
111
channel_colidx = []
100
112
palette = plttr .get_colors ()
@@ -109,7 +121,7 @@ def select_colors(plttr, src, def_palette):
109
121
110
122
def ready_plot_source (plttr , srcs , def_palette , index = 0 ):
111
123
"""Select the plot source by index from srcs list and then setup the
112
- plot parameters by retrieving meta-data from the PlotSource object."""
124
+ plot parameters by retrieving meta-data from the PlotSource object."""
113
125
src = srcs [index ]
114
126
# Put the description of the source on screen at the top
115
127
source_name = str (src )
@@ -132,12 +144,12 @@ def ready_plot_source(plttr, srcs, def_palette, index=0):
132
144
133
145
def wait_release (func , menu ):
134
146
"""Calls func repeatedly waiting for it to return a false value
135
- and goes through menu list as time passes.
147
+ and goes through menu list as time passes.
136
148
137
- The menu is a list of menu entries where each entry is a
138
- two element list of time passed in seconds and text to display
139
- for that period.
140
- The entries must be in ascending time order."""
149
+ The menu is a list of menu entries where each entry is a
150
+ two element list of time passed in seconds and text to display
151
+ for that period.
152
+ The entries must be in ascending time order."""
141
153
142
154
start_t_ns = time .monotonic_ns ()
143
155
menu_option = None
@@ -162,7 +174,7 @@ def wait_release(func, menu):
162
174
163
175
def popup_text (plttr , text , duration = 1.0 ):
164
176
"""Place some text on the screen using info property of Plotter object
165
- for duration seconds."""
177
+ for duration seconds."""
166
178
plttr .info = text
167
179
time .sleep (duration )
168
180
plttr .info = None
@@ -175,13 +187,15 @@ def popup_text(plttr, text, duration=1.0):
175
187
# displayio has some static limits on text - pre-calculate the maximum
176
188
# length of all of the different PlotSource objects
177
189
max_title_len = max (len (initial_title ), max ([len (str (so )) for so in sources ]))
178
- plotter = Plotter (board .DISPLAY ,
179
- style = stylemodes [current_sm_idx ][0 ],
180
- mode = stylemodes [current_sm_idx ][1 ],
181
- title = initial_title ,
182
- max_title_len = max_title_len ,
183
- mu_output = mu_plotter_output ,
184
- debug = debug )
190
+ plotter = Plotter (
191
+ board .DISPLAY ,
192
+ style = stylemodes [current_sm_idx ][0 ],
193
+ mode = stylemodes [current_sm_idx ][1 ],
194
+ title = initial_title ,
195
+ max_title_len = max_title_len ,
196
+ mu_output = mu_plotter_output ,
197
+ debug = debug ,
198
+ )
185
199
186
200
# If set to true this forces use of colour blindness friendly colours
187
201
use_def_pal = False
@@ -190,21 +204,28 @@ def popup_text(plttr, text, duration=1.0):
190
204
191
205
plotter .display_on ()
192
206
# Using left and right here in case the CLUE is cased hiding A/B labels
193
- popup_text (plotter ,
194
- "\n " .join (["Button Guide" ,
195
- "Left: next source" ,
196
- " 2secs: palette" ,
197
- " 4s: Mu plot" ,
198
- " 6s: range lock" ,
199
- "Right: style change" ]), duration = 10 )
207
+ popup_text (
208
+ plotter ,
209
+ "\n " .join (
210
+ [
211
+ "Button Guide" ,
212
+ "Left: next source" ,
213
+ " 2secs: palette" ,
214
+ " 4s: Mu plot" ,
215
+ " 6s: range lock" ,
216
+ "Right: style change" ,
217
+ ]
218
+ ),
219
+ duration = 10 ,
220
+ )
200
221
201
222
count = 0
202
223
203
224
while True :
204
225
# Set the source and start items
205
- (source , channels ) = ready_plot_source (plotter , sources ,
206
- use_def_pal ,
207
- current_source_idx )
226
+ (source , channels ) = ready_plot_source (
227
+ plotter , sources , use_def_pal , current_source_idx
228
+ )
208
229
209
230
while True :
210
231
# Read data from sensor or voltage from pad
@@ -213,25 +234,22 @@ def popup_text(plttr, text, duration=1.0):
213
234
# Check for left (A) and right (B) buttons
214
235
if clue .button_a :
215
236
# Wait for button release with time-based menu
216
- opt , _ = wait_release (lambda : clue .button_a ,
217
- [(2 , "Next\n source" ),
218
- (4 ,
219
- ("Source" if use_def_pal else "Default" )
220
- + "\n palette" ),
221
- (6 ,
222
- "Mu output "
223
- + ("off" if mu_plotter_output else "on" )),
224
- (8 ,
225
- "Range lock\n " + ("off" if range_lock else "on" ))
226
- ])
237
+ opt , _ = wait_release (
238
+ lambda : clue .button_a ,
239
+ [
240
+ (2 , "Next\n source" ),
241
+ (4 , ("Source" if use_def_pal else "Default" ) + "\n palette" ),
242
+ (6 , "Mu output " + ("off" if mu_plotter_output else "on" )),
243
+ (8 , "Range lock\n " + ("off" if range_lock else "on" )),
244
+ ],
245
+ )
227
246
if opt == 0 : # change plot source
228
247
current_source_idx = (current_source_idx + 1 ) % len (sources )
229
248
break # to leave inner while and select the new source
230
249
231
250
elif opt == 1 : # toggle palette
232
251
use_def_pal = not use_def_pal
233
- plotter .channel_colidx = select_colors (plotter , source ,
234
- use_def_pal )
252
+ plotter .channel_colidx = select_colors (plotter , source , use_def_pal )
235
253
236
254
elif opt == 2 : # toggle Mu output
237
255
mu_plotter_output = not mu_plotter_output
@@ -244,8 +262,7 @@ def popup_text(plttr, text, duration=1.0):
244
262
if clue .button_b : # change plot style and mode
245
263
current_sm_idx = (current_sm_idx + 1 ) % len (stylemodes )
246
264
(new_style , new_mode ) = stylemodes [current_sm_idx ]
247
- wait_release (lambda : clue .button_b ,
248
- [(2 , new_style + "\n " + new_mode )])
265
+ wait_release (lambda : clue .button_b , [(2 , new_style + "\n " + new_mode )])
249
266
d_print (1 , "Graph change" , new_style , new_mode )
250
267
plotter .change_stylemode (new_style , new_mode )
251
268
@@ -256,7 +273,7 @@ def popup_text(plttr, text, duration=1.0):
256
273
plotter .data_add (all_data )
257
274
258
275
# An occasional print of free heap
259
- if debug >= 3 and count % 15 == 0 :
276
+ if debug >= 3 and count % 15 == 0 :
260
277
gc .collect () # must collect() first to measure free memory
261
278
print ("Free memory:" , gc .mem_free ())
262
279
0 commit comments