• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

AP_EEProm.h

Go to the documentation of this file.
00001 #ifndef AP_EEProm_H
00002 #define AP_EEProm_H
00003 
00004 /*
00005  * AP_EEProm.h
00006  * Copyright (C) James Goppert 2010 <james.goppert@gmail.com>
00007  *
00008  * This file is free software: you can redistribute it and/or modify it
00009  * under the terms of the GNU General Public License as published by the
00010  * Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This file is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License along
00019  * with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 #include <AP_Common.h>
00023 #include <AP_Vector.h>
00024 #include <avr/eeprom.h>
00025 #include <avr/pgmspace.h>
00026 #include <BetterStream.h>
00027 
00029 class AP_EEPromEntryI
00030 {
00031 public:
00035         virtual void setEntry(const float & val) = 0;
00036 
00040         virtual const float getEntry() = 0;
00041 
00043         virtual const char * getEntryName() = 0;
00044 
00046         virtual const char * getEntryParentName() = 0;
00047 
00049         virtual const uint16_t & getEntryId() = 0;
00050 
00052         virtual const uint16_t & getEntryAddress() = 0;
00053 };
00054 
00056 class AP_EEPromRegistry : public Vector<AP_EEPromEntryI *>
00057 {
00058 public:
00059 
00061         AP_EEPromRegistry(uint16_t maxSize) :
00062                 _newAddress(0), _newId(0), _maxSize(maxSize)
00063         {
00064         }
00065 
00067         void add(AP_EEPromEntryI * entry, uint16_t & id, uint16_t & address, size_t size);
00068 
00070         void print(BetterStream & stream);
00071 
00072 private:
00073         uint16_t _newAddress; 
00074         uint16_t _newId; 
00075         uint16_t _maxSize; 
00076 };
00077 
00079 extern AP_EEPromRegistry eepromRegistry;
00080 
00084 template  <class type>
00085 class AP_EEPromVar : public AP_EEPromEntryI, public AP_Var<type>
00086 {
00087 public:
00089         AP_EEPromVar(type data = 0, const char * name = "", const char * parentName = "", bool sync=false) : 
00090                 AP_Var<type>(data,name,parentName,sync)
00091         {
00092                 eepromRegistry.add(this,_id,_address,sizeof(type));
00093         }
00094 
00095         virtual void setEntry(const float & val) { this->setF(val); }
00096         virtual const float getEntry() { return this->getF(); }
00097         virtual const char * getEntryName() { return this->getName(); }
00098         virtual const char * getEntryParentName() { return this->getParentName(); }
00099 
00101         virtual const uint16_t & getEntryId() { return _id; }
00102 
00104         virtual const uint16_t & getEntryAddress() { return _address; }
00105 
00106 private:
00107         uint16_t _id; 
00108         uint16_t _address;  
00109 };
00110 
00111 typedef AP_EEPromVar<float> AP_EEPROM_Float;
00112 typedef AP_EEPromVar<int8_t> AP_EEPROM_Int8;
00113 typedef AP_EEPromVar<uint8_t> AP_EEPROM_Uint8;
00114 typedef AP_EEPromVar<int16_t> AP_EEPROM_Int16;
00115 typedef AP_EEPromVar<uint16_t> AP_EEPROM_Uint16;
00116 typedef AP_EEPromVar<int32_t> AP_EEPROM_Int32;
00117 typedef AP_EEPromVar<uint32_t> AP_EEPROM_Unt32;
00118 typedef AP_EEPromVar<bool> AP_EEPROM_Bool;
00119 
00120 
00121 #endif

Generated for ArduPilot Libraries by doxygen