TemperatureControl: Move printf out of interrupt context
authorBen Gamari <bgamari.foss@gmail.com>
Sat, 26 Jan 2013 21:39:48 +0000 (16:39 -0500)
committerBen Gamari <bgamari.foss@gmail.com>
Sat, 16 Feb 2013 15:04:56 +0000 (10:04 -0500)
src/modules/tools/temperaturecontrol/TemperatureControl.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.h

index 6682535..6f9098e 100644 (file)
 
 #include "MRI_Hooks.h"
 
-TemperatureControl::TemperatureControl(){}
-
-TemperatureControl::TemperatureControl(uint16_t name){
-    this->name_checksum = name;
-//     this->error_count = 0;
-    this->waiting = false;
-}
+TemperatureControl::TemperatureControl(uint16_t name) :
+  name_checksum(name), waiting(false), min_temp_violated(false) {}
 
 void TemperatureControl::on_module_loaded(){
 
@@ -44,7 +39,12 @@ void TemperatureControl::on_module_loaded(){
 
 }
 
-void TemperatureControl::on_main_loop(void* argument){ }
+void TemperatureControl::on_main_loop(void* argument){
+    if (this->min_temp_violated) {
+        kernel->streams->printf("MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
+        this->min_temp_violated = false;
+    } 
+}
 
 // Get configuration from the config file
 void TemperatureControl::on_config_reload(void* argument){
@@ -221,7 +221,7 @@ uint32_t TemperatureControl::thermistor_read_tick(uint32_t dummy){
     {
         if ((r <= 1) || (r >= 4094))
         {
-            kernel->streams->printf("MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
+            this->min_temp_violated = true;
             target_temperature = UNDEFINED;
             heater_pin.set(0);
         }
index f7d8d62..fd92445 100644 (file)
@@ -48,7 +48,6 @@ class TemperatureControlPool;
 
 class TemperatureControl : public Module {
     public:
-        TemperatureControl();
         TemperatureControl(uint16_t name);
 
         void on_module_loaded();
@@ -105,6 +104,7 @@ class TemperatureControl : public Module {
         Pwm  heater_pin;
 
         bool waiting;
+        bool min_temp_violated;
 
         uint16_t set_m_code;
         uint16_t set_and_wait_m_code;