| #include "Display.h" | #include "Display.h" | ||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 48) | |||||
| const int epd_rotate_bitmap_allArray_LEN = 8; | |||||
| const static unsigned char *epd_rotate_bitmap_allArray[epd_rotate_bitmap_allArray_LEN] = { | |||||
| epd_bitmap_Rotate_0, | |||||
| epd_bitmap_Rotate_45, | |||||
| epd_bitmap_Rotate_90, | |||||
| epd_bitmap_Rotate_135, | |||||
| epd_bitmap_Rotate_180, | |||||
| epd_bitmap_Rotate_225, | |||||
| epd_bitmap_Rotate_270, | |||||
| epd_bitmap_Rotate_315 | |||||
| }; | |||||
| /***************** | /***************** | ||||
| ** Constructors. | ** Constructors. | ||||
| ****************/ | ****************/ | ||||
| Display::Display() { | |||||
| Display::Display() : mode(SLOW) { | |||||
| ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); | ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); | ||||
| u8g2_gfx.begin(ssd1306); | u8g2_gfx.begin(ssd1306); | ||||
| wlsConnected = false; | wlsConnected = false; | ||||
| angle = 0; | angle = 0; | ||||
| starttime = millis(); | starttime = millis(); | ||||
| refreshScreen = true; | refreshScreen = true; | ||||
| distanceValue = 0; | |||||
| } | } | ||||
| /****************** | /****************** | ||||
| } | } | ||||
| } | } | ||||
| void Display::setRefreshScreen() { | |||||
| refreshScreen = true; | |||||
| } | |||||
| void Display::display() { | void Display::display() { | ||||
| if (refreshScreen) { | if (refreshScreen) { | ||||
| refreshScreen = false; | refreshScreen = false; | ||||
| redrawFrame(); | redrawFrame(); | ||||
| ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE); | ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE); | ||||
| drawStatusText(STATUS_TXT_IDLE); | drawStatusText(STATUS_TXT_IDLE); | ||||
| drawMode(this->mode); | |||||
| break; | break; | ||||
| case NULLING: | case NULLING: | ||||
| case NULLING_TLS: | case NULLING_TLS: | ||||
| } | } | ||||
| } | } | ||||
| void Display::setDistanceUnit(const String &distanceUnit) { | |||||
| if (this->distanceUnit != distanceUnit) { | |||||
| this->distanceUnit = distanceUnit; | |||||
| setRefreshScreen(); | |||||
| } | |||||
| } | |||||
| void Display::setDistanceValue(const float &distanceValue) { | |||||
| if (this->distanceValue != distanceValue) { | |||||
| this->distanceValue = distanceValue; | |||||
| setRefreshScreen(); | |||||
| } | |||||
| } | |||||
| void Display::setMode(const ValueMode &mode) { | |||||
| if (!this->mode.equals(mode)) { | |||||
| Serial.println("Equal: " + this->mode.toString()); | |||||
| this->mode = mode; | |||||
| setRefreshScreen(); | |||||
| } | |||||
| } | |||||
| void Display::drawWLSStatus() { | void Display::drawWLSStatus() { | ||||
| String txt = wlsConnected ? "WLS" : ""; | String txt = wlsConnected ? "WLS" : ""; | ||||
| char *s = &txt[0]; | char *s = &txt[0]; | ||||
| u8g2_gfx.println(F(s)); | u8g2_gfx.println(F(s)); | ||||
| } | } | ||||
| void Display::drawMode(ValueMode mode) { | |||||
| String txt = mode.toString(); | |||||
| 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), 63 - 4); | |||||
| u8g2_gfx.println(F(s)); | |||||
| } | |||||
| void Display::drawDistanceValue(float distance) { | |||||
| } | |||||
| void Display::drawDistanceUnit(String unit) { | |||||
| } | |||||
| /******************************** | /******************************** | ||||
| ** Private methods | ** Private methods | ||||
| *******************************/ | *******************************/ | ||||
| display(); | display(); | ||||
| } | } | ||||
| } | } | ||||
| void Display::setRefreshScreen() { | |||||
| refreshScreen = true; | |||||
| } |
| #include "images/RotateBitmap.h" | #include "images/RotateBitmap.h" | ||||
| #include "images/DiveBitmap.h" | #include "images/DiveBitmap.h" | ||||
| #include "Status.h" | #include "Status.h" | ||||
| #include "ValueMode.h" | |||||
| #define SCREEN_WIDTH 128 | #define SCREEN_WIDTH 128 | ||||
| #define SCREEN_HEIGHT 64 | #define SCREEN_HEIGHT 64 | ||||
| U8G2_FOR_ADAFRUIT_GFX u8g2_gfx; | U8G2_FOR_ADAFRUIT_GFX u8g2_gfx; | ||||
| String configText; | String configText; | ||||
| String configOption; | String configOption; | ||||
| ValueMode mode; | |||||
| float distanceValue; | |||||
| String distanceUnit; | |||||
| bool wlsConnected; | bool wlsConnected; | ||||
| bool refreshScreen; | bool refreshScreen; | ||||
| int angle; | int angle; | ||||
| void showFrame(Status status); | void showFrame(Status status); | ||||
| void drawConfigText(String txt); | void drawConfigText(String txt); | ||||
| void drawConfigOption(String txt); | void drawConfigOption(String txt); | ||||
| const String& getConfigOption() const; | |||||
| void drawMode(ValueMode mode); | |||||
| void drawDistanceValue(float distance); | |||||
| void drawDistanceUnit(String unit); | |||||
| void setConfigOption(const String &configOption); | void setConfigOption(const String &configOption); | ||||
| const String& getConfigText() const; | |||||
| const String& getConfigOption() const; | |||||
| void setConfigText(const String &configText); | void setConfigText(const String &configText); | ||||
| const String& getConfigText() const; | |||||
| void setWlsConnected(bool wlsConnected); | void setWlsConnected(bool wlsConnected); | ||||
| void setRefreshScreen(); | void setRefreshScreen(); | ||||
| void setMode(const ValueMode &mode); | |||||
| void setDistanceValue(const float &distanceValue); | |||||
| void setDistanceUnit(const String &distanceUnit); | |||||
| }; | }; | ||||
| #endif /* DISPLAY_H_ */ | #endif /* DISPLAY_H_ */ |
| Display Display; | Display Display; | ||||
| ESP_FlexyStepper Stepper; | ESP_FlexyStepper Stepper; | ||||
| RouterSetup Router_Setup(Display); | RouterSetup Router_Setup(Display); | ||||
| RouterElevator Router_Elevator(Stepper, Display, WlsDetect, Wls, LIMIT_SWITCH, MOVE_DOWNWARD); // @suppress("Ambiguous problem") | |||||
| RouterElevator Router_Elevator(Stepper, Display, Router_Setup, WlsDetect, Wls, LIMIT_SWITCH, MOVE_DOWNWARD); | |||||
| Status actualStatus; | Status actualStatus; | ||||
| Status originStatus; | Status originStatus; | ||||
| case IDLE: | case IDLE: | ||||
| printStatus("IDLE"); | printStatus("IDLE"); | ||||
| if (RotaryControler.isSwitchPressed()) { | |||||
| Serial.println("RotaryControler.isSwitchPressed"); | |||||
| Router_Elevator.toggleMode(); | |||||
| } | |||||
| Router_Elevator.onRotaryControlerTurn(RotaryControler.getEncoderMove()); | |||||
| if (RedButton.isLongPressed()) { | if (RedButton.isLongPressed()) { | ||||
| if (WlsDetect.isConnected()) { | if (WlsDetect.isConnected()) { | ||||
| SetActualStatus(NULLING_TLS); | SetActualStatus(NULLING_TLS); |
| #include "RouterElevator.h" | #include "RouterElevator.h" | ||||
| RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR) : | |||||
| Stepper(_Stepper), display(_display), WlsDetect(_WlsDetect), Wls(_Wls) { | |||||
| RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | |||||
| WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR) | |||||
| : Stepper(_Stepper), display(_display), Router_Setup(_Router_Setup), WlsDetect(_WlsDetect), Wls(_Wls), mode(SLOW) { | |||||
| LimitSwitch = _LimitSwitch; | LimitSwitch = _LimitSwitch; | ||||
| DOWNWARD_DIR = _DOWNWARD_DIR; | DOWNWARD_DIR = _DOWNWARD_DIR; | ||||
| UPWARD_DIR = -DOWNWARD_DIR; | UPWARD_DIR = -DOWNWARD_DIR; | ||||
| targetDistance = 0; | |||||
| } | } | ||||
| void RouterElevator::setZeroPosition() { | void RouterElevator::setZeroPosition() { | ||||
| Stepper.setCurrentPositionAsHomeAndStop(); | |||||
| Stepper.setCurrentPositionInMillimeters(0); | Stepper.setCurrentPositionInMillimeters(0); | ||||
| Stepper.setTargetPositionRelativeInMillimeters(0); | Stepper.setTargetPositionRelativeInMillimeters(0); | ||||
| } | } | ||||
| void RouterElevator::moveRelativeInMillimeters(float distanceInMillimeters) { | void RouterElevator::moveRelativeInMillimeters(float distanceInMillimeters) { | ||||
| Stepper.setTargetPositionInMillimeters(distanceInMillimeters); | |||||
| Stepper.setTargetPositionRelativeInMillimeters(distanceInMillimeters); | |||||
| } | } | ||||
| void RouterElevator::moveToLowerLimitSwitch(void) { | void RouterElevator::moveToLowerLimitSwitch(void) { | ||||
| return Stepper.getDistanceToTargetSigned() == 0; | return Stepper.getDistanceToTargetSigned() == 0; | ||||
| } | } | ||||
| void RouterElevator::moveToTarget(void) { | |||||
| Stepper.moveToPositionInMillimeters(targetDistance); | |||||
| } | |||||
| void RouterElevator::moveToParkPosition(void) { | |||||
| float parkOffset = -5; //Router_Setup.getParkPostionOffset() * -1; | |||||
| Stepper.moveToPositionInMillimeters(parkOffset); | |||||
| } | |||||
| bool RouterElevator::isWLSTriggerd() { | bool RouterElevator::isWLSTriggerd() { | ||||
| if (WlsDetect.isConnected()) { | if (WlsDetect.isConnected()) { | ||||
| if (Wls.isPlugged()) { | if (Wls.isPlugged()) { | ||||
| previousDirection = Stepper.getDirectionOfMotion(); | previousDirection = Stepper.getDirectionOfMotion(); | ||||
| } | } | ||||
| ValueMode RouterElevator::getMode() const { | |||||
| return mode; | |||||
| } | |||||
| void RouterElevator::setMode(ValueMode mode) { | |||||
| this->mode = mode; | |||||
| Serial.println("RouterElevator::setMode: " + this->mode.toString()); | |||||
| display.setMode(this->mode); | |||||
| } | |||||
| void RouterElevator::toggleMode() { | |||||
| setMode((mode.getValueMode() == SLOW) ? ValueMode(FAST) : ValueMode(SLOW)); | |||||
| } | |||||
| void RouterElevator::onRotaryControlerTurn(RotaryEncoder::Direction turn) { | |||||
| // if (turn != RotaryEncoder::Direction::NOROTATION) { | |||||
| // int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1; | |||||
| // //TODO: Update the targetDistance and show it on display | |||||
| // } | |||||
| } |
| #include "Display.h" | #include "Display.h" | ||||
| #include "WLS.h" | #include "WLS.h" | ||||
| #include "RouterSetup.h" | |||||
| #include "ValueMode.h" | |||||
| class RouterElevator { | class RouterElevator { | ||||
| private: | private: | ||||
| ESP_FlexyStepper &Stepper; | ESP_FlexyStepper &Stepper; | ||||
| Display &display; | Display &display; | ||||
| RouterSetup &Router_Setup; | |||||
| int previousDirection = 0; | int previousDirection = 0; | ||||
| byte limitSwitchState = 1; | byte limitSwitchState = 1; | ||||
| int LimitSwitch; | int LimitSwitch; | ||||
| WLS &WlsDetect, &Wls; | WLS &WlsDetect, &Wls; | ||||
| int DOWNWARD_DIR; | int DOWNWARD_DIR; | ||||
| int UPWARD_DIR; | int UPWARD_DIR; | ||||
| float targetDistance; | |||||
| ValueMode mode; | |||||
| public: | public: | ||||
| RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR); | |||||
| RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, RouterSetup &_Router_Setup, | |||||
| WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR); | |||||
| void setZeroPosition(void); | void setZeroPosition(void); | ||||
| void moveRelativeInMillimeters(float distanceInMillimeters); | void moveRelativeInMillimeters(float distanceInMillimeters); | ||||
| void moveToLowerLimitSwitch(void); | void moveToLowerLimitSwitch(void); | ||||
| void moveToUpperLimitSwitch(void); | void moveToUpperLimitSwitch(void); | ||||
| void moveToTarget(void); | |||||
| void moveToParkPosition(void); | |||||
| void clearLimitSwitch(void); | void clearLimitSwitch(void); | ||||
| void tryReleaseLimitSwitch(void); | void tryReleaseLimitSwitch(void); | ||||
| bool isLimitSwitchTriggerd(void); | bool isLimitSwitchTriggerd(void); | ||||
| bool isTargetPositionReached(void); | bool isTargetPositionReached(void); | ||||
| void limitSwitchHandler(void); | void limitSwitchHandler(void); | ||||
| void checkDirection(void); | void checkDirection(void); | ||||
| ValueMode getMode() const; | |||||
| void setMode(ValueMode mode); | |||||
| void toggleMode(); | |||||
| void onRotaryControlerTurn(RotaryEncoder::Direction turn); | |||||
| }; | }; | ||||
| /* | |||||
| * ValueMode.cpp | |||||
| * | |||||
| * Created on: 23.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #include "ValueMode.h" | |||||
| static const char *mode_str[] = { "SLOW", "FAST" }; | |||||
| ValueMode::ValueMode(Mode mode) { | |||||
| this->valueMode = mode; | |||||
| } | |||||
| Mode ValueMode::getValueMode() const { | |||||
| return valueMode; | |||||
| } | |||||
| void ValueMode::setValueMode(Mode valueMode) | |||||
| { | |||||
| this->valueMode = valueMode; | |||||
| } | |||||
| String ValueMode::toString() { | |||||
| String tmp(mode_str[this->valueMode]); | |||||
| return tmp; | |||||
| } | |||||
| bool ValueMode::equals(ValueMode valueMode) { | |||||
| return this->valueMode == valueMode.getValueMode(); | |||||
| } |
| /* | |||||
| * ValueMode.h | |||||
| * | |||||
| * Created on: 23.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef VALUEMODE_H_ | |||||
| #define VALUEMODE_H_ | |||||
| #include <stdint.h> | |||||
| #include <WString.h> | |||||
| enum Mode { | |||||
| SLOW, FAST | |||||
| }; | |||||
| class ValueMode { | |||||
| private: | |||||
| Mode valueMode; | |||||
| public: | |||||
| ValueMode(Mode mode); | |||||
| String toString(); | |||||
| Mode getValueMode() const; | |||||
| void setValueMode(Mode valueMode); | |||||
| bool equals(ValueMode valueMode); | |||||
| }; | |||||
| #endif /* VALUEMODE_H_ */ |
| 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x07, 0xc0 | 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x07, 0xc0 | ||||
| }; | }; | ||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 48) | |||||
| const int epd_rotate_bitmap_allArray_LEN = 8; | |||||
| const static unsigned char *epd_rotate_bitmap_allArray[epd_rotate_bitmap_allArray_LEN] = { | |||||
| epd_bitmap_Rotate_0, | |||||
| epd_bitmap_Rotate_45, | |||||
| epd_bitmap_Rotate_90, | |||||
| epd_bitmap_Rotate_135, | |||||
| epd_bitmap_Rotate_180, | |||||
| epd_bitmap_Rotate_225, | |||||
| epd_bitmap_Rotate_270, | |||||
| epd_bitmap_Rotate_315 | |||||
| }; | |||||
| #endif /* IMAGES_ROTATEBITMAP_H_ */ | #endif /* IMAGES_ROTATEBITMAP_H_ */ | ||||
| //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-21 23:07:49 | |||||
| //This file has been generated on 2022-02-23 22:58:18 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <Arduino.h> | #include <Arduino.h> |