From a48dd7c9ddb8e6156239ed2f180f8f60e08554e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Sun, 16 Feb 2025 13:08:25 +0100 Subject: [PATCH] Safeguard serial error prints --- src/communication/Communication.cpp | 4 +++- src/display/Display.cpp | 4 +++- src/lightDetection/LightDetection.cpp | 10 ++++++++-- src/motion/Motion.cpp | 13 ++++++++++--- src/motionDetection/MotionDetection.cpp | 4 +++- src/multiColorLight/MultiColorLight.cpp | 4 +++- src/power/PowerScheduler.cpp | 2 +- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/communication/Communication.cpp b/src/communication/Communication.cpp index 146e8ca..1669ecf 100644 --- a/src/communication/Communication.cpp +++ b/src/communication/Communication.cpp @@ -81,7 +81,9 @@ void Communication::begin(void) { PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, MESH_MAX_EXECUTION_DELAY_MS, NULL)) { ESP_LOGE(TAG, "Failed to get power for mesh initialization"); - Serial.println("Failed to get power for mesh initialization"); + if(Serial) { + Serial.println("Failed to get power for mesh initialization"); + } } mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT); mesh.onReceive(&receivedCallback); diff --git a/src/display/Display.cpp b/src/display/Display.cpp index 342c48c..6fe4a6c 100644 --- a/src/display/Display.cpp +++ b/src/display/Display.cpp @@ -18,7 +18,9 @@ void Display::begin(void){ PowerParameters::PowerConsumers::DISPLAY_OLED, PowerParameters::CurrentConsumptions::CURRENT_DISPLAY ,DISPLAY_MAX_EXECUTION_DELAY_MS, NULL)){ ESP_LOGE(TAG,"Could not get power for Display"); - Serial.println("Could not get power for Display"); + if (Serial) { + Serial.println("Could not get power for Display"); + } } //set Mux Ratio sendDisplayCMD(muxRatio); diff --git a/src/lightDetection/LightDetection.cpp b/src/lightDetection/LightDetection.cpp index 1fbe3fa..46c52da 100644 --- a/src/lightDetection/LightDetection.cpp +++ b/src/lightDetection/LightDetection.cpp @@ -69,7 +69,10 @@ void LightDetection::beginInfrared(void){ PowerParameters::CurrentConsumptions::CURRENT_PT * 4, LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { ESP_LOGE(TAG,"Could not get power for Infrared Phototransistors"); - Serial.println("Could not get power for Infrared Phototransistors"); + if(Serial){ + Serial.println( + "Could not get power for Infrared Phototransistors"); + } } digitalWrite(IR_PT_ENABLE,true); pinMode(IR_PT_ENABLE, OUTPUT); @@ -85,7 +88,10 @@ void LightDetection::beginDaylight(void){ PowerParameters::CurrentConsumptions::CURRENT_PT * 2, LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { ESP_LOGE(TAG,"Could not get power for Daylight Phototransistors"); - Serial.println("Could not get power for Daylight Phototransistors"); + if(Serial){ + Serial.println( + "Could not get power for Daylight Phototransistors"); + } } digitalWrite(DL_PT_ENABLE,true); pinMode(DL_PT_ENABLE, OUTPUT); diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp index 0db820c..2852efa 100644 --- a/src/motion/Motion.cpp +++ b/src/motion/Motion.cpp @@ -32,7 +32,9 @@ void Motion::moveTask(void * args) { uint32_t runtime = (uint32_t)args; if (!Motion::left.setSpeed(LEFT_MOTOR_DUTY) || !Motion::right.setSpeed(RIGHT_MOTOR_DUTY)) { - Serial.println("ailed to start motors due to power constraints"); + if(Serial){ + Serial.println("Failed to start motors due to power constraints"); + } Motion::stop(); // Use to clean up return; } @@ -123,7 +125,9 @@ void Motion::leftMotorTask(void * args) { } Motion::right.setSpeed(0); if(!Motion::left.setSpeed(LEFT_MOTOR_DUTY)){ - Serial.println("Can not rotate Clockwise due to power constraints"); + if(Serial){ + Serial.println("Can not rotate Clockwise due to power constraints"); + } Motion::stop(); return; } @@ -166,7 +170,10 @@ void Motion::rightMotorTask(void * args) { xClockwiseTaskHandle = NULL; } if(!Motion::left.setSpeed(RIGHT_MOTOR_DUTY)){ - Serial.println("Can not rotate Antilockwise due to power constraints"); + if(Serial){ + Serial.println( + "Can not rotate Antilcockwise due to power constraints"); + } Motion::stop(); return; } diff --git a/src/motionDetection/MotionDetection.cpp b/src/motionDetection/MotionDetection.cpp index cfe2c77..19cdd7c 100644 --- a/src/motionDetection/MotionDetection.cpp +++ b/src/motionDetection/MotionDetection.cpp @@ -11,7 +11,9 @@ void MotionDetection::begin(void){ PowerParameters::CurrentConsumptions::CURRENT_IMU, IMU_MAX_EXECUTION_DELAY_MS, NULL)) { ESP_LOGE(TAG, "Could not get power for MotionDetection"); - Serial.println("Could not get power for MotionDetection"); + if(Serial){ + Serial.println("Could not get power for MotionDetection"); + } } pinMode(34,OUTPUT); digitalWrite(34,HIGH); diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index e439252..90e0ef8 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -19,7 +19,9 @@ void MultiColorLight::begin(void) { PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { ESP_LOGE(TAG, "Could not get power for MultiColorLight"); - Serial.println("Could not get power for MultiColorLight"); + if(Serial){ + Serial.println("Could not get power for MultiColorLight"); + } } rgbLeds.begin(); this->turnOffLed(); diff --git a/src/power/PowerScheduler.cpp b/src/power/PowerScheduler.cpp index 05c48a2..e2c6aa3 100644 --- a/src/power/PowerScheduler.cpp +++ b/src/power/PowerScheduler.cpp @@ -137,7 +137,7 @@ bool PowerScheduler::waitForCurrentAllowance( .requestedAt = initialTickCount, .grantedAt = xTaskGetTickCount(), .granted = true}); - ESP_LOGV(TAG, "%d mA granted to consumer %d after %d ms", + ESP_LOGI(TAG, "%d mA granted to consumer %d with a delay of %d ms", neededCurrent, static_cast(consumer), xTaskGetTickCount() - initialTickCount); return true;