HandsON-BuildHat-API 1.0.2__tar.gz → 1.0.3__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.2/src/HandsON_BuildHat_API.egg-info → handson_buildhat_api-1.0.3}/PKG-INFO +1 -1
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/pyproject.toml +1 -1
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API/SpikePI.py +38 -10
- handson_buildhat_api-1.0.3/src/HandsON_BuildHat_API/__init__.py +4 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3/src/HandsON_BuildHat_API.egg-info}/PKG-INFO +1 -1
- handson_buildhat_api-1.0.2/src/HandsON_BuildHat_API/__init__.py +0 -4
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/LICENSE +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/README.md +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/setup.cfg +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API.egg-info/SOURCES.txt +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API.egg-info/dependency_links.txt +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API.egg-info/requires.txt +0 -0
- {handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "HandsON-BuildHat-API"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.3"
|
|
8
8
|
description = "A third-party API for controlling LEGO SPIKE devices"
|
|
9
9
|
authors = [
|
|
10
10
|
{ name="HandsON Technology", email="caffeine.reload@gmail.com" }
|
{handson_buildhat_api-1.0.2 → handson_buildhat_api-1.0.3}/src/HandsON_BuildHat_API/SpikePI.py
RENAMED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
from serial import Serial
|
|
9
9
|
import time
|
|
10
10
|
|
|
11
|
+
class _ConstButtonID:
|
|
12
|
+
STOP = 0
|
|
13
|
+
START = 1
|
|
14
|
+
|
|
15
|
+
LEFT = 2
|
|
16
|
+
RIGHT = 3
|
|
17
|
+
|
|
11
18
|
class _ConstModuleID:
|
|
12
19
|
'''
|
|
13
20
|
모듈 ID 모음
|
|
@@ -24,8 +31,10 @@ class _ConstValue:
|
|
|
24
31
|
'''
|
|
25
32
|
기타 상수 모음
|
|
26
33
|
'''
|
|
27
|
-
|
|
34
|
+
HUB_DATA = 0b1010 << 4
|
|
35
|
+
TRA_DATA = 0b1000 << 4
|
|
28
36
|
GET_DATA = 0b1001 << 4
|
|
37
|
+
|
|
29
38
|
ALL_PORT = 0b1111
|
|
30
39
|
|
|
31
40
|
MOTOR_PWM_MODE = 0
|
|
@@ -88,6 +97,25 @@ class _SerialManager:
|
|
|
88
97
|
|
|
89
98
|
if serial == None:
|
|
90
99
|
raise Exception('사용 가능한 시리얼 포트를 찾을 수 없습니다.')
|
|
100
|
+
|
|
101
|
+
class _button:
|
|
102
|
+
def __init__(self, button_id = _ConstButtonID.STOP):
|
|
103
|
+
self.button_id = button_id
|
|
104
|
+
|
|
105
|
+
def is_pressed(self):
|
|
106
|
+
command = b'\xa0\x00\x00\x00\x00\x00\x00'
|
|
107
|
+
command += _Availability.make_checksum(command)
|
|
108
|
+
while True:
|
|
109
|
+
_SerialManager.serial.write(command)
|
|
110
|
+
data = _SerialManager.serial.read(16)
|
|
111
|
+
if _Availability.checksum_check(data): break
|
|
112
|
+
result = True if data[self.button_id + 1] == 1 else False
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
class BuildHat:
|
|
116
|
+
def __init__(self):
|
|
117
|
+
self.stop_button = _button(_ConstButtonID.STOP)
|
|
118
|
+
self.start_button = _button(_ConstButtonID.START)
|
|
91
119
|
|
|
92
120
|
class _ModuleParent:
|
|
93
121
|
def _get_data(self, byte:bytes) -> bytes:
|
|
@@ -178,7 +206,7 @@ class Motor(_ModuleParent):
|
|
|
178
206
|
self._module_check(self._PORT, (_ConstModuleID.SMALL_MOTOR, _ConstModuleID.MEDIUM_MOTOR, _ConstModuleID.LARGE_MOTOR))
|
|
179
207
|
|
|
180
208
|
def stop(self) -> None:
|
|
181
|
-
com = bytes((_ConstValue.
|
|
209
|
+
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_PWM_MODE, 0, 0))
|
|
182
210
|
self._send_data(com)
|
|
183
211
|
|
|
184
212
|
def start(self, speed:int) -> None:
|
|
@@ -188,7 +216,7 @@ class Motor(_ModuleParent):
|
|
|
188
216
|
if speed > 0: sw = 1
|
|
189
217
|
else: sw = 0
|
|
190
218
|
|
|
191
|
-
com = bytes((_ConstValue.
|
|
219
|
+
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
|
|
192
220
|
self._send_data(com)
|
|
193
221
|
|
|
194
222
|
def run_to_position(self, degrees, speed) -> None:
|
|
@@ -200,7 +228,7 @@ class Motor(_ModuleParent):
|
|
|
200
228
|
if degrees >= 0: target = degrees
|
|
201
229
|
else: target = degrees & 0xFFFF
|
|
202
230
|
|
|
203
|
-
com = bytes((_ConstValue.
|
|
231
|
+
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_ABS_MODE, speed, (target & 0xFF), (target >> 8)))
|
|
204
232
|
self._send_data(com)
|
|
205
233
|
|
|
206
234
|
def run_for_degrees(self, degrees, speed) -> None:
|
|
@@ -213,7 +241,7 @@ class Motor(_ModuleParent):
|
|
|
213
241
|
if degrees >= 0: target = degrees
|
|
214
242
|
else: target = degrees & 0xFFFFFFFF
|
|
215
243
|
|
|
216
|
-
com = bytes((_ConstValue.
|
|
244
|
+
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
217
245
|
self._send_data(com)
|
|
218
246
|
|
|
219
247
|
def get_speed(self) -> int:
|
|
@@ -241,7 +269,7 @@ class MotorPair(_ModuleParent):
|
|
|
241
269
|
|
|
242
270
|
def stop(self) -> None:
|
|
243
271
|
for i in self._PORTs:
|
|
244
|
-
com = bytes((_ConstValue.
|
|
272
|
+
com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.MOTOR_PWM_MODE, 0, 0))
|
|
245
273
|
self._send_data(com)
|
|
246
274
|
|
|
247
275
|
def start(self, steering, speed) -> None:
|
|
@@ -259,7 +287,7 @@ class MotorPair(_ModuleParent):
|
|
|
259
287
|
if speed > 0: sw = 1
|
|
260
288
|
else: sw = 0
|
|
261
289
|
|
|
262
|
-
com = bytes((_ConstValue.
|
|
290
|
+
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
|
|
263
291
|
self._send_data(com)
|
|
264
292
|
|
|
265
293
|
def move(self, degrees, steering, speed) -> None:
|
|
@@ -282,7 +310,7 @@ class MotorPair(_ModuleParent):
|
|
|
282
310
|
|
|
283
311
|
if count == 1: target = ~target
|
|
284
312
|
|
|
285
|
-
com = bytes((_ConstValue.
|
|
313
|
+
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
286
314
|
self._send_data(com)
|
|
287
315
|
|
|
288
316
|
|
|
@@ -304,7 +332,7 @@ class MotorPair(_ModuleParent):
|
|
|
304
332
|
|
|
305
333
|
if count == 1: target = ~target
|
|
306
334
|
|
|
307
|
-
com = bytes((_ConstValue.
|
|
335
|
+
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
308
336
|
self._send_data(com)
|
|
309
337
|
|
|
310
338
|
def start_tank(self, left_speed, right_speed) -> None:
|
|
@@ -320,5 +348,5 @@ class MotorPair(_ModuleParent):
|
|
|
320
348
|
if speed > 0: sw = 1
|
|
321
349
|
else: sw = 0
|
|
322
350
|
|
|
323
|
-
com = bytes((_ConstValue.
|
|
351
|
+
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
|
|
324
352
|
self._send_data(com)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|