-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicroscope.py
47 lines (39 loc) · 1.2 KB
/
picroscope.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
#! /user/bin/env python3
from picamera import PiCamera
from datetime import datetime
from os import path
class StubLED:
def on(self):
pass
def off(self):
pass
class Picroscope:
def __init__(self, led=None, rotation=0, captureDir="/home/pi/Desktop"):
self.captureDir = captureDir
self.led = led if led else StubLED()
self.camera = PiCamera()
self.camera.rotation = rotation
self.preview = False
def capture(self):
if self.preview:
now = datetime.now().isoformat()
file = path.join(self.captureDir, format(now) + ".jpg")
print("Image Captured: ", file)
self.camera.capture(file)
return file
return None
def toggle_preview(self):
self.preview = not self.preview
if self.preview:
self.led.on()
self.camera.start_preview()
else:
self.led.off()
self.camera.stop_preview()
@property
def help_text(self):
return (
"Press left button to start preview.\n"
+ "Press right button to send the image.\n"
+ "Press ctrl-C to quit the programme."
)