HandsON-BuildHat-API 1.0.2__tar.gz → 1.0.4__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.
@@ -1,10 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HandsON-BuildHat-API
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: A third-party API for controlling LEGO SPIKE devices
5
5
  Author-email: HandsON Technology <caffeine.reload@gmail.com>
6
6
  License: Proprietary - Personal/Educational Use Only
7
- Project-URL: Homepage, https://github.com/yourname/HandsON-BuildHat-API
8
7
  Classifier: Programming Language :: Python :: 3
9
8
  Classifier: License :: Other/Proprietary License
10
9
  Classifier: Operating System :: OS Independent
@@ -1,10 +1,7 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0"]
3
- build-backend = "setuptools.build_meta"
4
1
 
5
2
  [project]
6
3
  name = "HandsON-BuildHat-API"
7
- version = "1.0.2"
4
+ version = "1.0.4"
8
5
  description = "A third-party API for controlling LEGO SPIKE devices"
9
6
  authors = [
10
7
  { name="HandsON Technology", email="caffeine.reload@gmail.com" }
@@ -19,13 +16,4 @@ classifiers = [
19
16
  "Programming Language :: Python :: 3",
20
17
  "License :: Other/Proprietary License",
21
18
  "Operating System :: OS Independent",
22
- ]
23
-
24
- [project.urls]
25
- "Homepage" = "https://github.com/yourname/HandsON-BuildHat-API"
26
-
27
- [tool.setuptools]
28
- package-dir = {"" = "src"}
29
-
30
- [tool.setuptools.packages.find]
31
- where = ["src"]
19
+ ]
@@ -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
- COMMAND = 0b1000 << 4
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.COMMAND + self._PORT, _ConstValue.MOTOR_PWM_MODE, 0, 0))
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.COMMAND + self._PORT, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
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.COMMAND + self._PORT, _ConstValue.MOTOR_ABS_MODE, speed, (target & 0xFF), (target >> 8)))
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.COMMAND + self._PORT, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
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.COMMAND + i, _ConstValue.MOTOR_PWM_MODE, 0, 0))
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.COMMAND + motor, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
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.COMMAND + motor, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
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.COMMAND + motor, _ConstValue.MOTOR_REL_MODE, speed, (target & 0xFF), (target >> 8) & 0xFF, (target >> 16) & 0xFF, (target >> 24) & 0xFF))
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.COMMAND + motor, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
351
+ com = bytes((_ConstValue.TRA_DATA + motor, _ConstValue.MOTOR_PWM_MODE, sw, abs(speed)))
324
352
  self._send_data(com)
@@ -0,0 +1,4 @@
1
+
2
+ from .SpikePI import BuildHat, Motor, MotorPair, ColorSensor, DistanceSensor, ForceSensor
3
+
4
+ __all__ = ['BuildHat', 'Motor', 'MotorPair', 'ColorSensor', 'DistanceSensor', 'ForceSensor']
@@ -1,10 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HandsON-BuildHat-API
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: A third-party API for controlling LEGO SPIKE devices
5
5
  Author-email: HandsON Technology <caffeine.reload@gmail.com>
6
6
  License: Proprietary - Personal/Educational Use Only
7
- Project-URL: Homepage, https://github.com/yourname/HandsON-BuildHat-API
8
7
  Classifier: Programming Language :: Python :: 3
9
8
  Classifier: License :: Other/Proprietary License
10
9
  Classifier: Operating System :: OS Independent
@@ -1,4 +0,0 @@
1
-
2
- from .SpikePI import Motor, MotorPair, ColorSensor, DistanceSensor, ForceSensor
3
-
4
- __all__ = ['Motor', 'MotorPair', 'ColorSensor', 'DistanceSensor', 'ForceSensor']