Skip to content

Commit 40ff754

Browse files
committed
some beginnings of timelapse
1 parent f417055 commit 40ff754

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

adafruit_pycamera/__init__.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
_NVM_RESOLUTION = const(1)
7272
_NVM_EFFECT = const(2)
7373
_NVM_MODE = const(3)
74+
_NVM_TIMELAPSE_RATE = const(4)
7475

7576

7677
class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-public-methods
@@ -168,7 +169,25 @@ class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-pub
168169
"Sepia",
169170
"Solarize",
170171
)
171-
modes = ("JPEG", "GIF", "GBOY", "STOP")
172+
173+
timelapse_rates = (
174+
5,
175+
10,
176+
20,
177+
30,
178+
60,
179+
90,
180+
60 * 2,
181+
60 * 3,
182+
60 * 4,
183+
60 * 5,
184+
60 * 10,
185+
60 * 15,
186+
60 * 30,
187+
60 * 60
188+
)
189+
190+
modes = ("JPEG", "GIF", "GBOY", "STOP", "LAPS")
172191

173192
_INIT_SEQUENCE = (
174193
b"\x01\x80\x78" # _SWRESET and Delay 120ms
@@ -249,13 +268,13 @@ def make_debounced_expander_pin(pin_no):
249268
def make_camera_ui(self):
250269
"""Create displayio widgets for the standard camera UI"""
251270
self._sd_label = label.Label(
252-
terminalio.FONT, text="SD ??", color=0x0, x=150, y=10, scale=2
271+
terminalio.FONT, text="SD ??", color=0x0, x=170, y=10, scale=2
253272
)
254273
self._effect_label = label.Label(
255274
terminalio.FONT, text="EFFECT", color=0xFFFFFF, x=4, y=10, scale=2
256275
)
257276
self._mode_label = label.Label(
258-
terminalio.FONT, text="MODE", color=0xFFFFFF, x=150, y=10, scale=2
277+
terminalio.FONT, text="MODE", color=0xFFFFFF, x=170, y=10, scale=2
259278
)
260279
self._topbar = displayio.Group()
261280
self._res_label = label.Label(
@@ -268,8 +287,19 @@ def make_camera_ui(self):
268287
self._botbar.append(self._effect_label)
269288
self._botbar.append(self._mode_label)
270289

290+
self._timelapsebar = displayio.Group(x=0, y=180)
291+
self._timelapse_rate_label = label.Label(
292+
terminalio.FONT, text="Time", color=0xFFFFFF, x=150, y=10, scale=2
293+
)
294+
self._timelapsestatus_label = label.Label(
295+
terminalio.FONT, text="Status", color=0xFFFFFF, x=0, y=10, scale=2
296+
)
297+
self._timelapsebar.append(self._timelapse_rate_label)
298+
self._timelapsebar.append(self._timelapsestatus_label)
299+
271300
self.splash.append(self._topbar)
272301
self.splash.append(self._botbar)
302+
self.splash.append(self._timelapsebar)
273303

274304
def init_accelerometer(self):
275305
"""Initialize the accelerometer"""
@@ -338,6 +368,7 @@ def init_camera(self, init_autofocus=True) -> None:
338368
self.camera.saturation = 3
339369
self.resolution = microcontroller.nvm[_NVM_RESOLUTION]
340370
self.mode = microcontroller.nvm[_NVM_MODE]
371+
self.timelapse_rate = microcontroller.nvm[_NVM_TIMELAPSE_RATE]
341372

342373
if init_autofocus:
343374
self.autofocus_init()
@@ -461,6 +492,9 @@ def select_setting(self, setting_name):
461492
self._res_label.text = self.resolutions[self._resolution]
462493
self._mode_label.color = 0xFFFFFF
463494
self._mode_label.background_color = 0x0
495+
self._timelapse_rate_label.color = 0xFFFFFF
496+
self._timelapse_rate_label.background_color = 0x0
497+
464498
if setting_name == "effect":
465499
self._effect_label.color = 0x0
466500
self._effect_label.background_color = 0xFFFFFF
@@ -478,6 +512,13 @@ def select_setting(self, setting_name):
478512
self._res_label.text = "LED CLR"
479513
self._res_label.color = 0x0
480514
self._res_label.background_color = 0xFFFFFF
515+
elif setting_name == "led_color":
516+
self._res_label.text = "LED CLR"
517+
self._res_label.color = 0x0
518+
self._res_label.background_color = 0xFFFFFF
519+
elif setting_name == "timelapse_rate":
520+
self._timelapse_rate_label.color = 0x0
521+
self._timelapse_rate_label.background_color = 0xFFFFFF
481522
self.display.refresh()
482523

483524
@property
@@ -538,6 +579,24 @@ def resolution(self, res):
538579
self._res_label.text = self.resolutions[res]
539580
self.display.refresh()
540581

582+
583+
@property
584+
def timelapse_rate(self):
585+
"""Get or set the amount of time between timelapse shots"""
586+
return self._timelapse_rate
587+
588+
@timelapse_rate.setter
589+
def timelapse_rate(self, setting):
590+
setting = (setting + len(self.timelapse_rates)) % len(self.timelapse_rates)
591+
self._timelapse_rate = setting
592+
if self.timelapse_rates[setting] < 60:
593+
self._timelapse_rate_label.text = "%d S" % self.timelapse_rates[setting]
594+
else:
595+
self._timelapse_rate_label.text = "%d M" % (self.timelapse_rates[setting] / 60)
596+
microcontroller.nvm[_NVM_TIMELAPSE_RATE] = setting
597+
self.display.refresh()
598+
599+
541600
def init_display(self):
542601
"""Initialize the TFT display"""
543602
# construct displayio by hand

examples/camera/code.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
pycam = adafruit_pycamera.PyCamera()
1515
# pycam.live_preview_mode()
1616

17-
settings = (None, "resolution", "effect", "mode", "led_level", "led_color")
17+
settings = (None, "resolution", "effect", "mode", "led_level", "led_color", "timelapse_rate")
1818
curr_setting = 0
1919

2020
print("Starting!")
2121
# pycam.tone(200, 0.1)
2222
last_frame = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535)
2323
onionskin = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535)
24+
timelapse_remaining = None
25+
2426
while True:
2527
if pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0:
2628
# alpha blend
@@ -34,6 +36,15 @@
3436
last_frame, pycam.continuous_capture(), displayio.Colorspace.RGB565_SWAPPED
3537
)
3638
pycam.blit(last_frame)
39+
elif pycam.mode_text == "LAPS":
40+
pycam.blit(pycam.continuous_capture())
41+
pycam._timelapse_rate_label.text = pycam._timelapse_rate_label.text
42+
if timelapse_remaining is None:
43+
pycam._timelapsestatus_label.text = "STOP"
44+
#pycam.display_message("Timelapse\nNot Running\nPress Select to set timing")
45+
else:
46+
pycam.display_message("%d Seconds left", timelapse_remaining)
47+
pycam.display.refresh()
3748
else:
3849
pycam.blit(pycam.continuous_capture())
3950
# print("\t\t", capture_time, blit_time)
@@ -127,6 +138,7 @@
127138
except RuntimeError as e:
128139
pycam.display_message("Error\nNo SD Card", color=0xFF0000)
129140
time.sleep(0.5)
141+
130142
if pycam.card_detect.fell:
131143
print("SD card removed")
132144
pycam.unmount_sd_card()
@@ -152,6 +164,7 @@
152164
print("UP")
153165
key = settings[curr_setting]
154166
if key:
167+
print("getting", key, getattr(pycam, key))
155168
setattr(pycam, key, getattr(pycam, key) + 1)
156169
if pycam.down.fell:
157170
print("DN")
@@ -161,13 +174,17 @@
161174
if pycam.right.fell:
162175
print("RT")
163176
curr_setting = (curr_setting + 1) % len(settings)
177+
if pycam.mode_text != "LAPS" and settings[curr_setting] == "timelapse_rate":
178+
curr_setting = (curr_setting + 1) % len(settings)
164179
print(settings[curr_setting])
165180
# new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1)
166181
# pycam.set_resolution(pycam.resolutions[new_res])
167182
pycam.select_setting(settings[curr_setting])
168183
if pycam.left.fell:
169184
print("LF")
170185
curr_setting = (curr_setting - 1 + len(settings)) % len(settings)
186+
if pycam.mode_text != "LAPS" and settings[curr_setting] == "timelaps_rate":
187+
curr_setting = (curr_setting + 1) % len(settings)
171188
print(settings[curr_setting])
172189
pycam.select_setting(settings[curr_setting])
173190
# new_res = max(1, pycam.get_resolution()-1)

0 commit comments

Comments
 (0)