From b446d0fa98a54b791e9d36227fbf848358a89353 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 2 Feb 2020 12:32:12 +0100 Subject: [PATCH] Commented out all logging lines as it was using too much RAM --- src/include/config.h | 8 ++++---- src/lib/control.cpp | 36 ++++++++++++++++++------------------ src/lib/motor.cpp | 4 ++-- src/lib/screen/manual.cpp | 2 +- src/main.cpp | 6 +++--- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/include/config.h b/src/include/config.h index 67bde3b..cc5d3b0 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -13,11 +13,11 @@ every loop. Only turn on when required. - At the time of writing, turning both on uses more RAM - than the ATMega328P has. + Due to RAM/flash constraints, most logging lines have + been commented out as it would take up around 1.5k of RAM + and 4k of flash otherwise, which we don't have. + Uncomment those lines as required. - Turning DebugLog off saves around 1k of RAM and 3k of flash. - Turning VerboseLog off saves around 300 bytes of RAM and 1k of flash. */ //#define DebugLog //#define VerboseLog diff --git a/src/lib/control.cpp b/src/lib/control.cpp index f8bd02d..cf4d393 100644 --- a/src/lib/control.cpp +++ b/src/lib/control.cpp @@ -12,7 +12,7 @@ ControlManager Control = ControlManager(); VL53L0XInitResult ControlManager::init() { - dln("[ CONTROL ] Initializing"); + //dln("[ CONTROL ] Initializing"); Wire.begin(); this->heightSensor.setTimeout(500); @@ -36,14 +36,14 @@ ControlUpdateResult ControlManager::update() : VL53L0XRangeNotReady; - vl("[ CONTROL ] Update: asyncReading = "); vl(asyncReading); vl(", measurement = "); vl(measurement); - vl(", moveDirection = "); vl((uint8_t)this->moveDirection); vl(", stabilizationStart = "); vln(this->stabilizationStart); + //vl("[ CONTROL ] Update: asyncReading = "); vl(asyncReading); vl(", measurement = "); vl(measurement); + //vl(", moveDirection = "); vl((uint8_t)this->moveDirection); vl(", stabilizationStart = "); vln(this->stabilizationStart); bool moving = this->moveDirection != MoveDirection::None && this->stabilizationStart == 0; if (!moving && this->stabilizationStart == 0) { - vl("[ CONTROL ] Idle"); + //vl("[ CONTROL ] Idle"); return ControlUpdateResult::Idle; } @@ -55,7 +55,7 @@ ControlUpdateResult ControlManager::update() if (motorIsOvercurrent()) { - dln("[ CONTROL ] Overcurrent detected!"); + //dln("[ CONTROL ] Overcurrent detected!"); this->moveStop(); return ControlUpdateResult::Overcurrent; @@ -65,7 +65,7 @@ ControlUpdateResult ControlManager::update() // Read sensor if (!asyncReading) { - vln("[ CONTROL ] Starting async read"); + //vln("[ CONTROL ] Starting async read"); heightSensor.asyncStartReadRangeSingleMillimeters(); } @@ -77,7 +77,7 @@ ControlUpdateResult ControlManager::update() measurement = VL53L0XRangeTimeout; - dl("[ CONTROL ] Measurement: "); dln(measurement); + //dl("[ CONTROL ] Measurement: "); dln(measurement); this->lastMeasurement = measurement != VL53L0XRangeTimeout ? measurement : 0; } @@ -103,7 +103,7 @@ ControlUpdateResult ControlManager::update() // While moving, allow incidental invalid results if (CurrentTime - lastValidMeasurement >= Config::HeightMeasurementAbortTimeout) { - dln("[ CONTROL ] Timeout while moving!"); + //dln("[ CONTROL ] Timeout while moving!"); this->moveStop(); return ControlUpdateResult::SensorError; @@ -123,7 +123,7 @@ ControlUpdateResult ControlManager::update() // Pre-move stabilization if (this->stabilized()) { - dln("[ CONTROL ] Pre-move stabilization successful"); + //dln("[ CONTROL ] Pre-move stabilization successful"); // Sensor looks good, let's go! motorStart(this->moveDirection == MoveDirection::Up ? MotorDirection::Up : MotorDirection::Down); @@ -131,7 +131,7 @@ ControlUpdateResult ControlManager::update() } else if (CurrentTime - this->stabilizationStart >= Config::HeightMeasurementDeltaStableMoveTimeout) { - dln("[ CONTROL ] Timeout in pre-move stabilization!"); + //dln("[ CONTROL ] Timeout in pre-move stabilization!"); // Timeout expired, abort the move this->stabilizationStart = 0; @@ -147,7 +147,7 @@ ControlUpdateResult ControlManager::update() void ControlManager::stabilizeStart() { - dln("[ CONTROL ] Starting stabilization"); + //dln("[ CONTROL ] Starting stabilization"); this->stabilizationStart = CurrentTime; this->stabilizeTargetMeasurement = 0; @@ -177,7 +177,7 @@ bool ControlManager::stabilized() if (this->stabilizeCount >= Config::HeightMeasurementDeltaStableCount) { - dln("[ CONTROL ] Stable"); + //dln("[ CONTROL ] Stable"); this->stabilizationStart = 0; return true; } @@ -195,16 +195,16 @@ bool ControlManager::stabilized() void ControlManager::moveStart(uint16_t height) { - dl("[ CONTROL ] Starting move to: "); dln(height); + //dl("[ CONTROL ] Starting move to: "); dln(height); if (height < Settings.Height.Minimum) { - dl("[ CONTROL ] Target is below minimum, changing to: "); dln(Settings.Height.Minimum); + //dl("[ CONTROL ] Target is below minimum, changing to: "); dln(Settings.Height.Minimum); height = Settings.Height.Minimum; } else if (height > Settings.Height.Maximum) { - dl("[ CONTROL ] Target is above maximum, changing to: "); dln(Settings.Height.Maximum); + //dl("[ CONTROL ] Target is above maximum, changing to: "); dln(Settings.Height.Maximum); height = Settings.Height.Maximum; } @@ -218,7 +218,7 @@ void ControlManager::moveStart(uint16_t height) void ControlManager::moveStop() { - dln("[ CONTROL ] Stopping move"); + //dln("[ CONTROL ] Stopping move"); motorStop(); this->moveDirection = MoveDirection::None; @@ -253,7 +253,7 @@ bool ControlManager::targetReached() if (currentHeight - this->moveTargetHeight <= Config::HeightMeasurementDeltaOnTarget) this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset; - dln("[ CONTROL ] Target reached"); + //dln("[ CONTROL ] Target reached"); return true; } break; @@ -265,7 +265,7 @@ bool ControlManager::targetReached() if (this->moveTargetHeight - currentHeight <= Config::HeightMeasurementDeltaOnTarget) this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset; - dln("[ CONTROL ] Target reached"); + //dln("[ CONTROL ] Target reached"); return true; } break; diff --git a/src/lib/motor.cpp b/src/lib/motor.cpp index 7689df4..0a534f2 100644 --- a/src/lib/motor.cpp +++ b/src/lib/motor.cpp @@ -23,7 +23,7 @@ void motorInit() void motorStart(MotorDirection direction) { - dl("[ MOTOR ] Starting in direction: "); dln((uint8_t)direction); + //dl("[ MOTOR ] Starting in direction: "); dln((uint8_t)direction); digitalWrite(Config::MotorPinDirection, direction == MotorDirection::Up ? HIGH : LOW); digitalWrite(Config::MotorPinSleep, HIGH); @@ -33,7 +33,7 @@ void motorStart(MotorDirection direction) void motorStop() { - dln("[ MOTOR ] Stopping"); + //dln("[ MOTOR ] Stopping"); digitalWrite(Config::MotorPinPWM, LOW); digitalWrite(Config::MotorPinSleep, LOW); diff --git a/src/lib/screen/manual.cpp b/src/lib/screen/manual.cpp index a095b93..295d2fe 100644 --- a/src/lib/screen/manual.cpp +++ b/src/lib/screen/manual.cpp @@ -25,7 +25,7 @@ bool ManualScreen::nextPage() Control.moveStart(this->height); this->screenManager->show(); - return true; + return false; } diff --git a/src/main.cpp b/src/main.cpp index daa6dd3..88228d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -207,19 +207,19 @@ void loop() if (buttons[0].fell()) { - dln("[ MAIN ] Button pressed: Top"); + //dln("[ MAIN ] Button pressed: Top"); screenManager.button(Button::Top); } if (buttons[1].fell()) { - dln("[ MAIN ] Button pressed: Middle"); + //dln("[ MAIN ] Button pressed: Middle"); screenManager.button(Button::Middle); } if (buttons[2].fell()) { - dln("[ MAIN ] Button pressed: Bottom"); + //dln("[ MAIN ] Button pressed: Bottom"); screenManager.button(Button::Bottom); }