working basic logging
This commit is contained in:
parent
cbcf91b9bb
commit
5aa53913f3
38
main.py
38
main.py
@ -2,7 +2,6 @@
|
||||
# OLT protocol.
|
||||
# Tomas Krejci [Njord]
|
||||
|
||||
|
||||
import machine, time
|
||||
from sys import platform
|
||||
ESP32 = platform == 'esp32'
|
||||
@ -39,23 +38,24 @@ import primitives.queue as queue
|
||||
from primitives import Switch, Pushbutton
|
||||
from rgb import RGB
|
||||
|
||||
#### Logging ####
|
||||
import logging
|
||||
global logger
|
||||
init_ticks = time.ticks_ms()
|
||||
# change logging level here
|
||||
logging.basicConfig(level=logging.ERROR, format='%(name)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
#logger = logging.getLogger()
|
||||
logger.setLevel(level=logging.DEBUG)
|
||||
#logger.setLevel(logging.DEBUG)
|
||||
|
||||
#logging = logging.getLogger(__name__)
|
||||
|
||||
|
||||
### alive check ###
|
||||
async def alive_check():
|
||||
# loop for checked is alive
|
||||
logger.debug("alive check start")
|
||||
onboar_led = machine.Pin("LED", machine.Pin.OUT) # Pi Pico onboard LED
|
||||
init_ticks = time.ticks_ms()
|
||||
|
||||
|
||||
while True:
|
||||
logger.warning(f"main while running ms: {time.ticks_ms() - init_ticks}")
|
||||
logger.debug("Alive check")
|
||||
logger.debug(f"running ms: {time.ticks_ms() - init_ticks}")
|
||||
#print(f"main while running ms: {time.ticks_ms() - init_ticks}")
|
||||
onboar_led.on()
|
||||
await asyncio.sleep_ms(100)
|
||||
@ -64,7 +64,7 @@ async def alive_check():
|
||||
|
||||
### OLT Start game command functions ###
|
||||
async def start_game_comand(btn, rgb):
|
||||
print("Start game command")
|
||||
logger.debug("Start game command")
|
||||
await rgb.set_red()
|
||||
btn.press_func(None)
|
||||
btn.release_func(None)
|
||||
@ -72,31 +72,29 @@ async def start_game_comand(btn, rgb):
|
||||
btn.press.clear()
|
||||
btn.release.clear()
|
||||
await btn.press.wait()
|
||||
logger.debug("Start game button pressed")
|
||||
await rgb.set_green()
|
||||
# add IR TX here
|
||||
await btn.release.wait()
|
||||
logger.debug("Start game button released")
|
||||
await rgb.set_red()
|
||||
|
||||
btn.press_func(None)
|
||||
|
||||
async def main(proto):
|
||||
|
||||
### Logging ###
|
||||
global logger
|
||||
logger.debug("main start")
|
||||
|
||||
|
||||
|
||||
|
||||
### alive check ###
|
||||
asyncio.create_task(alive_check())
|
||||
|
||||
### RGB ###
|
||||
print("RGB init")
|
||||
logger.debug("RGB init")
|
||||
rgb1 = RGB()
|
||||
|
||||
|
||||
### Buttons ###
|
||||
print("Button init")
|
||||
logger.debug("Button init")
|
||||
pin3 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) # Button 3 on membrane switch
|
||||
btn3 = Pushbutton(pin3)
|
||||
|
||||
@ -106,7 +104,7 @@ async def main(proto):
|
||||
asyncio.create_task(start_game_comand(btn3, rgb1))
|
||||
|
||||
### OLT IR RX ###
|
||||
print("OLT IR RX init")
|
||||
logger.debug("OLT IR RX init")
|
||||
# User callback
|
||||
def cb(byte1, byte2, byte3, packet):
|
||||
print(f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}")
|
||||
@ -124,9 +122,9 @@ try:
|
||||
asyncio.run(main(0))
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Interrupted")
|
||||
logger.exception("App Interrupted")
|
||||
|
||||
finally:
|
||||
asyncio.new_event_loop()
|
||||
print('End')
|
||||
logger.exception('End')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user