Skip to content

Commit df92870

Browse files
committed
linting
1 parent a57dea8 commit df92870

9 files changed

+81
-77
lines changed

classes/StargateCmdMessenger/PyCmdMessenger.py

+54-54
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# pylint: skip-file
2+
13
### COMMAND FORMATS
24

35
__description__ = \
46
"""
57
PyCmdMessenger
68
79
Class for communication with an arduino using the CmdMessenger serial
8-
communication library.
10+
communication library.
911
"""
1012
__author__ = "Michael J. Harms"
1113
__date__ = "2016-05-20"
@@ -15,10 +17,10 @@
1517

1618
class CmdMessenger:
1719
"""
18-
Basic interface for interfacing over a serial connection to an arduino
20+
Basic interface for interfacing over a serial connection to an arduino
1921
using the CmdMessenger library.
2022
"""
21-
23+
2224
def __init__(self,
2325
board_instance,
2426
commands,
@@ -29,7 +31,7 @@ def __init__(self,
2931
"""
3032
Input:
3133
board_instance:
32-
instance of ArduinoBoard initialized with correct serial
34+
instance of ArduinoBoard initialized with correct serial
3335
connection (points to correct serial with correct baud rate) and
3436
correct board parameters (float bytes, etc.)
3537
@@ -46,19 +48,19 @@ def __init__(self,
4648
4749
command_separator:
4850
character that separates messages (commands) from each other
49-
Default: ";"
50-
51+
Default: ";"
52+
5153
escape_separator:
5254
escape character to allow separators within messages.
5355
Default: "/"
5456
5557
warnings:
5658
warnings for user
5759
Default: True
58-
60+
5961
The separators and escape_separator should match what's
6062
in the arduino code that initializes the CmdMessenger. The default
61-
separator values match the default values as of CmdMessenger 4.0.
63+
separator values match the default values as of CmdMessenger 4.0.
6264
"""
6365

6466
self.board = board_instance
@@ -79,7 +81,7 @@ def __init__(self,
7981
self._cmd_name_to_int[c[0]] = i
8082
self._int_to_cmd_name[i] = c[0]
8183
self._cmd_name_to_format[c[0]] = c[1]
82-
84+
8385
self._byte_field_sep = self.field_separator.encode("ascii")
8486
self._byte_command_sep = self.command_separator.encode("ascii")
8587
self._byte_escape_sep = self.escape_separator.encode("ascii")
@@ -119,13 +121,13 @@ def __init__(self,
119121

120122
def send(self,cmd,*args,arg_formats=None):
121123
"""
122-
Send a command (which may or may not have associated arguments) to an
124+
Send a command (which may or may not have associated arguments) to an
123125
arduino using the CmdMessage protocol. The command and any parameters
124-
should be passed as direct arguments to send.
126+
should be passed as direct arguments to send.
125127
126128
arg_formats is an optional string that specifies the formats to use for
127129
each argument when passed to the arduino. If specified here,
128-
arg_formats supercedes formats specified on initialization.
130+
arg_formats supercedes formats specified on initialization.
129131
"""
130132

131133
# Turn the command into an integer.
@@ -135,7 +137,7 @@ def send(self,cmd,*args,arg_formats=None):
135137
err = "Command '{}' not recognized.\n".format(cmd)
136138
raise ValueError(err)
137139

138-
# Figure out what formats to use for each argument.
140+
# Figure out what formats to use for each argument.
139141
arg_format_list = []
140142
if arg_formats != None:
141143

@@ -150,8 +152,8 @@ def send(self,cmd,*args,arg_formats=None):
150152
except KeyError:
151153
# if not, guess for all arguments
152154
arg_format_list = ["g" for i in range(len(args))]
153-
154-
# Deal with "*" format
155+
156+
# Deal with "*" format
155157
arg_format_list = self._treat_star_format(arg_format_list,args)
156158

157159
if len(args) > 0:
@@ -160,7 +162,7 @@ def send(self,cmd,*args,arg_formats=None):
160162
raise ValueError(err)
161163

162164
# Go through each argument and create a bytes representation in the
163-
# proper format to send. Escape appropriate characters.
165+
# proper format to send. Escape appropriate characters.
164166
fields = ["{}".format(command_as_int).encode("ascii")]
165167
for i, a in enumerate(args):
166168
fields.append(self._send_methods[arg_format_list[i]](a))
@@ -174,15 +176,15 @@ def send(self,cmd,*args,arg_formats=None):
174176

175177
def receive(self,arg_formats=None):
176178
"""
177-
Recieve commands coming off the serial port.
179+
Recieve commands coming off the serial port.
178180
179181
arg_formats is an optimal keyword that specifies the formats to use to
180182
parse incoming arguments. If specified here, arg_formats supercedes
181-
the formats specified on initialization.
183+
the formats specified on initialization.
182184
"""
183185

184186
# Read serial input until a command separator or empty character is
185-
# reached
187+
# reached
186188
msg = [[]]
187189
raw_msg = []
188190
escaped = False
@@ -218,26 +220,26 @@ def receive(self,arg_formats=None):
218220
command_sep_found = True
219221
break
220222

221-
# or any empty characater
223+
# or any empty characater
222224
elif tmp == b'':
223225
break
224226

225227
# okay, must be something
226228
else:
227229
msg[-1].append(tmp)
228-
230+
229231
# No message received given timeouts
230232
if len(msg) == 1 and len(msg[0]) == 0:
231233
return None
232234

233235
# Make sure the message terminated properly
234236
if not command_sep_found:
235-
236-
# empty message (likely from line endings being included)
237-
joined_raw = b''.join(raw_msg)
237+
238+
# empty message (likely from line endings being included)
239+
joined_raw = b''.join(raw_msg)
238240
if joined_raw.strip() == b'':
239241
return None
240-
242+
241243
err = "Incomplete message ({})".format(joined_raw.decode())
242244
raise EOFError(err)
243245

@@ -254,8 +256,8 @@ def receive(self,arg_formats=None):
254256
cmd_name = "unknown"
255257
w = "Recieved unrecognized command ({}).".format(cmd)
256258
warnings.warn(w,Warning)
257-
258-
# Figure out what formats to use for each argument.
259+
260+
# Figure out what formats to use for each argument.
259261
arg_format_list = []
260262
if arg_formats != None:
261263

@@ -271,7 +273,7 @@ def receive(self,arg_formats=None):
271273
# if not, guess for all arguments
272274
arg_format_list = ["g" for i in range(len(fields[1:]))]
273275

274-
# Deal with "*" format
276+
# Deal with "*" format
275277
arg_format_list = self._treat_star_format(arg_format_list,fields[1:])
276278

277279
if len(fields[1:]) > 0:
@@ -282,7 +284,7 @@ def receive(self,arg_formats=None):
282284
received = []
283285
for i, f in enumerate(fields[1:]):
284286
received.append(self._recv_methods[arg_format_list[i]](f))
285-
287+
286288
# Record the time the message arrived
287289
message_time = time.time()
288290

@@ -314,7 +316,7 @@ def _treat_star_format(self,arg_format_list,args):
314316
err = "'*' format must occur only once, be at end of string, and be preceded by at least one other format."
315317
raise ValueError(err)
316318

317-
return arg_format_list
319+
return arg_format_list
318320

319321
def _send_char(self,value):
320322
"""
@@ -367,7 +369,7 @@ def _send_int(self,value):
367369
bounds for signed int.
368370
"""
369371

370-
# Coerce to int. This will throw a ValueError if the value can't
372+
# Coerce to int. This will throw a ValueError if the value can't
371373
# actually be converted.
372374
if type(value) != int:
373375
new_value = int(value)
@@ -381,15 +383,15 @@ def _send_int(self,value):
381383
if value > self.board.int_max or value < self.board.int_min:
382384
err = "Value {} exceeds the size of the board's int.".format(value)
383385
raise OverflowError(err)
384-
386+
385387
return struct.pack(self.board.int_type,value)
386-
388+
387389
def _send_unsigned_int(self,value):
388390
"""
389391
Convert a numerical value into an integer, then to a bytes object. Check
390392
bounds for unsigned int.
391393
"""
392-
# Coerce to int. This will throw a ValueError if the value can't
394+
# Coerce to int. This will throw a ValueError if the value can't
393395
# actually be converted.
394396
if type(value) != int:
395397
new_value = int(value)
@@ -403,7 +405,7 @@ def _send_unsigned_int(self,value):
403405
if value > self.board.unsigned_int_max or value < self.board.unsigned_int_min:
404406
err = "Value {} exceeds the size of the board's unsigned int.".format(value)
405407
raise OverflowError(err)
406-
408+
407409
return struct.pack(self.board.unsigned_int_type,value)
408410

409411
def _send_long(self,value):
@@ -412,11 +414,11 @@ def _send_long(self,value):
412414
bounds for signed long.
413415
"""
414416

415-
# Coerce to int. This will throw a ValueError if the value can't
417+
# Coerce to int. This will throw a ValueError if the value can't
416418
# actually be converted.
417419
if type(value) != int:
418420
new_value = int(value)
419-
421+
420422
if self.give_warnings:
421423
w = "Coercing {} into int ({})".format(value,new_value)
422424
warnings.warn(w,Warning)
@@ -426,16 +428,16 @@ def _send_long(self,value):
426428
if value > self.board.long_max or value < self.board.long_min:
427429
err = "Value {} exceeds the size of the board's long.".format(value)
428430
raise OverflowError(err)
429-
431+
430432
return struct.pack(self.board.long_type,value)
431-
433+
432434
def _send_unsigned_long(self,value):
433435
"""
434-
Convert a numerical value into an integer, then to a bytes object.
436+
Convert a numerical value into an integer, then to a bytes object.
435437
Check bounds for unsigned long.
436438
"""
437439

438-
# Coerce to int. This will throw a ValueError if the value can't
440+
# Coerce to int. This will throw a ValueError if the value can't
439441
# actually be converted.
440442
if type(value) != int:
441443
new_value = int(value)
@@ -449,15 +451,15 @@ def _send_unsigned_long(self,value):
449451
if value > self.board.unsigned_long_max or value < self.board.unsigned_long_min:
450452
err = "Value {} exceeds the size of the board's unsigned long.".format(value)
451453
raise OverflowError(err)
452-
454+
453455
return struct.pack(self.board.unsigned_long_type,value)
454456

455457
def _send_float(self,value):
456458
"""
457459
Return a float as a IEEE 754 format bytes object.
458460
"""
459461

460-
# convert to float. this will throw a ValueError if the type is not
462+
# convert to float. this will throw a ValueError if the type is not
461463
# readily converted
462464
if type(value) != float:
463465
value = float(value)
@@ -468,13 +470,13 @@ def _send_float(self,value):
468470
raise OverflowError(err)
469471

470472
return struct.pack(self.board.float_type,value)
471-
473+
472474
def _send_double(self,value):
473475
"""
474476
Return a float as a IEEE 754 format bytes object.
475477
"""
476478

477-
# convert to float. this will throw a ValueError if the type is not
479+
# convert to float. this will throw a ValueError if the type is not
478480
# readily converted
479481
if type(value) != float:
480482
value = float(value)
@@ -489,7 +491,7 @@ def _send_double(self,value):
489491
def _send_string(self,value):
490492
"""
491493
Convert a string to a bytes object. If value is not a string, it is
492-
be converted to one with a standard string.format call.
494+
be converted to one with a standard string.format call.
493495
"""
494496

495497
if type(value) != bytes:
@@ -513,8 +515,8 @@ def _send_guess(self,value):
513515
"""
514516
Send the argument as a string in a way that should (probably, maybe!) be
515517
processed properly by C++ calls like atoi, atof, etc. This method is
516-
NOT RECOMMENDED, particularly for floats, because values are often
517-
mangled silently. Instead, specify a format (e.g. "f") and use the
518+
NOT RECOMMENDED, particularly for floats, because values are often
519+
mangled silently. Instead, specify a format (e.g. "f") and use the
518520
CmdMessenger::readBinArg<CAST> method (e.g. c.readBinArg<float>();) to
519521
read the values on the arduino side.
520522
"""
@@ -584,7 +586,7 @@ def _recv_double(self,value):
584586
"""
585587

586588
return struct.unpack(self.board.double_type,value)[0]
587-
589+
588590
def _recv_string(self,value):
589591
"""
590592
Recieve a binary (bytes) string, returning a python string.
@@ -604,13 +606,13 @@ def _recv_bool(self,value):
604606
"""
605607
Receive a binary bool, return as python bool.
606608
"""
607-
609+
608610
return struct.unpack("?",value)[0]
609611

610612
def _recv_guess(self,value):
611613
"""
612-
Take the binary spew and try to make it into a float or integer. If
613-
that can't be done, return a string.
614+
Take the binary spew and try to make it into a float or integer. If
615+
that can't be done, return a string.
614616
615617
Note: this is generally a bad idea, as values can be seriously mangled
616618
by going from float -> string -> float. You'll generally be better off
@@ -638,5 +640,3 @@ def _recv_guess(self,value):
638640

639641
# Return as string
640642
return self._recv_string(value)
641-
642-

classes/StargateCmdMessenger/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# pylint: skip-file
2+
13
__description__ = \
24
"""
35
Python class for interfacing with CmdMessenger arduino serial communications

classes/StargateCmdMessenger/arduino.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# pylint: skip-file
2+
13
__description__ = \
24
"""
35
Base class for allowing connections between arduino and PyCmdMessenger instances

classes/keyboard_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def handle_dhd_test(self, key):
119119
symbol_number = self.get_symbol_key_map()[key]
120120
self.log.log(f'DHD Test: Pressed Key {key} --> Symbol {symbol_number}')
121121
except KeyError:
122-
if (key == self.center_button_key):
122+
if key == self.center_button_key:
123123
self.log.log(f'DHD Test: Pressed Center Button {key} --> Symbol {symbol_number}')
124124
symbol_number = 0
125125
else:

0 commit comments

Comments
 (0)