Skip to content

Commit fa81fa0

Browse files
committed
add low power modes: med power turns off the camera preview, low power also dims the screen
1 parent ad34c6c commit fa81fa0

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

adafruit_pycamera/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
_NVM_EFFECT = const(2)
7373
_NVM_MODE = const(3)
7474
_NVM_TIMELAPSE_RATE = const(4)
75+
_NVM_TIMELAPSE_SUBMODE = const(5)
7576

7677

7778
class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-public-methods
@@ -186,6 +187,12 @@ class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-pub
186187
60 * 30,
187188
60 * 60
188189
)
190+
191+
timelapse_submodes = (
192+
"HiPwr",
193+
"MedPwr",
194+
"LowPwr"
195+
)
189196

190197
modes = ("JPEG", "GIF", "GBOY", "STOP", "LAPS")
191198

@@ -288,16 +295,18 @@ def make_camera_ui(self):
288295
self._botbar.append(self._mode_label)
289296

290297
self._timelapsebar = displayio.Group(x=0, y=180)
298+
self._timelapse_submode_label = label.Label(
299+
terminalio.FONT, text="SubM", color=0xFFFFFF,x=160, y=10, scale=2
300+
)
291301
self._timelapse_rate_label = label.Label(
292302
terminalio.FONT, text="Time", color=0xFFFFFF,x=90, y=10, scale=2
293303
)
294-
self._timelapse_rate_label.background_color = None
295304
self._timelapsestatus_label = label.Label(
296305
terminalio.FONT, text="Status", color=0xFFFFFF, x=0, y=10, scale=2
297306
)
298-
self._timelapsestatus_label.background_color = None
299307
self._timelapsebar.append(self._timelapse_rate_label)
300308
self._timelapsebar.append(self._timelapsestatus_label)
309+
self._timelapsebar.append(self._timelapse_submode_label)
301310

302311
self.splash.append(self._topbar)
303312
self.splash.append(self._botbar)
@@ -371,6 +380,7 @@ def init_camera(self, init_autofocus=True) -> None:
371380
self.resolution = microcontroller.nvm[_NVM_RESOLUTION]
372381
self.mode = microcontroller.nvm[_NVM_MODE]
373382
self.timelapse_rate = microcontroller.nvm[_NVM_TIMELAPSE_RATE]
383+
self.timelapse_submode = microcontroller.nvm[_NVM_TIMELAPSE_SUBMODE]
374384

375385
if init_autofocus:
376386
self.autofocus_init()
@@ -599,6 +609,18 @@ def timelapse_rate(self, setting):
599609
self.display.refresh()
600610

601611

612+
@property
613+
def timelapse_submode(self):
614+
"""Get or set the power mode for timelapsing"""
615+
return self._timelapse_submode
616+
617+
@timelapse_submode.setter
618+
def timelapse_submode(self, setting):
619+
setting = (setting + len(self.timelapse_submodes)) % len(self.timelapse_submodes)
620+
self._timelapse_submode = setting
621+
self._timelapse_submode_label.text = self.timelapse_submodes[self._timelapse_submode]
622+
microcontroller.nvm[_NVM_TIMELAPSE_SUBMODE] = setting
623+
602624
def init_display(self):
603625
"""Initialize the TFT display"""
604626
# construct displayio by hand

examples/camera/code.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,26 @@
3838
)
3939
pycam.blit(last_frame)
4040
elif pycam.mode_text == "LAPS":
41-
pycam.blit(pycam.continuous_capture())
42-
pycam._timelapse_rate_label.text = pycam._timelapse_rate_label.text
4341
if timelapse_remaining is None:
4442
pycam._timelapsestatus_label.text = "STOP"
4543
else:
4644
timelapse_remaining = timelapse_timestamp - time.time()
4745
pycam._timelapsestatus_label.text = f"{timelapse_remaining}s / "
46+
pycam._timelapse_rate_label.text = pycam._timelapse_rate_label.text
47+
pycam._timelapse_submode_label.text = pycam._timelapse_submode_label.text
48+
49+
# only in high power mode do we continuously preview
50+
if (timelapse_remaining is None) or (pycam._timelapse_submode_label.text == "HiPwr"):
51+
pycam.blit(pycam.continuous_capture())
52+
if pycam._timelapse_submode_label.text == "LowPwr" and (timelapse_remaining is not None):
53+
pycam.display.brightness = 0.05
54+
else:
55+
pycam.display.brightness = 1
4856
pycam.display.refresh()
4957

5058
if timelapse_remaining is not None and timelapse_remaining <= 0:
59+
# no matter what, show what was just on the camera
60+
pycam.blit(pycam.continuous_capture())
5161
#pycam.tone(200, 0.1) # uncomment to add a beep when a photo is taken
5262
try:
5363
pycam.display_message("Snap!", color=0x0000FF)
@@ -59,6 +69,8 @@
5969
pycam.display_message("Error\nNo SD Card", color=0xFF0000)
6070
time.sleep(0.5)
6171
pycam.live_preview_mode()
72+
pycam.display.refresh()
73+
pycam.blit(pycam.continuous_capture())
6274
timelapse_timestamp = time.time() + pycam.timelapse_rates[pycam.timelapse_rate] + 1
6375
else:
6476
pycam.blit(pycam.continuous_capture())
@@ -206,6 +218,9 @@
206218
# pycam.set_resolution(pycam.resolutions[new_res])
207219
if pycam.select.fell:
208220
print("SEL")
221+
if pycam.mode_text == "LAPS":
222+
pycam.timelapse_submode += 1
223+
pycam.display.refresh()
209224
if pycam.ok.fell:
210225
print("OK")
211226
if pycam.mode_text == "LAPS":

0 commit comments

Comments
 (0)