HandsON-BuildHat-API 1.0.7__tar.gz → 1.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {handson_buildhat_api-1.0.7/src/HandsON_BuildHat_API.egg-info → handson_buildhat_api-1.0.8}/PKG-INFO +1 -1
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/pyproject.toml +1 -1
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/SpikePI.py +34 -21
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8/src/HandsON_BuildHat_API.egg-info}/PKG-INFO +1 -1
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/LICENSE +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/README.md +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/setup.cfg +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/__init__.py +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/SOURCES.txt +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/dependency_links.txt +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/requires.txt +0 -0
- {handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/top_level.txt +0 -0
{handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/SpikePI.py
RENAMED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
from serial import Serial
|
|
9
9
|
import time
|
|
10
10
|
|
|
11
|
+
class _ConstLedID:
|
|
12
|
+
START_LED = 1
|
|
13
|
+
STOP_LED = 0
|
|
14
|
+
|
|
11
15
|
class _ConstButtonID:
|
|
12
16
|
START = 0
|
|
13
17
|
STOP = 1
|
|
@@ -31,7 +35,8 @@ class _ConstValue:
|
|
|
31
35
|
'''
|
|
32
36
|
기타 상수 모음
|
|
33
37
|
'''
|
|
34
|
-
|
|
38
|
+
HUB_GET_DATA = 0b1010 << 4
|
|
39
|
+
HUB_TRA_DATA = 0b1011 << 4
|
|
35
40
|
TRA_DATA = 0b1000 << 4
|
|
36
41
|
GET_DATA = 0b1001 << 4
|
|
37
42
|
|
|
@@ -99,25 +104,6 @@ class _SerialManager:
|
|
|
99
104
|
|
|
100
105
|
if serial == None:
|
|
101
106
|
raise Exception('사용 가능한 시리얼 포트를 찾을 수 없습니다.')
|
|
102
|
-
|
|
103
|
-
class _button:
|
|
104
|
-
def __init__(self, button_id = _ConstButtonID.STOP):
|
|
105
|
-
self.button_id = button_id
|
|
106
|
-
|
|
107
|
-
def is_pressed(self):
|
|
108
|
-
command = b'\xa0\x00\x00\x00\x00\x00\x00'
|
|
109
|
-
command += _Availability.make_checksum(command)
|
|
110
|
-
while True:
|
|
111
|
-
_SerialManager.serial.write(command)
|
|
112
|
-
data = _SerialManager.serial.read(16)
|
|
113
|
-
if _Availability.checksum_check(data): break
|
|
114
|
-
result = True if data[self.button_id + 1] == 1 else False
|
|
115
|
-
return result
|
|
116
|
-
|
|
117
|
-
class BuildHat:
|
|
118
|
-
def __init__(self):
|
|
119
|
-
self.stop_button = _button(_ConstButtonID.STOP)
|
|
120
|
-
self.start_button = _button(_ConstButtonID.START)
|
|
121
107
|
|
|
122
108
|
class _ModuleParent:
|
|
123
109
|
def _get_data(self, byte:bytes) -> bytes:
|
|
@@ -141,6 +127,33 @@ class _ModuleParent:
|
|
|
141
127
|
command = [_ConstValue.GET_DATA + _ConstValue.ALL_PORT]
|
|
142
128
|
if not self._get_data(byte=bytes(command))[port + 1] in ID:
|
|
143
129
|
raise Exception('해당 포트에 연결된 모듈이 다르거나 없습니다.')
|
|
130
|
+
|
|
131
|
+
class _button(_ModuleParent):
|
|
132
|
+
def __init__(self, button_id = _ConstButtonID.STOP):
|
|
133
|
+
self.button_id = button_id
|
|
134
|
+
|
|
135
|
+
def is_pressed(self):
|
|
136
|
+
command = [_ConstValue.HUB_GET_DATA]
|
|
137
|
+
data = self._get_data(bytes(command))
|
|
138
|
+
result = True if data[1 + self.button_id] == 1 else False
|
|
139
|
+
return result
|
|
140
|
+
|
|
141
|
+
class _led(_ModuleParent):
|
|
142
|
+
def __init__(self, led_id = _ConstLedID.STOP_LED):
|
|
143
|
+
self.led_id = led_id
|
|
144
|
+
|
|
145
|
+
def set(self, status):
|
|
146
|
+
command = [_ConstValue.HUB_TRA_DATA, self.led_id, status, 0, 0, 0, 0]
|
|
147
|
+
self._get_data(bytes(command))
|
|
148
|
+
return None
|
|
149
|
+
|
|
150
|
+
class BuildHat:
|
|
151
|
+
def __init__(self):
|
|
152
|
+
self.stop_button = _button(_ConstButtonID.STOP)
|
|
153
|
+
self.start_button = _button(_ConstButtonID.START)
|
|
154
|
+
|
|
155
|
+
self.stop_led = _led(_ConstLedID.STOP_LED)
|
|
156
|
+
self.start_led = _led(_ConstLedID.START_LED)
|
|
144
157
|
|
|
145
158
|
class ColorSensor(_ModuleParent):
|
|
146
159
|
def __init__(self, port:str):
|
|
@@ -272,7 +285,7 @@ class MotorPair(_ModuleParent):
|
|
|
272
285
|
|
|
273
286
|
def stop(self) -> None:
|
|
274
287
|
for i in self._PORTs:
|
|
275
|
-
com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.
|
|
288
|
+
com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.MOTOR_STOP, 0, 0))
|
|
276
289
|
self._get_data(com)
|
|
277
290
|
|
|
278
291
|
def start(self, steering, speed) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{handson_buildhat_api-1.0.7 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|