| angle = 0; | angle = 0; | ||||
| starttime = millis(); | starttime = millis(); | ||||
| refreshScreen = true; | refreshScreen = true; | ||||
| distanceValue = 0; | |||||
| distanceValue = 0.0; | |||||
| distanceUnit = "mm"; | distanceUnit = "mm"; | ||||
| maxDiveDistance = 0.0; | |||||
| levelHeightDiving = 0.0; | |||||
| } | } | ||||
| /****************** | /****************** | ||||
| drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive); | drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive); | ||||
| drawDistanceValue(distanceValue); | drawDistanceValue(distanceValue); | ||||
| drawDistanceUnit(distanceUnit); | drawDistanceUnit(distanceUnit); | ||||
| drawActualDiveStep(maxDiveDistance, levelHeightDiving, distanceValue); | |||||
| drawMaxDiveDistance(maxDiveDistance); | |||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| 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) { | void Display::setDistanceUnit(const String &distanceUnit) { | ||||
| if (this->distanceUnit != distanceUnit) { | if (this->distanceUnit != distanceUnit) { | ||||
| this->distanceUnit = distanceUnit; | this->distanceUnit = distanceUnit; | ||||
| u8g2_gfx.println(F(s)); | 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 | ** Private methods | ||||
| *******************************/ | *******************************/ |
| ValueMode mode; | ValueMode mode; | ||||
| float distanceValue; | float distanceValue; | ||||
| String distanceUnit; | String distanceUnit; | ||||
| float maxDiveDistance; | |||||
| float levelHeightDiving; | |||||
| bool wlsConnected; | bool wlsConnected; | ||||
| bool refreshScreen; | bool refreshScreen; | ||||
| int angle; | int angle; | ||||
| void drawMode(ValueMode mode); | void drawMode(ValueMode mode); | ||||
| void drawDistanceValue(float distance); | void drawDistanceValue(float distance); | ||||
| void drawDistanceUnit(String unit); | void drawDistanceUnit(String unit); | ||||
| void drawMaxDiveDistance(float maxDiveDistance); | |||||
| void drawActualDiveStep(float maxDiveDistance, float levelHeightDiving, float distance); | |||||
| void setConfigOption(const String &configOption); | void setConfigOption(const String &configOption); | ||||
| const String& getConfigOption() const; | const String& getConfigOption() const; | ||||
| void setConfigText(const String &configText); | void setConfigText(const String &configText); | ||||
| void setMode(const ValueMode &mode); | void setMode(const ValueMode &mode); | ||||
| void setDistanceValue(const float &distanceValue); | void setDistanceValue(const float &distanceValue); | ||||
| void setDistanceUnit(const String &distanceUnit); | void setDistanceUnit(const String &distanceUnit); | ||||
| void setLevelHeightDiving(float levelHeightDiving); | |||||
| void setMaxDiveDistance(float maxDiveDistance); | |||||
| }; | }; | ||||
| #endif /* DISPLAY_H_ */ | #endif /* DISPLAY_H_ */ |
| SetActualStatus(MOVING_ELEVATOR); | SetActualStatus(MOVING_ELEVATOR); | ||||
| intermediateState = 1; | intermediateState = 1; | ||||
| } else if (intermediateState == 1) { | } else if (intermediateState == 1) { | ||||
| Router_Elevator.setZeroPosition(); | |||||
| Router_Elevator.resetNullingDone(); | |||||
| if (RotaryControler.isSwitchLongPressed()) { | if (RotaryControler.isSwitchLongPressed()) { | ||||
| SetActualStatus(CONFIGURATION); | SetActualStatus(CONFIGURATION); | ||||
| intermediateState = 0; | intermediateState = 0; | ||||
| Router_Elevator.setMaxDiveDistance(); | Router_Elevator.setMaxDiveDistance(); | ||||
| if (GreenButton.isPressed()) { | if (GreenButton.isPressed()) { | ||||
| Serial.println("GB && BB pressing"); | 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; | originStatus = IDLE; | ||||
| Router_Elevator.setDoDiveInitialization(true); | Router_Elevator.setDoDiveInitialization(true); | ||||
| Router_Elevator.moveToParkPosition(); | Router_Elevator.moveToParkPosition(); |
| targetDistance = 0.0; | targetDistance = 0.0; | ||||
| maxDiveDistance = 0.0; | maxDiveDistance = 0.0; | ||||
| doDiveInitialization = true; | doDiveInitialization = true; | ||||
| nullingDone = false; | |||||
| } | } | ||||
| void RouterElevator::setZeroPosition() { | void RouterElevator::setZeroPosition() { | ||||
| Stepper.setCurrentPositionInMillimeters(0); | Stepper.setCurrentPositionInMillimeters(0); | ||||
| Stepper.setTargetPositionRelativeInMillimeters(0); | Stepper.setTargetPositionRelativeInMillimeters(0); | ||||
| targetDistance = 0.0; | targetDistance = 0.0; | ||||
| nullingDone = true; | |||||
| setMode(FAST); | setMode(FAST); | ||||
| display.setDistanceValue(targetDistance); | display.setDistanceValue(targetDistance); | ||||
| } | } | ||||
| void RouterElevator::moveToParkPosition(void) { | void RouterElevator::moveToParkPosition(void) { | ||||
| float parkOffset = -5; //Router_Setup.getParkPostionOffset() * -1; | float parkOffset = -5; //Router_Setup.getParkPostionOffset() * -1; | ||||
| Stepper.setTargetPositionInMillimeters(parkOffset); | |||||
| targetDistance = parkOffset; | |||||
| Stepper.setTargetPositionInMillimeters(targetDistance); | |||||
| display.setDistanceValue(targetDistance); | |||||
| } | } | ||||
| bool RouterElevator::isWLSTriggerd() { | bool RouterElevator::isWLSTriggerd() { | ||||
| if (turn != RotaryEncoder::Direction::NOROTATION) { | if (turn != RotaryEncoder::Direction::NOROTATION) { | ||||
| int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1; | int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1; | ||||
| float increment = mode.isSlow() ? Router_Setup.getEncoderSpeedSlow() : Router_Setup.getEncoderSpeedFast(); | 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.setDistanceValue(targetDistance); | ||||
| display.setDistanceUnit("mm"); | display.setDistanceUnit("mm"); | ||||
| } | } | ||||
| Serial.println("setMaxDiveDistance"); | Serial.println("setMaxDiveDistance"); | ||||
| maxDiveDistance = targetDistance; | maxDiveDistance = targetDistance; | ||||
| targetDistance = 0.0; | targetDistance = 0.0; | ||||
| display.setDistanceValue(maxDiveDistance); | |||||
| display.setDistanceValue(targetDistance); | |||||
| display.setDistanceUnit("mm"); | display.setDistanceUnit("mm"); | ||||
| display.setMaxDiveDistance(maxDiveDistance); | |||||
| display.setLevelHeightDiving(Router_Setup.getLevelHeightDiving()); | |||||
| display.setRefreshScreen(); | display.setRefreshScreen(); | ||||
| setDoDiveInitialization(false); | setDoDiveInitialization(false); | ||||
| } | } | ||||
| float increment = Router_Setup.getLevelHeightDiving(); | float increment = Router_Setup.getLevelHeightDiving(); | ||||
| targetDistance = min(maxDiveDistance, targetDistance + increment); | targetDistance = min(maxDiveDistance, targetDistance + increment); | ||||
| Serial.println("targetDistance: " + String(targetDistance, 2)); | Serial.println("targetDistance: " + String(targetDistance, 2)); | ||||
| display.setMaxDiveDistance(maxDiveDistance); | |||||
| display.setDistanceValue(targetDistance); | |||||
| display.setLevelHeightDiving(Router_Setup.getLevelHeightDiving()); | |||||
| return targetDistance == maxDiveDistance; | return targetDistance == maxDiveDistance; | ||||
| } | } | ||||
| bool RouterElevator::maxDiveDistanceReached() { | |||||
| return targetDistance == maxDiveDistance; | |||||
| } | |||||
| void RouterElevator::resetNullingDone() { | |||||
| this->nullingDone = false; | |||||
| } |
| float maxDiveDistance; | float maxDiveDistance; | ||||
| ValueMode mode; | ValueMode mode; | ||||
| bool doDiveInitialization; | bool doDiveInitialization; | ||||
| bool nullingDone; | |||||
| public: | public: | ||||
| RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | ||||
| WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR); | WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR); | ||||
| void setZeroPosition(void); | |||||
| void setZeroPosition(); | |||||
| void moveRelativeInMillimeters(float distanceInMillimeters); | void moveRelativeInMillimeters(float distanceInMillimeters); | ||||
| void moveToLowerLimitSwitch(void); | void moveToLowerLimitSwitch(void); | ||||
| void moveToUpperLimitSwitch(void); | void moveToUpperLimitSwitch(void); | ||||
| float getMaxDiveDistance() const; | float getMaxDiveDistance() const; | ||||
| void setMaxDiveDistance(); | void setMaxDiveDistance(); | ||||
| bool incrementDiveDistance(); | bool incrementDiveDistance(); | ||||
| bool maxDiveDistanceReached(); | |||||
| void resetNullingDone(); | |||||
| }; | }; | ||||
| //This is a automatic generated file | //This is a automatic generated file | ||||
| //Please do not modify this file | //Please do not modify this file | ||||
| //If you touch this file your change will be overwritten during the next build | //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" | ||||
| #include <Arduino.h> | #include <Arduino.h> |