-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcam.py
61 lines (51 loc) · 1.72 KB
/
cam.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
import camera
import machine
import utime
from time import sleep
class CameraBoard():
def __init__(self, os, photo_directory = "/sd/"):
self.os = os
self.cam_loading = True
self.photo_directory = photo_directory
self.microsd_config = {
'miso':8,
'mosi':9,
'cs':21,
'sck':7,
}
self.sd = machine.SDCard(slot=3, width=1,
sck=machine.Pin(self.microsd_config['sck']),
mosi=machine.Pin(self.microsd_config['mosi']),
miso=machine.Pin(self.microsd_config['miso']),
cs=machine.Pin(self.microsd_config['cs']))
self.expansion_board_init()
def cam_init(self):
while self.cam_loading:
cam_ready = camera.init() # Camera
print("Camera ready?: ", cam_ready)
self.cam_loading = not cam_ready
sleep(1)
def expansion_board_init(self):
print("mounting")
print(self.sd.info())
self.os.mount(self.sd, "/sd")
print(self.os.listdir("/sd"))
def get_time(self):
current_time = utime.localtime()
hour = current_time[3]
minute = current_time[4]
sec = current_time[5]
return str(hour) + "_" + str(minute) + "_" + str(sec)
def save_photo(self, file_name, data):
file_path = self.photo_directory + file_name + ".jpg"
imgFile = open(file_path, "wb")
imgFile.write(data)
imgFile.close()
def take_photo(self):
#self.cam_init()
p=camera.capture()
print("photo_captured")
#self.close()
return p
def close(self):
camera.deinit()