Browse Source

Only return the ReturnCode from _send_command

Now that I've implemented the protocol, I see how commands actually give
return values isn't how I thought it would be.  Accordingly,
_send_command now only returns the ReturnCode rather than wrapping it in
a list.  This allowed me to remove a few [0]s.
Clara Hobbs 7 years ago
parent
commit
cb98a96a7a
1 changed files with 7 additions and 8 deletions
  1. 7
    8
      alpaca_isp/__init__.py

+ 7
- 8
alpaca_isp/__init__.py View File

@@ -74,12 +74,11 @@ class LPC:
74 74
 
75 75
     def _send_command(self, cmd):
76 76
         """Send a command to the microcontroller, returning the result"""
77
-        rr = self._send_command_raw(cmd)
78
-        lr = [int(n) for n in rr.split()]
79
-        lr[0] = ReturnCode(lr[0])
80
-        if lr[0] != ReturnCode.CMD_SUCCESS:
81
-            raise ISPError(lr)
82
-        return lr
77
+        r = self._send_command_raw(cmd)
78
+        r = ReturnCode(int(r))
79
+        if r != ReturnCode.CMD_SUCCESS:
80
+            raise ISPError(r)
81
+        return r
83 82
 
84 83
     def enter_isp(self, delay=0.01):
85 84
         """Enter ISP mode by controlling the DTR (/RST) and RTS (/ISP) lines
@@ -244,7 +243,7 @@ class LPC:
244 243
                 "utf-8"))
245 244
         except ISPError as e:
246 245
             # Return a tuple for SECTOR_NOT_BLANK
247
-            if e.args[0][0] == ReturnCode.SECTOR_NOT_BLANK:
246
+            if e.args[0] == ReturnCode.SECTOR_NOT_BLANK:
248 247
                 offset = int(self._readline())
249 248
                 value = int(self._readline())
250 249
                 return (offset, value)
@@ -278,7 +277,7 @@ class LPC:
278 277
                 count).encode("utf-8"))
279 278
         except ISPError as e:
280 279
             # Return an offset for COMPARE_ERROR
281
-            if e.args[0][0] == ReturnCode.COMPARE_ERROR:
280
+            if e.args[0] == ReturnCode.COMPARE_ERROR:
282 281
                 return int(self._readline())
283 282
             raise
284 283
 

Loading…
Cancel
Save