fix aio handler init. Fix ble handler functionality. Remove go() function from code.pys
This commit is contained in:
parent
463ac6586b
commit
16145663c1
5 changed files with 63 additions and 66 deletions
|
|
@ -24,7 +24,7 @@ class AIOHandler(Handler):
|
|||
|
||||
def __init__(self, name, portal_device, level: int = NOTSET):
|
||||
"""Create an instance."""
|
||||
super().__init__(name)
|
||||
super().__init__(level)
|
||||
self._log_feed_name = f"{name}-logging"
|
||||
if not issubclass(type(portal_device), PortalBase):
|
||||
raise TypeError(
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ device = PyPortal()
|
|||
l = logging.getLogger("aio")
|
||||
l.addHandler(AIOHandler("test", device))
|
||||
|
||||
|
||||
def go():
|
||||
while True:
|
||||
while True:
|
||||
t = random.randint(1, 5)
|
||||
if t == 1:
|
||||
print("debug")
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ All text above must be included in any redistribution.
|
|||
|
||||
|
||||
from adafruit_logging import Handler, NOTSET
|
||||
from adafruit_ble.uart import UARTServer
|
||||
|
||||
from adafruit_ble import BLERadio
|
||||
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
||||
from adafruit_ble.services.nordic import UARTService
|
||||
|
||||
|
||||
class BLEHandler(Handler):
|
||||
|
|
@ -31,8 +34,10 @@ class BLEHandler(Handler):
|
|||
"""
|
||||
super().__init__(level)
|
||||
self._advertising_now = False
|
||||
self._uart = UARTServer()
|
||||
self._uart.start_advertising()
|
||||
ble = BLERadio()
|
||||
self._uart = UARTService()
|
||||
self._advertisement = ProvideServicesAdvertisement(self._uart)
|
||||
ble.start_advertising(self._advertisement)
|
||||
|
||||
def format(self, record):
|
||||
"""Generate a string to log.
|
||||
|
|
@ -46,7 +51,5 @@ class BLEHandler(Handler):
|
|||
|
||||
:param record: The record (message object) to be logged
|
||||
"""
|
||||
while not self._uart.connected:
|
||||
pass
|
||||
data = bytes(self.format(record), "utf-8")
|
||||
self._uart.write(data)
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ l = logging.getLogger("ble")
|
|||
|
||||
l.addHandler(BLEHandler())
|
||||
|
||||
|
||||
def go():
|
||||
while True:
|
||||
while True:
|
||||
t = random.randint(1, 5)
|
||||
if t == 1:
|
||||
print("debug")
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ storage.mount(vfs, "/sd")
|
|||
l = logging.getLogger("file")
|
||||
l.addHandler(logging.FileHandler("/sd/test.txt"))
|
||||
|
||||
|
||||
def go():
|
||||
while True:
|
||||
while True:
|
||||
t = random.randint(1, 5)
|
||||
if t == 1:
|
||||
print("debug")
|
||||
|
|
|
|||
Loading…
Reference in a new issue