From 3d5fb16f235f94d11135b3fe4744e27ea81572a7 Mon Sep 17 00:00:00 2001 From: Goldrak Date: Fri, 19 Aug 2016 22:09:02 +0000 Subject: [PATCH] Menu updated to current Adafruit LCD Libraries --- Menu.py | 34 +++++++++++++++++----------------- README.md | 3 ++- testMenu.py | 13 ++++++------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Menu.py b/Menu.py index 421585a..13f7592 100644 --- a/Menu.py +++ b/Menu.py @@ -1,6 +1,6 @@ #Daniel Juenger, github.com/sleeepyjack -import Adafruit_CharLCDPlate +import Adafruit_CharLCD as LCD from time import sleep import commands import psutil @@ -34,21 +34,21 @@ def subElement(self, name, type, content): def buttonPressed(self, lcd): boo = False - if (lcd.buttonPressed(lcd.SELECT) | lcd.buttonPressed(lcd.UP) | lcd.buttonPressed(lcd.DOWN) | lcd.buttonPressed(lcd.LEFT) | lcd.buttonPressed(lcd.RIGHT)): + if (lcd.is_pressed(LCD.SELECT) | lcd.is_pressed(LCD.UP) | lcd.is_pressed(LCD.DOWN) | lcd.is_pressed(LCD.LEFT) | lcd.is_pressed(LCD.RIGHT)): boo = True return boo def clearMenuRight(self, lcd): j = 0 while(j < 16): - lcd.scrollDisplayRight() + lcd.move_right() sleep(.03) j += 1 def clearMenuLeft(self, lcd): i = 0 while(i < 16): - lcd.scrollDisplayLeft() + lcd.move_left() sleep(.03) i += 1 @@ -154,12 +154,12 @@ def handleMenu(self,lcd): self.scroll(lcd, msg) self.count += 1 - def startMenu(self, lcd, color): + def startMenu(self, lcd): global isInterrupted global isOn global isOnCount lcd.clear() - lcd.backlight(color) + lcd.set_color(0,1,1) selfisOnCount = 0 self.firstTopElement() self.handleMenu(lcd) @@ -169,38 +169,38 @@ def startMenu(self, lcd, color): while not self.isInterrupted: try: if self.isOn == True: - if lcd.buttonPressed(lcd.RIGHT): + if lcd.is_pressed(LCD.RIGHT): self.nextTopElement(lcd) self.isOnCount = 0 sleep(.3) - if lcd.buttonPressed(lcd.LEFT): + if lcd.is_pressed(LCD.LEFT): self.prevTopElement(lcd) self.isOnCount = 0 sleep(.3) - if lcd.buttonPressed(lcd.DOWN): + if lcd.is_pressed(LCD.DOWN): self.nextSubElement(lcd) self.isOnCount = 0 sleep(.3) - if lcd.buttonPressed(lcd.UP): + if lcd.is_pressed(LCD.UP): self.prevSubElement(lcd) self.isOnCount = 0 sleep(.3) - if lcd.buttonPressed(lcd.SELECT): + if lcd.is_pressed(LCD.SELECT): self.returnToTopElement() self.isOnCount = 0 print "s" sleep(.3) if self.isOnCount > 100: - lcd.backlight(lcd.OFF) - lcd.noDisplay() + lcd.set_backlight(0.0) + lcd.enable_display(False) self.isOnCount = 0 self.isOn = False sleep(.3) else: if self.buttonPressed(lcd): - lcd.display() - lcd.backlight(color) + lcd.enable_display(True) + lcd.set_color(0,1,1) self.isOnCount = 0 self.isOn = True self.handleMenu(lcd) @@ -212,7 +212,7 @@ def startMenu(self, lcd, color): self.stopMenu(lcd) def stopMenu(self, lcd): global isInterrupted - lcd.backlight(lcd.OFF) - lcd.noDisplay() + lcd.set_backlight(0.0) + lcd.enable_display(False) self.isInterrupted = True diff --git a/README.md b/README.md index 6808fd6..85bbcb9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ The display will automatically turn off after some seconds and, what's also nice It will turn back on and show the last shown element when any button is clicked. To use this menu you will have to download the Adafruit library for the LCD: -(see: https://github.com/sleeepyjack/Adafruit-Raspberry-Pi-Python-Code/tree/master/Adafruit_CharLCDPlate) +UPDATED to support current Adafruit LCD libraries (see: https://github.com/adafruit/Adafruit_Python_CharLCD) + For further understanding look into the testMenu.py or contact me. diff --git a/testMenu.py b/testMenu.py index bc8668d..4d34f8e 100644 --- a/testMenu.py +++ b/testMenu.py @@ -1,10 +1,10 @@ #Daniel Juenger, github.com/sleeepyjack from time import sleep -from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate -from menu import Menu +import Adafruit_CharLCD as LCD +from Menu import Menu -lcd = Adafruit_CharLCDPlate() +lcd = LCD.Adafruit_CharLCDPlate() menu = Menu() #The menu can show strings, bash and python expressions @@ -21,7 +21,7 @@ sub13 = menu.subElement("Netzw.>Internet", "BASH", "ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error") sub21 = menu.subElement("System>CPU", "PYTHON", 'str(str(psutil.cpu_percent()) + "%")') sub22 = menu.subElement("System>CPU-Temp.", "STRING", "TODO") -sub23 = menu.subElement("System>RAM", "PYTHON", 'str(str(psutil.phymem_usage()[3])+"% used")') +sub23 = menu.subElement("System>RAM", "PYTHON", 'str(str(psutil.virtual_memory()[2])+"% used")') #Adding elements to the menu menu.addTopElement(top1) @@ -37,11 +37,10 @@ menu.addSubElement(top2, sub22) menu.addSubElement(top2, sub23) -color = lcd.TEAL #initializing display lcd.clear() -lcd.backlight(color) +lcd.set_color(0,1,1) #little loading animation i = 0 @@ -52,5 +51,5 @@ i += 1 #starting the menu -menu.startMenu(lcd, color) +menu.startMenu(lcd)