소스 검색

display routines

master
Flo Smilari 3 년 전
부모
커밋
7335182fb0
4개의 변경된 파일122개의 추가작업 그리고 45개의 파일을 삭제
  1. 52
    0
      Display.cpp
  2. 13
    1
      Display.h
  3. 48
    40
      Fraestisch_SFTools.ino
  4. 9
    4
      sloeber.ino.cpp

+ 52
- 0
Display.cpp 파일 보기

} }
} }
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) {
case TOOL_CHANGE:
drawStatusText(STATUS_TXT_TOOLCHG);
break;
case CONFIGURATION:
ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
drawStatusText (STATUS_TXT_CFG);
drawConfigText("Steigung");
drawConfigOption("03.00 mm");
break;
case IDLE:
ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
drawStatusText(STATUS_TXT_IDLE);
break;
default:
break;
}
display();
}
/******************************** /********************************
** Private methods ** Private methods
*******************************/ *******************************/
w = w1; w = w1;
h = h1; h = h1;
} }
void Display::drawStatusText(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_regular8pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((37 - w) / 2, 11);
ssd1306.println(txt);
}
void Display::drawConfigText(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_semibold12pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1);
ssd1306.println(txt);
}
void Display::drawConfigOption(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_semibold12pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
ssd1306.println(txt);
}

+ 13
- 1
Display.h 파일 보기

#ifndef DISPLAY_H_ #ifndef DISPLAY_H_
#define DISPLAY_H_ #define DISPLAY_H_
#include<Adafruit_SSD1306.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h> #include <stdint.h>
#include "fonts/titillium_web_6pt7b.h" #include "fonts/titillium_web_6pt7b.h"
#include "fonts/titillium_web_8pt7b.h" #include "fonts/titillium_web_8pt7b.h"
#include "fonts/titillium_web_24pt7b.h" #include "fonts/titillium_web_24pt7b.h"
#include "fonts/titillium_web_30pt7b.h" #include "fonts/titillium_web_30pt7b.h"
#include "fonts/SFToolsLogo.h" #include "fonts/SFToolsLogo.h"
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include "Status.h"
#define SCREEN_WIDTH 128 #define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64 #define SCREEN_HEIGHT 64
#define SCREEN_ADDRESS 0x3C #define SCREEN_ADDRESS 0x3C
#define STATUS_TXT_IDLE "OPR"
#define STATUS_TXT_TOOLCHG "WZW"
#define STATUS_TXT_CFG "SETUP"
class Display { class Display {
private: private:
Adafruit_SSD1306 ssd1306; Adafruit_SSD1306 ssd1306;
void calculateWH(String units, uint16_t &w, uint16_t &h); void calculateWH(String units, uint16_t &w, uint16_t &h);
void drawStatusText(String txt);
void drawConfigText(String txt);
void drawConfigOption(String txt);
public: public:
Display(); Display();
void init(void); void init(void);
void clearDisplay(void); void clearDisplay(void);
void showBrand(void); void showBrand(void);
void showInitialization(void); void showInitialization(void);
void showFrame(Status status);
}; };
#endif /* DISPLAY_H_ */ #endif /* DISPLAY_H_ */

+ 48
- 40
Fraestisch_SFTools.ino 파일 보기

*/ */


#include <Arduino.h> #include <Arduino.h>
#include <esp32-hal.h>
#include <esp32-hal-gpio.h>
#include <ESP_FlexyStepper.h>
#include <HardwareSerial.h>
#include <pins_arduino.h>
#include <RotaryEncoder.h> #include <RotaryEncoder.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h>
#include <ESP_FlexyStepper.h>
#include <WString.h>
#include "Display.h" #include "Display.h"
#include "WLS.h"
#include "ExEzButton.h" #include "ExEzButton.h"
#include "RotaryControler.h"
#include "RouterSetup.h" #include "RouterSetup.h"
#include "Status.h" #include "Status.h"
#include "WLS.h"


#define SDA 22 #define SDA 22
#define SCX 23 #define SCX 23
ExEzButton RedButton(RedBtn_Pin, false, 2000); ExEzButton RedButton(RedBtn_Pin, false, 2000);
ExEzButton GreenButton(GreenBtn_Pin, false, 2000); ExEzButton GreenButton(GreenBtn_Pin, false, 2000);
ExEzButton BlueButton(BlueBtn_Pin, false, 2000); ExEzButton BlueButton(BlueBtn_Pin, false, 2000);
ExEzButton RotarySwitch(RotEnc_Switch_Pin, true, 2000);
//ExEzButton RotarySwitch(RotEnc_Switch_Pin, true, 2000);


WLS WlsDetect(WLS_DETECT_Pin, true); WLS WlsDetect(WLS_DETECT_Pin, true);
WLS Wls(WLS_Pin); WLS Wls(WLS_Pin);


RotaryEncoder encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotaryEncoder::LatchMode::FOUR3);
RotaryControler RotaryControler(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotEnc_Switch_Pin);
Display Display; Display Display;
ESP_FlexyStepper stepper;
RouterSetup routerSetup;
ESP_FlexyStepper Stepper;
RouterSetup Router_Setup;


Status actualStatus; Status actualStatus;
Status originStatus; Status originStatus;
//*** Initialization routine. Reads the eeprom first and sets the (potentially new) configured values. //*** Initialization routine. Reads the eeprom first and sets the (potentially new) configured values.
//***************************************************************************************************** //*****************************************************************************************************
void Initialize() { void Initialize() {
routerSetup.readFromEEPROM();
routerSetup.printValues();
Router_Setup.readFromEEPROM();
Router_Setup.printValues();


Display.showInitialization(); Display.showInitialization();
//attach an interrupt to the IO pin of the limit switch and specify the handler function //attach an interrupt to the IO pin of the limit switch and specify the handler function
attachInterrupt(digitalPinToInterrupt(LIMIT_SWITCH), limitSwitchHandler, CHANGE); attachInterrupt(digitalPinToInterrupt(LIMIT_SWITCH), limitSwitchHandler, CHANGE);
stepper.connectToPins(STEP, DIR);
Stepper.connectToPins(STEP, DIR);
// set the speed and acceleration rates for the stepper motor // 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()) {
Stepper.setSpeedInStepsPerSecond(Router_Setup.getSpeed() * Router_Setup.getStepsPerRev());
Stepper.setStepsPerRevolution(Router_Setup.getStepsPerRev());
Stepper.setStepsPerMillimeter(Router_Setup.getStepsPerRev() / Router_Setup.getPitch());
Stepper.setAccelerationInStepsPerSecondPerSecond(Router_Setup.getAcceleration() * Router_Setup.getStepsPerRev());
Stepper.setDecelerationInStepsPerSecondPerSecond(Router_Setup.getAcceleration() * Router_Setup.getStepsPerRev());
Stepper.startAsService(0);
if (Router_Setup.isToolChangOnPowerOn()) {
actualStatus = TOOL_CHANGE; actualStatus = TOOL_CHANGE;
} else { } else {
actualStatus = IDLE; actualStatus = IDLE;
BlueButton.setDebounceTime(50); BlueButton.setDebounceTime(50);
WlsDetect.setDebounceTime(50); WlsDetect.setDebounceTime(50);
Wls.setDebounceTime(50); Wls.setDebounceTime(50);
RotarySwitch.setDebounceTime(50);
RotaryControler.setDebounceTime(50);


delay(1500); delay(1500);
Display.showBrand(); Display.showBrand();
BlueButton.loop(); BlueButton.loop();
WlsDetect.loop(); WlsDetect.loop();
Wls.loop(); Wls.loop();
RotarySwitch.loop();
RotaryControler.loop();

Display.showFrame(actualStatus);


switch (actualStatus) { switch (actualStatus) {




case TOOL_CHANGE: case TOOL_CHANGE:
printStatus("TOOL_CHANGE"); printStatus("TOOL_CHANGE");
if (RotarySwitch.isLongPressed()) {
if (RotaryControler.isSwitchLongPressed()) {
actualStatus = CONFIGURATION; actualStatus = CONFIGURATION;
} else if (BlueButton.isPressed()) { } else if (BlueButton.isPressed()) {
actualStatus = IDLE; actualStatus = IDLE;


case CONFIGURATION: case CONFIGURATION:
printStatus("CONFIGURATION"); printStatus("CONFIGURATION");
if (RotarySwitch.isLongPressed()) {
if (RotaryControler.isSwitchLongPressed()) {
actualStatus = INITIALIZATION; actualStatus = INITIALIZATION;
} else if (BlueButton.isPressed()) { } else if (BlueButton.isPressed()) {
actualStatus = IDLE; actualStatus = IDLE;
case NULLING: case NULLING:
printStatus("NULLING"); printStatus("NULLING");
if (RedButton.isPressed()) { if (RedButton.isPressed()) {
stepper.setCurrentPositionInMillimeters(0);
stepper.setTargetPositionRelativeInMillimeters(0);
Stepper.setCurrentPositionInMillimeters(0);
Stepper.setTargetPositionRelativeInMillimeters(0);
actualStatus = IDLE; actualStatus = IDLE;
} }
break; break;
if (nullingTLS_intermediateState == 0) { if (nullingTLS_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)
stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_DOWNWARD);
Stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_DOWNWARD);
actualStatus = MOVING_ELEVATOR; actualStatus = MOVING_ELEVATOR;
nullingTLS_intermediateState = 1; nullingTLS_intermediateState = 1;
} else if (nullingTLS_intermediateState == 1) { } else if (nullingTLS_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)
stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_UPWARD);
Stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_UPWARD);
actualStatus = MOVING_ELEVATOR; actualStatus = MOVING_ELEVATOR;
nullingTLS_intermediateState = 2; nullingTLS_intermediateState = 2;
} }
} else if (nullingTLS_intermediateState == 2) { } else if (nullingTLS_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)
stepper.clearLimitSwitchActive();
stepper.setTargetPositionRelativeInMillimeters(routerSetup.getToolLenghtSensorHeight() * MOVE_DOWNWARD);
Serial.println(String(routerSetup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2));
Stepper.clearLimitSwitchActive();
Stepper.setTargetPositionRelativeInMillimeters(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD);
Serial.println(String(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2));
actualStatus = MOVING_ELEVATOR; actualStatus = MOVING_ELEVATOR;
nullingTLS_intermediateState = 3; nullingTLS_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
stepper.setCurrentPositionInMillimeters(0);
stepper.setTargetPositionRelativeInMillimeters(0);
Stepper.setCurrentPositionInMillimeters(0);
Stepper.setTargetPositionRelativeInMillimeters(0);
actualStatus = IDLE; actualStatus = IDLE;
nullingTLS_intermediateState = 0; nullingTLS_intermediateState = 0;
} }
printStatus("MOVING_ELEVATOR"); printStatus("MOVING_ELEVATOR");
if (limitSwitchState == LOW) { 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 // 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);
Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END);
delay(200); delay(200);
actualStatus = RELEASE_SWITCH; actualStatus = RELEASE_SWITCH;
} else { // limitSwitchState is HIGH } else { // limitSwitchState is HIGH
if (stepper.getDistanceToTargetSigned() == 0) {
if (Stepper.getDistanceToTargetSigned() == 0) {
actualStatus = originStatus; actualStatus = originStatus;
delay(200); delay(200);
} else if (WlsDetect.isConnected()) { } else if (WlsDetect.isConnected()) {
if (Wls.isPlugged()) { if (Wls.isPlugged()) {
Serial.println("The Tool is away from WLS"); Serial.println("The Tool is away from WLS");
stepper.clearLimitSwitchActive();
Stepper.clearLimitSwitchActive();
} else if (Wls.isUnplugged()) { } else if (Wls.isUnplugged()) {
Serial.println("The Tool touched the WLS"); Serial.println("The Tool touched the WLS");
stepper.setLimitSwitchActive(stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END);
Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END);
actualStatus = originStatus; actualStatus = originStatus;
delay(200); delay(200);
} }
} }
stepper.clearLimitSwitchActive();
previousDirection = stepper.getDirectionOfMotion();
Stepper.clearLimitSwitchActive();
previousDirection = Stepper.getDirectionOfMotion();
} }
break; break;


case RELEASE_SWITCH: case RELEASE_SWITCH:
if (limitSwitchState == LOW) { if (limitSwitchState == LOW) {
stepper.moveRelativeInMillimeters(0.05 * previousDirection * -1); // move in opposite direction (away from switch)
Stepper.moveRelativeInMillimeters(0.05 * previousDirection * -1); // move in opposite direction (away from switch)
} else { } else {
actualStatus = originStatus; actualStatus = originStatus;
} }
// } // }
// //
// static int pos = 0; // static int pos = 0;
// encoder.tick();
// int newPos = encoder.getPosition();
//RotaryControler.tick();
//int newPos = RotaryControler.getPosition();
// if (pos != newPos) { // if (pos != newPos) {
// Serial.print("pos:"); // Serial.print("pos:");
// Serial.print(newPos); // Serial.print(newPos);
// Serial.print(" dir:"); // Serial.print(" dir:");
// Serial.println((int) (encoder.getDirection()));
// Serial.println((int) (RotaryControler.getDirection()));
// pos = newPos; // pos = newPos;
// } // }



+ 9
- 4
sloeber.ino.cpp 파일 보기

//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-02 13:52:27
//This file has been generated on 2022-02-04 21:44:36


#include "Arduino.h" #include "Arduino.h"
#include <Arduino.h> #include <Arduino.h>
#include <esp32-hal.h>
#include <esp32-hal-gpio.h>
#include <ESP_FlexyStepper.h>
#include <HardwareSerial.h>
#include <pins_arduino.h>
#include <RotaryEncoder.h> #include <RotaryEncoder.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h>
#include <ESP_FlexyStepper.h>
#include <WString.h>
#include "Display.h" #include "Display.h"
#include "WLS.h"
#include "ExEzButton.h" #include "ExEzButton.h"
#include "RotaryControler.h"
#include "RouterSetup.h" #include "RouterSetup.h"
#include "Status.h" #include "Status.h"
#include "WLS.h"


void printStatus(String actualStatus) ; void printStatus(String actualStatus) ;
void limitSwitchHandler() ; void limitSwitchHandler() ;

Loading…
취소
저장