-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequest.py
More file actions
34 lines (26 loc) · 743 Bytes
/
request.py
File metadata and controls
34 lines (26 loc) · 743 Bytes
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
from arduino import Arduino
class Request:
STP = 'a'
STR = 'b'
ROT = 'c'
GET_MODE = 'e'
GET_DIST = 'f'
GET_BATT = 'g'
def __init__(self):
self.arduino = Arduino()
def set(self, cmd_data):
self.arduino.send(cmd_data)
def get(self, mode):
cmd_data = [mode, 0, 0]
self.set(cmd_data)
return self.arduino.receive()
def get_dist(self):
cmd_data = self.get(Request.GET_DIST)
if cmd_data is False:
return False
return cmd_data[1], cmd_data[2] # Left, Rightの順番
def get_batt(self):
cmd_data = self.get(Request.GET_BATT)
if cmd_data is False:
return False
return cmd_data[1] / 100.0