Переглянути джерело

Optimized display refresh rate

master
Flo Smilari 3 роки тому
джерело
коміт
a0533b9132
5 змінених файлів з 130 додано та 239 видалено
  1. 27
    12
      Display.cpp
  2. 2
    0
      Display.h
  3. 44
    211
      Fraestisch_SFTools.ino
  4. 55
    15
      RouterSetup.cpp
  5. 2
    1
      sloeber.ino.cpp

+ 27
- 12
Display.cpp Переглянути файл

@@ -9,7 +9,6 @@
#include "Display.h"
/*****************
** Constructors.
****************/
@@ -19,6 +18,7 @@ Display::Display() {
wlsConnected = false;
angle = 0;
starttime = millis();
refreshScreen = true;
}
/******************
@@ -33,7 +33,10 @@ void Display::init() {
}
void Display::display() {
ssd1306.display();
if (refreshScreen) {
refreshScreen = false;
ssd1306.display();
}
}
void Display::clearDisplay() {
@@ -73,6 +76,7 @@ void Display::showInitialization() {
for (int i = 0; i < 6; i++) {
g = &gauge[0];
u8g2_gfx.print(g);
setRefreshScreen();
display();
delay(500);
if (i < 4) {
@@ -85,7 +89,6 @@ void Display::showInitialization() {
}
}
void Display::showFrame(Status status) {
switch (status) {
case MOVING_ELEVATOR:
@@ -100,7 +103,7 @@ void Display::showFrame(Status status) {
case CONFIGURATION:
redrawFrame();
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(this->configText);
drawConfigOption(this->configOption);
break;
@@ -110,7 +113,7 @@ void Display::showFrame(Status status) {
drawStatusText(STATUS_TXT_IDLE);
break;
case NULLING:
case NULLING_TLS:
case NULLING_TLS:
redrawFrame();
drawStatusText(STATUS_TXT_NULLING);
drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling);
@@ -149,19 +152,28 @@ const String& Display::getConfigOption() const {
}
void Display::setConfigOption(const String &configOption) {
this->configOption = configOption;
if (!this->configOption.equals(configOption)) {
this->configOption = configOption;
setRefreshScreen();
}
}
const String& Display::getConfigText() const {
return configText;
}
void Display::setWlsConnected(bool wlsConnected) {
this->wlsConnected = wlsConnected;
void Display::setConfigText(const String &configText) {
if (!this->configText.equals(configText)) {
this->configText = configText;
setRefreshScreen();
}
}
void Display::setConfigText(const String &configText) {
this->configText = configText;
void Display::setWlsConnected(bool wlsConnected) {
if (this->wlsConnected != wlsConnected) {
this->wlsConnected = wlsConnected;
setRefreshScreen();
}
}
void Display::drawWLSStatus() {
@@ -175,7 +187,6 @@ void Display::drawWLSStatus() {
u8g2_gfx.println(F(s));
}
/********************************
** Private methods
*******************************/
@@ -189,7 +200,6 @@ void Display::drawStatusText(String txt) {
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);
}
@@ -248,6 +258,11 @@ void Display::rotateAndDrawRotationBitmap() {
drawBitmap((37 - imageSide_R) / 2, 30, imageSide_R, imageSide_R, epd_rotate_bitmap_allArray[angle]);
angle = (angle + 1) % 8;
starttime = millis();
setRefreshScreen();
display();
}
}
void Display::setRefreshScreen() {
refreshScreen = true;
}

+ 2
- 0
Display.h Переглянути файл

@@ -36,6 +36,7 @@ class Display {
String configText;
String configOption;
bool wlsConnected;
bool refreshScreen;
int angle;
unsigned long starttime;
@@ -60,6 +61,7 @@ class Display {
const String& getConfigText() const;
void setConfigText(const String &configText);
void setWlsConnected(bool wlsConnected);
void setRefreshScreen();
};
#endif /* DISPLAY_H_ */

+ 44
- 211
Fraestisch_SFTools.ino Переглянути файл

@@ -71,6 +71,19 @@ Status actualStatus;
Status originStatus;
String oldStatus = "";

//********************* Rotary test **************

long TimeOfLastDebounce = 0;
long DelayofDebounce = 5;

// Store previous Pins state
int PreviousCLK;
int PreviousDATA;

int displaycounter = 0; // Store current counter value
volatile boolean TurnDetected;


void printStatus(String actualStatus) {
if (!oldStatus.equals(actualStatus)) {
Serial.println(actualStatus);
@@ -108,9 +121,9 @@ void Initialize() {
}

if (Router_Setup.isToolChangOnPowerOn()) {
actualStatus = TOOL_CHANGE;
SetActualStatus(TOOL_CHANGE);
} else {
actualStatus = IDLE;
SetActualStatus(IDLE);
}
}

@@ -119,7 +132,7 @@ void Initialize() {
//**********************
void setup() {

actualStatus = INITIALIZATION;
SetActualStatus(INITIALIZATION);

Wire.begin(SDA, SCX);

@@ -131,9 +144,9 @@ void setup() {
pinMode(GreenBtn_Pin, INPUT);
pinMode(RedBtn_Pin, INPUT);
pinMode(BlueBtn_Pin, INPUT);
pinMode(RotEnc_Switch_Pin, INPUT);
pinMode(RotEnc_Clk_Pin, INPUT);
pinMode(RotEnc_Dta_Pin, INPUT);
pinMode(RotEnc_Switch_Pin, INPUT_PULLUP);
// pinMode(RotEnc_Clk_Pin, INPUT_PULLUP);
// pinMode(RotEnc_Dta_Pin, INPUT_PULLUP);
pinMode(LIMIT_SWITCH, INPUT);

RedButton.setDebounceTime(50); // set debounce time to 50 millis
@@ -144,8 +157,10 @@ void setup() {
RotaryControler.setDebounceTime(50);

delay(1500);
Display.setRefreshScreen();
Display.showBrand();
delay(1500);
Display.setRefreshScreen();
Initialize();
}

@@ -174,14 +189,14 @@ void loop() {
originStatus = TOOL_CHANGE;
if (intermediateState == 0) {
Router_Elevator.moveToUpperLimitSwitch();
actualStatus = MOVING_ELEVATOR;
SetActualStatus(MOVING_ELEVATOR);
intermediateState = 1;
} else if (intermediateState == 1) {
if (RotaryControler.isSwitchLongPressed()) {
actualStatus = CONFIGURATION;
SetActualStatus(CONFIGURATION);
intermediateState = 0;
} else if (BlueButton.isPressed()) {
actualStatus = IDLE;
SetActualStatus(IDLE);
intermediateState = 0;
}
}
@@ -195,9 +210,9 @@ void loop() {
Router_Setup.onRotaryControlerSwitch();
} else if (RotaryControler.isSwitchLongPressed()) {
Router_Setup.onRotaryControlerLongSwitch();
actualStatus = INITIALIZATION;
SetActualStatus(INITIALIZATION);
} else if (BlueButton.isPressed()) {
actualStatus = IDLE;
SetActualStatus(IDLE);
}
break;

@@ -205,7 +220,7 @@ void loop() {
printStatus("NULLING");
if (RedButton.isPressed()) {
Router_Elevator.setZeroPosition();
actualStatus = IDLE;
SetActualStatus(IDLE);
}
break;

@@ -215,14 +230,14 @@ void loop() {
printStatus("NULLING_TLS,0");
//Move elevator to lowest point (lower limit switch triggers)
Router_Elevator.moveToLowerLimitSwitch();
actualStatus = MOVING_ELEVATOR;
SetActualStatus(MOVING_ELEVATOR);
intermediateState = 1;
} else if (intermediateState == 1) {
printStatus("NULLING_TLS,1");
if (RedButton.isPressed()) {
//Move elevator until it touch the TLS (WLS_PIN goes HIGH)
Router_Elevator.moveToUpperLimitSwitch();
actualStatus = MOVING_ELEVATOR;
SetActualStatus(MOVING_ELEVATOR);
intermediateState = 2;
}
} else if (intermediateState == 2) {
@@ -231,13 +246,13 @@ void loop() {
Router_Elevator.clearLimitSwitch();
Router_Elevator.moveRelativeInMillimeters(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD);
Serial.println(String(Router_Setup.getToolLenghtSensorHeight() * MOVE_DOWNWARD, 2));
actualStatus = MOVING_ELEVATOR;
SetActualStatus(MOVING_ELEVATOR);
intermediateState = 3;
} else { // nullingTLS_intermediateState is 3
printStatus("NULLING_TLS,3");
//Set the 0-Position as actual position
Router_Elevator.setZeroPosition();
actualStatus = IDLE;
SetActualStatus(IDLE);
intermediateState = 0;
}
break;
@@ -246,12 +261,12 @@ void loop() {
printStatus("IDLE");
if (RedButton.isLongPressed()) {
if (WlsDetect.isConnected()) {
actualStatus = NULLING_TLS;
SetActualStatus(NULLING_TLS);
} else {
actualStatus = NULLING;
SetActualStatus(NULLING);
}
} else if (BlueButton.isLongPressed()) {
actualStatus = TOOL_CHANGE;
SetActualStatus(TOOL_CHANGE);
}
break;

@@ -262,13 +277,13 @@ void loop() {
printStatus("MOVING_ELEVATOR");
if (Router_Elevator.isLimitSwitchTriggerd()) {
delay(200);
actualStatus = RELEASE_SWITCH;
SetActualStatus(RELEASE_SWITCH);
} else { // limitSwitchState is HIGH
if (Router_Elevator.isTargetPositionReached()) {
actualStatus = originStatus;
SetActualStatus(originStatus);
delay(200);
} else if (Router_Elevator.isWLSTriggerd()) {
actualStatus = originStatus;
SetActualStatus(originStatus);
delay(200);
}
Router_Elevator.clearLimitSwitch();
@@ -281,200 +296,18 @@ void loop() {
if (Router_Elevator.isLimitSwitchTriggerd()) {
Router_Elevator.tryReleaseLimitSwitch();
} else {
actualStatus = originStatus;
SetActualStatus(originStatus);
}
break;

default:
break;
}

//*********************** OLD EXAMPLE AND EXPERIMENTAL CODE ************************************

// 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;
//RotaryControler.tick();
//int newPos = RotaryControler.getPosition();
// if (pos != newPos) {
// Serial.print("pos:");
// Serial.print(newPos);
// Serial.print(" dir:");
// Serial.println((int) (RotaryControler.getDirection()));
// pos = newPos;
// }

// 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
// } else {
// stepper.clearLimitSwitchActive(); // clear the limit switch flag to allow movement in both directions again
// }
//
// if (limitSwitchState == HIGH && stepper.getDistanceToTargetSigned() == 0) {
// delay(100);
// previousDirection *= -1;
// long relativeTargetPosition = DISTANCE_TO_TRAVEL_IN_STEPS * previousDirection;
// Serial.printf("Moving stepper by %ld steps\n", relativeTargetPosition);
// stepper.setTargetPositionRelativeInSteps(relativeTargetPosition);
// }

}

//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.setTextSize(1); // Normal 1:1 pixel scale
// Display.setTextColor(SSD1306_WHITE); // Draw white text
// Display.setCursor(0, 8); // Start at top-left corner
// Display.println(F("Hello, world!"));
//
// Display.setFont(&Rubik_Regular12pt7b);
// Display.setTextSize(1); // Normal 1:1 pixel scale
// Display.setTextColor(SSD1306_WHITE); // Draw white text
// Display.setCursor(0, 24); // Start at top-left corner
// Display.println(F("Hello, world!"));

// Display.drawRect(0, 15, 128, 13, SSD1306_WHITE);

// Display.setFont(&Rubik_Regular24pt7b);
// Display.setTextSize(1); // Normal 1:1 pixel scale
// Display.setTextColor(SSD1306_WHITE); // Draw white text
// Display.setCursor(0, 55); // Start at top-left corner
// Display.println(F("Hello, world!"));
//
// Display.display();
// delay(2000);
//
// Display.clearDisplay();

// 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.setTextSize(1); // Normal 1:1 pixel scale
// Display.setTextColor(SSD1306_WHITE); // Draw white text
// Display.setCursor(0, 55); // Start at top-left corner
// Display.println(F("99.99"));
//
// Display.display();
// delay(1000);
//
// Display.clearDisplay();
//
// Display.setFont(&Rubik_Regular30pt7b);
// Display.setTextSize(1); // Normal 1:1 pixel scale
// Display.setTextColor(SSD1306_WHITE); // Draw white text
// Display.setCursor(0, 55); // Start at top-left corner
// Display.println(F("01.11"));

// Display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
// Display.println("3.141592");
//
// Display.setTextSize(2); // Draw 2X-scale text
// Display.setTextColor(SSD1306_WHITE);
// Display.print(F("0x"));
// Display.println(0xDEADBEEF, HEX);
//
// OLED.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.getTextBounds(units, x, y, &x1, &y1, &w1, &h1);
// w = w1;
// h = h1;
//}

void SetActualStatus(Status newStatus) {
if (actualStatus != newStatus) {
actualStatus = newStatus;
Display.setRefreshScreen();
}
}

+ 55
- 15
RouterSetup.cpp Переглянути файл

@@ -12,8 +12,8 @@
** Constructors
*****************/
RouterSetup::RouterSetup(Display &_display) : display(_display) {
this->doInitialization = true;
this->configStepIndex = 0;
doInitialization = true;
configStepIndex = 0;
}
/******************
@@ -114,7 +114,7 @@ void RouterSetup::readFromEEPROM() {
setSpeed(eeprom.getFloat(SPEED, 1.0));
setAcceleration(eeprom.getFloat(ACCELERATION, 1.0));
setStepsPerRev(eeprom.getUInt(STEPSPERREV, 1600));
setPitch(eeprom.getInt(PITCH, 3.0));
setPitch(eeprom.getFloat(PITCH, 3.0));
setToolLenghtSensorHeight(eeprom.getFloat(TOOLLENGHTSNHT, 10.0));
setEncoderSpeedSlow(eeprom.getInt(ENCSPEEDSLOW, 1));
setEncoderSpeedFast(eeprom.getInt(ENCSPEEDFAST, 20));
@@ -131,7 +131,7 @@ void RouterSetup::saveToEEPROM() {
eeprom.putFloat(SPEED, getSpeed());
eeprom.putFloat(ACCELERATION, getAcceleration());
eeprom.putUInt(STEPSPERREV, getStepsPerRev());
eeprom.putInt(PITCH, getPitch());
eeprom.putFloat(PITCH, getPitch());
eeprom.putFloat(TOOLLENGHTSNHT, getToolLenghtSensorHeight());
eeprom.putInt(ENCSPEEDSLOW, getEncoderSpeedSlow());
eeprom.putInt(ENCSPEEDFAST, getEncoderSpeedFast());
@@ -161,7 +161,7 @@ void RouterSetup::initialize() {
option.trim();
display.setConfigText(stepTxt);
display.setConfigOption(option);
this->doInitialization = false;
doInitialization = false;
}
}
@@ -176,21 +176,61 @@ void RouterSetup::onRotaryControlerSwitch() {
}
void RouterSetup::onRotaryControlerLongSwitch() {
saveToEEPROM();
this->doInitialization = true;
doInitialization = true;
}
void RouterSetup::onRotaryControlerTurn(RotaryEncoder::Direction turn) {
switch (turn) {
case RotaryEncoder::Direction::CLOCKWISE:
break;
case RotaryEncoder::Direction::COUNTERCLOCKWISE:
break;
default:
break;
}
if (turn != RotaryEncoder::Direction::NOROTATION) {
String value = "";
int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1;
String unit = getCfgOptUnitForStepIndex(configStepIndex);
switch (configStepIndex) {
case 0:
setSpeed(getSpeed() + 0.1 * sign);
value = String(getSpeed(), 1);
break;
case 1:
setAcceleration(getAcceleration() + 0.1 * sign);
value = String(getAcceleration(), 1);
break;
case 2:
setStepsPerRev(getStepsPerRev() + 1 * sign);
value = String(getStepsPerRev());
break;
case 3:
setPitch(getPitch() + 0.1 * sign);
value = String(getPitch(), 1);
break;
case 4:
setToolLenghtSensorHeight(getToolLenghtSensorHeight() + 0.01 * sign);
value = String(getToolLenghtSensorHeight(), 2);
break;
case 5:
setEncoderSpeedSlow(getEncoderSpeedSlow() + 1 * sign);
value = String(getEncoderSpeedSlow());
break;
case 6:
setEncoderSpeedFast(getEncoderSpeedFast() + 1 * sign);
value = String(getEncoderSpeedFast());
break;
case 7:
setLevelHeightDiving(getLevelHeightDiving() + 0.1 * sign);
value = String(getLevelHeightDiving(), 1);
break;
case 8:
setToolChangOnPowerOn(sign > 0 ? true : false);
value = isToolChangOnPowerOn() ? "JA" : "NEIN";
break;
default:
break;
}
display.setConfigOption(value + " " + unit);
}
}
String RouterSetup::getCfgOptForStepIndex(byte configStepIndex) {

+ 2
- 1
sloeber.ino.cpp Переглянути файл

@@ -2,7 +2,7 @@
//This is a automatic generated file
//Please do not modify this file
//If you touch this file your change will be overwritten during the next build
//This file has been generated on 2022-02-15 23:07:21
//This file has been generated on 2022-02-21 23:07:49

#include "Arduino.h"
#include <Arduino.h>
@@ -26,6 +26,7 @@ void limitSwitchHandler() ;
void Initialize() ;
void setup() ;
void loop() ;
void SetActualStatus(Status newStatus) ;

#include "Fraestisch_SFTools.ino"


Завантаження…
Відмінити
Зберегти