1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #!/usr/bin/env python
-
- import uasyncio as asyncio
-
- class States:
- def __init__(self, lcd):
- self.lcd = lcd
- self.states = []
- self.current = None
-
- def add(self, s):
- self.states.append(s)
-
- async def draw(self):
- self.lcd.fill(self.lcd.black)
- self.lcd.text("Volcano Remote Control App", 0, 0, self.lcd.green)
- r = await self.states[self.current].draw()
- self.lcd.show()
- return r
-
- def run(self):
- if self.current == None:
- self.current = 0
- self.states[self.current].enter()
-
- next = asyncio.run(self.draw())
- if next >= 0:
- val = self.states[self.current].exit()
- self.current = next
- self.states[self.current].enter(val)
-
- from lcd import LCD
- lcd = LCD()
- lcd.brightness(1.0)
-
- try:
- states = States(lcd)
-
- # 0 - Scan
- from state_scan import StateScan
- scan = StateScan(lcd)
- states.add(scan)
-
- # 1 - Connect
- from state_connect import StateConnect
- conn = StateConnect(lcd, True)
- states.add(conn)
-
- # 2 - Select
- from state_select import StateSelect
- select = StateSelect(lcd)
- states.add(select)
-
- # 3 - Heater On
- from state_heat import StateHeat
- heatOn = StateHeat(lcd, True)
- states.add(heatOn)
-
- # 4 - Heater Off
- heatOff = StateHeat(lcd, False)
- states.add(heatOff)
-
- # 5 - Disconnect
- disconn = StateConnect(lcd, False)
- states.add(disconn)
-
- # 6 - Wait for temperature
- from state_wait_temp import StateWaitTemp
- waitTemp = StateWaitTemp(lcd)
- states.add(waitTemp)
-
- # 7 - Wait for time
- from state_wait_time import StateWaitTime
- waitTime = StateWaitTime(lcd)
- states.add(waitTime)
-
- # 8 - Pump
- from state_pump import StatePump
- pump = StatePump(lcd)
- states.add(pump)
-
- # 9 - Notify
- from state_notify import StateNotify
- notify = StateNotify(lcd)
- states.add(notify)
-
- while True:
- states.run()
- except Exception as e:
- lcd.fill(self.lcd.black)
- lcd.text(str(e), 0, int(lcd.height / 2) - 5, lcd.white)
- lcd.show()
|