HandsON-BuildHat-API 1.0.7__tar.gz → 1.0.9__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HandsON-BuildHat-API
3
- Version: 1.0.7
3
+ Version: 1.0.9
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
@@ -1,7 +1,7 @@
1
1
 
2
2
  [project]
3
3
  name = "HandsON-BuildHat-API"
4
- version = "1.0.7"
4
+ version = "1.0.9"
5
5
  description = "A third-party API for controlling LEGO SPIKE devices"
6
6
  authors = [
7
7
  { name="HaNeul Jung", email="hnjung@handsontech.co.kr" }
@@ -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
- HUB_DATA = 0b1010 << 4
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):
@@ -216,10 +229,11 @@ class Motor(_ModuleParent):
216
229
  if not speed in range(-100, 101):
217
230
  raise Exception('모터의 속도는 ~100 ~ 100 사이의 정수만 입력 가능합니다.')
218
231
 
219
- if speed > 0: sw = 1
220
- else: sw = 0
232
+ # if speed > 0: sw = 1
233
+ # else: sw = 0
234
+ if speed < 0: speed = speed & 0xFF
221
235
 
222
- com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_PWM, abs(speed), sw))
236
+ com = bytes((_ConstValue.TRA_DATA + self._PORT, _ConstValue.MOTOR_PWM, speed))
223
237
  self._get_data(com)
224
238
 
225
239
  def run_to_position(self, degrees, speed) -> None:
@@ -272,7 +286,7 @@ class MotorPair(_ModuleParent):
272
286
 
273
287
  def stop(self) -> None:
274
288
  for i in self._PORTs:
275
- com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.MOTOR_PWM, 0, 0))
289
+ com = bytes((_ConstValue.TRA_DATA + i, _ConstValue.MOTOR_STOP, 0, 0))
276
290
  self._get_data(com)
277
291
 
278
292
  def start(self, steering, speed) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HandsON-BuildHat-API
3
- Version: 1.0.7
3
+ Version: 1.0.9
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