| switch (status) { | switch (status) { | ||||
| case MOVING_ELEVATOR: | case MOVING_ELEVATOR: | ||||
| rotateAndDrawRotationBitmap(); | rotateAndDrawRotationBitmap(); | ||||
| drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive); | |||||
| break; | break; | ||||
| case TOOL_CHANGE: | case TOOL_CHANGE: | ||||
| redrawFrame(); | redrawFrame(); | ||||
| drawStatusText(STATUS_TXT_NULLING); | drawStatusText(STATUS_TXT_NULLING); | ||||
| drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling); | drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling); | ||||
| break; | break; | ||||
| case DIVING: | |||||
| redrawFrame(); | |||||
| drawStatusText(STATUS_TXT_DIVING); | |||||
| drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive); | |||||
| drawDistanceValue(distanceValue); | |||||
| drawDistanceUnit(distanceUnit); | |||||
| break; | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| String txt = mode.toString(); | String txt = mode.toString(); | ||||
| char *s = &txt[0]; | char *s = &txt[0]; | ||||
| int16_t w = 0; | int16_t w = 0; | ||||
| u8g2_gfx.setFont(u8g2_font_helvB10_tf); | |||||
| u8g2_gfx.setFont(u8g2_font_helvB08_tf); | |||||
| w = u8g2_gfx.getUTF8Width(s); | w = u8g2_gfx.getUTF8Width(s); | ||||
| u8g2_gfx.setCursor((SCREEN_WIDTH - w - 6), 63 - 4); | |||||
| u8g2_gfx.setCursor((SCREEN_WIDTH - w - 6), 63 - 6); | |||||
| u8g2_gfx.println(F(s)); | u8g2_gfx.println(F(s)); | ||||
| } | } | ||||
| #define STATUS_TXT_TOOLCHG "WZW" | #define STATUS_TXT_TOOLCHG "WZW" | ||||
| #define STATUS_TXT_CFG "SETUP" | #define STATUS_TXT_CFG "SETUP" | ||||
| #define STATUS_TXT_NULLING "NULL" | #define STATUS_TXT_NULLING "NULL" | ||||
| #define STATUS_TXT_DIVING "EINT" | |||||
| class Display { | class Display { | ||||
| private: | private: |
| } else if (BlueButton.isLongPressed()) { | } else if (BlueButton.isLongPressed()) { | ||||
| SetActualStatus(TOOL_CHANGE); | SetActualStatus(TOOL_CHANGE); | ||||
| } else if (GreenButton.isLongPressed()) { | } else if (GreenButton.isLongPressed()) { | ||||
| SetActualStatus(DIVING); | |||||
| } else if (GreenButton.isPressed()) { | } else if (GreenButton.isPressed()) { | ||||
| Router_Elevator.moveToTarget(); | Router_Elevator.moveToTarget(); | ||||
| SetActualStatus(MOVING_ELEVATOR); | SetActualStatus(MOVING_ELEVATOR); | ||||
| case DIVING: | case DIVING: | ||||
| printStatus("DIVING"); | printStatus("DIVING"); | ||||
| originStatus = DIVING; | originStatus = DIVING; | ||||
| Router_Elevator.setMaxDiveDistance(); | |||||
| if (GreenButton.isPressed()) { | |||||
| Serial.println("GB && BB pressing"); | |||||
| bool maxDiveDistReached = Router_Elevator.incrementDiveDistance(); | |||||
| //Router_Elevator.moveToTarget(); | |||||
| SetActualStatus(MOVING_ELEVATOR); | |||||
| if (maxDiveDistReached) { | |||||
| originStatus = IDLE; | |||||
| Router_Elevator.setDoDiveInitialization(true); | |||||
| Router_Elevator.moveToParkPosition(); | |||||
| SetActualStatus(MOVING_ELEVATOR); | |||||
| } | |||||
| } else if (GreenButton.isLongPressed()) { | |||||
| originStatus = IDLE; | |||||
| Router_Elevator.setDoDiveInitialization(true); | |||||
| Router_Elevator.moveToParkPosition(); | |||||
| SetActualStatus(MOVING_ELEVATOR); | |||||
| } | |||||
| break; | break; | ||||
| case MOVING_ELEVATOR: | case MOVING_ELEVATOR: |
| LimitSwitch = _LimitSwitch; | LimitSwitch = _LimitSwitch; | ||||
| DOWNWARD_DIR = _DOWNWARD_DIR; | DOWNWARD_DIR = _DOWNWARD_DIR; | ||||
| UPWARD_DIR = -DOWNWARD_DIR; | UPWARD_DIR = -DOWNWARD_DIR; | ||||
| targetDistance = 0; | |||||
| targetDistance = 0.0; | |||||
| maxDiveDistance = 0.0; | |||||
| doDiveInitialization = true; | |||||
| } | } | ||||
| void RouterElevator::setZeroPosition() { | void RouterElevator::setZeroPosition() { | ||||
| targetDistance = max(0.0f, targetDistance + increment / 100 * sign); | targetDistance = max(0.0f, targetDistance + increment / 100 * sign); | ||||
| display.setDistanceValue(targetDistance); | display.setDistanceValue(targetDistance); | ||||
| display.setDistanceUnit("mm"); | display.setDistanceUnit("mm"); | ||||
| } | |||||
| } | |||||
| bool RouterElevator::isDoDiveInitialization() const { | |||||
| return doDiveInitialization; | |||||
| } | |||||
| void RouterElevator::setDoDiveInitialization(bool doDiveInitialization) { | |||||
| this->doDiveInitialization = doDiveInitialization; | |||||
| } | |||||
| float RouterElevator::getMaxDiveDistance() const { | |||||
| return maxDiveDistance; | |||||
| } | |||||
| void RouterElevator::setMaxDiveDistance() { | |||||
| if (isDoDiveInitialization()) { | |||||
| Serial.println("setMaxDiveDistance"); | |||||
| maxDiveDistance = targetDistance; | |||||
| targetDistance = 0.0; | |||||
| display.setDistanceValue(maxDiveDistance); | |||||
| display.setDistanceUnit("mm"); | |||||
| display.setRefreshScreen(); | display.setRefreshScreen(); | ||||
| setDoDiveInitialization(false); | |||||
| } | } | ||||
| } | } | ||||
| bool RouterElevator::incrementDiveDistance() { | |||||
| float increment = Router_Setup.getLevelHeightDiving(); | |||||
| targetDistance = min(maxDiveDistance, targetDistance + increment); | |||||
| Serial.println("targetDistance: " + String(targetDistance, 2)); | |||||
| return targetDistance == maxDiveDistance; | |||||
| } |
| int DOWNWARD_DIR; | int DOWNWARD_DIR; | ||||
| int UPWARD_DIR; | int UPWARD_DIR; | ||||
| float targetDistance; | float targetDistance; | ||||
| float maxDiveDistance; | |||||
| ValueMode mode; | ValueMode mode; | ||||
| bool doDiveInitialization; | |||||
| public: | public: | ||||
| RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | ||||
| void setMode(ValueMode mode); | void setMode(ValueMode mode); | ||||
| void toggleMode(); | void toggleMode(); | ||||
| void onRotaryControlerTurn(RotaryEncoder::Direction turn); | void onRotaryControlerTurn(RotaryEncoder::Direction turn); | ||||
| bool isDoDiveInitialization() const; | |||||
| void setDoDiveInitialization(bool doDiveInitialization); | |||||
| float getMaxDiveDistance() const; | |||||
| void setMaxDiveDistance(); | |||||
| bool incrementDiveDistance(); | |||||
| }; | }; | ||||
| //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-25 22:27:34 | |||||
| //This file has been generated on 2022-02-26 22:19:46 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <Arduino.h> | #include <Arduino.h> |