Skip to content

Commit 903db88

Browse files
committed
Tested against hw
1 parent cb757b4 commit 903db88

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/components/i2c/controller.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ bool I2cController::PublishI2cDeviceAddedorReplaced(
487487
bool I2cController::Handle_I2cDeviceRemove(pb_istream_t *stream) {
488488
// Attempt to decode an I2cDeviceRemove message
489489
WS_DEBUG_PRINTLN("[i2c] Decoding I2cDeviceRemove message...");
490-
if (!_i2c_model->DecodeI2cDeviceRemove(stream)) {
490+
if (! _i2c_model->DecodeI2cDeviceRemove(stream)) {
491491
WS_DEBUG_PRINTLN("[i2c] ERROR: Unable to decode I2cDeviceRemove message!");
492492
return false;
493493
}
@@ -624,6 +624,9 @@ bool I2cController::Handle_I2cBusScan(pb_istream_t *stream) {
624624
// Case 1: Scan the default I2C bus
625625
if (_i2c_model->GetI2cBusScanMsg()->scan_default_bus) {
626626
// Was the default bus initialized correctly and ready to scan?
627+
WS_DEBUG_PRINT("Bus State: ");
628+
WS_DEBUG_PRINTLN(_i2c_bus_default->GetBusStatus());
629+
WS_DEBUG_PRINTLN(IsBusStatusOK());
627630
if (IsBusStatusOK()) {
628631
if (!_i2c_bus_default->ScanBus(scan_results)) {
629632
WS_DEBUG_PRINTLN("[i2c] ERROR: Failed to scan default I2C bus!");
@@ -890,6 +893,7 @@ void I2cController::ConfigureMuxChannel(uint32_t mux_channel, bool is_alt_bus) {
890893
*/
891894
/***********************************************************************/
892895
void I2cController::update() {
896+
//WS_DEBUG_PRINTLN("[i2c] Updating I2C controller...");
893897
if (_i2c_drivers.size() == 0)
894898
return; // bail out if no drivers exist
895899

@@ -901,11 +905,13 @@ void I2cController::update() {
901905

902906
// Did driver's period elapse yet?
903907
ulong cur_time = millis();
904-
if (cur_time - drv->GetSensorPeriodPrv() < drv->GetSensorPeriod())
908+
if (cur_time - drv->GetSensorPeriodPrv() < drv->GetSensorPeriod()) {
905909
continue; // bail out if the period hasn't elapsed yet
910+
}
906911

907912
// Optionally configure the I2C MUX
908913
uint32_t mux_channel = drv->GetMuxChannel();
914+
WS_DEBUG_PRINTLN(mux_channel);
909915
if (drv->HasMux())
910916
ConfigureMuxChannel(mux_channel, drv->HasAltI2CBus());
911917

src/components/i2c/hardware.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
207207
WS_DEBUG_PRINTLN("[i2c] Did not find device: NACK on transmit of data!");
208208
continue;
209209
} else if (endTransmissionRC == 2) {
210-
WS_DEBUG_PRINTLN(
211-
"[i2c] Did not find device: NACK on transmit of address!");
210+
//WS_DEBUG_PRINTLN("[i2c] Did not find device: NACK on transmit of address!");
212211
continue;
213212
} else if (endTransmissionRC == 1) {
214213
WS_DEBUG_PRINTLN(

src/components/i2c/model.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ float GetValueFromSensorsEvent(wippersnapper_sensor_SensorType sensor_type,
134134
*/
135135
/****************************************************************************/
136136
bool I2cModel::DecodeI2cDeviceRemove(pb_istream_t *stream) {
137+
WS_DEBUG_PRINTLN("[i2c] Set _msg_i2c_device_remove...");
137138
_msg_i2c_device_remove = wippersnapper_i2c_I2cDeviceRemove_init_default;
138-
return pb_decode(stream, wippersnapper_i2c_I2cDeviceRemove_fields,
139-
&_msg_i2c_device_remove);
139+
bool is_success = false;
140+
is_success = pb_decode(stream, wippersnapper_i2c_I2cDeviceRemove_fields, &_msg_i2c_device_remove);
141+
WS_DEBUG_PRINT("is_success: "); WS_DEBUG_PRINTLN(is_success);
142+
return is_success;
140143
}
141144

142145
/**********************************************************************/

0 commit comments

Comments
 (0)