Sep-09-2020, 10:02 PM
Here is the code I use to control the lcd
from os import path import ast import time import json from lib.customLibs import lcdScreen import lib. i2cLCD as lcddriver from datetime import datetime from auth import * class displayScreen: def __passedData(): values = {} with open("systemHWDriverFiles/display_passValues.txt", 'rt') as inf: r = str(inf.read()[1:-1]).split(', ') for i in r: for key, value in ast.literal_eval(i).items(): if key not in values: values[key] = [] values[key].append(value) return values def __processData(data): resp = {} if 'apiCall' in data: Session = loginInfo() for i in data['apiCall']: resp[i] = Session.makeCall(i).text return resp def run(): return displayScreen.__processData(displayScreen.__passedData()) test = displayScreen.run() datetime.datetime.now() now = datetime.datetime.now() display = lcddriver.lcd() display.lcd_display_string("Time: %s" %now.strftime("%H:%M:%S"), 1) display.lcd_display_string(str(test['/api/phprobes/8/read']+'ppm '+test['/api/phprobes/9/read']+'F'), 2)My main script, loads in sensors based on api call, and ones that are manually entered and puts them into a while loop.
#Set up display /path from passed values import json from multiprocessing import Process import ast from os import path import time #Hardware Classes from sensorClass import * from lib.systemHW import * #importing custom libs from lib.customLibs import * #import cred config files and system info from auth import * #API Sessions Session = loginInfo() #Create Sensors list resp = Session.makeCall('/api/equipment') hwObjects = {} for k in json.loads(resp.text): senIndex = len(hwObjects) if chkFile(['Sensors/'+k['name']+'.py', 'driverFiles/'+k['name']+'_Sensor.txt', 'powerStatus/'+k['name']+'_Power.txt']): hwObjects[senIndex] = Sensor(k['id'], k['name'], k['outlet'], k['on'], senIndex) #adding SystemHW senIndex = len(hwObjects) hwObjects[senIndex] = (systemHW('display', senIndex)) hwObjects[senIndex].addArg({'apiCall': '/api/phprobes/8/read'}) hwObjects[senIndex].addArg({'apiCall': '/api/phprobes/9/read'}) hwObjects[senIndex].addArg({'path': 'driverFiles/TestEquipment_Sensor.txt'}) hwObjects[senIndex].addArg({'path': 'driverFiles/TestEquipment2_Sensor.txt'}) #Looping hwObjects def processLoop(): func = [] for processes in hwObjects: f = Process( target = hwObjects[processes].run, args=[]) f.start() func.append(f) for f in func: f.join() return True while processLoop(): passHere is the class that the lcd uses:
from os import path import json #define class class systemHW: def __init__(self, hwName, hwIndex): self.hwName = hwName self.hwFileLocation = "systemHWDriverFiles/"+hwName+"_passValues.txt" self.hwIndex = hwIndex self.arg = [] def addArg(self, *argv): for i in argv: self.arg.append(i) def show(self, ): return [str(self.hwName), str(self.hwFileLocation), str(self.hwIndex)] def online(self): return True def run(self, *argv): if self.online(): arg = self.arg updateValue = open(self.hwFileLocation, "w") updateValue.write(str(arg)) updateValue.close() __import__('systemHW.'+self.hwName)