-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpibooth_flashled.py
More file actions
101 lines (76 loc) · 3.71 KB
/
pibooth_flashled.py
File metadata and controls
101 lines (76 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
from time import sleep
import pigpio
import pibooth
from pibooth.utils import LOGGER
__version__ = "1.1.1"
@pibooth.hookimpl
def pibooth_configure(cfg):
"""Declare the new configuration options"""
cfg.add_option('FLASH', 'warmwhite_pin', 12,
"Physical GPIO OUT pin to light a warm white LED strip")
cfg.add_option('FLASH', 'coolwhite_pin', 13,
"Physical GPIO OUT pin to light a cool white LED strip")
cfg.add_option('FLASH', 'white_balance', (50, 50),
"The white balance (warm white, cool white) in percent",
'White balance (warm, cool)', [str((i, 100 - i)) for i in range(10, 100, 10)])
cfg.add_option('FLASH', 'brightness', 50,
"The brightness in percent",
'Brightness (%)', [str(i) for i in range(0, 101, 10)])
cfg.add_option('FLASH', 'fade_delay', 1000,
"How long is the fade light in milliseconds (0 to skip it)",
'Fade delay (ms)', [str(i) for i in range(0, 2001, 100)])
@pibooth.hookimpl
def state_chosen_exit(app, cfg):
"""Configure LED strips (warm white and cool white).
"""
app.pin_warmwhite = cfg.gettyped('FLASH', 'warmwhite_pin')
app.strip_warmwhite = pigpio.pi()
app.strip_warmwhite.set_mode(app.pin_warmwhite, pigpio.OUTPUT)
app.pin_coolwhite = cfg.gettyped('FLASH', 'coolwhite_pin')
app.strip_coolwhite = pigpio.pi()
app.strip_coolwhite.set_mode(app.pin_coolwhite, pigpio.OUTPUT)
"""Turn on the flash.
"""
white_balance = cfg.gettyped('FLASH', 'white_balance')
brightness = cfg.gettyped('FLASH', 'brightness')
fade_delay = cfg.gettyped('FLASH', 'fade_delay')
if fade_delay != 0:
level_warmwhite = 0
level_coolwhite = 0
steps_number = fade_delay / 10
step_warmwhite = white_balance[0] / steps_number
step_coolwhite = white_balance[1] / steps_number
while level_warmwhite <= white_balance[0] and level_coolwhite <= white_balance[1]:
app.strip_warmwhite.hardware_PWM(app.pin_warmwhite, 100, int(level_warmwhite * brightness * 100))
app.strip_coolwhite.hardware_PWM(app.pin_coolwhite, 100, int(level_coolwhite * brightness * 100))
sleep(10 / 1000)
level_warmwhite += step_warmwhite
level_coolwhite += step_coolwhite
app.strip_warmwhite.hardware_PWM(app.pin_warmwhite, 100, int(white_balance[0] * brightness * 100))
app.strip_coolwhite.hardware_PWM(app.pin_coolwhite, 100, int(white_balance[1] * brightness * 100))
@pibooth.hookimpl
def state_processing_enter(app, cfg):
"""Turn off the flash.
"""
white_balance = cfg.gettyped('FLASH', 'white_balance')
brightness = cfg.gettyped('FLASH', 'brightness')
fade_delay = cfg.gettyped('FLASH', 'fade_delay')
if fade_delay != 0:
level_warmwhite = white_balance[0]
level_coolwhite = white_balance[1]
steps_number = fade_delay / 10
step_warmwhite = white_balance[0] / steps_number
step_coolwhite = white_balance[1] / steps_number
while level_warmwhite >= 0 and level_coolwhite >= 0:
app.strip_warmwhite.hardware_PWM(app.pin_warmwhite, 100, int(level_warmwhite * brightness * 100))
app.strip_coolwhite.hardware_PWM(app.pin_coolwhite, 100, int(level_coolwhite * brightness * 100))
sleep(10 / 1000)
level_warmwhite -= step_warmwhite
level_coolwhite -= step_coolwhite
app.strip_warmwhite.hardware_PWM(app.pin_warmwhite, 100, 0)
app.strip_coolwhite.hardware_PWM(app.pin_coolwhite, 100, 0)
"""Stop LED strips (warm white and cool white).
"""
app.strip_warmwhite.stop()
app.strip_coolwhite.stop()