Skip to content

Commit c9a20b3

Browse files
committed
add 0a74dc96f50785d7f29d2f44b409033fd880d600
1 parent 263fbfa commit c9a20b3

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/components/i2c/controller.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ I2cController::~I2cController() {
459459
*/
460460
/***********************************************************************/
461461
bool I2cController::RemoveDriver(uint32_t address) {
462-
// Safely remove the i2c sensor drivers from the vector and free memory
462+
// Safely remove the i2c sensor driver from the vector and free memory
463463
for (drvBase *driver : _i2c_drivers) {
464464
if (driver == nullptr)
465465
continue;
@@ -475,7 +475,7 @@ bool I2cController::RemoveDriver(uint32_t address) {
475475
return true;
476476
}
477477

478-
// Safely remove the i2c output drivers from the vector and free memory
478+
// This was an output driver type, safely remove the i2c output driver from the vector and free memory
479479
for (drvOutputBase *driver : _i2c_drivers_output) {
480480
if (driver == nullptr)
481481
continue;
@@ -612,13 +612,7 @@ bool I2cController::Handle_I2cDeviceRemove(pb_istream_t *stream) {
612612
// TODO: Scan the mux to see what drivers are attached?
613613
wippersnapper_i2c_I2cBusScanned scan_results;
614614
_i2c_bus_default->ScanMux(&scan_results);
615-
// DEBUG - TODO REMOVE - Print out the scan results
616615
for (int i = 0; i < scan_results.i2c_bus_found_devices_count; i++) {
617-
WS_DEBUG_PRINT("[i2c] Found device at address: ");
618-
WS_DEBUG_PRINT(
619-
scan_results.i2c_bus_found_devices[i].i2c_device_address, HEX);
620-
WS_DEBUG_PRINT(" on mux channel #: ");
621-
WS_DEBUG_PRINTLN(
622616
scan_results.i2c_bus_found_devices[i].i2c_mux_channel);
623617
// Select the channel and remove the device
624618
_i2c_bus_default->SelectMuxChannel(
@@ -794,7 +788,7 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
794788
}
795789
wippersnapper_i2c_I2cDeviceDescriptor descriptor = _i2c_model->GetI2cDeviceOutputWriteMsg()->i2c_device_description;
796790

797-
// Get the driver
791+
// Attempt to find the driver
798792
drvOutputBase *driver = nullptr;
799793
for (auto *drv : _i2c_drivers_output) {
800794
if (drv == nullptr)
@@ -807,6 +801,12 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
807801
break;
808802
}
809803

804+
if (driver == nullptr) {
805+
WS_DEBUG_PRINT("[i2c] ERROR: Unable to find driver for device at addr 0x");
806+
WS_DEBUG_PRINTLN(descriptor.i2c_device_address, HEX);
807+
return false;
808+
}
809+
810810
// Optionally configure the I2C MUX
811811
uint32_t mux_channel = driver->GetMuxChannel();
812812
WS_DEBUG_PRINTLN(mux_channel);
@@ -816,8 +816,7 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
816816

817817
// Determine which driver cb function to use
818818
if (_i2c_model->GetI2cDeviceOutputWriteMsg()->has_led_backpack_write) {
819-
// TODO
820-
WS_DEBUG_PRINTLN("[i2c] LED backpack write!");
819+
WS_DEBUG_PRINT("[i2c] Writing message to LED backpack...");
821820
if (!driver->LedBackpackWrite(&_i2c_model->GetI2cDeviceOutputWriteMsg()->led_backpack_write)) {
822821
WS_DEBUG_PRINTLN("[i2c] ERROR: Unable to write to LED backpack!");
823822
return false;
@@ -828,7 +827,6 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
828827
WS_DEBUG_PRINTLN("[i2c] ERROR: Unable to determine I2C Output Write type!");
829828
return false;
830829
}
831-
832830

833831
return true;
834832
}
@@ -1045,6 +1043,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
10451043
// Create and publish the I2cDeviceAddedorReplaced message to the broker
10461044
WS_DEBUG_PRINTLN("[i2c] MQTT Publish I2cDeviceAddedorReplaced not yet "
10471045
"implemented!");
1046+
// TODO!
10481047
/* if (!PublishI2cDeviceAddedorReplaced(device_descriptor,
10491048
device_status)) return false; */
10501049
}

src/components/i2c/drivers/drvOutQuadAlphaNum.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define LED_BACKPACK_ALIGNMENT_UNSPECIFIED 0
2424
#define LED_BACKPACK_ALIGNMENT_LEFT 1
2525
#define LED_BACKPACK_ALIGNMENT_RIGHT 2
26+
#define LED_BACKPACK_ALIGNMENT_DEFAULT LED_BACKPACK_ALIGNMENT_LEFT
2627
#define LED_MAX_CHARS 4
2728

2829
/*!
@@ -80,8 +81,7 @@ class drvOutQuadAlphaNum : public drvOutputBase {
8081
if (alignment == LED_BACKPACK_ALIGNMENT_RIGHT) {
8182
_alignment = LED_BACKPACK_ALIGNMENT_RIGHT;
8283
} else {
83-
// default: left alignment
84-
_alignment = LED_BACKPACK_ALIGNMENT_LEFT;
84+
_alignment = LED_BACKPACK_ALIGNMENT_DEFAULT;
8585
}
8686
_brightness = brightness;
8787
}
@@ -177,8 +177,7 @@ class drvOutQuadAlphaNum : public drvOutputBase {
177177
nullptr; ///< ptr to a 4-digit alphanumeric display object
178178
int32_t _brightness; ///< Brightness of the LED backpack, from 0 (off) to 15
179179
///< (full brightness)
180-
uint32_t _alignment =
181-
LED_BACKPACK_ALIGNMENT_RIGHT; ///< Determines L/R alignment of the message
180+
uint32_t _alignment = LED_BACKPACK_ALIGNMENT_DEFAULT; ///< Determines L/R alignment of the message
182181
///< displayed
183182
};
184183

0 commit comments

Comments
 (0)