Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix with -I option #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions Software/Chameleon/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import Chameleon


class Device:
COMMAND_VERSION = "VERSION"
COMMAND_UPLOAD = "UPLOAD"
Expand Down Expand Up @@ -57,7 +58,7 @@ class Device:
SET_CHAR = "="
GET_CHAR = "?"

def __init__(self, verboseFunc = None):
def __init__(self, verboseFunc=None):
self.verboseFunc = verboseFunc
self.serial = serial.Serial(None, 9600, timeout=5.0)
self.versionString = ""
Expand Down Expand Up @@ -130,6 +131,7 @@ def writeCmd(self, cmd):

# Get status response
status = self.serial.readline().decode('ascii').rstrip()
self.verboseLog(status)

if (len(status) == 0):
self.verboseLog("Executing <{}>: Timeout".format(cmd))
Expand All @@ -140,10 +142,11 @@ def writeCmd(self, cmd):
statusCode, statusText = status.split(":")
statusCode = int(statusCode)

result = {'statusCode': statusCode, 'statusText': statusText, 'response': None}
result = {'statusCode': statusCode,
'statusText': statusText, 'response': None}

if (statusCode == self.STATUS_CODE_OK_WITH_TEXT):
result['response'] = self.readResponse()
result['response'] = self.readResponse()
elif (statusCode == self.STATUS_CODE_TRUE):
result['response'] = True
elif (statusCode == self.STATUS_CODE_FALSE):
Expand All @@ -153,7 +156,11 @@ def writeCmd(self, cmd):

def readResponse(self):
# Read response to command, if any
response = self.serial.readline().decode('ascii').rstrip()
response = ""
while self.serial.in_waiting:
line = self.serial.read().decode('ascii')
response += line
response = response.rstrip().replace('\t', ' ').replace('\r\n', ' | ')
self.verboseLog("Response: {}".format(response))
return response

Expand Down Expand Up @@ -214,10 +221,10 @@ def cmdLogMode(self, newLogMode):
def cmdVersion(self):
return self.getSetCmd(self.COMMAND_VERSION)

def cmdSetting(self, newSetting = None):
def cmdSetting(self, newSetting=None):
return self.getSetCmd(self.COMMAND_SETTING, newSetting)

def cmdUID(self, newUID = None):
def cmdUID(self, newUID=None):
return self.getSetCmd(self.COMMAND_UID, newUID)

def cmdGetUID(self):
Expand All @@ -229,43 +236,43 @@ def cmdIdentify(self):
def cmdDumpMFU(self):
return self.returnCmd(self.COMMAND_DUMPMFU)

def cmdConfig(self, newConfig = None):
def cmdConfig(self, newConfig=None):
if (newConfig == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_CONFIG)
else:
return self.getSetCmd(self.COMMAND_CONFIG, newConfig)

def cmdLButton(self, newAction = None):
def cmdLButton(self, newAction=None):
if (newAction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_LBUTTON)
else:
return self.getSetCmd(self.COMMAND_LBUTTON, newAction)

def cmdLButtonLong(self, newAction = None):
def cmdLButtonLong(self, newAction=None):
if (newAction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_LBUTTONLONG)
else:
return self.getSetCmd(self.COMMAND_LBUTTONLONG, newAction)

def cmdRButton(self, newAction = None):
def cmdRButton(self, newAction=None):
if (newAction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_RBUTTON)
else:
return self.getSetCmd(self.COMMAND_RBUTTON, newAction)

def cmdRButtonLong(self, newAction = None):
def cmdRButtonLong(self, newAction=None):
if (newAction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_RBUTTONLONG)
else:
return self.getSetCmd(self.COMMAND_RBUTTONLONG, newAction)

def cmdGreenLED(self, newFunction = None):
def cmdGreenLED(self, newFunction=None):
if (newFunction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_GREEN_LED)
else:
return self.getSetCmd(self.COMMAND_GREEN_LED, newFunction)

def cmdRedLED(self, newFunction = None):
def cmdRedLED(self, newFunction=None):
if (newFunction == self.SUGGEST_CHAR):
return self.getCmdSuggestions(self.COMMAND_RED_LED)
else:
Expand Down
Loading