@@ -49,10 +49,10 @@ interface HasInOut:
4949 out -> io.Writer
5050
5151/*
52- A base class for Lightbug devices
52+ A base class for Lightbug I2C devices
5353Containing the common I2C implementation
5454*/
55- abstract class LightbugDevice implements Device :
55+ abstract class LightbugI2CDevice implements Device :
5656 static I2C-SDA := 6
5757 static I2C-SCL := 7
5858
@@ -73,16 +73,17 @@ abstract class LightbugDevice implements Device:
7373 constructor name / string i2c-sda / int= I2C-SDA i2c-scl / int= I2C-SCL --i2c-frequency / int= 100_000
7474 --strobe / Strobe= NoStrobe
7575 --open / bool= true
76- --logger / log.Logger= ( log .default .with-name "lb-device" ) :
76+ // Default to a logger named "lb" with ERROR level
77+ --logger / log.Logger= ( ( log .default .with-name "lb" ) .with-level log .ERROR-LEVEL ) :
7778 // TODO if more than one device is instantiated, things will likely break due to gpio / i2c conflicts, so WARN / throw in this case
7879 name_ = name
7980 strobe_ = strobe
8081 logger_ = logger
8182 open_ = open
8283 i2c-bus = LBI2CBus --sda = i2c-sda --scl = i2c-scl --frequency = i2c-frequency
8384 i2c-device_ = LBI2CDevice i2c-bus
84- i2c-reader_ = Reader i2c-device_ --logger = logger_
85- i2c-writer_ = Writer i2c-device_ --logger = logger_
85+ i2c-reader_ = Reader i2c-device_ --logger = ( logger_ . with-name "i2c.read" )
86+ i2c-writer_ = Writer i2c-device_ --logger = ( logger_ . with-name "i2c.write" )
8687
8788 name -> string :
8889 return name_
@@ -93,6 +94,7 @@ abstract class LightbugDevice implements Device:
9394 comms_ = Comms
9495 --device = this
9596 --open = open_
97+ --logger = ( logger_ .with-name "comms" )
9698 // Auto-register BLE handler for all devices with BLE support
9799 auto-register-ble-handler_
98100 // Auto-register WiFi handler for all devices with WiFi support
@@ -104,11 +106,11 @@ abstract class LightbugDevice implements Device:
104106 return buttons_
105107 ble -> BLE :
106108 if not ble_ :
107- ble_ = BLE
109+ ble_ = BLE --logger = ( logger_ . with-name "ble" )
108110 return ble_
109111 wifi -> WiFi :
110112 if not wifi_ :
111- wifi_ = WiFi
113+ wifi_ = WiFi --logger = ( logger_ . with-name "wifi" )
112114 return wifi_
113115 messages-supported -> List :
114116 return []
@@ -148,15 +150,15 @@ abstract class LightbugDevice implements Device:
148150 */
149151 auto-register-ble-handler_ :
150152 e := catch :
151- ble-handler := BLEHandler this comms_
153+ ble-handler := BLEHandler this comms_ --logger = ( logger_ . with-name "h.ble" )
152154 comms_ .register-handler ble-handler
153155 logger_ .debug "Auto-registered BLE message handler"
154156 if e :
155157 logger_ .warn "Failed to register BLE handler: $ e "
156158
157159 auto-register-wifi-handler_ :
158160 e := catch :
159- wifi-handler := WiFiHandler this comms_
161+ wifi-handler := WiFiHandler this comms_ --logger = ( logger_ . with-name "h.wifi" )
160162 comms_ .register-handler wifi-handler
161163 logger_ .debug "Auto-registered WiFi message handler"
162164 if e :
0 commit comments