-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportmanager.py
More file actions
75 lines (62 loc) · 1.7 KB
/
portmanager.py
File metadata and controls
75 lines (62 loc) · 1.7 KB
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
"""Interface between the XBee and the algorithm."""
from __future__ import division, print_function
from serial import Serial
from xbee import XBee
from pyglet.event import EventDispatcher
__author__ = "Zander Otavka"
class PortManager(EventDispatcher):
"""
:type _serial_port: Serial
:type _xbee: XBee
"""
FAKE_DATA = [
200, 100,
400, 285,
600, 200,
800, 400,
230, 450,
120, 300,
110, 130,
345, 139,
824, 460,
000, 000,
400, 250,
600, 100,
800, 204,
230, 250,
120, 200,
110, 230,
]
_serial_port = None
_xbee = None
def __init__(self, port):
"""
:type port: unicode
"""
# self._serial_port = Serial(port, 9600)
print("open port: {}".format(port))
self._serial_port = Serial()
def send_data(self, data):
"""
:type data: tuple
"""
# TODO: implement PortManager.send_data
print("send data: {} to xbee: {}".format(data, self._xbee))
def open(self):
def on_get_data_callback(data):
# TODO: parse the data into an array
array = data
self.dispatch_event("on_get_data", array)
# self._xbee = XBee(self._serial_port, callback=on_get_data_callback)
on_get_data_callback(PortManager.FAKE_DATA)
def close(self):
print("closing port {}".format(self._serial_port))
self._xbee.halt()
self._serial_port.close()
# noinspection PyMethodMayBeStatic
def on_get_data(self, data):
"""
:type data: list[int]
"""
pass
PortManager.register_event_type("on_get_data")