forked from dps/rpi-timelapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtl.py
executable file
·124 lines (106 loc) · 3.51 KB
/
tl.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python
from datetime import datetime
from datetime import timedelta
import subprocess
import time
from wrappers import GPhoto
from wrappers import Identify
from wrappers import NetworkInfo
from ui import TimelapseUi
MIN_INTER_SHOT_DELAY_SECONDS = timedelta(seconds=30)
MIN_BRIGHTNESS = 20000
MAX_BRIGHTNESS = 30000
CONFIGS = [("1/1600", 200),
("1/1000", 200),
("1/800", 200),
("1/500", 200),
("1/320", 200),
("1/250", 200),
("1/200", 200),
("1/160", 200),
("1/100", 200),
("1/80", 200),
("1/60", 200),
("1/50", 200),
("1/40", 200),
("1/30", 200),
("1/20", 200),
("1/15", 200),
("1/13", 200),
("1/10", 200),
("1/6", 200),
("1/5", 200),
("1/4", 200),
("0.3", 200),
("0.5", 200),
("0.6", 200),
("0.8", 200),
("1", 200),
("1.6", 200),
("2.5", 200),
("3.2", 200),
("5", 200),
("8", 200),
("10", 200),
("13", 200),
("15", 200),
("20", 200),
("30", 200),
("30", 400),
("30", 800),
("30", 1600)]
def test_configs():
camera = GPhoto(subprocess)
for config in CONFIGS:
camera.set_shutter_speed(secs=config[0])
camera.set_iso(iso=str(config[1]))
time.sleep(1)
def main():
#print "Testing Configs"
#test_configs()
print "Timelapse"
camera = GPhoto(subprocess)
idy = Identify(subprocess)
netinfo = NetworkInfo(subprocess)
ui = TimelapseUi()
current_config = 11
shot = 0
prev_acquired = None
last_acquired = None
last_started = None
network_status = netinfo.network_status()
current_config = ui.main(CONFIGS, current_config, network_status)
try:
while True:
last_started = datetime.now()
config = CONFIGS[current_config]
print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1])
ui.backlight_on()
ui.show_status(shot, CONFIGS, current_config)
camera.set_shutter_speed(secs=config[0])
camera.set_iso(iso=str(config[1]))
ui.backlight_off()
try:
filename = camera.capture_image_and_download()
except Exception, e:
print "Error on capture." + str(e)
print "Retrying..."
# Occasionally, capture can fail but retries will be successful.
continue
prev_acquired = last_acquired
brightness = float(idy.mean_brightness(filename))
last_acquired = datetime.now()
print "-> %s %s" % (filename, brightness)
if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1:
current_config = current_config + 1
elif brightness > MAX_BRIGHTNESS and current_config > 0:
current_config = current_config - 1
else:
if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS:
print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started))
time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds)
shot = shot + 1
except Exception,e:
ui.show_error(str(e))
if __name__ == "__main__":
main()