Advertisement
trippyt

propermain

Jul 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import sys
  2. import time
  3. import dothat.backlight as backlight
  4. import dothat.lcd as lcd
  5. import dothat.touch as nav
  6. from dot3k.menu import Menu, MenuOption
  7. from time import sleep, time
  8.  
  9.  
  10. sys.path.append ('/usr/local/lib/python2.7/dist-packages')
  11. sys.path.append('/home/pi/Pimoroni/displayotron/examples')
  12. sys.path.append('/home/pi/.local/lib/python2.7/site-packages')
  13. sys.path.append('/home/pi/Aquarium/')
  14.  
  15. from Mycontroller import Myclock
  16. from plugins.clock import Clock
  17. from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
  18. from plugins.text import Text
  19. from plugins.utils import Backlight, Contrast
  20.  
  21. import logging
  22. from logging.handlers import TimedRotatingFileHandler
  23.  
  24.  
  25.  
  26. class Mymenu(MenuOption):
  27. def __init__(self):
  28. MenuOption.__init__(self)
  29.  
  30. class TimeoutManager():
  31. def __init__(self):
  32. self.TIMEOUT = 5
  33. self.last_button_press = time()
  34.  
  35. def button_press(self):
  36. self.last_button_press = time()
  37. # turn backlight on
  38. backlight.rgb(127,127,127)
  39. backlight.update()
  40.  
  41. def check_timeout(self):
  42. # check if current time is more than TIMEOUT seconds later than last button press
  43. if time() - self.last_button_press > self.TIMEOUT:
  44. # Turn backlight off
  45. backlight.off()
  46.  
  47.  
  48. clock = Myclock()
  49. #Unordered menu
  50. menu = Menu(
  51. structure={
  52. 'Power Options': {
  53. 'Reboot':GraphSysReboot(),
  54. 'Shutdown':GraphSysShutdown(),
  55. },
  56. 'Aquarium': {
  57. 'Lighting': {
  58. 'Control': clock,
  59. }
  60. },
  61. 'Clock': Clock(backlight),
  62. 'Status': {
  63. 'IP': IPAddress(),
  64. 'CPU': GraphCPU(backlight),
  65. 'Temp': GraphTemp()
  66. },
  67. 'Settings': {
  68. 'Display': {
  69. 'Contrast': Contrast(lcd),
  70. 'Backlight': Backlight(backlight)
  71. }
  72. }
  73. },
  74. lcd=lcd,
  75. input_handler=Text())
  76.  
  77. tm = TimeoutManager()
  78. nav.bind_defaults(menu)
  79.  
  80. @nav.on(nav.UP)
  81. def handle_up(pin):
  82. menu.up()
  83. tm.button_press()
  84.  
  85. @nav.on(nav.DOWN)
  86. def handle_down(pin):
  87. menu.down()
  88. tm.button_press()
  89.  
  90. @nav.on(nav.BUTTON)
  91. def handle_button(pin):
  92. menu.select()
  93. tm.button_press()
  94.  
  95. @nav.on(nav.LEFT)
  96. def handle_left(pin):
  97. menu.left()
  98. tm.button_press()
  99.  
  100. @nav.on(nav.RIGHT)
  101. def handle_right(pin):
  102. menu.right()
  103. tm.button_press()
  104.  
  105. @nav.on(nav.CANCEL)
  106. def handle_cancel(pin):
  107. menu.cancel()
  108. tm.button_press()
  109.  
  110. def create_timed_rotating_log(path):
  111. logger = logging.getLogger("Rotating Log")
  112. logger.setLevel(logging.INFO)
  113.  
  114. handler = TimedRotatingFileHandler(path,
  115. when="m",
  116. interval=1,
  117. backupCount=2)
  118. logger.addHandler(handler)
  119.  
  120. for i in range(1):
  121.  
  122. logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
  123. logger.info("This is a test!")
  124.  
  125. log_file = "/home/pi/Aquarium/Logs/logfile.log"
  126. create_timed_rotating_log(log_file)
  127.  
  128.  
  129.  
  130. while True:
  131. clock.check()
  132. menu.redraw()
  133. tm.check_timeout()
  134. sleep(3.0 / 20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement