| Display::Display() { | Display::Display() { | ||||
| ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); | ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); | ||||
| u8g2_gfx.begin(ssd1306); | u8g2_gfx.begin(ssd1306); | ||||
| wlsConnected = false; | |||||
| } | } | ||||
| /****************** | /****************** | ||||
| void Display::showBrand() { | void Display::showBrand() { | ||||
| ssd1306.clearDisplay(); | ssd1306.clearDisplay(); | ||||
| ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, 128, 34, SSD1306_WHITE); | |||||
| ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, imageWidth, imageHeight, SSD1306_WHITE); | |||||
| char *s = &String("Frästisch N172")[0]; | char *s = &String("Frästisch N172")[0]; | ||||
| int16_t w = 0, h = 0; | int16_t w = 0, h = 0; | ||||
| void Display::showFrame(Status status) { | void Display::showFrame(Status status) { | ||||
| ssd1306.clearDisplay(); | |||||
| ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE); | |||||
| ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE); | |||||
| ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE); | |||||
| switch (status) { | switch (status) { | ||||
| case MOVING_ELEVATOR: | |||||
| drawBitmap((37 - imageSide_R) / 2, 30, imageSide_R, imageSide_R, epd_bitmap_Rotate); | |||||
| drawBitmap((37 - imageSide_R) / 2, 47, imageSide_R, imageSide_R, epd_bitmap_Dive); | |||||
| break; | |||||
| case TOOL_CHANGE: | case TOOL_CHANGE: | ||||
| redrawFrame(); | |||||
| drawStatusText(STATUS_TXT_TOOLCHG); | drawStatusText(STATUS_TXT_TOOLCHG); | ||||
| drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Tools); | |||||
| break; | break; | ||||
| case CONFIGURATION: | case CONFIGURATION: | ||||
| redrawFrame(); | |||||
| ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE); | ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE); | ||||
| drawStatusText (STATUS_TXT_CFG); | drawStatusText (STATUS_TXT_CFG); | ||||
| drawConfigText("Höhe WLS"); | |||||
| drawConfigOption("03.00 mm"); | |||||
| drawConfigText(this->configText); | |||||
| drawConfigOption(this->configOption); | |||||
| break; | break; | ||||
| case IDLE: | case IDLE: | ||||
| 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); | ||||
| break; | break; | ||||
| case NULLING: | |||||
| case NULLING_TLS: | |||||
| redrawFrame(); | |||||
| drawStatusText(STATUS_TXT_NULLING); | |||||
| drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling); | |||||
| break; | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| display(); | display(); | ||||
| } | } | ||||
| /******************************** | |||||
| ** Private methods | |||||
| *******************************/ | |||||
| void Display::calculateWH(String units, uint16_t &w, uint16_t &h) { | |||||
| int x = 0; | |||||
| int y = 0; | |||||
| int16_t x1, y1; | |||||
| uint16_t w1, h1; | |||||
| ssd1306.getTextBounds(units, x, y, &x1, &y1, &w1, &h1); | |||||
| w = w1; | |||||
| h = h1; | |||||
| } | |||||
| void Display::drawStatusText(String txt) { | |||||
| char *s = &txt[0]; | |||||
| int16_t w = 0; | |||||
| u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | |||||
| w = u8g2_gfx.getUTF8Width(s); | |||||
| u8g2_gfx.setCursor((37 - w) / 2, 12); | |||||
| u8g2_gfx.println(F(s)); | |||||
| } | |||||
| void Display::drawConfigText(String txt) { | void Display::drawConfigText(String txt) { | ||||
| char *s = &txt[0]; | char *s = &txt[0]; | ||||
| int16_t w = 0, h = 0; | int16_t w = 0, h = 0; | ||||
| u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1); | u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1); | ||||
| u8g2_gfx.println(F(s)); | u8g2_gfx.println(F(s)); | ||||
| } | } | ||||
| const String& Display::getConfigOption() const { | |||||
| return configOption; | |||||
| } | |||||
| void Display::setConfigOption(const String &configOption) { | |||||
| this->configOption = configOption; | |||||
| } | |||||
| const String& Display::getConfigText() const { | |||||
| return configText; | |||||
| } | |||||
| void Display::setWlsConnected(bool wlsConnected) { | |||||
| this->wlsConnected = wlsConnected; | |||||
| } | |||||
| void Display::setConfigText(const String &configText) { | |||||
| this->configText = configText; | |||||
| } | |||||
| void Display::drawWLSStatus() { | |||||
| String txt = wlsConnected ? "WLS" : ""; | |||||
| char *s = &txt[0]; | |||||
| int16_t w = 0; | |||||
| u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | |||||
| w = u8g2_gfx.getUTF8Width(s); | |||||
| u8g2_gfx.setCursor((37 - w) / 2, 27); | |||||
| u8g2_gfx.println(F(s)); | |||||
| } | |||||
| /******************************** | |||||
| ** Private methods | |||||
| *******************************/ | |||||
| void Display::drawStatusText(String txt) { | |||||
| char *s = &txt[0]; | |||||
| int16_t w = 0; | |||||
| u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | |||||
| w = u8g2_gfx.getUTF8Width(s); | |||||
| u8g2_gfx.setCursor((37 - w) / 2, 12); | |||||
| u8g2_gfx.println(F(s)); | |||||
| } | |||||
| void Display::drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[]) { | |||||
| ssd1306.drawBitmap(x, y, bitmap, w, h, SSD1306_WHITE); | |||||
| } | |||||
| void Display::redrawFrame() { | |||||
| ssd1306.clearDisplay(); | |||||
| ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE); | |||||
| ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE); | |||||
| ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE); | |||||
| drawWLSStatus(); | |||||
| } |
| #include <Adafruit_SSD1306.h> | #include <Adafruit_SSD1306.h> | ||||
| #include <U8g2_for_Adafruit_GFX.h> | #include <U8g2_for_Adafruit_GFX.h> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include "fonts/titillium_web_6pt7b.h" | |||||
| #include "fonts/titillium_web_8pt7b.h" | |||||
| #include "fonts/titillium_web_12pt7b.h" | |||||
| #include "fonts/titillium_web_24pt7b.h" | |||||
| #include "fonts/titillium_web_30pt7b.h" | |||||
| #include "fonts/SFToolsLogo.h" | |||||
| #include <Fonts/FreeSans12pt7b.h> | |||||
| #include <Fonts/FreeSans9pt7b.h> | |||||
| #include "images/SFToolsLogo.h" | |||||
| #include "images/ToolsBitmap.h" | |||||
| #include "images/NullingBitmap.h" | |||||
| #include "images/RotateBitmap.h" | |||||
| #include "images/DiveBitmap.h" | |||||
| #include "Status.h" | #include "Status.h" | ||||
| #define SCREEN_WIDTH 128 | #define SCREEN_WIDTH 128 | ||||
| #define STATUS_TXT_IDLE "OPR" | #define STATUS_TXT_IDLE "OPR" | ||||
| #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" | |||||
| class Display { | class Display { | ||||
| private: | private: | ||||
| Adafruit_SSD1306 ssd1306; | Adafruit_SSD1306 ssd1306; | ||||
| U8G2_FOR_ADAFRUIT_GFX u8g2_gfx; | U8G2_FOR_ADAFRUIT_GFX u8g2_gfx; | ||||
| void calculateWH(String units, uint16_t &w, uint16_t &h); | |||||
| String configText; | |||||
| String configOption; | |||||
| bool wlsConnected; | |||||
| void drawStatusText(String txt); | void drawStatusText(String txt); | ||||
| void drawConfigText(String txt); | |||||
| void drawConfigOption(String txt); | |||||
| void drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[]); | |||||
| void redrawFrame(); | |||||
| void drawWLSStatus(); | |||||
| public: | public: | ||||
| Display(); | Display(); | ||||
| void showBrand(void); | void showBrand(void); | ||||
| void showInitialization(void); | void showInitialization(void); | ||||
| void showFrame(Status status); | void showFrame(Status status); | ||||
| void drawConfigText(String txt); | |||||
| void drawConfigOption(String txt); | |||||
| const String& getConfigOption() const; | |||||
| void setConfigOption(const String &configOption); | |||||
| const String& getConfigText() const; | |||||
| void setConfigText(const String &configText); | |||||
| void setWlsConnected(bool wlsConnected); | |||||
| }; | }; | ||||
| #endif /* DISPLAY_H_ */ | #endif /* DISPLAY_H_ */ |
| static const int MOVE_DOWNWARD = -1; // motor rotation counter clock wise | static const int MOVE_DOWNWARD = -1; // motor rotation counter clock wise | ||||
| //static const int MOVE_UPWARD = 1; // motor rotation clock wise | //static const int MOVE_UPWARD = 1; // motor rotation clock wise | ||||
| int nullingTLS_intermediateState = 0; | |||||
| int intermediateState = 0; | |||||
| ExEzButton RedButton(RedBtn_Pin, false, 2000); | ExEzButton RedButton(RedBtn_Pin, false, 2000); | ||||
| ExEzButton GreenButton(GreenBtn_Pin, false, 2000); | ExEzButton GreenButton(GreenBtn_Pin, false, 2000); | ||||
| RotaryControler RotaryControler(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotEnc_Switch_Pin); | RotaryControler RotaryControler(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotEnc_Switch_Pin); | ||||
| Display Display; | Display Display; | ||||
| ESP_FlexyStepper Stepper; | ESP_FlexyStepper Stepper; | ||||
| RouterSetup Router_Setup; | |||||
| RouterElevator Router_Elevator(Stepper, Display, WlsDetect, Wls, LIMIT_SWITCH, MOVE_DOWNWARD); | |||||
| RouterSetup Router_Setup(Display); | |||||
| RouterElevator Router_Elevator(Stepper, Display, WlsDetect, Wls, LIMIT_SWITCH, MOVE_DOWNWARD); // @suppress("Ambiguous problem") | |||||
| Status actualStatus; | Status actualStatus; | ||||
| Status originStatus; | Status originStatus; | ||||
| Wls.loop(); | Wls.loop(); | ||||
| RotaryControler.loop(); | RotaryControler.loop(); | ||||
| Display.setWlsConnected(WlsDetect.isConnected()); | |||||
| Display.showFrame(actualStatus); | Display.showFrame(actualStatus); | ||||
| switch (actualStatus) { | switch (actualStatus) { | ||||
| case TOOL_CHANGE: | case TOOL_CHANGE: | ||||
| printStatus("TOOL_CHANGE"); | printStatus("TOOL_CHANGE"); | ||||
| if (RotaryControler.isSwitchLongPressed()) { | |||||
| actualStatus = CONFIGURATION; | |||||
| } else if (BlueButton.isPressed()) { | |||||
| actualStatus = IDLE; | |||||
| originStatus = TOOL_CHANGE; | |||||
| if (intermediateState == 0) { | |||||
| Router_Elevator.moveToUpperLimitSwitch(); | |||||
| actualStatus = MOVING_ELEVATOR; | |||||
| intermediateState = 1; | |||||
| } else if (intermediateState == 1) { | |||||
| if (RotaryControler.isSwitchLongPressed()) { | |||||
| actualStatus = CONFIGURATION; | |||||
| intermediateState = 0; | |||||
| } else if (BlueButton.isPressed()) { | |||||
| actualStatus = IDLE; | |||||
| intermediateState = 0; | |||||
| } | |||||
| } | } | ||||
| break; | break; | ||||
| case CONFIGURATION: | case CONFIGURATION: | ||||
| printStatus("CONFIGURATION"); | printStatus("CONFIGURATION"); | ||||
| if (RotaryControler.isSwitchLongPressed()) { | |||||
| Router_Setup.initialize(); | |||||
| Router_Setup.onRotaryControlerTurn(RotaryControler.getEncoderMove()); | |||||
| if (RotaryControler.isSwitchPressed()) { | |||||
| Router_Setup.onRotaryControlerSwitch(); | |||||
| } else if (RotaryControler.isSwitchLongPressed()) { | |||||
| Router_Setup.onRotaryControlerLongSwitch(); | |||||
| actualStatus = INITIALIZATION; | actualStatus = INITIALIZATION; | ||||
| } else if (BlueButton.isPressed()) { | } else if (BlueButton.isPressed()) { | ||||
| actualStatus = IDLE; | actualStatus = IDLE; | ||||
| case NULLING_TLS: | case NULLING_TLS: | ||||
| originStatus = NULLING_TLS; | originStatus = NULLING_TLS; | ||||
| if (nullingTLS_intermediateState == 0) { | |||||
| if (intermediateState == 0) { | |||||
| printStatus("NULLING_TLS,0"); | printStatus("NULLING_TLS,0"); | ||||
| //Move elevator to lowest point (lower limit switch triggers) | //Move elevator to lowest point (lower limit switch triggers) | ||||
| Router_Elevator.moveToLowerLimitSwitch(); | Router_Elevator.moveToLowerLimitSwitch(); | ||||
| actualStatus = MOVING_ELEVATOR; | actualStatus = MOVING_ELEVATOR; | ||||
| nullingTLS_intermediateState = 1; | |||||
| } else if (nullingTLS_intermediateState == 1) { | |||||
| intermediateState = 1; | |||||
| } else if (intermediateState == 1) { | |||||
| printStatus("NULLING_TLS,1"); | printStatus("NULLING_TLS,1"); | ||||
| if (RedButton.isPressed()) { | if (RedButton.isPressed()) { | ||||
| //Move elevator until it touch the TLS (WLS_PIN goes HIGH) | //Move elevator until it touch the TLS (WLS_PIN goes HIGH) | ||||
| Router_Elevator.moveToUpperLimitSwitch(); | Router_Elevator.moveToUpperLimitSwitch(); | ||||
| actualStatus = MOVING_ELEVATOR; | actualStatus = MOVING_ELEVATOR; | ||||
| nullingTLS_intermediateState = 2; | |||||
| intermediateState = 2; | |||||
| } | } | ||||
| } else if (nullingTLS_intermediateState == 2) { | |||||
| } else if (intermediateState == 2) { | |||||
| printStatus("NULLING_TLS,2"); | printStatus("NULLING_TLS,2"); | ||||
| //Move elevator back about toolLenghtSensorHeight (will be the 0-Position) | //Move elevator back about toolLenghtSensorHeight (will be the 0-Position) | ||||
| Router_Elevator.clearLimitSwitch(); | Router_Elevator.clearLimitSwitch(); | ||||
| Router_Elevator.moveRelativeInMillimeters(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD); | Router_Elevator.moveRelativeInMillimeters(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD); | ||||
| Serial.println(String(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2)); | Serial.println(String(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2)); | ||||
| actualStatus = MOVING_ELEVATOR; | actualStatus = MOVING_ELEVATOR; | ||||
| nullingTLS_intermediateState = 3; | |||||
| intermediateState = 3; | |||||
| } else { // nullingTLS_intermediateState is 3 | } else { // nullingTLS_intermediateState is 3 | ||||
| printStatus("NULLING_TLS,3"); | printStatus("NULLING_TLS,3"); | ||||
| //Set the 0-Position as actual position | //Set the 0-Position as actual position | ||||
| Router_Elevator.setZeroPosition(); | Router_Elevator.setZeroPosition(); | ||||
| actualStatus = IDLE; | actualStatus = IDLE; | ||||
| nullingTLS_intermediateState = 0; | |||||
| intermediateState = 0; | |||||
| } | } | ||||
| break; | break; | ||||
| ****************/ | ****************/ | ||||
| RotaryControler::RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin) : Encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, | RotaryControler::RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin) : Encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, | ||||
| RotaryEncoder::LatchMode::FOUR3), RotarySwitch(RotEnc_Switch_Pin, true, 2000) { | RotaryEncoder::LatchMode::FOUR3), RotarySwitch(RotEnc_Switch_Pin, true, 2000) { | ||||
| position = 0; | |||||
| Encoder.setPosition(position); | |||||
| } | } | ||||
| /****************** | /****************** | ||||
| RotarySwitch.loop(); | RotarySwitch.loop(); | ||||
| Encoder.tick(); | Encoder.tick(); | ||||
| } | } | ||||
| RotaryEncoder::Direction RotaryControler::getEncoderMove() { | |||||
| long newPos = Encoder.getPosition(); | |||||
| RotaryEncoder::Direction dir = Encoder.getDirection(); | |||||
| if (position != newPos) { | |||||
| Serial.print("pos:"); | |||||
| Serial.print(newPos); | |||||
| Serial.print(" dir:"); | |||||
| Serial.println((int) dir); | |||||
| position = newPos; | |||||
| } | |||||
| return dir; | |||||
| } |
| private: | private: | ||||
| RotaryEncoder Encoder; | RotaryEncoder Encoder; | ||||
| ExEzButton RotarySwitch; | ExEzButton RotarySwitch; | ||||
| long position; | |||||
| public: | public: | ||||
| RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin); | RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin); | ||||
| bool isSwitchLongPressed(void); | bool isSwitchLongPressed(void); | ||||
| long getPosition(void); | long getPosition(void); | ||||
| int getDirection(void); | int getDirection(void); | ||||
| RotaryEncoder::Direction getEncoderMove(); | |||||
| void setDebounceTime(unsigned long time); | void setDebounceTime(unsigned long time); | ||||
| void loop(void); | void loop(void); | ||||
| }; | }; |
| RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR) : | RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR) : | ||||
| Stepper(_Stepper), display(_display), WlsDetect(_WlsDetect), Wls(_Wls) { | Stepper(_Stepper), display(_display), WlsDetect(_WlsDetect), Wls(_Wls) { | ||||
| // Stepper = _Stepper; | |||||
| // display = _display; | |||||
| // WlsDetect = _WlsDetect; | |||||
| // Wls = _Wls; | |||||
| LimitSwitch = _LimitSwitch; | LimitSwitch = _LimitSwitch; | ||||
| DOWNWARD_DIR = _DOWNWARD_DIR; | DOWNWARD_DIR = _DOWNWARD_DIR; | ||||
| UPWARD_DIR = -DOWNWARD_DIR; | UPWARD_DIR = -DOWNWARD_DIR; | ||||
| void RouterElevator::checkDirection() { | void RouterElevator::checkDirection() { | ||||
| previousDirection = Stepper.getDirectionOfMotion(); | previousDirection = Stepper.getDirectionOfMotion(); | ||||
| } | } | ||||
| #include "RouterSetup.h" | #include "RouterSetup.h" | ||||
| /****************** | |||||
| ** Constructors | |||||
| *****************/ | |||||
| RouterSetup::RouterSetup(Display &_display) : display(_display) { | |||||
| this->doInitialization = true; | |||||
| this->configStepIndex = 0; | |||||
| } | |||||
| /****************** | /****************** | ||||
| ** Public methods | ** Public methods | ||||
| *****************/ | *****************/ | ||||
| eeprom.end(); | eeprom.end(); | ||||
| } | } | ||||
| void RouterSetup::printValues() { | void RouterSetup::printValues() { | ||||
| Serial.print(String(SPEED) + ": " + String(getSpeed(), 1) + ", "); | Serial.print(String(SPEED) + ": " + String(getSpeed(), 1) + ", "); | ||||
| Serial.print(String(ACCELERATION) + ": " + String(getAcceleration(), 1) + ", "); | Serial.print(String(ACCELERATION) + ": " + String(getAcceleration(), 1) + ", "); | ||||
| Serial.print(String(LVLHEIGHTDIVE) + ": " + String(getLevelHeightDiving(), 2) + ", "); | Serial.print(String(LVLHEIGHTDIVE) + ": " + String(getLevelHeightDiving(), 2) + ", "); | ||||
| Serial.println(String(TOOLCHGONPWRON) + ": " + String(isToolChangOnPowerOn())); | Serial.println(String(TOOLCHGONPWRON) + ": " + String(isToolChangOnPowerOn())); | ||||
| } | } | ||||
| void RouterSetup::initialize() { | |||||
| if (doInitialization) { | |||||
| configStepIndex = 0; | |||||
| String stepTxt = ConfigStep[configStepIndex]; | |||||
| String option = getCfgOptForStepIndex(configStepIndex); | |||||
| option.trim(); | |||||
| display.setConfigText(stepTxt); | |||||
| display.setConfigOption(option); | |||||
| this->doInitialization = false; | |||||
| } | |||||
| } | |||||
| void RouterSetup::onRotaryControlerSwitch() { | |||||
| configStepIndex++; | |||||
| configStepIndex = configStepIndex % 9; | |||||
| String stepTxt = ConfigStep[configStepIndex]; | |||||
| String option = getCfgOptForStepIndex(configStepIndex); | |||||
| option.trim(); | |||||
| display.setConfigText(stepTxt); | |||||
| display.setConfigOption(option); | |||||
| } | |||||
| void RouterSetup::onRotaryControlerLongSwitch() { | |||||
| saveToEEPROM(); | |||||
| this->doInitialization = true; | |||||
| } | |||||
| void RouterSetup::onRotaryControlerTurn(RotaryEncoder::Direction turn) { | |||||
| switch (turn) { | |||||
| case RotaryEncoder::Direction::CLOCKWISE: | |||||
| break; | |||||
| case RotaryEncoder::Direction::COUNTERCLOCKWISE: | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| String RouterSetup::getCfgOptForStepIndex(byte configStepIndex) { | |||||
| String value = ""; | |||||
| String unit = getCfgOptUnitForStepIndex(configStepIndex); | |||||
| switch (configStepIndex) { | |||||
| case 0: | |||||
| value = String(getSpeed(), 1); | |||||
| break; | |||||
| case 1: | |||||
| value = String(getAcceleration(), 1); | |||||
| break; | |||||
| case 2: | |||||
| value = String(getStepsPerRev()); | |||||
| break; | |||||
| case 3: | |||||
| value = String(getPitch(), 1); | |||||
| break; | |||||
| case 4: | |||||
| value = String(getToolLenghtSensorHeight(), 2); | |||||
| break; | |||||
| case 5: | |||||
| value = String(getEncoderSpeedSlow()); | |||||
| break; | |||||
| case 6: | |||||
| value = String(getEncoderSpeedFast()); | |||||
| break; | |||||
| case 7: | |||||
| value = String(getLevelHeightDiving(), 1); | |||||
| break; | |||||
| case 8: | |||||
| value = isToolChangOnPowerOn() ? "JA" : "NEIN"; | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| return value + " " + unit; | |||||
| } | |||||
| String RouterSetup::getCfgOptUnitForStepIndex(byte configStepIndex) { | |||||
| String value = ""; | |||||
| switch (configStepIndex) { | |||||
| case 0: | |||||
| value = "U/sec"; | |||||
| break; | |||||
| case 1: | |||||
| value = "U/sec2"; | |||||
| break; | |||||
| case 3: | |||||
| value = "mm"; | |||||
| break; | |||||
| case 4: | |||||
| value = "mm"; | |||||
| break; | |||||
| case 5: | |||||
| value = "mm/100"; | |||||
| break; | |||||
| case 6: | |||||
| value = "mm/100"; | |||||
| break; | |||||
| case 7: | |||||
| value = "mm"; | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| return value; | |||||
| } |
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <Preferences.h> | #include <Preferences.h> | ||||
| #include <RotaryEncoder.h> | |||||
| #include "Display.h" | |||||
| const static char ROUTER_NAMESPACE[] = "routerelv_stp"; | const static char ROUTER_NAMESPACE[] = "routerelv_stp"; | ||||
| const static char SPEED[] = "speed"; | const static char SPEED[] = "speed"; | ||||
| const static char LVLHEIGHTDIVE[] = "lvlHeightDive"; | const static char LVLHEIGHTDIVE[] = "lvlHeightDive"; | ||||
| const static char TOOLCHGONPWRON[] = "toolChgOnPwrOn"; | const static char TOOLCHGONPWRON[] = "toolChgOnPwrOn"; | ||||
| const static String ConfigStep[9] = { "Geschw.", "Beschl.", "Schritte/U", "Steigung", "Höhe WLS", "SLOW", "FAST", "Ink. Eint.", "WzW P-ON" }; | |||||
| class RouterSetup { | class RouterSetup { | ||||
| private: | private: | ||||
| Preferences eeprom; | Preferences eeprom; | ||||
| Display &display; | |||||
| float speed; // in revolutions/second (U/s) | float speed; // in revolutions/second (U/s) | ||||
| float accelleration; // in revolutions/second (U/s) | |||||
| float accelleration; // in revolutions/second^2 (U/s^2) | |||||
| uint16_t stepsPerRev; // micro stepping: 200 400 800 1600 3200 6400 | uint16_t stepsPerRev; // micro stepping: 200 400 800 1600 3200 6400 | ||||
| float pitch; // in mm | float pitch; // in mm | ||||
| float toolLenghtSensorHeight; // in mm | float toolLenghtSensorHeight; // in mm | ||||
| float levelHeightDiving; // in mm | float levelHeightDiving; // in mm | ||||
| bool toolChangeOnPowerOn; // Yes or No | bool toolChangeOnPowerOn; // Yes or No | ||||
| bool doInitialization; | |||||
| byte configStepIndex; | |||||
| String getCfgOptForStepIndex(byte configStepIndex); | |||||
| String getCfgOptUnitForStepIndex(byte configStepIndex); | |||||
| public: | public: | ||||
| const static int eeprom_start_adress = 0; | const static int eeprom_start_adress = 0; | ||||
| const static int eeprom_signatur = 1024; | const static int eeprom_signatur = 1024; | ||||
| const static uint8_t version = 1; | const static uint8_t version = 1; | ||||
| RouterSetup(Display &display); | |||||
| float getSpeed() const; | float getSpeed() const; | ||||
| void setSpeed(float speed); | void setSpeed(float speed); | ||||
| float getAcceleration() const; | float getAcceleration() const; | ||||
| void readFromEEPROM(); | void readFromEEPROM(); | ||||
| void saveToEEPROM(); | void saveToEEPROM(); | ||||
| void initialize(); | |||||
| void onRotaryControlerSwitch(); | |||||
| void onRotaryControlerLongSwitch(); | |||||
| void onRotaryControlerTurn(RotaryEncoder::Direction turn); | |||||
| void printValues(); | void printValues(); | ||||
| }; | }; |
| /* | |||||
| * DiveBitmap.h | |||||
| * | |||||
| * Created on: 14.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef IMAGES_DIVEBITMAP_H_ | |||||
| #define IMAGES_DIVEBITMAP_H_ | |||||
| #define imageSide_D 15 | |||||
| // 'Dive', 15x15px | |||||
| const unsigned char epd_bitmap_Dive [] PROGMEM = { | |||||
| 0x01, 0x00, 0x07, 0xc0, 0x09, 0x20, 0x13, 0x90, 0x25, 0x48, 0x49, 0x24, 0x53, 0x94, 0xff, 0xfe, | |||||
| 0x53, 0x94, 0x49, 0x24, 0x25, 0x48, 0x13, 0x90, 0x09, 0x20, 0x07, 0xc0, 0x01, 0x00 | |||||
| }; | |||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 48) | |||||
| //const int epd_bitmap_allArray_LEN = 1; | |||||
| //const unsigned char* epd_bitmap_allArray[1] = { | |||||
| // epd_bitmap_Dive | |||||
| //}; | |||||
| #endif /* IMAGES_DIVEBITMAP_H_ */ |
| /* | |||||
| * NullingBitmap.h | |||||
| * | |||||
| * Created on: 14.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef IMAGES_NULLINGBITMAP_H_ | |||||
| #define IMAGES_NULLINGBITMAP_H_ | |||||
| // 'Nulling', 60x60px | |||||
| const unsigned char epd_bitmap_Nulling [] PROGMEM = { | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x07, 0xf8, 0x01, 0xfe, 0x00, 0x7f, 0xee, 0x00, 0x0f, 0xfc, 0x03, 0xff, 0x00, 0x7f, 0xee, 0x00, | |||||
| 0x1f, 0x3e, 0x07, 0xcf, 0x80, 0x7f, 0xee, 0x00, 0x1e, 0x1e, 0x07, 0x87, 0x80, 0x00, 0x0e, 0x00, | |||||
| 0x1c, 0x0e, 0x07, 0x03, 0x80, 0x00, 0x0e, 0x00, 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x07, 0xee, 0x00, | |||||
| 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x07, 0xee, 0x00, 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x00, 0x0e, 0x00, | |||||
| 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x00, 0x0e, 0x00, 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x07, 0xee, 0x00, | |||||
| 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x07, 0xee, 0x00, 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x00, 0x0e, 0x00, | |||||
| 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x00, 0x0e, 0x00, 0x3c, 0x0f, 0x0f, 0x03, 0xc0, 0x07, 0xee, 0x00, | |||||
| 0x1e, 0x0e, 0x07, 0x83, 0x80, 0x07, 0xee, 0x00, 0x1e, 0x1e, 0x07, 0x87, 0x80, 0x00, 0x0e, 0x00, | |||||
| 0x1f, 0x3e, 0xf7, 0xcf, 0x80, 0x00, 0x0e, 0x00, 0x0f, 0xfc, 0xf3, 0xff, 0x00, 0x07, 0xee, 0x00, | |||||
| 0x07, 0xf8, 0xf1, 0xfe, 0x00, 0x07, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xee, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xee, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x7f, 0xee, 0x00, | |||||
| 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x00, 0x1c, 0x03, 0x80, 0x00, 0x07, 0xee, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x00, 0x07, 0xee, 0x00, | |||||
| 0x00, 0x1c, 0x03, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x00, 0x1c, 0x03, 0x80, 0x00, 0x07, 0xee, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x00, 0x07, 0xee, 0x00, | |||||
| 0x00, 0x1c, 0x03, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x07, 0xfc, 0x03, 0xfe, 0x00, 0x07, 0xee, 0x00, 0x07, 0xfc, 0x03, 0xfe, 0x00, 0x07, 0xee, 0x00, | |||||
| 0x07, 0xf8, 0x01, 0xfe, 0x00, 0x00, 0x0e, 0x00, 0x03, 0xe0, 0x00, 0x7c, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x01, 0xf0, 0x00, 0xf8, 0x00, 0x07, 0xee, 0x00, 0x00, 0x78, 0x01, 0xf0, 0x00, 0x07, 0xee, 0x00, | |||||
| 0x00, 0x3c, 0x03, 0xe0, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1e, 0x07, 0x80, 0x00, 0x00, 0x0e, 0x00, | |||||
| 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x7f, 0xee, 0x00, 0x00, 0x07, 0x9e, 0x00, 0x00, 0x7f, 0xee, 0x00, | |||||
| 0x00, 0x03, 0xfc, 0x00, 0x00, 0x7f, 0xee, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |||||
| }; | |||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 496) | |||||
| //const int epd_bitmap_allArray_LEN = 1; | |||||
| //const unsigned char* epd_bitmap_allArray[1] = { | |||||
| // epd_bitmap_Nulling | |||||
| //}; | |||||
| #endif /* IMAGES_NULLINGBITMAP_H_ */ |
| /* | |||||
| * RotateBitmap.h | |||||
| * | |||||
| * Created on: 14.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef IMAGES_ROTATEBITMAP_H_ | |||||
| #define IMAGES_ROTATEBITMAP_H_ | |||||
| #define imageSide_R 15 | |||||
| // 'Rotate', 15x15px | |||||
| const unsigned char epd_bitmap_Rotate [] PROGMEM = { | |||||
| 0x07, 0xc4, 0x1f, 0xf4, 0x38, 0x3c, 0x70, 0x1c, 0x60, 0x7c, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x06, | |||||
| 0x00, 0x06, 0x00, 0x06, 0x7c, 0x0c, 0x70, 0x1c, 0x78, 0x38, 0x5f, 0xf0, 0x47, 0xc0 | |||||
| }; | |||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 48) | |||||
| //const int epd_bitmap_allArray_LEN = 1; | |||||
| //const unsigned char* epd_bitmap_allArray[1] = { | |||||
| // epd_bitmap_Rotate | |||||
| //}; | |||||
| #endif /* IMAGES_ROTATEBITMAP_H_ */ |
| /* | |||||
| * ToolsBitmap.h | |||||
| * | |||||
| * Created on: 13.02.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef IMAGES_TOOLSBITMAP_H_ | |||||
| #define IMAGES_TOOLSBITMAP_H_ | |||||
| #define imageSide 60 | |||||
| // 'Tools', 60x60px | |||||
| const unsigned char epd_bitmap_Tools [] PROGMEM = { | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0x02, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0x03, 0x80, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0xff, 0xc0, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0xff, 0xe0, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0xff, 0xf0, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x09, 0x00, 0xff, 0xf8, 0x09, 0x00, 0x00, 0x00, 0x1f, 0x80, 0xff, 0xf0, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x1f, 0x80, 0xff, 0xe0, 0x09, 0x00, 0x00, 0x00, 0x1f, 0x80, 0xff, 0xc0, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x7f, 0xe0, 0x03, 0x80, 0x1f, 0x80, 0x00, 0x00, 0x5e, 0x20, 0x03, 0x00, 0x1f, 0x80, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x02, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0x00, 0x00, 0x7f, 0xe0, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0x02, 0x00, 0x7f, 0xe0, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x06, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0x0e, 0x00, 0x7f, 0xe0, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x1f, 0xf8, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0x3b, 0xf8, 0x7f, 0xe0, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x70, 0x18, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0xe0, 0x18, 0x7f, 0xe0, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x70, 0x18, 0x7f, 0xe0, 0x00, 0x00, 0x5e, 0x20, 0x3b, 0xf8, 0x3e, 0x40, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x1f, 0xf8, 0x3e, 0x40, 0x00, 0x00, 0x5e, 0x20, 0x0e, 0x00, 0x1c, 0x80, 0x00, | |||||
| 0x00, 0x5e, 0x20, 0x06, 0x00, 0x1c, 0x80, 0x00, 0x00, 0x5e, 0x20, 0x02, 0x00, 0x09, 0x00, 0x00, | |||||
| 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, | |||||
| 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xc0, 0x3f, 0xc0, | |||||
| 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xe0, 0x7f, 0xc0, | |||||
| 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xe0, 0x7f, 0xc0, 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xf0, 0xff, 0xc0, | |||||
| 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xf0, 0xff, 0xc0, 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xf9, 0xff, 0xc0, | |||||
| 0x3f, 0x80, 0x1f, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, | |||||
| 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |||||
| }; | |||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 496) | |||||
| //const int epd_bitmap_allArray_LEN = 1; | |||||
| //const unsigned char* epd_bitmap_allArray[1] = { | |||||
| // epd_bitmap_Tools | |||||
| //}; | |||||
| #endif /* IMAGES_TOOLSBITMAP_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-13 17:01:01 | |||||
| //This file has been generated on 2022-02-14 19:37:01 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <Arduino.h> | #include <Arduino.h> |