Commented out all logging lines as it was using too much RAM
This commit is contained in:
parent
b9f5394d53
commit
b446d0fa98
@ -13,11 +13,11 @@
|
|||||||
every loop. Only turn on when required.
|
every loop. Only turn on when required.
|
||||||
|
|
||||||
|
|
||||||
At the time of writing, turning both on uses more RAM
|
Due to RAM/flash constraints, most logging lines have
|
||||||
than the ATMega328P has.
|
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 DebugLog
|
||||||
//#define VerboseLog
|
//#define VerboseLog
|
||||||
|
@ -12,7 +12,7 @@ ControlManager Control = ControlManager();
|
|||||||
|
|
||||||
VL53L0XInitResult ControlManager::init()
|
VL53L0XInitResult ControlManager::init()
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Initializing");
|
//dln("[ CONTROL ] Initializing");
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
this->heightSensor.setTimeout(500);
|
this->heightSensor.setTimeout(500);
|
||||||
@ -36,14 +36,14 @@ ControlUpdateResult ControlManager::update()
|
|||||||
: VL53L0XRangeNotReady;
|
: VL53L0XRangeNotReady;
|
||||||
|
|
||||||
|
|
||||||
vl("[ CONTROL ] Update: asyncReading = "); vl(asyncReading); vl(", measurement = "); vl(measurement);
|
//vl("[ CONTROL ] Update: asyncReading = "); vl(asyncReading); vl(", measurement = "); vl(measurement);
|
||||||
vl(", moveDirection = "); vl((uint8_t)this->moveDirection); vl(", stabilizationStart = "); vln(this->stabilizationStart);
|
//vl(", moveDirection = "); vl((uint8_t)this->moveDirection); vl(", stabilizationStart = "); vln(this->stabilizationStart);
|
||||||
|
|
||||||
|
|
||||||
bool moving = this->moveDirection != MoveDirection::None && this->stabilizationStart == 0;
|
bool moving = this->moveDirection != MoveDirection::None && this->stabilizationStart == 0;
|
||||||
if (!moving && this->stabilizationStart == 0)
|
if (!moving && this->stabilizationStart == 0)
|
||||||
{
|
{
|
||||||
vl("[ CONTROL ] Idle");
|
//vl("[ CONTROL ] Idle");
|
||||||
return ControlUpdateResult::Idle;
|
return ControlUpdateResult::Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
|
|
||||||
if (motorIsOvercurrent())
|
if (motorIsOvercurrent())
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Overcurrent detected!");
|
//dln("[ CONTROL ] Overcurrent detected!");
|
||||||
this->moveStop();
|
this->moveStop();
|
||||||
|
|
||||||
return ControlUpdateResult::Overcurrent;
|
return ControlUpdateResult::Overcurrent;
|
||||||
@ -65,7 +65,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
// Read sensor
|
// Read sensor
|
||||||
if (!asyncReading)
|
if (!asyncReading)
|
||||||
{
|
{
|
||||||
vln("[ CONTROL ] Starting async read");
|
//vln("[ CONTROL ] Starting async read");
|
||||||
heightSensor.asyncStartReadRangeSingleMillimeters();
|
heightSensor.asyncStartReadRangeSingleMillimeters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
measurement = VL53L0XRangeTimeout;
|
measurement = VL53L0XRangeTimeout;
|
||||||
|
|
||||||
|
|
||||||
dl("[ CONTROL ] Measurement: "); dln(measurement);
|
//dl("[ CONTROL ] Measurement: "); dln(measurement);
|
||||||
this->lastMeasurement = measurement != VL53L0XRangeTimeout ? measurement : 0;
|
this->lastMeasurement = measurement != VL53L0XRangeTimeout ? measurement : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
// While moving, allow incidental invalid results
|
// While moving, allow incidental invalid results
|
||||||
if (CurrentTime - lastValidMeasurement >= Config::HeightMeasurementAbortTimeout)
|
if (CurrentTime - lastValidMeasurement >= Config::HeightMeasurementAbortTimeout)
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Timeout while moving!");
|
//dln("[ CONTROL ] Timeout while moving!");
|
||||||
this->moveStop();
|
this->moveStop();
|
||||||
|
|
||||||
return ControlUpdateResult::SensorError;
|
return ControlUpdateResult::SensorError;
|
||||||
@ -123,7 +123,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
// Pre-move stabilization
|
// Pre-move stabilization
|
||||||
if (this->stabilized())
|
if (this->stabilized())
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Pre-move stabilization successful");
|
//dln("[ CONTROL ] Pre-move stabilization successful");
|
||||||
|
|
||||||
// Sensor looks good, let's go!
|
// Sensor looks good, let's go!
|
||||||
motorStart(this->moveDirection == MoveDirection::Up ? MotorDirection::Up : MotorDirection::Down);
|
motorStart(this->moveDirection == MoveDirection::Up ? MotorDirection::Up : MotorDirection::Down);
|
||||||
@ -131,7 +131,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
}
|
}
|
||||||
else if (CurrentTime - this->stabilizationStart >= Config::HeightMeasurementDeltaStableMoveTimeout)
|
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
|
// Timeout expired, abort the move
|
||||||
this->stabilizationStart = 0;
|
this->stabilizationStart = 0;
|
||||||
@ -147,7 +147,7 @@ ControlUpdateResult ControlManager::update()
|
|||||||
|
|
||||||
void ControlManager::stabilizeStart()
|
void ControlManager::stabilizeStart()
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Starting stabilization");
|
//dln("[ CONTROL ] Starting stabilization");
|
||||||
|
|
||||||
this->stabilizationStart = CurrentTime;
|
this->stabilizationStart = CurrentTime;
|
||||||
this->stabilizeTargetMeasurement = 0;
|
this->stabilizeTargetMeasurement = 0;
|
||||||
@ -177,7 +177,7 @@ bool ControlManager::stabilized()
|
|||||||
|
|
||||||
if (this->stabilizeCount >= Config::HeightMeasurementDeltaStableCount)
|
if (this->stabilizeCount >= Config::HeightMeasurementDeltaStableCount)
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Stable");
|
//dln("[ CONTROL ] Stable");
|
||||||
this->stabilizationStart = 0;
|
this->stabilizationStart = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -195,16 +195,16 @@ bool ControlManager::stabilized()
|
|||||||
|
|
||||||
void ControlManager::moveStart(uint16_t height)
|
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)
|
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;
|
height = Settings.Height.Minimum;
|
||||||
}
|
}
|
||||||
else if (height > Settings.Height.Maximum)
|
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;
|
height = Settings.Height.Maximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ void ControlManager::moveStart(uint16_t height)
|
|||||||
|
|
||||||
void ControlManager::moveStop()
|
void ControlManager::moveStop()
|
||||||
{
|
{
|
||||||
dln("[ CONTROL ] Stopping move");
|
//dln("[ CONTROL ] Stopping move");
|
||||||
|
|
||||||
motorStop();
|
motorStop();
|
||||||
this->moveDirection = MoveDirection::None;
|
this->moveDirection = MoveDirection::None;
|
||||||
@ -253,7 +253,7 @@ bool ControlManager::targetReached()
|
|||||||
if (currentHeight - this->moveTargetHeight <= Config::HeightMeasurementDeltaOnTarget)
|
if (currentHeight - this->moveTargetHeight <= Config::HeightMeasurementDeltaOnTarget)
|
||||||
this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset;
|
this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset;
|
||||||
|
|
||||||
dln("[ CONTROL ] Target reached");
|
//dln("[ CONTROL ] Target reached");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -265,7 +265,7 @@ bool ControlManager::targetReached()
|
|||||||
if (this->moveTargetHeight - currentHeight <= Config::HeightMeasurementDeltaOnTarget)
|
if (this->moveTargetHeight - currentHeight <= Config::HeightMeasurementDeltaOnTarget)
|
||||||
this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset;
|
this->currentMeasurement = this->moveTargetHeight - Settings.Height.Offset;
|
||||||
|
|
||||||
dln("[ CONTROL ] Target reached");
|
//dln("[ CONTROL ] Target reached");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -23,7 +23,7 @@ void motorInit()
|
|||||||
|
|
||||||
void motorStart(MotorDirection direction)
|
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::MotorPinDirection, direction == MotorDirection::Up ? HIGH : LOW);
|
||||||
digitalWrite(Config::MotorPinSleep, HIGH);
|
digitalWrite(Config::MotorPinSleep, HIGH);
|
||||||
@ -33,7 +33,7 @@ void motorStart(MotorDirection direction)
|
|||||||
|
|
||||||
void motorStop()
|
void motorStop()
|
||||||
{
|
{
|
||||||
dln("[ MOTOR ] Stopping");
|
//dln("[ MOTOR ] Stopping");
|
||||||
|
|
||||||
digitalWrite(Config::MotorPinPWM, LOW);
|
digitalWrite(Config::MotorPinPWM, LOW);
|
||||||
digitalWrite(Config::MotorPinSleep, LOW);
|
digitalWrite(Config::MotorPinSleep, LOW);
|
||||||
|
@ -25,7 +25,7 @@ bool ManualScreen::nextPage()
|
|||||||
Control.moveStart(this->height);
|
Control.moveStart(this->height);
|
||||||
|
|
||||||
this->screenManager->show<MoveScreen>();
|
this->screenManager->show<MoveScreen>();
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,19 +207,19 @@ void loop()
|
|||||||
|
|
||||||
if (buttons[0].fell())
|
if (buttons[0].fell())
|
||||||
{
|
{
|
||||||
dln("[ MAIN ] Button pressed: Top");
|
//dln("[ MAIN ] Button pressed: Top");
|
||||||
screenManager.button(Button::Top);
|
screenManager.button(Button::Top);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttons[1].fell())
|
if (buttons[1].fell())
|
||||||
{
|
{
|
||||||
dln("[ MAIN ] Button pressed: Middle");
|
//dln("[ MAIN ] Button pressed: Middle");
|
||||||
screenManager.button(Button::Middle);
|
screenManager.button(Button::Middle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttons[2].fell())
|
if (buttons[2].fell())
|
||||||
{
|
{
|
||||||
dln("[ MAIN ] Button pressed: Bottom");
|
//dln("[ MAIN ] Button pressed: Bottom");
|
||||||
screenManager.button(Button::Bottom);
|
screenManager.button(Button::Bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user