tick = false;
this->kernel->slow_ticker->attach(20, this, &PID_Autotuner::on_tick );
register_for_event(ON_IDLE);
+ register_for_event(ON_GCODE_RECEIVED);
}
void PID_Autotuner::begin(TemperatureControl *temp, double target, StreamOutput *stream)
if (t)
t->heater_pin.set(0);
+ s = stream;
t = temp;
t->target_temperature = 0.0;
}
cycle = 0;
- s = stream;
-
- s->printf("%s: Starting PID Autotune\n", t->designator.c_str());
+ s->printf("%s: Starting PID Autotune, M304 aborts\n", t->designator.c_str());
bias = d = t->heater_pin.max_pwm() >> 1;
last_output = true;
}
+void PID_Autotuner::abort()
+{
+ if (!t)
+ return;
+
+ t->target_temperature = 0;
+ t->heater_pin.set(0);
+ t = NULL;
+
+ if (s)
+ s->printf("PID Autotune Aborted\n");
+ s = NULL;
+}
+
+void PID_Autotuner::on_gcode_received(void* argument)
+{
+ Gcode* gcode = static_cast<Gcode*>(argument);
+
+ if ((gcode->has_m) && (gcode->m == 304))
+ abort();
+}
+
uint32_t PID_Autotuner::on_tick(uint32_t dummy)
{
if (t)
t->i_factor = ki;
t->d_factor = kd;
+ s->printf("PID Autotune Complete! The settings above have been loaded into memory, but not written to your config file.\n");
+
t = NULL;
s = NULL;
public:
PID_Autotuner();
void begin(TemperatureControl*, double, StreamOutput*);
+ void abort();
void on_module_loaded(void);
uint32_t on_tick(uint32_t);
void on_idle(void*);
+ void on_gcode_received(void*);
TemperatureControl *t;