Skip to content

Commit 5bb291d

Browse files
Limit brightness, use 'production' DotStar color order
1 parent 9e8ce11 commit 5bb291d

2 files changed

Lines changed: 32 additions & 41 deletions

File tree

CLUE_Light_Painter/bmp2led.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
BMP-to-DotStar-ready-bytearrays.
33
"""
44

5-
from time import monotonic
65
# pylint: disable=import-error
76
import os
87
import math
@@ -265,11 +264,7 @@ def process(self, input_filename, output_filename, rows,
265264
led_file.write(b'\0')
266265
led_file.seek(0)
267266
err = 0
268-
time1, time2, time3, time4 = 0, 0, 0, 0
269-
start_time = monotonic()
270267
for row in range(rows): # For each output row...
271-
row_start_time = monotonic()
272-
273268
# Scale position into pixel space...
274269
if loop: # 0 to <image height
275270
position = self.bmp_specs.height * row / rows
@@ -301,7 +296,6 @@ def process(self, input_filename, output_filename, rows,
301296

302297
prev_row_a_index = row_a_index
303298
prev_row_b_index = row_b_index
304-
time1 += (monotonic() - row_start_time)
305299

306300
# Pixel values are stored as bytes from 0-255.
307301
# Gamma correction requires floats from 0.0 to 1.0.
@@ -352,7 +346,6 @@ def process(self, input_filename, output_filename, rows,
352346
# will be used on subsequent rows.
353347
err = err - err_bits
354348

355-
time2 += (monotonic() - row_start_time)
356349
# Reorder data from BGR to DotStar color order,
357350
# allowing for header and start-of-pixel markers
358351
# in the DotStar data.
@@ -366,8 +359,6 @@ def process(self, input_filename, output_filename, rows,
366359
dotstar_row_size] = memoryview(
367360
dotstar_buffer)
368361

369-
time3 += (monotonic() - row_start_time)
370-
371362
# Add converted data to output buffer.
372363
# Periodically write when full.
373364
output_position += dotstar_row_size
@@ -377,8 +368,6 @@ def process(self, input_filename, output_filename, rows,
377368
callback(row / (rows - 1))
378369
output_position = 0
379370

380-
time4 += (monotonic() - row_start_time)
381-
382371
# Write any remaining buffered data
383372
if output_position:
384373
led_file.write(output_buffer[:output_position])
@@ -395,15 +384,6 @@ def process(self, input_filename, output_filename, rows,
395384
[255] *
396385
((self.num_pixels + 15) //
397386
16)))
398-
print('Total time', monotonic() - start_time)
399-
time4 -= time3
400-
time3 -= time2
401-
time2 -= time1
402-
print(rows, 'rows')
403-
print('BMP-reading time', time1)
404-
print('ulab time', time2)
405-
print('Reordering time', time3)
406-
print('File-writing time', time4)
407387

408388
#print("Loaded OK!")
409389
return rows

CLUE_Light_Painter/code.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@
2828

2929
NUM_PIXELS = 72 # LED strip length
3030
PIXEL_PINS = board.SDA, board.SCL # Data, clock pins for DotStars
31-
PIXEL_ORDER = 'brg' # Pixel color order
32-
PATH = '/bmps-72px' # Folder containing BMP images (or '' for root path)
33-
TEMPFILE = '/led.dat' # Working file for LED data (will be clobbered!)
34-
FLIP_SCREEN = False # If True, turn CLUE screen & buttons upside-down
35-
GAMMA = 2.4 # Correction factor for perceptually linear brightness
31+
PIXEL_ORDER = 'bgr' # Pixel color order
32+
PATH = '/bmps-72px' # Folder with BMP images (or '' for root path)
33+
TEMPFILE = '/led.dat' # Working file for LED data (will be clobbered!)
34+
FLIP_SCREEN = False # If True, turn CLUE screen & buttons upside-down
35+
GAMMA = 2.4 # Correction for perceptually linear brightness
36+
BRIGHTNESS_RANGE = 0.15, 0.75 # Min, max brightness (0.0-1.0)
3637
TIMES = ['1/8', '1/4', '1/3', '1/2', '2/3', '1', '1.5', '2', '3', '4']
3738
TIMES.sort(key=eval) # Ensure times are shortest-to-longest
3839

3940
# Temporary line during development, delete before use:
40-
PIXEL_ORDER = 'gbr' # Old DotStar strip with different color order
41+
#PIXEL_ORDER = 'gbr' # Old DotStar strip with different color order
4142

4243

4344
def centered_label(text, y_pos, scale):
@@ -63,25 +64,33 @@ class ClueLightPainter:
6364

6465
# pylint: disable=too-many-arguments
6566
def __init__(self, flip, path, tempfile, num_pixels, pixel_order,
66-
pixel_pins, gamma):
67+
pixel_pins, gamma, brightness):
6768
"""
6869
App constructor. Follow up with a call to ClueLightPainter.run().
6970
Arguments:
70-
flip (boolean) : If True, CLUE display and buttons are
71-
flipped 180 degrees from normal (makes
72-
wiring easier in some situations).
73-
path (string) : Directory containing BMP images.
74-
tempfile (string) : Full path/filename of temporary working
75-
file for LED data (will be clobbered).
76-
num_pixels (int) : LED strip length.
77-
pixel_order (string) : LED data order, e.g. 'grb'.
78-
pixel_pins (tuple) : Board pin for LED data output (SPI data
79-
and clock pins respectively).
80-
gamma (float) : Correction for perceptual linearity.
71+
flip (boolean) : If True, CLUE display and buttons are
72+
flipped 180 degrees from normal (makes
73+
wiring easier in some situations).
74+
path (string) : Directory containing BMP images.
75+
tempfile (string) : Full path/filename of temporary working
76+
file for LED data (will be clobbered).
77+
num_pixels (int) : LED strip length.
78+
pixel_order (string) : LED data order, e.g. 'grb'.
79+
pixel_pins (tuple) : Board pin for LED data output (SPI data
80+
and clock pins respectively).
81+
gamma (float) : Correction for perceptual linearity.
82+
brightness (2 floats) : Minimum and maximum LED brightness
83+
settings, each 0.0 (off) to 1.0 (full
84+
brightness). Too-low brightness levels
85+
just don't photograph well. Too-high
86+
levels may draw more current than the
87+
battery can provide, board may lock up
88+
and may even need CircuitPython re-flash.
8189
"""
8290
self.bmp2led = BMP2LED(num_pixels, pixel_order, gamma)
8391
self.path = path
8492
self.tempfile = tempfile
93+
self.brightness_range = brightness
8594

8695
# The SPI peripheral is locked and config'd once here and never
8796
# relinquished, to save some time on every row (need them issued
@@ -204,8 +213,9 @@ def load_image(self):
204213
# The 0.9 here is an empirical guesstimate; playback is ever-so-
205214
# slightly slower than benchmark speed due to button testing.
206215
rows = int(duration * self.rows_per_second * 0.9 + 0.5)
207-
# Remap brightness from 0.0-1.0 to 15-100%
208-
brightness = 0.15 + self.brightness * 0.85
216+
# Remap brightness from 0.0-1.0 to brightness_range.
217+
brightness = (self.brightness_range[0] + self.brightness *
218+
(self.brightness_range[1] - self.brightness_range[0]))
209219
try:
210220
self.num_rows = self.bmp2led.process(self.path + '/' +
211221
self.images[self.image_num],
@@ -507,4 +517,5 @@ def run(self):
507517

508518

509519
ClueLightPainter(FLIP_SCREEN, PATH, TEMPFILE,
510-
NUM_PIXELS, PIXEL_ORDER, PIXEL_PINS, GAMMA).run()
520+
NUM_PIXELS, PIXEL_ORDER, PIXEL_PINS, GAMMA,
521+
BRIGHTNESS_RANGE).run()

0 commit comments

Comments
 (0)