@@ -518,15 +518,13 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
518518
519519 // Before we do anything on the bus - was the bus initialized correctly?
520520 if (!IsBusStatusOK (use_alt_bus)) {
521- WS_DEBUG_PRINTLN (" [i2c] ERROR: I2C bus is not operational or stuck, please "
522- " restart device!" );
521+ WsV2.haltErrorV2 (" [i2c] I2C bus is stuck or not operational, reset the board!" , WS_LED_STATUS_ERROR_RUNTIME, false );
523522 if (!PublishI2cDeviceAddedorReplaced (device_descriptor, device_status))
524523 return false ;
525524 return true ;
526525 }
527526
528527 // Mux case #1 - We are creating a mux via I2cDeviceAddorReplace message
529- // TODO: Refactor
530528 if ((strcmp (device_name, " pca9546" ) == 0 ) ||
531529 (strcmp (device_name, " pca9548" ) == 0 )) {
532530 WS_DEBUG_PRINTLN (" [i2c] Creating a new MUX driver obj" );
@@ -536,15 +534,15 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
536534 _i2c_bus_alt->AddMuxToBus (device_descriptor.i2c_mux_address ,
537535 device_name);
538536 } else {
539- WS_DEBUG_PRINTLN (" [i2c] ERROR: Mux specified but not created " );
537+ WsV2. haltErrorV2 (" [i2c] Unable to initialize I2C MUX! " , WS_LED_STATUS_ERROR_RUNTIME, false );
540538 }
541539 } else {
542540 if (!_i2c_bus_default->HasMux ()) {
543541 WS_DEBUG_PRINT (" [i2c] Adding MUX to default bus..." );
544542 _i2c_bus_default->AddMuxToBus (device_descriptor.i2c_mux_address ,
545543 device_name);
546544 } else {
547- WS_DEBUG_PRINTLN (" [i2c] ERROR: Mux specified but not created " );
545+ WsV2. haltErrorV2 (" [i2c] Unable to initialize I2C MUX! " , WS_LED_STATUS_ERROR_RUNTIME, false );
548546 }
549547 }
550548 // TODO: Publish back out to IO instead of blindly returning true
@@ -562,11 +560,10 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
562560 WS_DEBUG_PRINTLN (mux_channel);
563561 did_set_mux_ch = true ;
564562 } else {
565- WS_DEBUG_PRINTLN (" [i2c] ERROR: Device requests a MUX but MUX has not "
566- " been initialized first" );
567- device_status =
568- wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
569- PublishI2cDeviceAddedorReplaced (device_descriptor, device_status);
563+ WsV2.haltErrorV2 (" [i2c] Device requires a MUX but MUX not present within config.json!" , WS_LED_STATUS_ERROR_RUNTIME, false );
564+ // TODO: Online mode needs the below implemented
565+ // device_status = wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
566+ // PublishI2cDeviceAddedorReplaced(device_descriptor, device_status);
570567 return false ;
571568 }
572569 } else {
@@ -576,11 +573,10 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
576573 WS_DEBUG_PRINTLN (mux_channel);
577574 did_set_mux_ch = true ;
578575 } else {
579- WS_DEBUG_PRINTLN (" [i2c] ERROR: Device requests a MUX but MUX has not "
580- " been initialized first" );
581- device_status =
582- wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
583- PublishI2cDeviceAddedorReplaced (device_descriptor, device_status);
576+ WsV2.haltErrorV2 (" [i2c] Device requires a MUX but MUX not present within config.json!" , WS_LED_STATUS_ERROR_RUNTIME, false );
577+ // TODO: Online mode needs the below implemented
578+ // device_status = wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
579+ // PublishI2cDeviceAddedorReplaced(device_descriptor, device_status);
584580 return false ;
585581 }
586582 }
@@ -636,15 +632,11 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
636632 wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
637633
638634 if (WsV2._sdCardV2 ->isModeOffline ()) {
639- WS_DEBUG_PRINTLN (" [i2c] Driver failed to initialize!\n\t Did you set "
635+ WsV2. haltErrorV2 (" [i2c] Driver failed to initialize!\n\t Did you set "
640636 " the correct value for i2cDeviceName?\n\t Did you set "
641637 " the correct value for"
642- " i2cDeviceAddress?" );
643- while (
644- 1 ) { // Keep the WIPPER drive open to allow user to edit config.json
645- WsV2.feedWDTV2 ();
646- delay (500 );
647- }
638+ " i2cDeviceAddress?" ,
639+ WS_LED_STATUS_ERROR_RUNTIME, false );
648640 }
649641 if (!PublishI2cDeviceAddedorReplaced (device_descriptor, device_status))
650642 return false ;
@@ -656,15 +648,11 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
656648 wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_UNSUPPORTED_SENSOR;
657649
658650 if (WsV2._sdCardV2 ->isModeOffline ()) {
659- WS_DEBUG_PRINTLN (" [i2c] Driver failed to initialize!\n\t Did you set "
651+ WsV2. haltErrorV2 (" [i2c] Driver failed to initialize!\n\t Did you set "
660652 " the correct value for i2cDeviceName?\n\t Did you set "
661653 " the correct value for"
662- " i2cDeviceAddress?" );
663- while (
664- 1 ) { // Keep the WIPPER drive open to allow user to edit config.json
665- WsV2.feedWDTV2 ();
666- delay (500 );
667- }
654+ " i2cDeviceAddress?" ,
655+ WS_LED_STATUS_ERROR_RUNTIME, false );
668656 }
669657
670658 if (!PublishI2cDeviceAddedorReplaced (device_descriptor, device_status))
0 commit comments