| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/FreeRTOS}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/FreeRTOS}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Preferences/src}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.cpp.sketch.input.1777418047" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | <inputType id="io.sloeber.compiler.cpp.sketch.input.1777418047" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/FreeRTOS}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/FreeRTOS}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Preferences/src}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.c.sketch.input.1282698896" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | <inputType id="io.sloeber.compiler.c.sketch.input.1282698896" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ezButton/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/RotaryEncoder/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/SPI/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Wire}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/STM32duino_RTC}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Simple_Repository_IO}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Simple_Repository_IO}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/ESP-FlexyStepper/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Preferences/src}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}""/> | |||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.S.sketch.input.1238595277" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | <inputType id="io.sloeber.compiler.S.sketch.input.1238595277" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | ||||
| </tool> | </tool> |
| <type>2</type> | <type>2</type> | ||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/FreeRTOS/10.4.6-0</locationURI> | <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/FreeRTOS/10.4.6-0</locationURI> | ||||
| </link> | </link> | ||||
| <link> | |||||
| <name>libraries/Preferences</name> | |||||
| <type>2</type> | |||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp32/hardware/esp32/1.0.6/libraries/Preferences</locationURI> | |||||
| </link> | |||||
| <link> | <link> | ||||
| <name>libraries/RotaryEncoder</name> | <name>libraries/RotaryEncoder</name> | ||||
| <type>2</type> | <type>2</type> |
| /* | |||||
| * Display.cpp | |||||
| * | |||||
| * Wrapper class for Adafruit OLED display. | |||||
| * | |||||
| * Created on: 28.01.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #include "Display.h" | |||||
| /***************** | |||||
| ** Constructors. | |||||
| ****************/ | |||||
| Display::Display() { | |||||
| ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); | |||||
| } | |||||
| /****************** | |||||
| ** Public methods | |||||
| *****************/ | |||||
| void Display::init() { | |||||
| if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) { | |||||
| Serial.println(F("SSD1306 allocation failed")); | |||||
| for (;;) | |||||
| ; // Don't proceed, loop forever | |||||
| } | |||||
| } | |||||
| void Display::display() { | |||||
| ssd1306.display(); | |||||
| } | |||||
| void Display::clearDisplay() { | |||||
| ssd1306.clearDisplay(); | |||||
| } | |||||
| void Display::showBrand() { | |||||
| ssd1306.clearDisplay(); | |||||
| ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, 128, 34, SSD1306_WHITE); | |||||
| ssd1306.setFont(&titillium_web_semibold12pt7b); | |||||
| ssd1306.setTextSize(1); | |||||
| ssd1306.setTextColor(SSD1306_WHITE); | |||||
| uint16_t w = 0, h = 0; | |||||
| calculateWH("Fraestisch N172", w, h); | |||||
| ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2); | |||||
| ssd1306.println("Fraestisch N172"); | |||||
| display(); | |||||
| } | |||||
| void Display::showInitialization() { | |||||
| ssd1306.clearDisplay(); | |||||
| ssd1306.setFont(&titillium_web_semibold12pt7b); | |||||
| ssd1306.setTextSize(1); | |||||
| ssd1306.setTextColor(SSD1306_WHITE); | |||||
| uint16_t w = 0, h = 0; | |||||
| calculateWH("Initialisieren", w, h); | |||||
| ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 30); | |||||
| ssd1306.println("Initialisieren"); | |||||
| calculateWH(". . . . .", w, h); | |||||
| ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 50); | |||||
| String s = ""; | |||||
| for (int i = 0; i < 6; i++) { | |||||
| ssd1306.print(s); | |||||
| display(); | |||||
| delay(500); | |||||
| if (i < 5) { | |||||
| ssd1306.print(s + ". "); | |||||
| } else { | |||||
| ssd1306.println(s + "."); | |||||
| } | |||||
| } | |||||
| } | |||||
| /******************************** | |||||
| ** 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; | |||||
| } |
| /* | |||||
| * Display.h | |||||
| * | |||||
| * Wrapper class for Adafruit OLED display. | |||||
| * | |||||
| * Created on: 28.01.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef DISPLAY_H_ | |||||
| #define DISPLAY_H_ | |||||
| #include<Adafruit_SSD1306.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" | |||||
| #define SCREEN_WIDTH 128 | |||||
| #define SCREEN_HEIGHT 64 | |||||
| #define SCREEN_ADDRESS 0x3C | |||||
| class Display { | |||||
| private: | |||||
| Adafruit_SSD1306 ssd1306; | |||||
| void calculateWH(String units, uint16_t &w, uint16_t &h); | |||||
| public: | |||||
| Display(); | |||||
| void init(void); | |||||
| void display(void); | |||||
| void clearDisplay(void); | |||||
| void showBrand(void); | |||||
| void showInitialization(void); | |||||
| }; | |||||
| #endif /* DISPLAY_H_ */ |
| #include "ExEzButton.h" | #include "ExEzButton.h" | ||||
| /***************** | |||||
| ** Constructors. | |||||
| ****************/ | |||||
| ExEzButton::ExEzButton(int pin) : | ExEzButton::ExEzButton(int pin) : | ||||
| ExEzButton(pin, false) { | ExEzButton(pin, false) { | ||||
| } | } | ||||
| releasedTime = 0; | releasedTime = 0; | ||||
| } | } | ||||
| /****************** | |||||
| ** Public methods | |||||
| *****************/ | |||||
| void ExEzButton::loop(void) { | void ExEzButton::loop(void) { | ||||
| int lastSteadyStateBefore = getState(); | int lastSteadyStateBefore = getState(); | ||||
| ezButton::loop(); | ezButton::loop(); |
| #include <Arduino.h> | #include <Arduino.h> | ||||
| #include <RotaryEncoder.h> | #include <RotaryEncoder.h> | ||||
| #include "WLS.h" | |||||
| #include "ExEzButton.h" | |||||
| #include <Wire.h> | #include <Wire.h> | ||||
| #include <Adafruit_GFX.h> | #include <Adafruit_GFX.h> | ||||
| #include <Adafruit_SSD1306.h> | |||||
| #include <ESP_FlexyStepper.h> | #include <ESP_FlexyStepper.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" | |||||
| #define SCREEN_WIDTH 128 | |||||
| #define SCREEN_HEIGHT 64 | |||||
| #define SCREEN_ADDRESS 0x3C | |||||
| #include "Display.h" | |||||
| #include "WLS.h" | |||||
| #include "ExEzButton.h" | |||||
| #include "RouterSetup.h" | |||||
| #include "Status.h" | |||||
| #define SDA 22 | #define SDA 22 | ||||
| #define SCX 23 | #define SCX 23 | ||||
| #define STEP 2 | #define STEP 2 | ||||
| #define DIR 4 | #define DIR 4 | ||||
| #define LIMIT_SWITCH 5 | #define LIMIT_SWITCH 5 | ||||
| static const byte led_gpio = 15; | static const byte led_gpio = 15; | ||||
| static const int WLS_Pin = 34; | static const int WLS_Pin = 34; | ||||
| static const int RotEnc_Clk_Pin = 32; | static const int RotEnc_Clk_Pin = 32; | ||||
| static const int RotEnc_Dta_Pin = 33; | static const int RotEnc_Dta_Pin = 33; | ||||
| // Speed settings | |||||
| const int DISTANCE_TO_TRAVEL_IN_STEPS = 2000; | |||||
| const int SPEED_IN_STEPS_PER_SECOND = 300; | |||||
| const int ACCELERATION_IN_STEPS_PER_SECOND = 800; | |||||
| const int DECELERATION_IN_STEPS_PER_SECOND = 800; | |||||
| static const float MOVE_DOWNWARD = -1; // motor rotation counter clock wise | |||||
| static const float MOVE_UPWARD = 1; // motor rotation clock wise | |||||
| //variables for software debouncing of the limit switches | |||||
| unsigned long lastDebounceTime = 0; | |||||
| unsigned long debounceDelay = 100; //the minimum delay in milliseconds to check for bouncing of the switch. Increase this slighlty if you switches tend to bounce a lot | |||||
| byte limitSwitchState = 1; | byte limitSwitchState = 1; | ||||
| byte oldConfirmedLimitSwitchState = 0; | |||||
| int previousDirection = 0; | |||||
| int nullingTLS_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); | ||||
| WLS Wls(WLS_Pin); | WLS Wls(WLS_Pin); | ||||
| RotaryEncoder encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotaryEncoder::LatchMode::FOUR3); | RotaryEncoder encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotaryEncoder::LatchMode::FOUR3); | ||||
| Adafruit_SSD1306 Display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // SCK on Pin 23, SDA on PIN 22 | |||||
| Display Display; | |||||
| ESP_FlexyStepper stepper; | ESP_FlexyStepper stepper; | ||||
| RouterSetup routerSetup; | |||||
| int previousDirection = 1; | |||||
| Status actualStatus; | |||||
| Status originStatus; | |||||
| String oldStatus = ""; | |||||
| void printStatus(String actualStatus) { | |||||
| if (!oldStatus.equals(actualStatus)) { | |||||
| Serial.println(actualStatus); | |||||
| oldStatus = actualStatus; | |||||
| } | |||||
| } | |||||
| void limitSwitchHandler() | |||||
| { | |||||
| //********************************** | |||||
| //*** Limit switch interrupt routine | |||||
| //********************************** | |||||
| void limitSwitchHandler() { | |||||
| limitSwitchState = digitalRead(LIMIT_SWITCH); | limitSwitchState = digitalRead(LIMIT_SWITCH); | ||||
| lastDebounceTime = millis(); | |||||
| } | } | ||||
| //***************************************************************************************************** | |||||
| //*** Initialization routine. Reads the eeprom first and sets the (potentially new) configured values. | |||||
| //***************************************************************************************************** | |||||
| void Initialize() { | |||||
| routerSetup.readFromEEPROM(); | |||||
| routerSetup.printValues(); | |||||
| Display.showInitialization(); | |||||
| //attach an interrupt to the IO pin of the limit switch and specify the handler function | |||||
| attachInterrupt(digitalPinToInterrupt(LIMIT_SWITCH), limitSwitchHandler, CHANGE); | |||||
| stepper.connectToPins(STEP, DIR); | |||||
| // set the speed and acceleration rates for the stepper motor | |||||
| stepper.setSpeedInStepsPerSecond(routerSetup.getSpeed() * routerSetup.getStepsPerRev()); | |||||
| stepper.setStepsPerRevolution(routerSetup.getStepsPerRev()); | |||||
| stepper.setStepsPerMillimeter(routerSetup.getStepsPerRev() / routerSetup.getPitch()); | |||||
| stepper.setAccelerationInStepsPerSecondPerSecond(routerSetup.getAcceleration() * routerSetup.getStepsPerRev()); | |||||
| stepper.setDecelerationInStepsPerSecondPerSecond(routerSetup.getAcceleration() * routerSetup.getStepsPerRev()); | |||||
| stepper.startAsService(0); | |||||
| if (routerSetup.isToolChangOnPowerOn()) { | |||||
| actualStatus = TOOL_CHANGE; | |||||
| } else { | |||||
| actualStatus = IDLE; | |||||
| } | |||||
| } | |||||
| //********************** | //********************** | ||||
| //*** SETUP ************ | //*** SETUP ************ | ||||
| //********************** | //********************** | ||||
| void setup() { | void setup() { | ||||
| actualStatus = INITIALIZATION; | |||||
| Wire.begin(SDA, SCX); | Wire.begin(SDA, SCX); | ||||
| Serial.begin(115200); | Serial.begin(115200); | ||||
| if (!Display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) { | |||||
| Serial.println(F("SSD1306 allocation failed")); | |||||
| for (;;) | |||||
| ; // Don't proceed, loop forever | |||||
| } | |||||
| Display.init(); | |||||
| Display.display(); | |||||
| pinMode(led_gpio, OUTPUT); | pinMode(led_gpio, OUTPUT); | ||||
| pinMode(GreenBtn_Pin, INPUT); | pinMode(GreenBtn_Pin, INPUT); | ||||
| Wls.setDebounceTime(50); | Wls.setDebounceTime(50); | ||||
| RotarySwitch.setDebounceTime(50); | RotarySwitch.setDebounceTime(50); | ||||
| Display.display(); | |||||
| delay(2000); // Pause for 2 seconds | |||||
| // testdrawchar(); | |||||
| // delay(5000); // Pause for 5 seconds | |||||
| testdrawstyles(); | |||||
| //attach an interrupt to the IO pin of the limit switch and specify the handler function | |||||
| // attachInterrupt(digitalPinToInterrupt(LIMIT_SWITCH), limitSwitchHandler, CHANGE); | |||||
| // | |||||
| // stepper.connectToPins(STEP, DIR); | |||||
| // set the speed and acceleration rates for the stepper motor | |||||
| // stepper.setSpeedInStepsPerSecond(SPEED_IN_STEPS_PER_SECOND); | |||||
| // stepper.setAccelerationInStepsPerSecondPerSecond(ACCELERATION_IN_STEPS_PER_SECOND); | |||||
| // stepper.setDecelerationInStepsPerSecondPerSecond(DECELERATION_IN_STEPS_PER_SECOND); | |||||
| // | |||||
| // stepper.startAsService(1); | |||||
| delay(1500); | |||||
| Display.showBrand(); | |||||
| delay(1500); | |||||
| Initialize(); | |||||
| } | } | ||||
| //********************** | //********************** | ||||
| Wls.loop(); | Wls.loop(); | ||||
| RotarySwitch.loop(); | RotarySwitch.loop(); | ||||
| if (WlsDetect.isPlugged()) { | |||||
| Serial.println("The WLS was connected"); | |||||
| } else if (WlsDetect.isUnplugged()) { | |||||
| Serial.println("The WLS was disconnected"); | |||||
| switch (actualStatus) { | |||||
| case INITIALIZATION: | |||||
| Initialize(); | |||||
| break; | |||||
| case TOOL_CHANGE: | |||||
| printStatus("TOOL_CHANGE"); | |||||
| if (RotarySwitch.isLongPressed()) { | |||||
| actualStatus = CONFIGURATION; | |||||
| } else if (BlueButton.isPressed()) { | |||||
| actualStatus = IDLE; | |||||
| } | |||||
| break; | |||||
| case CONFIGURATION: | |||||
| printStatus("CONFIGURATION"); | |||||
| if (RotarySwitch.isLongPressed()) { | |||||
| actualStatus = INITIALIZATION; | |||||
| } else if (BlueButton.isPressed()) { | |||||
| actualStatus = IDLE; | |||||
| } | |||||
| break; | |||||
| case NULLING: | |||||
| printStatus("NULLING"); | |||||
| if (RedButton.isPressed()) { | |||||
| stepper.setCurrentPositionInMillimeters(0); | |||||
| stepper.setTargetPositionRelativeInMillimeters(0); | |||||
| actualStatus = IDLE; | |||||
| } | |||||
| break; | |||||
| case NULLING_TLS: | |||||
| originStatus = NULLING_TLS; | |||||
| if (nullingTLS_intermediateState == 0) { | |||||
| printStatus("NULLING_TLS,0"); | |||||
| //Move elevator to lowest point (lower limit switch triggers) | |||||
| stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_DOWNWARD); | |||||
| actualStatus = MOVING_ELEVATOR; | |||||
| nullingTLS_intermediateState = 1; | |||||
| } else if (nullingTLS_intermediateState == 1) { | |||||
| printStatus("NULLING_TLS,1"); | |||||
| if (RedButton.isPressed()) { | |||||
| //Move elevator until it touch the TLS (WLS_PIN goes HIGH) | |||||
| stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_UPWARD); | |||||
| actualStatus = MOVING_ELEVATOR; | |||||
| nullingTLS_intermediateState = 2; | |||||
| } | |||||
| } else if (nullingTLS_intermediateState == 2) { | |||||
| printStatus("NULLING_TLS,2"); | |||||
| //Move elevator back about toolLenghtSensorHeight (will be the 0-Position) | |||||
| stepper.clearLimitSwitchActive(); | |||||
| stepper.setTargetPositionRelativeInMillimeters(routerSetup.getToolLenghtSensorHeight() * MOVE_DOWNWARD); | |||||
| Serial.println(String(routerSetup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2)); | |||||
| actualStatus = MOVING_ELEVATOR; | |||||
| nullingTLS_intermediateState = 3; | |||||
| } else { // nullingTLS_intermediateState is 3 | |||||
| printStatus("NULLING_TLS,3"); | |||||
| //Set the 0-Position as actual position | |||||
| stepper.setCurrentPositionInMillimeters(0); | |||||
| stepper.setTargetPositionRelativeInMillimeters(0); | |||||
| actualStatus = IDLE; | |||||
| nullingTLS_intermediateState = 0; | |||||
| } | |||||
| break; | |||||
| case IDLE: | |||||
| printStatus("IDLE"); | |||||
| if (RedButton.isLongPressed()) { | |||||
| if (WlsDetect.isConnected()) { | |||||
| actualStatus = NULLING_TLS; | |||||
| } else { | |||||
| actualStatus = NULLING; | |||||
| } | |||||
| } else if (BlueButton.isLongPressed()) { | |||||
| actualStatus = TOOL_CHANGE; | |||||
| } | |||||
| break; | |||||
| case DIVING: | |||||
| break; | |||||
| case MOVING_ELEVATOR: | |||||
| printStatus("MOVING_ELEVATOR"); | |||||
| if (limitSwitchState == LOW) { | |||||
| // this will cause to stop any motion that is currently going on and block further movement in the same direction as long as the switch is active | |||||
| stepper.setLimitSwitchActive(stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); | |||||
| delay(200); | |||||
| actualStatus = RELEASE_SWITCH; | |||||
| } else { // limitSwitchState is HIGH | |||||
| if (stepper.getDistanceToTargetSigned() == 0) { | |||||
| actualStatus = originStatus; | |||||
| delay(200); | |||||
| } else if (WlsDetect.isConnected()) { | |||||
| if (Wls.isPlugged()) { | |||||
| Serial.println("The Tool is away from WLS"); | |||||
| stepper.clearLimitSwitchActive(); | |||||
| } else if (Wls.isUnplugged()) { | |||||
| Serial.println("The Tool touched the WLS"); | |||||
| stepper.setLimitSwitchActive(stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); | |||||
| actualStatus = originStatus; | |||||
| delay(200); | |||||
| } | |||||
| } | |||||
| stepper.clearLimitSwitchActive(); | |||||
| previousDirection = stepper.getDirectionOfMotion(); | |||||
| } | |||||
| break; | |||||
| case RELEASE_SWITCH: | |||||
| if (limitSwitchState == LOW) { | |||||
| stepper.moveRelativeInMillimeters(0.05 * previousDirection * -1); // move in opposite direction (away from switch) | |||||
| } else { | |||||
| actualStatus = originStatus; | |||||
| } | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | } | ||||
| if (WlsDetect.getStateRaw() == HIGH) { | |||||
| if (Wls.isPlugged()) { | |||||
| Serial.println("The Tool is away from WLS"); | |||||
| } else if (Wls.isUnplugged()) { | |||||
| Serial.println("The Tool touched the WLS"); | |||||
| } | |||||
| } | |||||
| if (RedButton.isPressed()) { | |||||
| Serial.println("Red button was pressed"); | |||||
| digitalWrite(led_gpio, HIGH); | |||||
| Serial.print("Limit Switch: "); | |||||
| Serial.println(digitalRead(LIMIT_SWITCH) ? "HIGH" : "LOW"); | |||||
| } | |||||
| //*********************** OLD EXAMPLE AND EXPERIMENTAL CODE ************************************ | |||||
| if (RedButton.isLongPressed()) { | |||||
| Serial.println("Red button was long pressed"); | |||||
| digitalWrite(led_gpio, LOW); | |||||
| } | |||||
| bool greenPressed = GreenButton.isPressed(); | |||||
| bool bluePressed = BlueButton.isPressed(); | |||||
| if (GreenButton.isPressing() && BlueButton.isPressing()) { | |||||
| Serial.println("Blue and green button were simultaneous pressed"); | |||||
| } else if (greenPressed) { | |||||
| Serial.println("Green button was pressed"); | |||||
| } else if (bluePressed) { | |||||
| Serial.println("Blue button was pressed"); | |||||
| } | |||||
| if (RotarySwitch.isPressed()) { | |||||
| Serial.println("Rotary switch was pressed"); | |||||
| } | |||||
| if (RotarySwitch.isLongPressed()) { | |||||
| Serial.println("Rotary switch long was pressed"); | |||||
| } | |||||
| static int pos = 0; | |||||
| encoder.tick(); | |||||
| int newPos = encoder.getPosition(); | |||||
| if (pos != newPos) { | |||||
| Serial.print("pos:"); | |||||
| Serial.print(newPos); | |||||
| Serial.print(" dir:"); | |||||
| Serial.println((int) (encoder.getDirection())); | |||||
| pos = newPos; | |||||
| } | |||||
| // if (WlsDetect.isPlugged()) { | |||||
| // Serial.println("The WLS was connected"); | |||||
| // } else if (WlsDetect.isUnplugged()) { | |||||
| // Serial.println("The WLS was disconnected"); | |||||
| // } | |||||
| // | |||||
| // if (WlsDetect.getStateRaw() == HIGH) { | |||||
| // if (Wls.isPlugged()) { | |||||
| // Serial.println("The Tool is away from WLS"); | |||||
| // } else if (Wls.isUnplugged()) { | |||||
| // Serial.println("The Tool touched the WLS"); | |||||
| // } | |||||
| // } | |||||
| // | |||||
| // if (RedButton.isPressed()) { | |||||
| // Serial.println("Red button was pressed"); | |||||
| // digitalWrite(led_gpio, HIGH); | |||||
| // Serial.print("Limit Switch: "); | |||||
| // Serial.println(digitalRead(LIMIT_SWITCH) ? "HIGH" : "LOW"); | |||||
| // } | |||||
| // | |||||
| // if (RedButton.isLongPressed()) { | |||||
| // Serial.println("Red button was long pressed"); | |||||
| // digitalWrite(led_gpio, LOW); | |||||
| // } | |||||
| // | |||||
| // bool greenPressed = GreenButton.isPressed(); | |||||
| // bool bluePressed = BlueButton.isPressed(); | |||||
| // | |||||
| // if (GreenButton.isPressing() && BlueButton.isPressing()) { | |||||
| // Serial.println("Blue and green button were simultaneous pressed"); | |||||
| // } else if (greenPressed) { | |||||
| // Serial.println("Green button was pressed"); | |||||
| // } else if (bluePressed) { | |||||
| // Serial.println("Blue button was pressed"); | |||||
| // } | |||||
| // | |||||
| // if (RotarySwitch.isPressed()) { | |||||
| // Serial.println("Rotary switch was pressed"); | |||||
| // } | |||||
| // if (RotarySwitch.isLongPressed()) { | |||||
| // Serial.println("Rotary switch long was pressed"); | |||||
| // } | |||||
| // | |||||
| // static int pos = 0; | |||||
| // encoder.tick(); | |||||
| // int newPos = encoder.getPosition(); | |||||
| // if (pos != newPos) { | |||||
| // Serial.print("pos:"); | |||||
| // Serial.print(newPos); | |||||
| // Serial.print(" dir:"); | |||||
| // Serial.println((int) (encoder.getDirection())); | |||||
| // pos = newPos; | |||||
| // } | |||||
| // if (limitSwitchState == LOW) { | // if (limitSwitchState == LOW) { | ||||
| // stepper.setLimitSwitchActive(stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); // this will cause to stop any motion that is currently going on and block further movement in the same direction as long as the switch is agtive | // stepper.setLimitSwitchActive(stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); // this will cause to stop any motion that is currently going on and block further movement in the same direction as long as the switch is agtive | ||||
| } | } | ||||
| void testdrawchar(void) { | |||||
| Display.clearDisplay(); | |||||
| Display.setTextSize(1); // Normal 1:1 pixel scale | |||||
| Display.setTextColor(SSD1306_WHITE); // Draw white text | |||||
| Display.setCursor(0, 0); // Start at top-left corner | |||||
| Display.cp437(true); // Use full 256 char 'Code Page 437' font | |||||
| // Not all the characters will fit on the Display. This is normal. | |||||
| // Library will draw what it can and the rest will be clipped. | |||||
| for (int16_t i = 0; i < 256; i++) { | |||||
| if (i == '\n') | |||||
| Display.write(' '); | |||||
| else | |||||
| Display.write(i); | |||||
| } | |||||
| Display.display(); | |||||
| delay(2000); | |||||
| } | |||||
| void testdrawstyles(void) { | |||||
| Display.clearDisplay(); | |||||
| //void testdrawchar(void) { | |||||
| // OLED.clearDisplay(); | |||||
| // | |||||
| // OLED.setTextSize(1); // Normal 1:1 pixel scale | |||||
| // OLED.setTextColor(SSD1306_WHITE); // Draw white text | |||||
| // OLED.setCursor(0, 0); // Start at top-left corner | |||||
| // OLED.cp437(true); // Use full 256 char 'Code Page 437' font | |||||
| // | |||||
| // // Not all the characters will fit on the Display. This is normal. | |||||
| // // Library will draw what it can and the rest will be clipped. | |||||
| // for (int16_t i = 0; i < 256; i++) { | |||||
| // if (i == '\n') | |||||
| // OLED.write(' '); | |||||
| // else | |||||
| // OLED.write(i); | |||||
| // } | |||||
| // | |||||
| // OLED.display(); | |||||
| // delay(2000); | |||||
| //} | |||||
| // | |||||
| //void testdrawstyles(void) { | |||||
| // OLED.clearDisplay(); | |||||
| // Display.setFont(&Rubik_Regular8pt7b); | // Display.setFont(&Rubik_Regular8pt7b); | ||||
| // Display.setTextSize(1); // Normal 1:1 pixel scale | // Display.setTextSize(1); // Normal 1:1 pixel scale | ||||
| // | // | ||||
| // Display.clearDisplay(); | // Display.clearDisplay(); | ||||
| char decimals[3]; | |||||
| uint16_t w = 0, h = 0; | |||||
| for (int i = 0; i <= 99; i++) { | |||||
| Display.clearDisplay(); | |||||
| Display.setFont(&titillium_web_semibold30pt7b); | |||||
| Display.setTextSize(1); // Normal 1:1 pixel scale | |||||
| Display.setTextColor(SSD1306_WHITE); // Draw white text | |||||
| sprintf(decimals, "%02d", i); | |||||
| if (i < 33) { | |||||
| calculateWH("99.", w, h); | |||||
| Display.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| Display.print("99."); | |||||
| } else if (i >= 33 && i < 66) { | |||||
| calculateWH("01.", w, h); | |||||
| Display.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| Display.print("01."); | |||||
| } else { | |||||
| calculateWH("77.", w, h); | |||||
| Display.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| Display.print("77."); | |||||
| } | |||||
| Display.println(decimals); | |||||
| Display.display(); | |||||
| delay(100); | |||||
| } | |||||
| // char decimals[3]; | |||||
| // uint16_t w = 0, h = 0; | |||||
| // for (int i = 0; i <= 99; i++) { | |||||
| // OLED.clearDisplay(); | |||||
| // OLED.drawRect(0, 0, 128, 64, SSD1306_WHITE); | |||||
| // OLED.setFont(&titillium_web_semibold30pt7b); | |||||
| // OLED.setTextSize(1); // Normal 1:1 pixel scale | |||||
| // OLED.setTextColor(SSD1306_WHITE); // Draw white text | |||||
| // sprintf(decimals, "%02d", i); | |||||
| // if (i < 33) { | |||||
| // calculateWH("99.", w, h); | |||||
| // OLED.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| // OLED.print("99."); | |||||
| // } else if (i >= 33 && i < 66) { | |||||
| // calculateWH("01.", w, h); | |||||
| // OLED.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| // OLED.print("01."); | |||||
| // } else { | |||||
| // calculateWH("55.", w, h); | |||||
| // OLED.setCursor((SCREEN_WIDTH / 2 - 1) - w, SCREEN_HEIGHT / 2 + h / 2); | |||||
| // OLED.print("55."); | |||||
| // } | |||||
| // OLED.println(decimals); | |||||
| // OLED.display(); | |||||
| // delay(100); | |||||
| // } | |||||
| // Display.setFont(&Rubik_Regular30pt7b); | // Display.setFont(&Rubik_Regular30pt7b); | ||||
| // Display.setTextSize(1); // Normal 1:1 pixel scale | // Display.setTextSize(1); // Normal 1:1 pixel scale | ||||
| // Display.setCursor(0, 55); // Start at top-left corner | // Display.setCursor(0, 55); // Start at top-left corner | ||||
| // Display.println(F("01.11")); | // Display.println(F("01.11")); | ||||
| // Display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text | // Display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text | ||||
| // Display.println("3.141592"); | // Display.println("3.141592"); | ||||
| // | // | ||||
| // Display.print(F("0x")); | // Display.print(F("0x")); | ||||
| // Display.println(0xDEADBEEF, HEX); | // Display.println(0xDEADBEEF, HEX); | ||||
| // | // | ||||
| Display.display(); | |||||
| delay(2000); | |||||
| } | |||||
| void calculateWH(String units, uint16_t &w, uint16_t &h) { | |||||
| int x = 0; | |||||
| int y = 0; | |||||
| int16_t x1, y1; | |||||
| uint16_t w1, h1; | |||||
| // OLED.display(); | |||||
| // delay(2000); | |||||
| //} | |||||
| Display.getTextBounds(units, x, y, &x1, &y1, &w1, &h1); | |||||
| w = w1; | |||||
| h = h1; | |||||
| } | |||||
| //void calculateWH(String units, uint16_t &w, uint16_t &h) { | |||||
| // int x = 0; | |||||
| // int y = 0; | |||||
| // int16_t x1, y1; | |||||
| // uint16_t w1, h1; | |||||
| // | |||||
| // OLED.getTextBounds(units, x, y, &x1, &y1, &w1, &h1); | |||||
| // w = w1; | |||||
| // h = h1; | |||||
| //} | |||||
| /* | |||||
| * RouterSetup.cpp | |||||
| * | |||||
| * Created on: 25.01.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #include "RouterSetup.h" | |||||
| /****************** | |||||
| ** Public methods | |||||
| *****************/ | |||||
| float RouterSetup::getSpeed() const { | |||||
| return speed; | |||||
| } | |||||
| void RouterSetup::setSpeed(float speed) { | |||||
| this->speed = speed; | |||||
| } | |||||
| float RouterSetup::getAcceleration() const { | |||||
| return accelleration; | |||||
| } | |||||
| void RouterSetup::setAcceleration(float accelleration) { | |||||
| this->accelleration = accelleration; | |||||
| } | |||||
| uint8_t RouterSetup::getEncoderSpeedFast() const { | |||||
| return encoderSpeedFast; | |||||
| } | |||||
| void RouterSetup::setEncoderSpeedFast(uint8_t encoderSpeedFast) { | |||||
| this->encoderSpeedFast = encoderSpeedFast; | |||||
| } | |||||
| uint8_t RouterSetup::getEncoderSpeedSlow() const { | |||||
| return encoderSpeedSlow; | |||||
| } | |||||
| void RouterSetup::setEncoderSpeedSlow(uint8_t encoderSpeedSlow) { | |||||
| this->encoderSpeedSlow = encoderSpeedSlow; | |||||
| } | |||||
| float RouterSetup::getLevelHeightDiving() const { | |||||
| return levelHeightDiving; | |||||
| } | |||||
| void RouterSetup::setLevelHeightDiving(float levelHeightDiving) { | |||||
| this->levelHeightDiving = levelHeightDiving; | |||||
| } | |||||
| float RouterSetup::getPitch() const { | |||||
| return pitch; | |||||
| } | |||||
| void RouterSetup::setPitch(float pitch) { | |||||
| this->pitch = pitch; | |||||
| } | |||||
| uint16_t RouterSetup::getStepsPerRev() const { | |||||
| return stepsPerRev; | |||||
| } | |||||
| void RouterSetup::setStepsPerRev(uint16_t stepsPerRev) { | |||||
| this->stepsPerRev = stepsPerRev; | |||||
| } | |||||
| float RouterSetup::getToolLenghtSensorHeight() const { | |||||
| return toolLenghtSensorHeight; | |||||
| } | |||||
| void RouterSetup::setToolLenghtSensorHeight(float toolLenghtSensorHeight) { | |||||
| this->toolLenghtSensorHeight = toolLenghtSensorHeight; | |||||
| } | |||||
| bool RouterSetup::isToolChangOnPowerOn() const { | |||||
| return toolChangeOnPowerOn; | |||||
| } | |||||
| void RouterSetup::setToolChangOnPowerOn(bool toolChangOnPowerOn) { | |||||
| this->toolChangeOnPowerOn = toolChangOnPowerOn; | |||||
| } | |||||
| void RouterSetup::clear() { | |||||
| speed = 0; | |||||
| accelleration = 0; | |||||
| stepsPerRev = 0; | |||||
| pitch = 0; | |||||
| toolLenghtSensorHeight = 0; | |||||
| encoderSpeedSlow = 0; | |||||
| encoderSpeedFast = 0; | |||||
| levelHeightDiving = 0; | |||||
| toolChangeOnPowerOn = true; | |||||
| } | |||||
| /** | |||||
| * Reads the RouterSetup from EEPROM | |||||
| */ | |||||
| void RouterSetup::readFromEEPROM() { | |||||
| clear(); | |||||
| eeprom.begin(ROUTER_NAMESPACE, false); | |||||
| setSpeed(eeprom.getFloat(SPEED, 1.0)); | |||||
| setAcceleration(eeprom.getFloat(ACCELERATION, 1.0)); | |||||
| setStepsPerRev(eeprom.getUInt(STEPSPERREV, 1600)); | |||||
| setPitch(eeprom.getInt(PITCH, 3.0)); | |||||
| setToolLenghtSensorHeight(eeprom.getFloat(TOOLLENGHTSNHT, 10.0)); | |||||
| setEncoderSpeedSlow(eeprom.getInt(ENCSPEEDSLOW, 1)); | |||||
| setEncoderSpeedFast(eeprom.getInt(ENCSPEEDFAST, 20)); | |||||
| setLevelHeightDiving(eeprom.getFloat(LVLHEIGHTDIVE, 3.0)); | |||||
| setToolChangOnPowerOn(eeprom.getBool(TOOLCHGONPWRON, true)); | |||||
| eeprom.end(); | |||||
| } | |||||
| /** | |||||
| * Writes the RouterSetup to EEPROM | |||||
| */ | |||||
| void RouterSetup::saveToEEPROM() { | |||||
| eeprom.begin(ROUTER_NAMESPACE, false); | |||||
| eeprom.putFloat(SPEED, getSpeed()); | |||||
| eeprom.putFloat(ACCELERATION, getAcceleration()); | |||||
| eeprom.putUInt(STEPSPERREV, getStepsPerRev()); | |||||
| eeprom.putInt(PITCH, getPitch()); | |||||
| eeprom.putFloat(TOOLLENGHTSNHT, getToolLenghtSensorHeight()); | |||||
| eeprom.putInt(ENCSPEEDSLOW, getEncoderSpeedSlow()); | |||||
| eeprom.putInt(ENCSPEEDFAST, getEncoderSpeedFast()); | |||||
| eeprom.putFloat(LVLHEIGHTDIVE, getLevelHeightDiving()); | |||||
| eeprom.putBool(TOOLCHGONPWRON, isToolChangOnPowerOn()); | |||||
| eeprom.end(); | |||||
| } | |||||
| void RouterSetup::printValues() { | |||||
| Serial.print(String(SPEED) + ": " + String(getSpeed(), 1) + ", "); | |||||
| Serial.print(String(ACCELERATION) + ": " + String(getAcceleration(), 1) + ", "); | |||||
| Serial.print(String(STEPSPERREV) + ": " + String(getStepsPerRev()) + ", "); | |||||
| Serial.print(String(PITCH) + ": " + String(getPitch(), 1) + ", "); | |||||
| Serial.print(String(TOOLLENGHTSNHT) + ": " + String(getToolLenghtSensorHeight(), 2) + ", "); | |||||
| Serial.print(String(ENCSPEEDSLOW) + ": " + String(getEncoderSpeedSlow()) + ", "); | |||||
| Serial.print(String(ENCSPEEDFAST) + ": " + String(getEncoderSpeedFast()) + ", "); | |||||
| Serial.print(String(LVLHEIGHTDIVE) + ": " + String(getLevelHeightDiving(), 2) + ", "); | |||||
| Serial.println(String(TOOLCHGONPWRON) + ": " + String(isToolChangOnPowerOn())); | |||||
| } |
| /* | |||||
| * RouterSetup.h | |||||
| * | |||||
| * Created on: 25.01.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef ROUTER_SETUP_H_ | |||||
| #define ROUTER_SETUP_H_ | |||||
| #include <stdint.h> | |||||
| #include <Preferences.h> | |||||
| const static char ROUTER_NAMESPACE[] = "routerelv_stp"; | |||||
| const static char SPEED[] = "speed"; | |||||
| const static char ACCELERATION[] = "acceleration"; | |||||
| const static char STEPSPERREV[] = "stepsPerRev"; | |||||
| const static char PITCH[] = "pitch"; | |||||
| const static char TOOLLENGHTSNHT[] = "toolLenghtSnHt"; | |||||
| const static char ENCSPEEDSLOW[] = "encSpeedSlow"; | |||||
| const static char ENCSPEEDFAST[] = "encSpeedFast"; | |||||
| const static char LVLHEIGHTDIVE[] = "lvlHeightDive"; | |||||
| const static char TOOLCHGONPWRON[] = "toolChgOnPwrOn"; | |||||
| class RouterSetup { | |||||
| private: | |||||
| Preferences eeprom; | |||||
| float speed; // in revolutions/second (U/s) | |||||
| float accelleration; // in revolutions/second (U/s) | |||||
| uint16_t stepsPerRev; // micro stepping: 200 400 800 1600 3200 6400 | |||||
| float pitch; // in mm | |||||
| float toolLenghtSensorHeight; // in mm | |||||
| uint8_t encoderSpeedSlow; // in 1/100 mm | |||||
| uint8_t encoderSpeedFast; // in 1/100 mm | |||||
| float levelHeightDiving; // in mm | |||||
| bool toolChangeOnPowerOn; // Yes or No | |||||
| public: | |||||
| const static int eeprom_start_adress = 0; | |||||
| const static int eeprom_signatur = 1024; | |||||
| const static uint8_t version = 1; | |||||
| float getSpeed() const; | |||||
| void setSpeed(float speed); | |||||
| float getAcceleration() const; | |||||
| void setAcceleration(float accelleration); | |||||
| uint8_t getEncoderSpeedFast() const; | |||||
| void setEncoderSpeedFast(uint8_t encoderSpeedFast); | |||||
| uint8_t getEncoderSpeedSlow() const; | |||||
| void setEncoderSpeedSlow(uint8_t encoderSpeedSlow); | |||||
| float getLevelHeightDiving() const; | |||||
| void setLevelHeightDiving(float levelHeightDiving); | |||||
| float getPitch() const; | |||||
| void setPitch(float pitch); | |||||
| uint16_t getStepsPerRev() const; | |||||
| void setStepsPerRev(uint16_t stepsPerRev); | |||||
| float getToolLenghtSensorHeight() const; | |||||
| void setToolLenghtSensorHeight(float toolLenghtSensorHeight); | |||||
| bool isToolChangOnPowerOn() const; | |||||
| void setToolChangOnPowerOn(bool toolChangOnPowerOn); | |||||
| void clear(); | |||||
| void readFromEEPROM(); | |||||
| void saveToEEPROM(); | |||||
| void printValues(); | |||||
| }; | |||||
| #endif /* ROUTER_SETUP_H_ */ |
| /* | |||||
| * Status.h | |||||
| * | |||||
| * Created on: 28.01.2022 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef STATUS_H_ | |||||
| #define STATUS_H_ | |||||
| enum Status { | |||||
| INITIALIZATION, TOOL_CHANGE, CONFIGURATION, NULLING, NULLING_TLS, IDLE, DIVING, MOVING_ELEVATOR, RELEASE_SWITCH | |||||
| }; | |||||
| #endif /* STATUS_H_ */ |
| #include "WLS.h" | #include "WLS.h" | ||||
| WLS::WLS(int pin) : | |||||
| WLS(pin, false) { | |||||
| /***************** | |||||
| ** Constructors. | |||||
| ****************/ | |||||
| WLS::WLS(int pin) : WLS(pin, false) { | |||||
| } | } | ||||
| WLS::WLS(int pin, bool _inverted) : | |||||
| ezButton(pin) { | |||||
| WLS::WLS(int pin, bool _inverted) : ezButton(pin) { | |||||
| inverted = _inverted; | inverted = _inverted; | ||||
| } | } | ||||
| /****************** | |||||
| ** Public methods | |||||
| *****************/ | |||||
| bool WLS::isPlugged(void) { | bool WLS::isPlugged(void) { | ||||
| if (inverted) | if (inverted) | ||||
| return isReleased(); | return isReleased(); | ||||
| } | } | ||||
| bool WLS::isConnected(void) { | |||||
| if (inverted) { | |||||
| return getStateRaw() == HIGH; | |||||
| } else { | |||||
| return getStateRaw() == LOW; | |||||
| } | |||||
| } |
| * Autor: Flo Smilari | * Autor: Flo Smilari | ||||
| */ | */ | ||||
| #ifndef WLS_H_ | |||||
| #define WLS_H_ | |||||
| #include <ezButton.h> | #include <ezButton.h> | ||||
| class WLS: public ezButton { | class WLS: public ezButton { | ||||
| private: | private: | ||||
| bool inverted; | |||||
| bool inverted; | |||||
| public: | public: | ||||
| WLS(int pin); | |||||
| WLS(int pin, bool _inverted); | |||||
| bool isPlugged(void); | |||||
| bool isUnplugged(void); | |||||
| WLS(int pin); | |||||
| WLS(int pin, bool _inverted); | |||||
| bool isPlugged(void); | |||||
| bool isUnplugged(void); | |||||
| bool isConnected(void); | |||||
| }; | }; | ||||
| //Added by Sloeber | |||||
| #pragma once | |||||
| //Added by Sloeber | |||||
| #endif | |||||
| // Filename: SFTools-Logo.png | |||||
| // Filesize: 1300 Bytes | |||||
| // Size bitmap: 640 bytes | |||||
| #ifndef _SFTOOLSLOGO_H_ | |||||
| #define _SFTOOLSLOGO_H_ | |||||
| #define imageWidth 128 | |||||
| #define imageHeight 34 | |||||
| // 'SFTools-Logo', 128x34px | |||||
| const unsigned char epd_bitmap_SFTools_Logo [] 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, | |||||
| 0x01, 0xff, 0xfe, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x78, 0xff, 0xf8, | |||||
| 0x07, 0xff, 0xfe, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x73, 0xff, 0xf8, | |||||
| 0x0f, 0xff, 0xfe, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x67, 0xff, 0xf8, | |||||
| 0x1f, 0xff, 0xfe, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x6f, 0xff, 0xf8, | |||||
| 0x1f, 0xff, 0xfe, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x6f, 0xff, 0xf8, | |||||
| 0x1f, 0x80, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0xc0, 0x00, | |||||
| 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x80, 0x00, | |||||
| 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x80, 0x00, | |||||
| 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x80, 0x00, | |||||
| 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x80, 0x00, | |||||
| 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x80, 0x00, | |||||
| 0x1f, 0x80, 0x00, 0xf8, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0xc0, 0x00, | |||||
| 0x1f, 0xff, 0x00, 0xff, 0xfc, 0x00, 0xf8, 0x07, 0xfc, 0x00, 0x3f, 0xe0, 0x1f, 0x0f, 0xff, 0x80, | |||||
| 0x1f, 0xff, 0xc0, 0xff, 0xfc, 0x00, 0xf8, 0x1f, 0xff, 0x00, 0xff, 0xf8, 0x1f, 0x0f, 0xff, 0xe0, | |||||
| 0x1f, 0xff, 0xe0, 0xff, 0xfc, 0x00, 0xf8, 0x3f, 0xff, 0x81, 0xff, 0xfc, 0x1f, 0x0f, 0xff, 0xf0, | |||||
| 0x0f, 0xff, 0xe0, 0xff, 0xfc, 0x00, 0xf8, 0x3f, 0xff, 0x81, 0xff, 0xfc, 0x1f, 0x07, 0xff, 0xf0, | |||||
| 0x07, 0xff, 0xf0, 0xff, 0xfc, 0x00, 0xf8, 0x7f, 0xff, 0xc3, 0xff, 0xfe, 0x1f, 0x03, 0xff, 0xf8, | |||||
| 0x00, 0xff, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7e, 0x0f, 0xc3, 0xf0, 0x7e, 0x1f, 0x00, 0x7f, 0xf8, | |||||
| 0x00, 0x03, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7c, 0x07, 0xc3, 0xe0, 0x3e, 0x1f, 0x00, 0x01, 0xf8, | |||||
| 0x00, 0x01, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7c, 0x07, 0xc3, 0xe0, 0x3e, 0x1f, 0x00, 0x00, 0xf8, | |||||
| 0x00, 0x01, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7c, 0x07, 0xc3, 0xe0, 0x3e, 0x1f, 0x00, 0x00, 0xf8, | |||||
| 0x00, 0x01, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7c, 0x07, 0xc3, 0xe0, 0x3e, 0x1f, 0x00, 0x00, 0xf8, | |||||
| 0x00, 0x01, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7c, 0x07, 0xc3, 0xe0, 0x3e, 0x1f, 0x00, 0x00, 0xf8, | |||||
| 0x00, 0x03, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7e, 0x0f, 0xc3, 0xf0, 0x7e, 0x1f, 0x00, 0x01, 0xf8, | |||||
| 0x1f, 0xff, 0xf0, 0xf8, 0x00, 0x00, 0xf8, 0x7f, 0xff, 0xc3, 0xff, 0xfe, 0x1f, 0x0f, 0xff, 0xf8, | |||||
| 0x1f, 0xff, 0xe0, 0xf8, 0x00, 0x00, 0xf8, 0x3f, 0xff, 0x81, 0xff, 0xfc, 0x1f, 0x0f, 0xff, 0xf0, | |||||
| 0x1f, 0xff, 0xe0, 0xf8, 0x00, 0x00, 0xf8, 0x3f, 0xff, 0x81, 0xff, 0xfc, 0x1f, 0x0f, 0xff, 0xf0, | |||||
| 0x1f, 0xff, 0xc0, 0xf8, 0x00, 0x00, 0xf8, 0x1f, 0xff, 0x00, 0xff, 0xf8, 0x1f, 0x0f, 0xff, 0xe0, | |||||
| 0x1f, 0xff, 0x80, 0xf8, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x00, 0x3f, 0xe0, 0x1f, 0x0f, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |||||
| }; | |||||
| // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 560) | |||||
| //const int epd_bitmap_allArray_LEN = 1; | |||||
| //const unsigned char *epd_bitmap_allArray[1] = { | |||||
| // epd_bitmap_SFTools_Logo | |||||
| //}; | |||||
| #endif |
| //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-01-23 21:46:12 | |||||
| //This file has been generated on 2022-02-02 13:52:27 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <Arduino.h> | #include <Arduino.h> | ||||
| #include <RotaryEncoder.h> | #include <RotaryEncoder.h> | ||||
| #include "WLS.h" | |||||
| #include "ExEzButton.h" | |||||
| #include <Wire.h> | #include <Wire.h> | ||||
| #include <Adafruit_GFX.h> | #include <Adafruit_GFX.h> | ||||
| #include <Adafruit_SSD1306.h> | |||||
| #include <ESP_FlexyStepper.h> | #include <ESP_FlexyStepper.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 "Display.h" | |||||
| #include "WLS.h" | |||||
| #include "ExEzButton.h" | |||||
| #include "RouterSetup.h" | |||||
| #include "Status.h" | |||||
| void printStatus(String actualStatus) ; | |||||
| void limitSwitchHandler() ; | void limitSwitchHandler() ; | ||||
| void Initialize() ; | |||||
| void setup() ; | void setup() ; | ||||
| void loop() ; | void loop() ; | ||||
| void testdrawchar(void) ; | |||||
| void testdrawstyles(void) ; | |||||
| void calculateWH(String units, uint16_t &w, uint16_t &h) ; | |||||
| #include "Fraestisch_SFTools.ino" | #include "Fraestisch_SFTools.ino" | ||||