Skip to content

Commit

Permalink
replaced prints by ESP logs in library code
Browse files Browse the repository at this point in the history
  • Loading branch information
qfisch committed Oct 28, 2024
1 parent 196887f commit 2a527bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/SensorList.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SensorList.h"

static const char* TAG = "SensorList";

size_t SensorList::_hashSensorType(SensorType sensorType) const {
SensorHash sensorHash = SensorHash::_UNDEFINED;
switch (sensorType) {
Expand Down Expand Up @@ -41,8 +43,7 @@ size_t SensorList::_hashSensorType(SensorType sensorType) const {
}

if (sensorHash == SensorHash::_UNDEFINED) {
Serial.printf("Error: invalid sensor type %s encountered. Aborting!\n",
sensorLabel(sensorType));
ESP_LOGE(TAG, "Error: invalid sensor type %s encountered. Aborting!", sensorLabel(sensorType));
assert(0);
}

Expand Down
16 changes: 6 additions & 10 deletions src/SensorManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SensorManager.h"

static const char* TAG = "SensorManager";

void SensorManager::refreshConnectedSensors() {
_sensorList.removeLostSensors();
_detector.findSensors(_sensorList);
Expand All @@ -14,20 +16,14 @@ void SensorManager::executeSensorCommunication() {
sensorLabel(ssm->getSensor()->getSensorType());
switch (error) {
case I2C_ERROR:
Serial.printf("An I2C error occurred while attempting to "
"execute a command on sensor %s.\n",
sensorName);
ESP_LOGW(TAG, "An I2C error occurred while attempting to "
"execute a command on sensor %s.", sensorName);
break;
case LOST_SENSOR_ERROR:
Serial.printf(
"Sensor %s was removed from list of active sensors.\n",
sensorName);
ESP_LOGI(TAG, "Sensor %s was removed from list of active sensors.", sensorName);
break;
case SENSOR_READY_STATE_DECAYED_ERROR:
Serial.printf(
"AutoDetect refresh rate too low: sensor %s "
"conditioning deprecated. Decrease update interval.\n",
sensorName);
ESP_LOGW(TAG, "AutoDetect refresh rate too low: sensor %s conditioning deprecated. Decrease update interval.", sensorName);
break;
case NO_ERROR:
default:
Expand Down
7 changes: 4 additions & 3 deletions src/SensorStateMachine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SensorStateMachine.h"

static const char* TAG = "SensorStateMachine";

bool timeIntervalPassed(const uint32_t interval,
const uint32_t currentTimeStamp,
const uint32_t latestUpdateTimeStamp) {
Expand All @@ -22,7 +24,7 @@ AutoDetectorError SensorStateMachine::_initialize() {
if (error) {
char errorMsg[256];
errorToString(error, errorMsg, 256);
Serial.printf("Failed to perform initialization step: %s\n", errorMsg);
ESP_LOGE(TAG, "Failed to perform initialization step of sensor %s: %s", sensorLabel(_sensor->getSensorType()), errorMsg);
return I2C_ERROR;
}

Expand Down Expand Up @@ -109,8 +111,7 @@ AutoDetectorError SensorStateMachine::_readSignals() {
if (error) {
char errorMsg[256];
errorToString(error, errorMsg, 256);
Serial.printf("Failed to read measurements for sensor %s: %s\n",
sensorLabel(_sensor->getSensorType()), errorMsg);
ESP_LOGE(TAG, "Failed to read measurements for sensor %s: %s", sensorLabel(_sensor->getSensorType()), errorMsg);
return I2C_ERROR;
}

Expand Down
8 changes: 4 additions & 4 deletions src/SensorStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SensorStateMachine {
* to UNINITIALIZED
*
* @return I2C_ERROR if ISensor::initializationStep() fails (in which case
* the driver error is decoded and printed to console)
* the driver error is decoded and printed to logs)
* NO_ERROR on success
*/
AutoDetectorError _initialize();
Expand All @@ -60,7 +60,7 @@ class SensorStateMachine {
* short, or too long.
*
* @return I2C_ERROR if _readSignals() fails (in which case the driver
* error is decoded and printed to console)
* error is decoded and printed to logs)
* SENSOR_READY_STATE_DECAYED_ERROR if too much time has elapsed
* since last measurement was performed NO_ERROR on success
*/
Expand All @@ -70,7 +70,7 @@ class SensorStateMachine {
* @brief Query sensor for new signals
*
* @return I2C_ERROR if ISensor::measureAndWrite() fails (in which case the
* error is decoded and printed to console)
* error is decoded and printed to logs)
* NO_ERROR on success
*/
AutoDetectorError _readSignals();
Expand Down Expand Up @@ -110,7 +110,7 @@ class SensorStateMachine {
* Serial, but such errors may not be fatal.
*
* @return I2C_ERROR if bus communication fails (in which case the
* driver error is decoded and printed to console)
* driver error is decoded and printed to logs)
* SENSOR_LOST_ERROR if allowable number of consecutive operation
* errors was exceeded during update
* SENSOR_READY_STATE_DECAYED_ERROR if too much time has elapsed
Expand Down

0 comments on commit 2a527bc

Please sign in to comment.