Go to the documentation of this file.00001 #ifndef AP_EEProm_H
00002 #define AP_EEProm_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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