From b3089a9c733e8bdf11cec9d1909b3204120afbb2 Mon Sep 17 00:00:00 2001 From: "james.goppert" Date: Thu, 30 Dec 2010 06:46:40 +0000 Subject: [PATCH] Fixed casting issues with EEPROM Registry git-svn-id: https://arducopter.googlecode.com/svn/trunk@1371 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/AP_Common/AP_Var.h | 24 ++++++++++++------- libraries/AP_EEProm/AP_EEProm.cpp | 8 +++---- libraries/AP_EEProm/AP_EEProm.h | 16 ++++++------- .../examples/ServoSweep/ServoSweep.pde | 18 +++++++------- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/libraries/AP_Common/AP_Var.h b/libraries/AP_Common/AP_Var.h index 7e7c87ef32..6ef976aca8 100644 --- a/libraries/AP_Common/AP_Var.h +++ b/libraries/AP_Common/AP_Var.h @@ -19,13 +19,19 @@ public: virtual void setF(const float & val) = 0; /// Get the variable value as a float - virtual const float & getF() = 0; + virtual const float getF() = 0; - /// Set the variable value as an Int16 + /// Set the variable value as an int16 virtual void setI(const int16_t & val) = 0; - /// Get the variable value as an Int16 - virtual const int16_t & getI() = 0; + /// Get the variable value as an int16 + virtual const int16_t getI() = 0; + + /// Set the variable value as a bool + virtual void setB(const bool & val) = 0; + + /// Get the variable value as an bool + virtual const bool getB() = 0; /// Save a variable to eeprom virtual void save() = 0; @@ -41,7 +47,7 @@ public: virtual const bool & getSync() = 0; /// Set the sync property - virtual void setSync(bool sync) = 0; + virtual void setSync(const bool & sync) = 0; }; /// The variable template class. This class @@ -81,7 +87,7 @@ public: } /// Get the variable as a float - virtual const float & getF() { + virtual const float getF() { return get(); } @@ -91,7 +97,7 @@ public: } /// Get the variable value as an Int16 - virtual const int16_t & getI() { + virtual const int16_t getI() { return get(); } @@ -101,7 +107,7 @@ public: } /// Get the variable value as an Int16 - virtual const bool & getB() { + virtual const bool getB() { return get(); } @@ -124,7 +130,7 @@ public: /// If sync is true the a load will always occure before a get and a save will always /// occure before a set. virtual const bool & getSync() { return _sync; } - virtual void setSync(bool sync) { _sync = sync; } + virtual void setSync(const bool & sync) { _sync = sync; } protected: type _data; /// The data that is stored on the heap */ diff --git a/libraries/AP_EEProm/AP_EEProm.cpp b/libraries/AP_EEProm/AP_EEProm.cpp index 9811be788b..df30c9c46e 100644 --- a/libraries/AP_EEProm/AP_EEProm.cpp +++ b/libraries/AP_EEProm/AP_EEProm.cpp @@ -22,12 +22,12 @@ void AP_EEPromRegistry::print(BetterStream & stream) stream.printf("\nEEPROM Registry\n"); for (int i=0;igetEntryId(), (*this)[i]->getEntryParentName(), (*this)[i]->getEntryName(), - (*this)[i]->getEntryId(), - (*this)[i]->getEntryAddress(), - (*this)[i]->getEntry()); + (*this)[i]->getEntry(), + (*this)[i]->getEntryAddress()); } } diff --git a/libraries/AP_EEProm/AP_EEProm.h b/libraries/AP_EEProm/AP_EEProm.h index e8eb397b38..f9daef2ad0 100644 --- a/libraries/AP_EEProm/AP_EEProm.h +++ b/libraries/AP_EEProm/AP_EEProm.h @@ -32,12 +32,12 @@ public: /// Pure virtual function for setting the data value /// as a float. The function must handle the cast to /// the stored variable types. - virtual void setEntry(float val) = 0; + virtual void setEntry(const float & val) = 0; /// Pure virtual function for getting data as a float. /// The function must handle the cast from the /// stored variable types. - virtual float getEntry() = 0; + virtual const float getEntry() = 0; /// Pure virtual function for getting entry name. virtual const char * getEntryName() = 0; @@ -46,10 +46,10 @@ public: virtual const char * getEntryParentName() = 0; /// Get the id of the variable. - virtual uint16_t getEntryId() = 0; + virtual const uint16_t & getEntryId() = 0; /// Get the address of the variable. - virtual uint16_t getEntryAddress() = 0; + virtual const uint16_t & getEntryAddress() = 0; }; ///The main EEProm Registry class. @@ -92,16 +92,16 @@ public: eepromRegistry.add(this,_id,_address,sizeof(type)); } - virtual void setEntry(float val) { this->setF(val); } - virtual float getEntry() { return this->getF(); } + virtual void setEntry(const float & val) { this->setF(val); } + virtual const float getEntry() { return this->getF(); } virtual const char * getEntryName() { return this->getName(); } virtual const char * getEntryParentName() { return this->getParentName(); } /// Get the id of the variable. - virtual uint16_t getEntryId() { return _id; } + virtual const uint16_t & getEntryId() { return _id; } /// Get the address of the variable. - virtual uint16_t getEntryAddress() { return _address; } + virtual const uint16_t & getEntryAddress() { return _address; } private: uint16_t _id; /// Variable identifier diff --git a/libraries/AP_RcChannel/examples/ServoSweep/ServoSweep.pde b/libraries/AP_RcChannel/examples/ServoSweep/ServoSweep.pde index f5ebc49537..997707a726 100644 --- a/libraries/AP_RcChannel/examples/ServoSweep/ServoSweep.pde +++ b/libraries/AP_RcChannel/examples/ServoSweep/ServoSweep.pde @@ -39,27 +39,29 @@ void setup() Serial.begin(115200); Serial.println("ArduPilot RC Channel test"); - eepromRegistry.print(Serial); // show eeprom map APM_RC.Init(); // APM Radio initialization - for (int i=0;i