-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtimelapse.py
executable file
·91 lines (73 loc) · 1.79 KB
/
timelapse.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
#!/usr/bin/env python
import datetime
import logging
import os
import re
import requests
import subprocess
import sys
import threading
import time
import status
from novatek import Novatek
logging.basicConfig(
datefmt='%m-%d-%y %H:%M:%S',
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO
)
N = Novatek()
logging.info('Waiting for camera on network')
status.led_on()
while True:
try:
N.ping()
break
except requests.exceptions.ConnectionError:
pass
except KeyboardInterrupt:
sys.exit(1)
except Exception:
logging.exception('Unhandled exception while waiting for camera')
raise
time.sleep(1.0)
logging.info('Configuring camera')
N.set_mode(Novatek.MODE['Video']) # needs to be in video mode to take photos??
def capture():
logging.info('Starting capture')
try:
N.set_ev(Novatek.EV['+2.0'])
N.take_photo()
N.set_ev(Novatek.EV['0.0'])
N.take_photo()
N.set_ev(Novatek.EV['-2.0'])
N.take_photo()
return True
except Exception as e:
logging.exception('Capture failed')
raise
def get_remaining_captures():
try:
x = N.get_capture_num()
logging.info('Space remaining to store %i photos', x)
return x
except Exception as e:
logging.exception('Failed to get remaining space')
raise
def report_status(healthy):
threading.Thread(target=status.report_status, args=(healthy,)).start()
# Capture
while True:
healthy = True
try:
capture()
while get_remaining_captures() < 20:
files = N.get_file_list()
oldest = files[0] # big assumption that this is oldest
logging.warn('Disk space is too low, purging %s', oldest)
Novatek().delete_file(oldest)
except KeyboardInterrupt:
break
except Exception:
healthy = False
report_status(healthy)
time.sleep(30)