Oct-22-2020, 06:38 PM
Hey everyone,
I'm working on a function that helps phrase the values for a 16x2 char lcd. every 5 seconds the screen changes to a different 'page'.
at the moment it does what I need, but I feel there is a cleaner way to do what I want
Here is the script:
However, if I want to add more pages to a screen, I have to add another 'if' statement, and readjust the screenMax variables.
I would like to find a more elegant way, that is able to calculate the "screenMax" on its own, and doesn't need to add an additional 'if' statement to the code.
Anyone have any ideas?
I'm working on a function that helps phrase the values for a 16x2 char lcd. every 5 seconds the screen changes to a different 'page'.
at the moment it does what I need, but I feel there is a cleaner way to do what I want
Here is the script:
def __value(self, data, Session, screenNum=0, line=1): now = display.datetime.now() r = None #phrase line 1 if line == 1: #phrase line 1 screen 2 if screenNum == 1: r = "\x07\x03"+self.__PiTemp() #phrase line 1 screen 1, or default if none valid screen number is given if r == None: # screen 0 / default r = "Time: %s" %now.strftime("%H:%M:%S") #screen 0 screenMax = 1 else: #line 2 #phrase line 2 screen 2 if screenNum == 1: #r = self.__co2Levels(resp['/api/equipment/9']) r = self.__co2Levels('22') #phrase line 2 screen 3 if screenNum == 2: r = self.__equipmentStatus1() #phrase line 2 screen 4 if screenNum == 3: r = self.__equipmentStatus2() #phrase line 2 screen 1, or default if none valid screen number is given if r == None: # screen 0 / default r = "H20\x03"+self.__tankTemp(data) screenMax = 3 return [r, (screenMax < screenNum)]above you can see it takes the line and page number (represented by screenNum, line respectively), and returns the phrased script along with a boolean value showing if the page number exists. Which is great.
However, if I want to add more pages to a screen, I have to add another 'if' statement, and readjust the screenMax variables.
I would like to find a more elegant way, that is able to calculate the "screenMax" on its own, and doesn't need to add an additional 'if' statement to the code.
Anyone have any ideas?