| @@ -32,8 +32,10 @@ Display::Display() : mode(FAST) { | |||
| angle = 0; | |||
| starttime = millis(); | |||
| refreshScreen = true; | |||
| distanceValue = 0; | |||
| distanceValue = 0.0; | |||
| distanceUnit = "mm"; | |||
| maxDiveDistance = 0.0; | |||
| levelHeightDiving = 0.0; | |||
| } | |||
| /****************** | |||
| @@ -145,6 +147,8 @@ void Display::showFrame(Status status) { | |||
| drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive); | |||
| drawDistanceValue(distanceValue); | |||
| drawDistanceUnit(distanceUnit); | |||
| drawActualDiveStep(maxDiveDistance, levelHeightDiving, distanceValue); | |||
| drawMaxDiveDistance(maxDiveDistance); | |||
| break; | |||
| default: | |||
| break; | |||
| @@ -204,6 +208,20 @@ void Display::setWlsConnected(bool wlsConnected) { | |||
| } | |||
| } | |||
| void Display::setLevelHeightDiving(float levelHeightDiving) { | |||
| if (this->levelHeightDiving != levelHeightDiving) { | |||
| this->levelHeightDiving = levelHeightDiving; | |||
| setRefreshScreen(); | |||
| } | |||
| } | |||
| void Display::setMaxDiveDistance(float maxDiveDistance) { | |||
| if (this->maxDiveDistance != maxDiveDistance) { | |||
| this->maxDiveDistance = maxDiveDistance; | |||
| setRefreshScreen(); | |||
| } | |||
| } | |||
| void Display::setDistanceUnit(const String &distanceUnit) { | |||
| if (this->distanceUnit != distanceUnit) { | |||
| this->distanceUnit = distanceUnit; | |||
| @@ -267,6 +285,28 @@ void Display::drawDistanceUnit(String unit) { | |||
| u8g2_gfx.println(F(s)); | |||
| } | |||
| void Display::drawMaxDiveDistance(float maxDiveDistance) { | |||
| String txt = String(maxDiveDistance, 2) + "mm"; | |||
| char *s = &txt[0]; | |||
| int16_t w = 0; | |||
| u8g2_gfx.setFont(u8g2_font_helvB10_tf); | |||
| w = u8g2_gfx.getUTF8Width(s); | |||
| u8g2_gfx.setCursor((SCREEN_WIDTH - w - 6), 59); | |||
| u8g2_gfx.println(F(s)); | |||
| } | |||
| void Display::drawActualDiveStep(float maxDiveDistance, float levelHeightDiving, float distance) { | |||
| int totalSteps = ceil(maxDiveDistance / levelHeightDiving); | |||
| int actualStep = ceil(distance / levelHeightDiving); | |||
| String txt = String(actualStep) + "/" + String(totalSteps); | |||
| char *s = &txt[0]; | |||
| int16_t w = 0; | |||
| u8g2_gfx.setFont(u8g2_font_helvB10_tf); | |||
| w = u8g2_gfx.getUTF8Width(s); | |||
| u8g2_gfx.setCursor(42, 59); | |||
| u8g2_gfx.println(F(s)); | |||
| } | |||
| /******************************** | |||
| ** Private methods | |||
| *******************************/ | |||
| @@ -40,6 +40,8 @@ class Display { | |||
| ValueMode mode; | |||
| float distanceValue; | |||
| String distanceUnit; | |||
| float maxDiveDistance; | |||
| float levelHeightDiving; | |||
| bool wlsConnected; | |||
| bool refreshScreen; | |||
| int angle; | |||
| @@ -64,6 +66,8 @@ class Display { | |||
| void drawMode(ValueMode mode); | |||
| void drawDistanceValue(float distance); | |||
| void drawDistanceUnit(String unit); | |||
| void drawMaxDiveDistance(float maxDiveDistance); | |||
| void drawActualDiveStep(float maxDiveDistance, float levelHeightDiving, float distance); | |||
| void setConfigOption(const String &configOption); | |||
| const String& getConfigOption() const; | |||
| void setConfigText(const String &configText); | |||
| @@ -73,6 +77,8 @@ class Display { | |||
| void setMode(const ValueMode &mode); | |||
| void setDistanceValue(const float &distanceValue); | |||
| void setDistanceUnit(const String &distanceUnit); | |||
| void setLevelHeightDiving(float levelHeightDiving); | |||
| void setMaxDiveDistance(float maxDiveDistance); | |||
| }; | |||
| #endif /* DISPLAY_H_ */ | |||
| @@ -192,6 +192,8 @@ void loop() { | |||
| SetActualStatus(MOVING_ELEVATOR); | |||
| intermediateState = 1; | |||
| } else if (intermediateState == 1) { | |||
| Router_Elevator.setZeroPosition(); | |||
| Router_Elevator.resetNullingDone(); | |||
| if (RotaryControler.isSwitchLongPressed()) { | |||
| SetActualStatus(CONFIGURATION); | |||
| intermediateState = 0; | |||
| @@ -287,10 +289,11 @@ void loop() { | |||
| Router_Elevator.setMaxDiveDistance(); | |||
| if (GreenButton.isPressed()) { | |||
| Serial.println("GB && BB pressing"); | |||
| bool maxDiveDistReached = Router_Elevator.incrementDiveDistance(); | |||
| //Router_Elevator.moveToTarget(); | |||
| SetActualStatus(MOVING_ELEVATOR); | |||
| if (maxDiveDistReached) { | |||
| if (!Router_Elevator.maxDiveDistanceReached()) { | |||
| Router_Elevator.incrementDiveDistance(); | |||
| Router_Elevator.moveToTarget(); | |||
| SetActualStatus(MOVING_ELEVATOR); | |||
| } else { | |||
| originStatus = IDLE; | |||
| Router_Elevator.setDoDiveInitialization(true); | |||
| Router_Elevator.moveToParkPosition(); | |||
| @@ -16,6 +16,7 @@ RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, Ro | |||
| targetDistance = 0.0; | |||
| maxDiveDistance = 0.0; | |||
| doDiveInitialization = true; | |||
| nullingDone = false; | |||
| } | |||
| void RouterElevator::setZeroPosition() { | |||
| @@ -23,6 +24,7 @@ void RouterElevator::setZeroPosition() { | |||
| Stepper.setCurrentPositionInMillimeters(0); | |||
| Stepper.setTargetPositionRelativeInMillimeters(0); | |||
| targetDistance = 0.0; | |||
| nullingDone = true; | |||
| setMode(FAST); | |||
| display.setDistanceValue(targetDistance); | |||
| } | |||
| @@ -61,7 +63,9 @@ void RouterElevator::moveToTarget(void) { | |||
| void RouterElevator::moveToParkPosition(void) { | |||
| float parkOffset = -5; //Router_Setup.getParkPostionOffset() * -1; | |||
| Stepper.setTargetPositionInMillimeters(parkOffset); | |||
| targetDistance = parkOffset; | |||
| Stepper.setTargetPositionInMillimeters(targetDistance); | |||
| display.setDistanceValue(targetDistance); | |||
| } | |||
| bool RouterElevator::isWLSTriggerd() { | |||
| @@ -111,7 +115,11 @@ void RouterElevator::onRotaryControlerTurn(RotaryEncoder::Direction turn) { | |||
| if (turn != RotaryEncoder::Direction::NOROTATION) { | |||
| int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1; | |||
| float increment = mode.isSlow() ? Router_Setup.getEncoderSpeedSlow() : Router_Setup.getEncoderSpeedFast(); | |||
| targetDistance = max(0.0f, targetDistance + increment / 100 * sign); | |||
| if (nullingDone) { | |||
| targetDistance = max(0.0f, targetDistance + increment / 100 * sign); | |||
| } else { | |||
| targetDistance = targetDistance + increment / 100 * sign; | |||
| } | |||
| display.setDistanceValue(targetDistance); | |||
| display.setDistanceUnit("mm"); | |||
| } | |||
| @@ -134,8 +142,10 @@ void RouterElevator::setMaxDiveDistance() { | |||
| Serial.println("setMaxDiveDistance"); | |||
| maxDiveDistance = targetDistance; | |||
| targetDistance = 0.0; | |||
| display.setDistanceValue(maxDiveDistance); | |||
| display.setDistanceValue(targetDistance); | |||
| display.setDistanceUnit("mm"); | |||
| display.setMaxDiveDistance(maxDiveDistance); | |||
| display.setLevelHeightDiving(Router_Setup.getLevelHeightDiving()); | |||
| display.setRefreshScreen(); | |||
| setDoDiveInitialization(false); | |||
| } | |||
| @@ -145,5 +155,17 @@ bool RouterElevator::incrementDiveDistance() { | |||
| float increment = Router_Setup.getLevelHeightDiving(); | |||
| targetDistance = min(maxDiveDistance, targetDistance + increment); | |||
| Serial.println("targetDistance: " + String(targetDistance, 2)); | |||
| display.setMaxDiveDistance(maxDiveDistance); | |||
| display.setDistanceValue(targetDistance); | |||
| display.setLevelHeightDiving(Router_Setup.getLevelHeightDiving()); | |||
| return targetDistance == maxDiveDistance; | |||
| } | |||
| bool RouterElevator::maxDiveDistanceReached() { | |||
| return targetDistance == maxDiveDistance; | |||
| } | |||
| void RouterElevator::resetNullingDone() { | |||
| this->nullingDone = false; | |||
| } | |||
| @@ -32,11 +32,12 @@ class RouterElevator { | |||
| float maxDiveDistance; | |||
| ValueMode mode; | |||
| bool doDiveInitialization; | |||
| bool nullingDone; | |||
| public: | |||
| RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | |||
| WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR); | |||
| void setZeroPosition(void); | |||
| void setZeroPosition(); | |||
| void moveRelativeInMillimeters(float distanceInMillimeters); | |||
| void moveToLowerLimitSwitch(void); | |||
| void moveToUpperLimitSwitch(void); | |||
| @@ -58,6 +59,8 @@ class RouterElevator { | |||
| float getMaxDiveDistance() const; | |||
| void setMaxDiveDistance(); | |||
| bool incrementDiveDistance(); | |||
| bool maxDiveDistanceReached(); | |||
| void resetNullingDone(); | |||
| }; | |||
| @@ -2,7 +2,7 @@ | |||
| //This is a automatic generated file | |||
| //Please do not modify this file | |||
| //If you touch this file your change will be overwritten during the next build | |||
| //This file has been generated on 2022-02-26 22:19:46 | |||
| //This file has been generated on 2022-02-27 18:38:05 | |||
| #include "Arduino.h" | |||
| #include <Arduino.h> | |||