Use a struct to return public data requests, see example in temerature control
authorJim Morris <morris@wolfman.com>
Fri, 7 Jun 2013 05:45:54 +0000 (22:45 -0700)
committerJim Morris <morris@wolfman.com>
Fri, 7 Jun 2013 05:45:54 +0000 (22:45 -0700)
src/modules/tools/temperaturecontrol/TemperatureControl.cpp
src/modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h
src/modules/utils/simpleshell/SimpleShell.cpp
src/version.cpp

index 7aed75b..5a35eba 100644 (file)
@@ -208,18 +208,17 @@ void TemperatureControl::on_get_public_data(void* argument){
 
        if(!pdr->second_element_is(this->name_checksum)) return; // will be bed or hotend
 
-       // ok this is us send back the requested value
+       // ok this is targeted at us, so send back the requested data
        if(pdr->third_element_is(current_temperature_checksum)) {
-               pdr->set_data_ptr(&this->last_reading);
-               pdr->set_taken();
-       }else if(pdr->third_element_is(target_temperature_checksum)) {
-               pdr->set_data_ptr((target_temperature == UNDEFINED) ? NULL : &this->target_temperature);
-               pdr->set_taken();
-       }else if(pdr->third_element_is(temperature_pwm_checksum)) {
-               pdr->set_data_ptr(&this->o);
+               // this must be static as it will be accessed long after we have returned
+               static struct pad_temperature temp_return;
+               temp_return.current_temperature= this->get_temperature();
+               temp_return.target_temperature= (target_temperature == UNDEFINED) ? 0 : this->target_temperature;
+               temp_return.pwm= this->o;
+               
+               pdr->set_data_ptr(&temp_return);
                pdr->set_taken();
        }
-
 }
 
 void TemperatureControl::set_desired_temperature(double desired_temperature)
index 696d7d0..78c2dc5 100644 (file)
@@ -9,4 +9,9 @@
 #define target_temperature_checksum       CHECKSUM("target_temperature")
 #define temperature_pwm_checksum          CHECKSUM("temperature_pwm")
 
+struct pad_temperature {
+       double current_temperature;
+       double target_temperature;
+       int pwm;
+};
 #endif
\ No newline at end of file
index 6a6aea5..ea1778a 100644 (file)
@@ -177,11 +177,12 @@ void SimpleShell::break_command( string parameters, StreamOutput* stream){
 // used to test out the get public data events
 void SimpleShell::get_temp_command( string parameters, StreamOutput* stream){
        string type= shift_parameter( parameters );
-       double* temp;
-       bool ok= this->kernel->public_data->get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, (void**)&temp );
+       void *returned_data;
+       bool ok= this->kernel->public_data->get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, &returned_data );
 
        if(ok) {
-               stream->printf("%s temp: %f\r\n", type.c_str(), *temp);
+               struct pad_temperature temp=  *static_cast<struct pad_temperature*>(returned_data);
+               stream->printf("%s temp: %f/%f @%d\r\n", type.c_str(), temp.current_temperature, temp.target_temperature, temp.pwm);
        }else{
                stream->printf("%s is not a known temperature device\r\n", type.c_str());
        }
index a11ff58..54f219b 100644 (file)
@@ -1,6 +1,6 @@
 #include "version.h"
 const char *Version::get_build(void) const {
-    return "feature/get_public_value_event-688c613";
+    return "feature/get_public_value_event-47339e4";
 }
 const char *Version::get_build_date(void) const {
     return __DATE__ " " __TIME__;