Advertisement
trippyt

LightsMenu.py

Sep 30th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.78 KB | None | 0 0
  1. import time
  2. import AquariumLights
  3. from dot3k.menu import MenuOption
  4.  
  5. class LightsMenu(MenuOption):
  6.     def __init__(self, aquarium_lights): #Default settings
  7.         self.running = False
  8.         self.is_setup = False
  9.         self.lights_control = aquarium_lights
  10.         self.curr_idx = 0
  11.         self.curr_val = self.lights_control._schedule[ self.curr_idx ]
  12.         MenuOption.__init__(self)
  13.  
  14.     def begin(self):
  15.         self.is_setup = False
  16.         self.running = True
  17.  
  18.     def setup(self, config):
  19.         MenuOption.setup(self, config)
  20.         self.curr_idx = 0
  21.         self.curr_val = self.lights_control._schedule[ self.curr_idx ]
  22.        
  23.     def cleanup(self):
  24.         self.running = False
  25.         time.sleep(0.01)
  26.         self.is_setup = False
  27.  
  28.     def left(self):
  29.         val = (self.curr_val - 1) % len(AquariumLights.VALID_TOGGLE_MODES)
  30.         sch = self.lights_control._schedule
  31.         sch[ self.curr_idx ] = val
  32.         self.lights_control.schedule = sch
  33.         return True
  34.        
  35.     def right(self):
  36.         val = (self.curr_val + 1) % len(AquariumLights.VALID_TOGGLE_MODES)
  37.         sch = self.lights_control._schedule
  38.         sch[ self.curr_idx ] = val
  39.         self.lights_control.schedule = sch
  40.         return True
  41.        
  42.  
  43.     def up(self):
  44.         self.curr_idx = (self.curr_idx - 1) % len(self.lights_control._schedule)
  45.         self.curr_val = self.lights_control._schedule[ self.curr_idx ]
  46.         return True
  47.  
  48.     def down(self):
  49.         self.curr_idx = (self.curr_idx + 1) % len(self.lights_control._schedule)
  50.         self.curr_val = self.lights_control._schedule[ self.curr_idx ]
  51.         return True
  52.  
  53.     def redraw(self, menu):
  54.         if not self.running:
  55.             return False
  56.  
  57.         if not self.is_setup:
  58.             menu.lcd.create_char(0, [0, 0, 0, 14, 17, 17, 14, 0])
  59.             menu.lcd.create_char(1, [0, 0, 0, 14, 31, 31, 14, 0])
  60.             menu.lcd.create_char(2, [0, 14, 17, 17, 17, 14, 0, 0])
  61.             menu.lcd.create_char(3, [0, 14, 31, 31, 31, 14, 0, 0])
  62.             menu.lcd.create_char(4, [0, 4, 14, 0, 0, 14, 4, 0])  # Up down arrow
  63.             menu.lcd.create_char(5, [0, 0, 10, 27, 10, 0, 0, 0])  # Left right arrow
  64.             self.is_setup = True
  65.  
  66.         hour = float(time.strftime('%H'))
  67.         print(hour)
  68.         menu.write_row(0, time.strftime('  %a %H:%M:%S  '))
  69.  
  70.         menu.write_row(1, '-' * 16)
  71.  
  72.         if self.idling:
  73.             menu.clear_row(2)
  74.             return True
  75.  
  76.         self.curr_val = self.lights_control._schedule[ self.curr_idx ]
  77.  
  78.         bottom_row = ''
  79.  
  80.         mode_str = AquariumLights.TOGGLE_MODE_STR[ self.curr_val ].upper()
  81.         bottom_row = '{:02}:00 \x05Mode:{}'.format(self.curr_idx, mode_str)
  82.  
  83.         menu.write_row(2, chr(4) + bottom_row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement