Implement safe cooldown for both fans
This commit is contained in:
parent
d599ebb4d7
commit
8a8c28a6f0
|
@ -1,4 +1,4 @@
|
|||
//#define PRINTER //uncomment for 3d-Printer (cooldown functions)
|
||||
#define PRINTER //uncomment for 3d-Printer (cooldown functions)
|
||||
|
||||
#include <SPI.h>
|
||||
#include <LiquidCrystal.h>
|
||||
|
@ -6,9 +6,13 @@
|
|||
#include <MFRC522.h>
|
||||
|
||||
#ifdef PRINTER
|
||||
#define BTN_FANPROBE A3
|
||||
#define FANOFFVALUE 50 //adc value for fan
|
||||
#define BTN_FANPROBE_R A3
|
||||
#define BTN_FANPROBE_L A2
|
||||
#define FANOFFVALUE 512 //adc value for fan. high value = fan off
|
||||
boolean flag_switchOff = false; //set true-> loop switches output off if possible
|
||||
#define SWITCHOFFTRYBLINKDELAY 500 //blink period time in millis
|
||||
long lastSwitchOffTryMillis=0;
|
||||
#define QUICKRESTARTHOLDTIME 1000 //time to hold button during fan waiting to quick restart printer
|
||||
#endif
|
||||
|
||||
#define BTN_PIN A0 // lcd buttons are Voltage-Divider analog
|
||||
|
@ -40,6 +44,7 @@ long lastActionMillis = 0;
|
|||
|
||||
boolean unlocked = false;
|
||||
boolean outputOn = false;
|
||||
boolean lcdbacklight = false;
|
||||
int displayLogIndex = -1;
|
||||
int displayLogIndexLast = -1;
|
||||
|
||||
|
@ -130,6 +135,8 @@ void lcd_print_home() {
|
|||
void handleCards(long currentMillis) {
|
||||
if(mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
|
||||
|
||||
|
||||
|
||||
mfrc522.PICC_HaltA();
|
||||
|
||||
cardWasPresent = true;
|
||||
|
@ -141,6 +148,12 @@ void handleCards(long currentMillis) {
|
|||
|
||||
int cardIndex = check_uid(&(mfrc522.uid));
|
||||
|
||||
#ifdef PRINTER
|
||||
if (flag_switchOff && cardIndex>=0){
|
||||
abortSwitchoff(); //abort automatic switchoff
|
||||
}else{
|
||||
#endif
|
||||
|
||||
if(cardIndex == 0) { // card is master
|
||||
lcd.setCursor(0, 1);
|
||||
|
||||
|
@ -170,11 +183,7 @@ void handleCards(long currentMillis) {
|
|||
if(outputOn) {
|
||||
#ifdef PRINTER
|
||||
if (!flag_switchOff){
|
||||
flag_switchOff=true;
|
||||
lcd.clear();
|
||||
lcd.print("Wartet auf");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Luefter");
|
||||
flag_switchOff=true; //set flag to turn off printer
|
||||
}else{
|
||||
flag_switchOff=false; //cancel switchoff
|
||||
}
|
||||
|
@ -223,17 +232,60 @@ void handleCards(long currentMillis) {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
lcd_print_home();
|
||||
}
|
||||
}
|
||||
|
||||
long lastPrint=0;
|
||||
|
||||
void loop() {
|
||||
|
||||
long currentMillis = millis();
|
||||
|
||||
handleCards(currentMillis);
|
||||
|
||||
#ifdef PRINTER
|
||||
/*if (currentMillis>lastPrint+1000){ //TESTING
|
||||
int fanvalue=analogRead(BTN_FANPROBE_R);
|
||||
Serial.println(fanvalue);
|
||||
lastPrint=currentMillis;
|
||||
}*/
|
||||
if (flag_switchOff){
|
||||
|
||||
if (readButtons()!=0){ //any buttons pressed
|
||||
long _buttonPressStart=millis();
|
||||
while (readButtons()==1){ //select button
|
||||
delay(100); //wait for button to release
|
||||
}
|
||||
|
||||
if (millis()-_buttonPressStart > QUICKRESTARTHOLDTIME) { //pressed button for long time
|
||||
quickRestart();
|
||||
}else{ //just pressed short
|
||||
abortSwitchoff();
|
||||
}
|
||||
|
||||
}
|
||||
if (!fanActive()){
|
||||
set_output(false);
|
||||
flag_switchOff=false;
|
||||
lcd_print_home();
|
||||
}else{ //fan is active
|
||||
if (lastSwitchOffTryMillis+SWITCHOFFTRYBLINKDELAY < currentMillis){
|
||||
lcd_backlight(!get_lcd_backlight()); //blink backlight
|
||||
lcd.clear();
|
||||
lcd.print("Wartet auf");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Luefter");
|
||||
lastSwitchOffTryMillis=currentMillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if(readButtons() == 1 && !cardsshow) { //select button shows log, if not showing cards atm
|
||||
displayLogIndex++;
|
||||
|
@ -304,7 +356,7 @@ void loop() {
|
|||
}
|
||||
|
||||
// timeout handling for returning to locked state
|
||||
if(currentMillis - lastActionMillis > 30000) {
|
||||
if(unlocked && currentMillis - lastActionMillis > 30000) {
|
||||
unlocked = false;
|
||||
displayLogIndex = -1;
|
||||
displayCardsIndex = -1;
|
||||
|
@ -316,28 +368,14 @@ void loop() {
|
|||
lcd_print_home();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PRINTER
|
||||
int fanvalue=analogRead(BTN_FANPROBE);
|
||||
Serial.println(fanvalue);
|
||||
if (flag_switchOff){
|
||||
if (readButtons()!=0){ //any buttons pressed
|
||||
abortSwitchoff();
|
||||
}
|
||||
if (!fanActive()){
|
||||
set_output(false);
|
||||
flag_switchOff=false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PRINTER
|
||||
bool fanActive()
|
||||
{
|
||||
int fanvalue=analogRead(BTN_FANPROBE);
|
||||
Serial.println(fanvalue);
|
||||
if (fanvalue<FANOFFVALUE){
|
||||
int fanvalue_r=analogRead(BTN_FANPROBE_R);
|
||||
int fanvalue_l=analogRead(BTN_FANPROBE_L);
|
||||
if (fanvalue_l>FANOFFVALUE && fanvalue_r>FANOFFVALUE){ //fan value high = fan off
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
|
@ -345,11 +383,27 @@ bool fanActive()
|
|||
}
|
||||
|
||||
void abortSwitchoff(){
|
||||
lcd_backlight(true);
|
||||
if (flag_switchOff){
|
||||
flag_switchOff=false;
|
||||
lcd.clear();
|
||||
lcd.print("Ausschalten");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Abgebrochen");
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void quickRestart(){
|
||||
lcd_backlight(true);
|
||||
flag_switchOff=false;
|
||||
lcd.clear();
|
||||
lcd.print("SCHNELLER");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("NEUSTART");
|
||||
set_output(false);
|
||||
delay(500);
|
||||
set_output(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -30,12 +30,18 @@ void set_output(boolean on) {
|
|||
// switch the LDC Backlight on/off
|
||||
void lcd_backlight(boolean on) {
|
||||
if(on) {
|
||||
lcdbacklight=true;
|
||||
digitalWrite(LCD_BACKLIGHT, HIGH);
|
||||
} else {
|
||||
lcdbacklight=false;
|
||||
digitalWrite(LCD_BACKLIGHT, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
bool get_lcd_backlight(){
|
||||
return lcdbacklight;
|
||||
}
|
||||
|
||||
// print a Mifare UID at current LDC position
|
||||
void lcd_print_uid(MFRC522::Uid *uid) {
|
||||
for (byte i=0; i < uid->size; i++) {
|
||||
|
|
Loading…
Reference in New Issue