schaltuhr und temp lohik
This commit is contained in:
parent
38e76e1e6f
commit
bad613780e
1 changed files with 47 additions and 18 deletions
39
main.ino
39
main.ino
|
|
@ -26,6 +26,7 @@ FastAccelStepper *stepper = NULL;
|
||||||
|
|
||||||
// ################ Variabeln ################
|
// ################ Variabeln ################
|
||||||
const uint32_t MAX_SPEED_HZ = 106000;
|
const uint32_t MAX_SPEED_HZ = 106000;
|
||||||
|
const int32_t COLDTEMP_C = 50;
|
||||||
|
|
||||||
bool clickPlus = 0;
|
bool clickPlus = 0;
|
||||||
bool clickMinus = 0;
|
bool clickMinus = 0;
|
||||||
|
|
@ -38,7 +39,7 @@ int32_t lastControl = 0;
|
||||||
uint32_t lastPlotTime = 0;
|
uint32_t lastPlotTime = 0;
|
||||||
|
|
||||||
uint32_t lastDispTime = 0;
|
uint32_t lastDispTime = 0;
|
||||||
bool stop = false;
|
bool autoStop = false;
|
||||||
bool bSettings = false;
|
bool bSettings = false;
|
||||||
uint32_t curTemp = 0;
|
uint32_t curTemp = 0;
|
||||||
|
|
||||||
|
|
@ -52,7 +53,7 @@ struct settings{
|
||||||
int endMin = 0;
|
int endMin = 0;
|
||||||
bool timerEnabled = false;
|
bool timerEnabled = false;
|
||||||
bool editMaxTemp = false;
|
bool editMaxTemp = false;
|
||||||
int maxTemp = 50; //in °C
|
int maxTemp = 70; //in °C
|
||||||
bool editAcc = false;
|
bool editAcc = false;
|
||||||
int32_t accelRate = 2000;
|
int32_t accelRate = 2000;
|
||||||
}
|
}
|
||||||
|
|
@ -160,6 +161,22 @@ int getTempInC(uint8_t senTemp){
|
||||||
return ((milliVolt - 500)/10)
|
return ((milliVolt - 500)/10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Liefert true wenn der Timer aktuell Active ist und false wenn nicht aktiv
|
||||||
|
bool isTimerActiveNow(int curH, int curM, int startH, int startM, int endH, int endM) {
|
||||||
|
int current = curH * 60 + curM;
|
||||||
|
int start = startH * 60 + startM;
|
||||||
|
int end = endH * 60 + endM;
|
||||||
|
|
||||||
|
// Fall A: Zeitfenster am selben Tag (z. B. 08:00 bis 16:00)
|
||||||
|
if (start <= end) {
|
||||||
|
return (current >= start && current < end);
|
||||||
|
}
|
||||||
|
// Fall B: Zeitfenster über Mitternacht (z. B. 22:00 bis 04:00)
|
||||||
|
else {
|
||||||
|
return (current >= start || current < end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Die Funktion behandelt das gesammte Einstellungs menu
|
// Die Funktion behandelt das gesammte Einstellungs menu
|
||||||
void setting(){
|
void setting(){
|
||||||
//######### Timer Edit #########
|
//######### Timer Edit #########
|
||||||
|
|
@ -293,6 +310,7 @@ void updateDisplay(){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void printStatus(FastAccelStepper *stepper, int speed, int clickPlus, int clickMinus){
|
void printStatus(FastAccelStepper *stepper, int speed, int clickPlus, int clickMinus){
|
||||||
// Plotter-Ausgabe alle 50 ms (überflutet den Bus nicht)
|
// Plotter-Ausgabe alle 50 ms (überflutet den Bus nicht)
|
||||||
|
|
@ -330,15 +348,26 @@ void loop() {
|
||||||
getInputs(clickPlus, clickMinus, clickStop, holdPlus, holdMinus, holdStop);
|
getInputs(clickPlus, clickMinus, clickStop, holdPlus, holdMinus, holdStop);
|
||||||
curTemp = getTempInC(senTemp);
|
curTemp = getTempInC(senTemp);
|
||||||
|
|
||||||
|
// zeitschaltuhr prüfen
|
||||||
|
int curH, curM, curS;
|
||||||
|
if (settings.timerEnabled && getCurrentTime(curH, curM, curS)) {
|
||||||
|
bool shouldRun = isTimerActiveNow(curH, curM, settings.startHour, settings.startMin, settings.endHour, settings.endMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(curTemp >= settings.maxTemp || !shouldRun){
|
||||||
|
autoStop = true;
|
||||||
|
}else if(curTemp <= COLDTEMP_C){
|
||||||
|
autoStop = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Main Control
|
// Main Control
|
||||||
if(bSettings){
|
if(bSettings){
|
||||||
settings()
|
settings()
|
||||||
}else if(clickStop || stop){
|
}else if(clickStop || autoStop){
|
||||||
stepper->stopMove();
|
stepper->stopMove();
|
||||||
speed = 0;
|
speed = 0;
|
||||||
if(clickPlus){
|
if(clickStop && clickPlus){
|
||||||
bSettings = true;
|
bSettings = true;
|
||||||
settings();
|
|
||||||
}
|
}
|
||||||
}else if(holdPlus){
|
}else if(holdPlus){
|
||||||
speed = accelRate;
|
speed = accelRate;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue