We're nearly there, the code works and i can change which gpio is true or false via the doHAT only problem is when your faced with the on or off options the previous error appears in the shell,
however the on and off also dont scroll so you dont know which is selected it appears like:
Off
>On
Off
you also cant seem to go back once on this screen
Just tried this think thats what you meant but now i get the name 'handle_on'is not defined again
however the on and off also dont scroll so you dont know which is selected it appears like:
Off
>On
Off
you also cant seem to go back once on this screen
#!/usr/bin/env python import sys import time import dothat.backlight as backlight import dothat.lcd as lcd import dothat.touch as nav from dot3k.menu import Menu, MenuOption from time import sleep # Add the root examples dir so Python can find the plugins sys.path.append('/home/pi/Pimoroni/displayotron/examples') from plugins.clock import Clock from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown from plugins.text import Text from plugins.utils import Backlight, Contrast import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setup(13,GPIO.OUT) GPIO.setup(5,GPIO.OUT) print(""" This advanced example uses the menu framework. It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings! Press CTRL+C to exit. """) class Lightcontrol(MenuOption): """Control; Lights""" def __init__(self): self.selected_option = 0 self.options = [ 'On', 'Off', ] self.actions = [ self.handle_On, self.handle_Off, ] def handle_On(self): GPIO.output(13,0) GPIO.output(5,0) GPIO.output(13,1) print('ON! Doing monkey stuff!') time.sleep(2) print('Done monkey stuff!') def handle_Off(self): GPIO.output(5,0) GPIO.output(13,0) GPIO.output(5,1) print("OFF! Doing donkey stuff!") time.sleep(2) print("Done donkey stuff!") def select_option(self): self.actions[self.selected_option]() def next_option(self): self.selected_option = (self.selected_option + 1) % len(self.options) def prev_option(self): self.selected_option = (self.selected_option - 1) % len(self.options) def up(self): self.prev_option() def down(self): self.next_option() def right(self): self.select_option() def get_current_option(self): return self.options[self.selected_option] def get_next_option(self): return self.options[(self.selected_option + 1) % len(self.options)] def get_prev_option(self): return self.options[(self.selected_option - 1) % len(self.options)] def redraw(self, menu): menu.write_option( row=0, margin=1, icon='', text=self.get_prev_option() ) menu.write_option( row=1, margin=1, icon='>', # Let's use a > to denote the currently selected option text=self.get_current_option() ) menu.write_option( row=2, margin=1, icon='', text=self.get_next_option() ) """ Using a set of nested lists you can describe the menu you want to display on dot3k. Instances of classes derived from MenuOption can be used as menu items to show information or change settings. See GraphTemp, GraphCPU, Contrast and Backlight for examples. """ menu = Menu( structure={ 'Power Options': { 'Reboot':GraphSysReboot(), 'Shutdown':GraphSysShutdown(), }, 'Aquarium': { 'Lighting': { 'Control': Lightcontrol(), } }, 'Clock': Clock(backlight), 'Status': { 'IP': IPAddress(), 'CPU': GraphCPU(backlight), 'Temp': GraphTemp() }, 'Settings': { 'Display': { 'Contrast': Contrast(lcd), 'Backlight': Backlight(backlight) } } }, lcd=lcd, idle_timeout=30, input_handler=Text()) """ You can use anything to control dot3k.menu, but you'll probably want to use dot3k.touch """ nav.bind_defaults(menu) while 1: menu.redraw() time.sleep(0.05)
Just tried this think thats what you meant but now i get the name 'handle_on'is not defined again
#!/usr/bin/env python import sys import time import dothat.backlight as backlight import dothat.lcd as lcd import dothat.touch as nav from dot3k.menu import Menu, MenuOption from time import sleep # Add the root examples dir so Python can find the plugins sys.path.append('/home/pi/Pimoroni/displayotron/examples') from plugins.clock import Clock from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown from plugins.text import Text from plugins.utils import Backlight, Contrast import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setup(13,GPIO.OUT) GPIO.setup(5,GPIO.OUT) print(""" This advanced example uses the menu framework. It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings! Press CTRL+C to exit. """) class Lightcontrol(MenuOption): """Control; Lights""" def __init__(self): self.selected_option = 0 self.options = [ 'On', 'Off', ] self.actions = [ handle_On, handle_Off, ] def handle_On(self): GPIO.output(13,0) GPIO.output(5,0) GPIO.output(13,1) print('ON! Doing monkey stuff!') time.sleep(2) print('Done monkey stuff!') def handle_Off(self): GPIO.output(5,0) GPIO.output(13,0) GPIO.output(5,1) print("OFF! Doing donkey stuff!") time.sleep(2) print("Done donkey stuff!") def select_option(self): self.actions[self.selected_option]() def next_option(self): self.selected_option = (self.selected_option + 1) % len(self.options) def prev_option(self): self.selected_option = (self.selected_option - 1) % len(self.options) def up(self): self.prev_option() def down(self): self.next_option() def right(self): self.select_option() def get_current_option(self): return self.options[self.selected_option] def get_next_option(self): return self.options[(self.selected_option + 1) % len(self.options)] def get_prev_option(self): return self.options[(self.selected_option - 1) % len(self.options)] def redraw(self, menu): menu.write_option( row=0, margin=1, icon='', text=self.get_prev_option() ) menu.write_option( row=1, margin=1, icon='>', # Let's use a > to denote the currently selected option text=self.get_current_option() ) menu.write_option( row=2, margin=1, icon='', text=self.get_next_option() ) """ Using a set of nested lists you can describe the menu you want to display on dot3k. Instances of classes derived from MenuOption can be used as menu items to show information or change settings. See GraphTemp, GraphCPU, Contrast and Backlight for examples. """ menu = Menu( structure={ 'Power Options': { 'Reboot':GraphSysReboot(), 'Shutdown':GraphSysShutdown(), }, 'Aquarium': { 'Lighting': { 'Control': Lightcontrol(), } }, 'Clock': Clock(backlight), 'Status': { 'IP': IPAddress(), 'CPU': GraphCPU(backlight), 'Temp': GraphTemp() }, 'Settings': { 'Display': { 'Contrast': Contrast(lcd), 'Backlight': Backlight(backlight) } } }, lcd=lcd, idle_timeout=30, input_handler=Text()) """ You can use anything to control dot3k.menu, but you'll probably want to use dot3k.touch """ nav.bind_defaults(menu) while 1: menu.redraw() time.sleep(0.05)