def __init__(self): global instance, cfgPath instance = self try: if os.path.exists("apps/python/acSLI.cfg"): shutil.move("apps/python/acSLI.cfg", "apps/python/acSLI/") self.config = Config(cfgPath) self.cfgPort = str(self.config.getOption("SETTINGS", "port", True, self.cfgPort)).upper() self.cfgRemoteVersion = str(self.config.getOption("SETTINGS", "remoteVersion", True, self.cfgRemoteVersion)) self.cfgSpeedUnit = str(self.config.getOption("SETTINGS", "unitSpeed", True, self.cfgSpeedUnit)).upper() self.cfgFuelDisp = str(self.config.getOption("SETTINGS", "fuelDisplay", True, self.cfgFuelDisp)).upper() self.cfgStartPage = int(self.config.getOption("SETTINGS", "startupPage", True, self.cfgStartPage)) self.cfgIntensity = int(self.config.getOption("SETTINGS", "intensity", True, self.cfgIntensity)) self.cfgTickFreq = int(self.config.getOption("ADVANCED", "tickFrequency", True, self.cfgTickFreq)) self.cfgEnableUpdater = int(self.config.getOption("ADVANCED", "enableUpdater", True, self.cfgEnableUpdater)) self.cfgLapOffset = int(self.config.getOption("ADVANCED", "lapOffset", True, self.cfgLapOffset)) self.cfgBrakeEnable = int(self.config.getOption("BRAKE-VIBE", "enable", True, self.cfgBrakeEnable)) self.cfgBrakeTol = int(self.config.getOption("BRAKE-VIBE", "tolerance", True, self.cfgBrakeTol)) self.cfgBrakeSens = int(self.config.getOption("BRAKE-VIBE", "sensitivity", True, self.cfgBrakeSens)) except Exception as e: Log.error("Loading Config File: %s" % e)
def onUpdate(self): if self.ticker % Config.instance.cfgTickFreq == 0: if Connection.instance.handshake: Connection.instance.send(self.compileDataPacket()) elif Connection.instance.dispSelect: Selector.instance.open(Connection.instance.dispSelectMsg) Connection.instance.dispSelect = False if self.simInfo.graphics.completedLaps > self.prevLap: self.prevLap = self.simInfo.graphics.completedLaps self.sendTimeReset = 1 if self.prevFuel != 0: self.sendTime = 1 self.estimateFuel() if self.simInfo.physics.pitLimiterOn or self.simInfo.graphics.isInPit: self.prevFuel = 0 if self.ticker == (Config.instance.cfgTickFreq * 10): if self.fuelCache == 0 and self.simInfo.static.track != "" and self.simInfo.static.carModel != "": Log.info("Load Fuel Usage Cache") self.fuelCache = Utils.Config("apps/python/acSLI/user.cache") self.track = self.simInfo.static.track self.car = self.simInfo.static.carModel self.fuelEst = float(self.fuelCache.getOption(self.track, self.car, True, self.fuelEst)) self.fuelEstLaps = int(self.fuelCache.getOption(self.track, self.car + "_l", True, self.fuelEstLaps)) self.ticker = 0 else: self.ticker += 1
def __init__(self, window, changeFunc, width=120, height=20, x=0, y=0, title="spn", minVal=0, maxVal=1, startVal=0): self.spinner = ac.addSpinner(window, title) self.setSize(width, height) self.setPos(x, y) self.setRange(minVal, maxVal) ac.addOnValueChangeListener(self.spinner, changeFunc) Log.blank(ac.setValue(self.spinner, startVal)) # logging it fixes really weird bug
def removeOption(self, section, option): if self.hasOption(section, option): self.parser.remove_option(section, option) self._write() return True else: Log.info("Utils.Config.Config.remOption -- option not found.") return False
def removeOption(self, section, option): if self.hasOption(section,option): self.parser.remove_option(section, option) self._write() return True else: Log.info("Utils.Config.Config.remOption -- option not found.") return False
def removeSection(self, section): if self.hasSection(section): self.parser.remove_section(section) self._write() return True else: Log.info("Utils.Config.remSection -- section not found.") return False
def onStart(self): global Version Selector.Selector() AdvSet.AdvSet() Connection.Connection() Connection.findConnection().start() self.ticker = 0 Log.info("Loaded Successfully")
def addSection(self, section = None): if section is not None: if not self.hasSection(section): self.parser.add_section(section) self._write() return True else: Log.info("Utils.Config.addSection -- Section '" + section + "' already exists.") return False
def acShutdown(deltaT): global acSLI try: if not Updater.instance.isOpen: acSLI.onClose() except Exception as e: Log.error("On Close: %s" % e)
def addSection(self, section=None): if section is not None: if not self.hasSection(section): self.parser.add_section(section) self._write() return True else: Log.info("Utils.Config.addSection -- Section '" + section + "' already exists.") return False
def getOption(self, section, option, create = False, default = ""): if self.hasOption(section, option): return self.parser.get(section, option) else: if create: Log.info("Utils.Config.getOption -- Option '" + option + "' in section '" + section + "' doesn't exist. Creating with default value...") self.addOption(section, option, default) return default else: Log.info("Utils.Config.getOption -- Option '" + option + "' in section '" + section + "' doesn't exist.") return -1
def __init__(self): global instance, progInstance progInstance = self try: self.appWindow = Window("acSLI Update Progress", 800, 100).setVisible(1).setPos(560, 350)\ .setBackgroundTexture("apps/python/acSLI/image/backError.png") self.lblMsg = Label(self.appWindow.app, "Downloading[0/0][0%]: ", 20, 32)\ .setSize(760, 10).setAlign("center").setFontSize(20).setColor(Utils.rgb(Utils.colours["green"])) except Exception as e: Log.error("On Update: %s" % e)
def __init__(self, currVersion): global instance instance = self self.currVersion = currVersion self.cV = "".join(self.currVersion.split(".")) if len(self.cV) < 4: self.cV = self.cV[0] + self.cV[1] + "0" + self.cV[2] try: if Config.instance.cfgEnableUpdater == 1: conn = http.client.HTTPSConnection("raw.githubusercontent.com", 443) conn.request("GET", "/Turnermator13/ArduinoRacingDash/master/version.txt") versionStr = re.findall(r"\'(.+?)\'", str(conn.getresponse().read()))[0].split("|") self.remoteVersion = versionStr[0] self.reqArduinoUpdate = versionStr[1] self.changeLog = versionStr[2] self.statsURL = versionStr[3] conn.close() except Exception as e: Log.error("Couldn't get Version Information: %s" % e) self.updaterError = True logStats("Login") self.rV = "".join(self.remoteVersion.split(".")) if len(self.rV) < 4: self.rV = self.rV[0] + self.rV[1] + "0" + self.rV[2] if (self.remoteVersion != 0) and (self.remoteVersion != Config.instance.cfgRemoteVersion)\ and (int(self.rV) > int(self.cV)): self.isOpen = True if self.reqArduinoUpdate == "1": Log.info("New acSLI Version Available: v" + self.remoteVersion + ". Requires Arduino Sketch Update") else: Log.info("New acSLI Version Available: v" + self.remoteVersion) self.appWindow = Window("acSLI Updater", 400, 120).setVisible(1).setPos(760, 350)\ .setBackgroundTexture("apps/python/acSLI/image/backUpdater.png") self.btnYes = Button(self.appWindow.app, bFunc_Yes, 110, 20, 20, 90, "Update")\ .setAlign("center").hasCustomBackground().setBackgroundTexture("apps/python/acSLI/image/backBtnUpdater.png") self.btnNo = Button(self.appWindow.app, bFunc_No, 110, 20, 145, 90, "Not Now")\ .setAlign("center").hasCustomBackground().setBackgroundTexture("apps/python/acSLI/image/backBtnUpdater.png") self.btnIgnore = Button(self.appWindow.app, bFunc_Ignore, 110, 20, 270, 90, "Ignore Version")\ .setAlign("center").hasCustomBackground().setBackgroundTexture("apps/python/acSLI/image/backBtnUpdater.png") self.lblVersionTxt = Label(self.appWindow.app, "New acSLI Version Available: v" + self.remoteVersion, 20, 30)\ .setSize(360, 10).setAlign("center").setFontSize(20).setColor(Utils.rgb(Utils.colours["red"])) self.lblLog = Label(self.appWindow.app, self.changeLog, 20, 60)\ .setSize(360, 10).setAlign("center").setColor(Utils.rgb(Utils.colours["green"])) else: if self.updaterError: Log.info("Updater Encounter an Error. Version Check Incomplete") elif Config.instance.cfgEnableUpdater == 1: Log.info("Running Latest Version (v%s)" % self.remoteVersion)
def __init__(self, filePath): self.file = filePath self.parser = 0 if not os.path.isfile(self.file): open(self.file, 'a').close() try: self.parser = configparser.RawConfigParser() except: Log.info("Utils.Config: Failed to initialize ConfigParser.") self._read()
def __init__(self): global instance, cfgPath instance = self try: if os.path.exists("apps/python/acSLI.cfg"): shutil.move("apps/python/acSLI.cfg", "apps/python/acSLI/") self.config = Config(cfgPath) self.cfgPort = str( self.config.getOption("SETTINGS", "port", True, self.cfgPort)).upper() self.cfgRemoteVersion = str( self.config.getOption("SETTINGS", "remoteVersion", True, self.cfgRemoteVersion)) self.cfgSpeedUnit = str( self.config.getOption("SETTINGS", "unitSpeed", True, self.cfgSpeedUnit)).upper() self.cfgFuelDisp = str( self.config.getOption("SETTINGS", "fuelDisplay", True, self.cfgFuelDisp)).upper() self.cfgStartPage = int( self.config.getOption("SETTINGS", "startupPage", True, self.cfgStartPage)) self.cfgIntensity = int( self.config.getOption("SETTINGS", "intensity", True, self.cfgIntensity)) self.cfgTickFreq = int( self.config.getOption("ADVANCED", "tickFrequency", True, self.cfgTickFreq)) self.cfgEnableUpdater = int( self.config.getOption("ADVANCED", "enableUpdater", True, self.cfgEnableUpdater)) self.cfgLapOffset = int( self.config.getOption("ADVANCED", "lapOffset", True, self.cfgLapOffset)) self.cfgBrakeEnable = int( self.config.getOption("BRAKE-VIBE", "enable", True, self.cfgBrakeEnable)) self.cfgBrakeTol = int( self.config.getOption("BRAKE-VIBE", "tolerance", True, self.cfgBrakeTol)) self.cfgBrakeSens = int( self.config.getOption("BRAKE-VIBE", "sensitivity", True, self.cfgBrakeSens)) except Exception as e: Log.error("Loading Config File: %s" % e)
def acUpdate(deltaT): global acSLI, hasInit try: if not Updater.instance.isOpen and not hasInit: hasInit = True acSLI = App.App() acSLI.onStart() if hasInit: acSLI.onUpdate() except Exception as e: Log.error("On Update: %s" % e)
def getOption(self, section, option, create=False, default=""): if self.hasOption(section, option): return self.parser.get(section, option) else: if create: Log.info("Utils.Config.getOption -- Option '" + option + "' in section '" + section + "' doesn't exist. Creating with default value...") self.addOption(section, option, default) return default else: Log.info("Utils.Config.getOption -- Option '" + option + "' in section '" + section + "' doesn't exist.") return -1
def addOption(self, section = None, option = None, value = None): if not self.hasSection(section): self.addSection(section) if (option is not None) and (not self.hasOption(section, option)): if (value is not None): self.parser.set(section, option, value) self._write() return True else: Log.info("Utils.Config.addOption -- Value cannot be null") return False else: Log.info("Utils.Config.addOption -- Option '" + option + "' is blank or already exists in section '" + section + "'.") return False
def updateOption(self, section = None, option = None, value = None, create = False): if self.hasOption(section, option): if value is not None: self.parser.set(section, option, value) self._write() return True else: Log.info("Utils.Config.updateOption -- Value cannot be null") return False else: if create: return self.addOption(section, option, value) else: Log.info("Utils.Config.updateOption -- Option '" + option + "' in section '" + section + "' doesn't exist.") return False
def addOption(self, section=None, option=None, value=None): if not self.hasSection(section): self.addSection(section) if (option is not None) and (not self.hasOption(section, option)): if (value is not None): self.parser.set(section, option, value) self._write() return True else: Log.info("Utils.Config.addOption -- Value cannot be null") return False else: Log.info("Utils.Config.addOption -- Option '" + option + "' is blank or already exists in section '" + section + "'.") return False
def acMain(acVerison): global acSLI, hasInit, Log try: Log.info("Start Loading acSLI v" + App.Version) Loader.ConfigLoader() Updater.Updater(App.Version) cleanInstall() if not Updater.instance.isOpen: hasInit = True acSLI = App.App() acSLI.onStart() return "acSLI" except Exception as e: Log.error("On Start: %s" % e)
def updateOption(self, section=None, option=None, value=None, create=False): if self.hasOption(section, option): if value is not None: self.parser.set(section, option, value) self._write() return True else: Log.info("Utils.Config.updateOption -- Value cannot be null") return False else: if create: return self.addOption(section, option, value) else: Log.info("Utils.Config.updateOption -- Option '" + option + "' in section '" + section + "' doesn't exist.") return False
def run(self): global instance, progInstance try: Log.info("Updating Files. Please Wait.") UpdateProg() logStats("Update") Log.info("Creating Backup") progInstance.setMsg("Creating Backup") shutil.copytree('apps/python/acSLI', 'apps/python/acSLI-BACKUP', ignore=shutil.ignore_patterns("stdlib", "stdlib64", ".idea", "acSLI.txt", "acSLI.ini")) conn = http.client.HTTPSConnection("raw.githubusercontent.com", 443) conn.request("GET", "/Turnermator13/ArduinoRacingDash/v" + instance.remoteVersion + "/fileList.txt") Files = re.findall(r"\'(.+?)\'", str(conn.getresponse().read()))[0].split('\\n') Files.append("ArduinoDash.ino") lenFiles = len(Files) + 1 i = 0 error = "N" for filename in Files: if filename == "ArduinoDash.ino": conn.request("GET", "/Turnermator13/ArduinoRacingDash/v" + instance.remoteVersion + "/ArduinoDash/" + filename) else: conn.request("GET", "/Turnermator13/ArduinoRacingDash/v" + instance.remoteVersion + "/acSLI/" + filename) i += 1 Log.info("Downloading: " + filename) progInstance.setMsg("Downloading[%s/%s][%s]: '%s'" % (str(i), str(lenFiles), str(round((i/lenFiles)*100)) + "%", filename)) if (filename.split('/')[0] == "stdlib" or filename.split('/')[0] == "stdlib64") and os.path.isfile("apps/python/acSLI/" + filename): Log.info("DLL Exists, Skipping") conn.getresponse().read() else: res = conn.getresponse().read() if re.findall(r"\'(.+?)\'", str(res))[0] == "Not Found": error = "Couldn't Find File '%s'?? Please report this to the App Author" % filename Log.info("Couldn't Find File '%s'?? Please report this to the App Author" % filename) break else: try: localfile = open("apps/python/acSLI/" + filename,'wb') localfile.write(res) localfile.close() except FileNotFoundError: os.makedirs(filename.split('/')[0]) localfile = open("apps/python/acSLI/" + filename,'wb') localfile.write(res) localfile.close() except Exception as e: Log.error("On Update: %s" % e) conn.close() if error == "N": shutil.rmtree("apps/python/acSLI-BACKUP") Log.info("Successfully Updated to " + instance.remoteVersion + " , please restart AC Session") progInstance.setMsg("Update Successful. Please Restart Session") if instance.reqArduinoUpdate == "1": progInstance.setMsg("Success, Please Update Arduino (latest sketch in apps/python/acsli) and Restart Session") else: progInstance.setColour(Utils.rgb(Utils.colours["red"])) progInstance.setMsg("Error Updating. Restoring from Backup") Log.info("Error Updating, Restoring from Backup") for obj in os.listdir("apps/python/acSLI/"): if not (str(obj) == "stdlib" or str(obj) == "stdlib64" or str(obj) == ".idea" or str(obj) == "acSLI.txt" or str(obj) == "acSLI.ini"): if not "." in str(obj): shutil.rmtree("apps/python/acSLI/" + obj) else: os.remove("apps/python/acSLI/" + obj) for obj in os.listdir("apps/python/acSLI-BACKUP/"): if not "." in str(obj): shutil.copytree("apps/python/acSLI-BACKUP/" + obj, "apps/python/acSLI/" + obj) else: shutil.copy("apps/python/acSLI-BACKUP/" + obj, "apps/python/acSLI/" + obj) shutil.rmtree("apps/python/acSLI-BACKUP") progInstance.setMsg(error) progInstance.dispButton() except Exception as e: Log.error("On Update: %s" % e)
def _findConnect(): global instance portValid = False instance.handshake = False instance.dispSelect = False for sPort, desc, hwid in sorted(serial.tools.list_ports.comports()): Log.log("%s: %s [%s]" % (sPort, desc, hwid)) if Config.instance.cfgPort == "AUTO": if "Arduino" in desc: instance.port = sPort portValid = True else: if Config.instance.cfgPort == sPort: instance.port = sPort portValid = True if portValid: break if portValid: try: instance.ser = serial.Serial(instance.port, 9600, timeout=5) time.sleep(2) instance.ser.write(bytes([1, 1])) arduinoVer = instance.ser.read(5) if str(arduinoVer) == "b''": instance.port = "----" Log.warning( "No Response From Arduino. Please Ensure Arduino is running at least v" + acSLI.App.ArduinoVersion) instance.dispSelect = True instance.dispSelectMsg = "No Response from Arduino" instance.ser.close() else: aV = re.findall(r"\'(.+?)\'", str(arduinoVer))[0].split('.')[1] if len(aV) < 4: aV = aV[0] + aV[1] + "0" + aV[2] aLV = "".join(acSLI.App.ArduinoVersion.split(".")) if len(aLV) < 4: aLV = aLV[0] + aLV[1] + "0" + aLV[2] if aLV > aV: instance.port = "----" instance.ser.close() Log.warning( "Arduino Code Outdated(v%s). Please Update Arduino to at least v%s and then Restart AC" % (arduinoVer, acSLI.App.ArduinoVersion)) Error.ErrorBox( "Arduino Code Outdated. Please Update Arduino to at least v" + acSLI.App.ArduinoVersion + " and then Restart AC") else: instance.handshake = True Log.info("Connected to Arduino running v" + aV[0] + '.' + aV[1] + '.' + aV[2] + aV[3] + " on port " + instance.port) except Exception as e: Log.error("On Open Port: %s" % e) else: instance.port = "----" if Config.instance.cfgPort == "AUTO": Log.warning("No Arduino Detected") instance.dispSelect = True instance.dispSelectMsg = "No Arduino Detected" else: Log.warning("Invalid COM Port Configured") instance.dispSelect = True instance.dispSelectMsg = "Invalid COM Port Configured" if instance.port != "----": acSLI.acSLI.lblPort.setText("Connected COM Port: {}".format( instance.port)).setColor(Utils.rgb(Utils.colours["green"])) else: acSLI.acSLI.lblPort.setText("Connected COM Port: {}".format( instance.port)).setColor(Utils.rgb(Utils.colours["red"]))
def _findConnect(): global instance portValid = False instance.handshake = False instance.dispSelect = False for sPort, desc, hwid in sorted(serial.tools.list_ports.comports()): Log.log("%s: %s [%s]" % (sPort, desc, hwid)) if Config.instance.cfgPort == "AUTO": if "Arduino" in desc: instance.port = sPort portValid = True else: if Config.instance.cfgPort == sPort: instance.port = sPort portValid = True if portValid: break if portValid: try: instance.ser = serial.Serial(instance.port, 9600, timeout=5) time.sleep(2) instance.ser.write(bytes([1, 1])) arduinoVer = instance.ser.read(5) if str(arduinoVer) == "b''": instance.port = "----" Log.warning("No Response From Arduino. Please Ensure Arduino is running at least v" + acSLI.App.ArduinoVersion) instance.dispSelect = True instance.dispSelectMsg = "No Response from Arduino" instance.ser.close() else: aV = re.findall(r"\'(.+?)\'", str(arduinoVer))[0].split('.')[1] if len(aV) < 4: aV = aV[0] + aV[1] + "0" + aV[2] aLV = "".join(acSLI.App.ArduinoVersion.split(".")) if len(aLV) < 4: aLV = aLV[0] + aLV[1] + "0" + aLV[2] if aLV > aV: instance.port = "----" instance.ser.close() Log.warning("Arduino Code Outdated(v%s). Please Update Arduino to at least v%s and then Restart AC" % (arduinoVer, acSLI.App.ArduinoVersion)) Error.ErrorBox("Arduino Code Outdated. Please Update Arduino to at least v" + acSLI.App.ArduinoVersion + " and then Restart AC") else: instance.handshake = True Log.info("Connected to Arduino running v" + aV[0] + '.' + aV[1] + '.' + aV[2] + aV[3] + " on port " + instance.port) except Exception as e: Log.error("On Open Port: %s" % e) else: instance.port = "----" if Config.instance.cfgPort == "AUTO": Log.warning("No Arduino Detected") instance.dispSelect = True instance.dispSelectMsg = "No Arduino Detected" else: Log.warning("Invalid COM Port Configured") instance.dispSelect = True instance.dispSelectMsg = "Invalid COM Port Configured" if instance.port != "----": acSLI.acSLI.lblPort.setText("Connected COM Port: {}".format(instance.port)).setColor(Utils.rgb(Utils.colours["green"])) else: acSLI.acSLI.lblPort.setText("Connected COM Port: {}".format(instance.port)).setColor(Utils.rgb(Utils.colours["red"]))