TemperatureControl: static Pins
authorMichael Moon <triffid.hunter@gmail.com>
Sat, 9 Feb 2013 13:54:24 +0000 (00:54 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Sat, 9 Feb 2013 13:54:24 +0000 (00:54 +1100)
src/modules/tools/temperaturecontrol/PID_Autotuner.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.h

index a8c70cf..e64a108 100644 (file)
@@ -16,7 +16,7 @@ void PID_Autotuner::on_module_loaded()
 void PID_Autotuner::begin(TemperatureControl *temp, double target, StreamOutput *stream)
 {
     if (t)
-        t->heater_pin->set(0);
+        t->heater_pin.set(0);
 
     t = temp;
 
@@ -37,7 +37,7 @@ void PID_Autotuner::begin(TemperatureControl *temp, double target, StreamOutput
 
     s->printf("%s: Starting PID Autotune\n", t->designator.c_str());
 
-    bias = d = t->heater_pin->max_pwm() >> 1;
+    bias = d = t->heater_pin.max_pwm() >> 1;
 
     output = true;
     last_output = true;
@@ -61,9 +61,9 @@ uint32_t PID_Autotuner::on_tick(uint32_t dummy)
 
         // this code taken from http://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp
         bias += (d * (cycles[cycle].ticks_high - cycles[cycle].ticks_low) * (1000.0 / 20.0)) / ((cycles[cycle].ticks_high + cycles[cycle].ticks_low) * (1000.0 / 20.0));
-        bias = confine(bias, 20, t->heater_pin->max_pwm() - 20);
-        if (bias > (t->heater_pin->max_pwm() / 2))
-            d = t->heater_pin->max_pwm() - 1 - bias;
+        bias = confine(bias, 20, t->heater_pin.max_pwm() - 20);
+        if (bias > (t->heater_pin.max_pwm() / 2))
+            d = t->heater_pin.max_pwm() - 1 - bias;
         else
             d = bias;
         // end code from Marlin firmware
@@ -71,7 +71,7 @@ uint32_t PID_Autotuner::on_tick(uint32_t dummy)
         cycle++;
         if (cycle == PID_AUTOTUNER_CYCLES)
         {
-            t->heater_pin->set(0);
+            t->heater_pin.set(0);
             t->set_desired_temperature(0.0);
             // TODO: finish
             double tmax_avg   = 0.0,
@@ -122,12 +122,12 @@ uint32_t PID_Autotuner::on_tick(uint32_t dummy)
     if (output)
     {
         ticks = ++cycles[cycle].ticks_high;
-        t->heater_pin->pwm((t->o = ((bias + d) >> 1)));
+        t->heater_pin.pwm((t->o = ((bias + d) >> 1)));
     }
     else
     {
         ticks = ++cycles[cycle].ticks_low;
-        t->heater_pin->set((t->o = 0));
+        t->heater_pin.set((t->o = 0));
     }
 
     if ((ticks % 16) == 0)
index 469ee45..6bfbcaa 100644 (file)
@@ -54,7 +54,7 @@ void TemperatureControl::on_config_reload(void* argument){
     this->set_and_wait_m_code = this->kernel->config->value(temperature_control_checksum, this->name_checksum, set_and_wait_m_code_checksum)->by_default(109)->as_number();
     this->get_m_code          = this->kernel->config->value(temperature_control_checksum, this->name_checksum, get_m_code_checksum)->by_default(105)->as_number();
     this->readings_per_second = this->kernel->config->value(temperature_control_checksum, this->name_checksum, readings_per_second_checksum)->by_default(20)->as_number();
-    
+
     this->max_pwm             = this->kernel->config->value(temperature_control_checksum, this->name_checksum, max_pwm_checksum)->by_default(255)->as_number();
 
     this->designator          = this->kernel->config->value(temperature_control_checksum, this->name_checksum, designator_checksum)->by_default(string("T"))->as_string();
@@ -90,17 +90,17 @@ void TemperatureControl::on_config_reload(void* argument){
     o = 0;
 
     // Thermistor pin for ADC readings
-    this->thermistor_pin = this->kernel->config->value(temperature_control_checksum, this->name_checksum, thermistor_pin_checksum )->required()->as_pin();
-    this->kernel->adc->enable_pin(this->thermistor_pin);
+    this->thermistor_pin.from_string(this->kernel->config->value(temperature_control_checksum, this->name_checksum, thermistor_pin_checksum )->required()->as_string());
+    this->kernel->adc->enable_pin(&thermistor_pin);
 
     // Heater pin
-    this->heater_pin     =  this->kernel->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_pwm()->as_output();
-    this->heater_pin->set(0);
+    this->heater_pin.from_string(    this->kernel->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_string())->as_output();
+    this->heater_pin.set(0);
 
-    set_low_on_debug(heater_pin->pin->port_number, heater_pin->pin->pin);
+    set_low_on_debug(heater_pin.pin->port_number, heater_pin.pin->pin);
 
     // activate SD-DAC timer
-    this->kernel->slow_ticker->attach(1000, this->heater_pin, &Pwm::on_tick);
+    this->kernel->slow_ticker->attach(1000, &heater_pin, &Pwm::on_tick);
 
     // reading tick
     this->kernel->slow_ticker->attach( this->readings_per_second, this, &TemperatureControl::thermistor_read_tick );
@@ -165,7 +165,7 @@ void TemperatureControl::on_gcode_execute(void* argument){
             if (gcode->get_value('S') == 0)
             {
                 this->target_temperature = UNDEFINED;
-                this->heater_pin->set(0);
+                this->heater_pin.set(0);
             }
             else
             {
@@ -178,7 +178,7 @@ void TemperatureControl::on_gcode_execute(void* argument){
             if (gcode->get_value('S') == 0)
             {
                 this->target_temperature = UNDEFINED;
-                this->heater_pin->set(0);
+                this->heater_pin.set(0);
             }
             else
             {
@@ -195,7 +195,7 @@ void TemperatureControl::on_gcode_execute(void* argument){
 void TemperatureControl::set_desired_temperature(double desired_temperature){
     target_temperature = desired_temperature;
     if (desired_temperature == 0.0)
-        heater_pin->set((o = 0));
+        heater_pin.set((o = 0));
 }
 
 double TemperatureControl::get_temperature(){
@@ -221,9 +221,9 @@ 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);
+            kernel->streams->printf("MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
             target_temperature = UNDEFINED;
-            heater_pin->set(0);
+            heater_pin.set(0);
         }
         else
         {
@@ -237,7 +237,7 @@ uint32_t TemperatureControl::thermistor_read_tick(uint32_t dummy){
     }
     else
     {
-        heater_pin->set((o = 0));
+        heater_pin.set((o = 0));
     }
     last_reading = temperature;
     return 0;
@@ -258,28 +258,28 @@ void TemperatureControl::pid_process(double temperature)
     if (i < -this->i_max)
         i = -this->i_max;
 
-    this->o = (p + i + d) * heater_pin->max_pwm() / 256;
+    this->o = (p + i + d) * heater_pin.max_pwm() / 256;
 
-    if (this->o >= heater_pin->max_pwm())
+    if (this->o >= heater_pin.max_pwm())
     {
         i = 0;
-        this->o = heater_pin->max_pwm();
+        this->o = heater_pin.max_pwm();
     }
     if (this->o < 0)
     {
-        if (this->o < -(heater_pin->max_pwm()))
+        if (this->o < -(heater_pin.max_pwm()))
             i = 0;
         this->o = 0;
     }
 
     if( this->o > this->max_pwm ){ this->o = max_pwm; }
 
-    this->heater_pin->pwm(o);
+    this->heater_pin.pwm(o);
 }
 
 int TemperatureControl::new_thermistor_reading()
 {
-    int last_raw = this->kernel->adc->read(this->thermistor_pin);
+    int last_raw = this->kernel->adc->read(&thermistor_pin);
     if (queue.size() >= queue.capacity())
     {
         uint16_t l;
index a071fff..f7d8d62 100644 (file)
@@ -101,8 +101,8 @@ class TemperatureControl : public Module {
 
         uint16_t name_checksum;
 
-        Pin* thermistor_pin;
-        Pwm* heater_pin;
+        Pin  thermistor_pin;
+        Pwm  heater_pin;
 
         bool waiting;