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
00028 class AP_EEPromEntry
00029 {
00030 public:
00034 virtual void setEntry(float val) = 0;
00035
00039 virtual float getEntry() = 0;
00040
00042 virtual const char * getEntryName() = 0;
00043
00045 virtual uint16_t getEntryId() = 0;
00046
00048 virtual uint16_t getEntryAddress() = 0;
00049 };
00050
00052 class AP_EEPromRegistry : public Vector<AP_EEPromEntry *>
00053 {
00054 public:
00055
00057 AP_EEPromRegistry(uint16_t maxSize) :
00058 _newAddress(0), _newId(0), _maxSize(maxSize)
00059 {
00060 }
00061
00063 void add(AP_EEPromEntry * entry, uint16_t & id, uint16_t & address, size_t size);
00064
00065 private:
00066 uint16_t _newAddress;
00067 uint16_t _newId;
00068 uint16_t _maxSize;
00069 };
00070
00072 extern AP_EEPromRegistry eepromRegistry;
00073
00077 template <class type>
00078 class AP_EEPromVar : public AP_EEPromEntry, public AP_Var<type>
00079 {
00080 public:
00082 AP_EEPromVar(type data = 0, const char * name = "", bool sync=false) :
00083 AP_Var<type>(data,name,sync)
00084 {
00085 eepromRegistry.add(this,_id,_address,sizeof(type));
00086 }
00087
00088 virtual void setEntry(float val) { this->setAsFloat(val); }
00089 virtual float getEntry() { return this->getAsFloat(); }
00090 virtual const char * getEntryName() { return this->getName(); }
00091
00093 virtual uint16_t getEntryId() { return _id; }
00094
00096 virtual uint16_t getEntryAddress() { return _address; }
00097
00098 private:
00099 uint16_t _id;
00100 uint16_t _address;
00101 };
00102
00103 #endif