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

/home/jgoppert/Projects/ap/libraries/AP_EEProm/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 
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

Generated for ArduPilot Libraries by doxygen