forked from Make3DPrintingProjects/Skycam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskycam.py
69 lines (66 loc) · 2.43 KB
/
skycam.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
#!/usr/bin/python3.5
from PyQt5.QtCore import QObject, QThread
from communication import Communication
from flask import Flask, Response
from streamer import Streamer, main, FlaskThread
from functools import partial
class Skycam(QObject):
def __init__(self, master, cam, communication=None):
super().__init__()
self.master = master
if not communication:
self.comm = Communication(self, 0x50)
else:
self.comm = communication
self.fapp = Flask(__name__)
self.streamer = Streamer(self, cam)
@self.fapp.route('/')
def feed():
return Response(self.streamer.stream(), mimetype='multipart/x-mixed-replace; boundary=frame')
self.th = FlaskThread(self.fapp)
self.th.start()
def move(self, direction=None):
'''Moves the Skycam in the direction specified
Usage: Skycam.move(direction)
where direction is either 0 for forward or 1 for backward'''
if direction is not None:
self.comm.write("move," + str(direction))
return int(self.comm.read())
else:
self.comm.write("move,-1")
return int(self.comm.read())
def pan(self, direction=None):
'''Pans the Skycam's camera in the direction specified
Usage: Skycam.pan(direction)
where direction is either 0 for right or 1 for left'''
if direction is not None:
self.comm.write("pan," + str(direction))
return int(self.comm.read())
else:
self.comm.write("pan,-1")
return int(self.comm.read())
def tilt(self, direction):
'''Tilts the Skycam's camera in the direction specified
Usage: Skycam.tilt(direction)
where direction is either 0 for up or 1 for down'''
if direction is not None:
self.comm.write("tilt," + str(direction))
return int(self.comm.read())
else:
self.comm.write("tilt,-1")
return int(self.comm.read())
def pan_to(self, angle=None):
if angle:
self.comm.write("panto," + str(angle))
else:
self.comm.write("panto,-1")
return int(self.comm.read())
def tilt_to(self, angle=None):
if angle:
self.comm.write("tiltto," + str(angle))
else:
self.comm.write("tiltto,-1")
return int(self.comm.read())
if __name__ == '__main__':
from picamera import PiCamera
sk = Skycam(None, PiCamera())