HandsON-BuildHat-API 1.0.6__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.6/src/HandsON_BuildHat_API.egg-info → handson_buildhat_api-1.0.8}/PKG-INFO +2 -2
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/README.md +1 -1
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/pyproject.toml +1 -1
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/SpikePI.py +47 -33
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8/src/HandsON_BuildHat_API.egg-info}/PKG-INFO +2 -2
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/LICENSE +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/setup.cfg +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/__init__.py +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/SOURCES.txt +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/dependency_links.txt +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/requires.txt +0 -0
- {handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API.egg-info/top_level.txt +0 -0
{handson_buildhat_api-1.0.6/src/HandsON_BuildHat_API.egg-info → handson_buildhat_api-1.0.8}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: HandsON-BuildHat-API
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.8
|
|
4
4
|
Summary: A third-party API for controlling LEGO SPIKE devices
|
|
5
5
|
Author-email: HaNeul Jung <hnjung@handsontech.co.kr>
|
|
6
6
|
License: Proprietary - Personal/Educational Use Only
|
|
@@ -17,7 +17,7 @@ HandsON Build Hat API
|
|
|
17
17
|
=======
|
|
18
18
|
**Production** : HandsON Technology co., ltd.
|
|
19
19
|
**Author** : HaNeul Jung (hnjung@handsontech.co.kr)
|
|
20
|
-
**Last Update** : 2025-
|
|
20
|
+
**Last Update** : 2025-09-01
|
|
21
21
|
|
|
22
22
|
## 주의
|
|
23
23
|
2025-08-27 이전 판매된 빌드햇 제품의 경우 1.0.4 버전을 사용
|
{handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8}/src/HandsON_BuildHat_API/SpikePI.py
RENAMED
|
@@ -8,9 +8,13 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
16
|
+
START = 0
|
|
17
|
+
STOP = 1
|
|
14
18
|
|
|
15
19
|
LEFT = 2
|
|
16
20
|
RIGHT = 3
|
|
@@ -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
|
|
|
@@ -93,31 +98,12 @@ class _SerialManager:
|
|
|
93
98
|
serial = None
|
|
94
99
|
|
|
95
100
|
for i in _serial_port:
|
|
96
|
-
try: serial = Serial(port=i, baudrate=115200, timeout=0.
|
|
101
|
+
try: serial = Serial(port=i, baudrate=115200, timeout=0.02)
|
|
97
102
|
except: pass
|
|
98
103
|
else: break
|
|
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:
|
|
@@ -128,6 +114,7 @@ class _ModuleParent:
|
|
|
128
114
|
if data == b'': continue
|
|
129
115
|
|
|
130
116
|
if _Availability.checksum_check(data): return data
|
|
117
|
+
if ((len(data) == 1) and (data[0] == 0x04)): return data
|
|
131
118
|
|
|
132
119
|
def _send_data(self, byte:bytes) -> None:
|
|
133
120
|
com = byte
|
|
@@ -140,6 +127,33 @@ class _ModuleParent:
|
|
|
140
127
|
command = [_ConstValue.GET_DATA + _ConstValue.ALL_PORT]
|
|
141
128
|
if not self._get_data(byte=bytes(command))[port + 1] in ID:
|
|
142
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)
|
|
143
157
|
|
|
144
158
|
class ColorSensor(_ModuleParent):
|
|
145
159
|
def __init__(self, port:str):
|
|
@@ -209,7 +223,7 @@ class Motor(_ModuleParent):
|
|
|
209
223
|
|
|
210
224
|
def stop(self) -> None:
|
|
211
225
|
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_STOP, 0, 0))
|
|
212
|
-
self.
|
|
226
|
+
self._get_data(com)
|
|
213
227
|
|
|
214
228
|
def start(self, speed:int) -> None:
|
|
215
229
|
if not speed in range(-100, 101):
|
|
@@ -219,7 +233,7 @@ class Motor(_ModuleParent):
|
|
|
219
233
|
else: sw = 0
|
|
220
234
|
|
|
221
235
|
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_PWM, abs(speed), sw))
|
|
222
|
-
self.
|
|
236
|
+
self._get_data(com)
|
|
223
237
|
|
|
224
238
|
def run_to_position(self, degrees, speed) -> None:
|
|
225
239
|
if not speed in range(0, 101):
|
|
@@ -231,7 +245,7 @@ class Motor(_ModuleParent):
|
|
|
231
245
|
else: target = degrees & 0xFFFF
|
|
232
246
|
|
|
233
247
|
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_ABS, speed, (target & 0xFF), (target >> 8)))
|
|
234
|
-
self.
|
|
248
|
+
self._get_data(com)
|
|
235
249
|
|
|
236
250
|
def run_for_degrees(self, degrees, speed) -> None:
|
|
237
251
|
if not speed in range(0, 101):
|
|
@@ -244,7 +258,7 @@ class Motor(_ModuleParent):
|
|
|
244
258
|
else: target = degrees & 0xFFFFFFFF
|
|
245
259
|
|
|
246
260
|
com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_REL, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
247
|
-
self.
|
|
261
|
+
self._get_data(com)
|
|
248
262
|
|
|
249
263
|
def get_speed(self) -> int:
|
|
250
264
|
command = [_ConstValue.GET_DATA + self._PORT]
|
|
@@ -271,8 +285,8 @@ class MotorPair(_ModuleParent):
|
|
|
271
285
|
|
|
272
286
|
def stop(self) -> None:
|
|
273
287
|
for i in self._PORTs:
|
|
274
|
-
com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.
|
|
275
|
-
self.
|
|
288
|
+
com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.MOTOR_STOP, 0, 0))
|
|
289
|
+
self._get_data(com)
|
|
276
290
|
|
|
277
291
|
def start(self, steering, speed) -> None:
|
|
278
292
|
if not steering in range(-100, 101):
|
|
@@ -290,7 +304,7 @@ class MotorPair(_ModuleParent):
|
|
|
290
304
|
else: sw = 0
|
|
291
305
|
|
|
292
306
|
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_PWM, abs(speed), sw))
|
|
293
|
-
self.
|
|
307
|
+
self._get_data(com)
|
|
294
308
|
|
|
295
309
|
def move(self, degrees, steering, speed) -> None:
|
|
296
310
|
if not steering in range(-100, 101):
|
|
@@ -313,7 +327,7 @@ class MotorPair(_ModuleParent):
|
|
|
313
327
|
if count == 1: target = ~target
|
|
314
328
|
|
|
315
329
|
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_REL, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
316
|
-
self.
|
|
330
|
+
self._get_data(com)
|
|
317
331
|
|
|
318
332
|
|
|
319
333
|
def move_tank(self, degrees, left_speed, right_speed) -> None:
|
|
@@ -335,7 +349,7 @@ class MotorPair(_ModuleParent):
|
|
|
335
349
|
if count == 1: target = ~target
|
|
336
350
|
|
|
337
351
|
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_REL, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
|
|
338
|
-
self.
|
|
352
|
+
self._get_data(com)
|
|
339
353
|
|
|
340
354
|
def start_tank(self, left_speed, right_speed) -> None:
|
|
341
355
|
if not left_speed in range(-100, 101) or not right_speed in range(-100, 101):
|
|
@@ -351,4 +365,4 @@ class MotorPair(_ModuleParent):
|
|
|
351
365
|
else: sw = 0
|
|
352
366
|
|
|
353
367
|
com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_PWM, abs(speed), sw))
|
|
354
|
-
self.
|
|
368
|
+
self._get_data(com)
|
{handson_buildhat_api-1.0.6 → handson_buildhat_api-1.0.8/src/HandsON_BuildHat_API.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: HandsON-BuildHat-API
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.8
|
|
4
4
|
Summary: A third-party API for controlling LEGO SPIKE devices
|
|
5
5
|
Author-email: HaNeul Jung <hnjung@handsontech.co.kr>
|
|
6
6
|
License: Proprietary - Personal/Educational Use Only
|
|
@@ -17,7 +17,7 @@ HandsON Build Hat API
|
|
|
17
17
|
=======
|
|
18
18
|
**Production** : HandsON Technology co., ltd.
|
|
19
19
|
**Author** : HaNeul Jung (hnjung@handsontech.co.kr)
|
|
20
|
-
**Last Update** : 2025-
|
|
20
|
+
**Last Update** : 2025-09-01
|
|
21
21
|
|
|
22
22
|
## 주의
|
|
23
23
|
2025-08-27 이전 판매된 빌드햇 제품의 경우 1.0.4 버전을 사용
|
|
File without changes
|
|
File without changes
|
{handson_buildhat_api-1.0.6 → 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
|