Use realtime on filament sensor

Instead of incrementing a variable on every iteration on the filament sensor trigger loop, we now use a real time macro that ensure better repeatability and is easier to customize.
This commit is contained in:
David Ramiro 2019-03-08 16:05:54 +01:00
parent 90e27ff21b
commit cea54723e7
No known key found for this signature in database
GPG Key ID: 5B042737EBEEB736
2 changed files with 26 additions and 9 deletions

View File

@ -33,6 +33,7 @@
#include "stepper.h"
#include "serial.h"
#include "printcounter.h"
#include "macros.h"
#ifdef ANYCUBIC_TFT_MODEL
#include "AnycubicTFT.h"
@ -598,10 +599,26 @@ void AnycubicTFTClass::FilamentRunout()
if(FilamentTestStatus>FilamentTestLastStatus)
{
FilamentRunoutCounter++;
if(FilamentRunoutCounter>=31600)
{
FilamentRunoutCounter=0;
// something changed! save current timestamp.
const millis_t fil_ms = millis();
static millis_t fil_delay;
// since this is inside a loop, only set delay time once
if (FilamentSetMillis){
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set filament trigger time");
#endif
// set the delayed timestamp to 3000ms later
fil_delay = fil_ms + 3000UL;
// this doesn't need to run until the filament is recovered again
FilamentSetMillis=false;
}
// have three seconds passed?
if ((FilamentTestStatus>FilamentTestLastStatus) && (fil_ms>fil_delay)) {
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done");
#endif
#ifdef SDSUPPORT
if((card.sdprinting==true))
{
@ -613,21 +630,20 @@ void AnycubicTFTClass::FilamentRunout()
}
else if((card.sdprinting==false))
{
#endif
ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15");
#endif
#ifdef SDSUPPORT
FilamentTestLastStatus=FilamentTestStatus;
}
#endif
FilamentTestLastStatus=FilamentTestStatus;
}
}
else if(FilamentTestStatus!=FilamentTestLastStatus)
{
FilamentRunoutCounter=0;
// set the timestamps on the next loop again
FilamentSetMillis=true;
FilamentTestLastStatus=FilamentTestStatus;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered");

View File

@ -107,7 +107,8 @@ private:
#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR)
char FilamentTestStatus=false;
char FilamentTestLastStatus=false;
long FilamentRunoutCounter=0;
bool FilamentSetMillis=true;
#endif
};