Skip to content

Commit

Permalink
Merge pull request #1 from securipy/master
Browse files Browse the repository at this point in the history
Menu updated to current Adafruit LCD Libraries
  • Loading branch information
Daniel Juenger authored Aug 19, 2016
2 parents 1cd5c67 + 3d5fb16 commit 27a1f8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
34 changes: 17 additions & 17 deletions Menu.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
13 changes: 6 additions & 7 deletions testMenu.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -52,5 +51,5 @@
i += 1

#starting the menu
menu.startMenu(lcd, color)
menu.startMenu(lcd)

0 comments on commit 27a1f8a

Please sign in to comment.