Skip to content

Commit 3086cf0

Browse files
committed
examples.iodevices diagnostics lint #2
2nd batch of lint errors
1 parent ec78713 commit 3086cf0

File tree

1 file changed

+29
-46
lines changed

1 file changed

+29
-46
lines changed

examples/pup/iodevices_pupdevice/diagnostics.py

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def HubInit(mounted_top=Axis.Z, mounted_front=Axis.X):
110110
64: "SPIKE 3x3 Color Light Matrix",
111111
}
112112

113+
113114
def ConnectToDevice(port):
114115
# Returns a device dict()
115116
device = {'type': None, 'id': None, 'name': None, 'object': None}
@@ -129,7 +130,7 @@ def ConnectToDevice(port):
129130
device['name'] = device_names[device['id']]
130131
except KeyError:
131132
device['name'] = "Unknown"
132-
#print(port, ":", "Unknown device with ID", xid)
133+
# print(port, ":", "Unknown device with ID", xid)
133134
if len(temp_info) > 1:
134135
print(temp_info)
135136

@@ -151,7 +152,7 @@ def ConnectToDevice(port):
151152
print("Motor could not be initiated: ", err)
152153
device['type'] = "Custom"
153154
pass
154-
elif xid is 8:
155+
elif xid == 8:
155156
try:
156157
device['object'] = Light(port)
157158
device['object'].on(brightness=50)
@@ -160,72 +161,54 @@ def ConnectToDevice(port):
160161
print("Light could not be initiated: ", err)
161162
device['type'] = "Custom"
162163
pass
163-
elif xid is None: #ToDo
164+
elif xid == 64:
164165
try:
165166
device['object'] = ColorLightMatrix(port)
167+
device['object'].on([Color.RED, Color.GREEN, Color.BLUE])
166168
device['type'] = "Matrix3x3"
167169
except OSError as err:
168170
print("Matrix could not be initiated: ", err)
169171
device['type'] = "Custom"
170172
pass
171173
elif xid in (34, 35, 37, 61, 62, 63):
172174
device['type'] = "Sensor"
173-
if xid is 34:
174-
try:
175+
sensor_class = None
176+
try:
177+
if xid == 34:
178+
sensor_class = "TiltSensor"
175179
device['object'] = TiltSensor(port)
176180
device['type'] += "/Tilt"
177-
except OSError as err:
178-
print("TiltSensor could not be initiated: ", err)
179-
device['type'] += "/Custom"
180-
pass
181-
elif xid is 35:
182-
try:
181+
elif xid == 35:
182+
sensor_class = "InfraredSensor"
183183
device['object'] = InfraredSensor(port)
184184
device['type'] += "/IR/Distance"
185-
except OSError as err:
186-
print("InfraredSensor could not be initiated: ", err)
187-
device['type'] += "/Custom"
188-
pass
189-
elif xid is 37:
190-
try:
185+
elif xid == 37:
186+
sensor_class = "ColorDistanceSensor"
191187
device['object'] = ColorDistanceSensor(port)
192188
device['type'] += "/Distance/Color/Light"
193-
except OSError as err:
194-
print("ColorDistanceSensor could not be initiated: ", err)
195-
device['type'] += "/Custom"
196-
pass
197-
elif xid is 61:
198-
try:
189+
elif xid == 61:
190+
sensor_class = "ColorSensor"
199191
device['object'] = ColorSensor(port)
200192
device['type'] += "/Color/Light"
201-
except OSError as err:
202-
print("ColorSensor could not be initiated: ", err)
203-
device['type'] += "/Custom"
204-
pass
205-
elif xid is 62:
206-
try:
193+
elif xid == 62:
194+
sensor_class = "UltrasonicSensor"
207195
device['object'] = UltrasonicSensor(port)
208196
device['type'] += "/Distance/Light"
209-
except OSError as err:
210-
print("UltrasonicSensor could not be initiated: ", err)
211-
device['type'] += "/Custom"
212-
pass
213-
elif xid is 63:
214-
try:
197+
elif xid == 63:
198+
sensor_class = "ForceSensor"
215199
device['object'] = ForceSensor(port)
216200
device['type'] += "/Force/Distance/Press"
217-
except OSError as err:
218-
print("ForceSensor could not be initiated: ", err)
219-
device['type'] += "/Custom"
220-
pass
201+
except OSError as err:
202+
print("class", sensor_class, "could not be initiated: ", err)
203+
device['type'] += "/Custom"
204+
pass
221205
else:
206+
print("Not able to translate id:", xid, "to a class!")
222207
pass
223-
224208
return device
225-
226209
# end of ConnectToDevice(port)
227210
# -------------------------------------------------------------------
228-
211+
229212
# Make a list of known ports.
230213
ports = [Port.A, Port.B]
231214
try: # to add more ports, on hubs that support it.
@@ -250,7 +233,7 @@ def ConnectRemote():
250233
try:
251234
remote = Remote(name=None,timeout=10000)
252235
print("Remote: " + remote.name())
253-
#remote.name("Remote of <user>")
236+
# remote.name("Remote of <user>")
254237
except OSError as ex:
255238
if ex.errno == ETIMEDOUT:
256239
print("No Remote found.")
@@ -270,7 +253,7 @@ def ServiceRemote():
270253
return (ch1_val, ch2_val)
271254
if len(pressed) is 0:
272255
return (ch1_val, ch2_val)
273-
#print(pressed)
256+
# print(pressed)
274257

275258
ch1_val_new = ch1_val
276259
ch2_val_new = ch2_val
@@ -303,7 +286,7 @@ def ServiceRemote():
303286

304287
# 4: Main / Monitor changes
305288
# -------------------------------------------------------------------
306-
DIAGNOSTICS_PERIOD = 5000 # 5s
289+
DIAGNOSTICS_PERIOD = 5000 # 5s
307290
sys_tick = StopWatch()
308291
(hub, hub_info) = HubInit()
309292
print(hub_info)
@@ -322,7 +305,7 @@ def ServiceRemote():
322305
if dev['type'] is None:
323306
print(port, ": ---")
324307
else:
325-
print(port,dev['id'], ":", dev['name'], ":", dev['type'])
308+
print(port, dev['id'], ":", dev['name'], ":", dev['type'])
326309
devices.append(dev)
327310

328311
ConnectRemote()

0 commit comments

Comments
 (0)