change the temperature public data access to pass in the pad_temp for the result...
[clinton/Smoothieware.git] / src / modules / tools / temperaturecontrol / TemperatureControl.cpp
index 8078cfe..40bb805 100644 (file)
@@ -356,25 +356,20 @@ void TemperatureControl::on_get_public_data(void *argument)
 
     }else if(!pdr->second_element_is(poll_controls_checksum)) {
         // polling for all temperature controls
-        // add our data to the list
-        std::vector<struct pad_temperature*> *v;
-        void *data= pdr->get_data_ptr();
-        if(data == nullptr) {
-            // first one allocates a vector for the return data
-            v= new std::vector<struct pad_temperature*> ;
-            pdr->set_data_ptr(v);
-
-        }else{
-            v= static_cast<std::vector<pad_temperature*>*>(data);
-        }
+        // add our data to the list which is passed in via the data_ptr
+
+        std::vector<struct pad_temperature> *v= static_cast<std::vector<pad_temperature>*>(pdr->get_data_ptr());
 
+        struct pad_temperature t;
         // setup data
-        this->public_data_return.current_temperature = this->get_temperature();
-        this->public_data_return.target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
-        this->public_data_return.pwm = this->o;
-        this->public_data_return.designator= this->designator;
-        this->public_data_return.id= this->name_checksum;
-        v->push_back(&this->public_data_return);
+        t.current_temperature = this->get_temperature();
+        t.target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
+        t.pwm = this->o;
+        t.designator= this->designator;
+        t.id= this->name_checksum;
+        v->push_back(t);
+        pdr->set_taken();
+        pdr->clear_returned_data();
         return;
     }
 
@@ -383,13 +378,14 @@ void TemperatureControl::on_get_public_data(void *argument)
 
     // ok this is targeted at us, so send back the requested data
     if(pdr->third_element_is(current_temperature_checksum)) {
-        this->public_data_return.current_temperature = this->get_temperature();
-        this->public_data_return.target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
-        this->public_data_return.pwm = this->o;
-        this->public_data_return.designator= this->designator;
-        this->public_data_return.id= this->name_checksum;
-        pdr->set_data_ptr(&this->public_data_return);
+        struct pad_temperature *t= static_cast<pad_temperature*>(pdr->get_data_ptr());
+        t->current_temperature = this->get_temperature();
+        t->target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
+        t->pwm = this->o;
+        t->designator= this->designator;
+        t->id= this->name_checksum;
         pdr->set_taken();
+        pdr->clear_returned_data();
     }
 
 }