From 46a414a6c055343f680381502f7a391b491a13de Mon Sep 17 00:00:00 2001 From: Ryler Hockenbury Date: Tue, 10 Dec 2013 20:01:27 -0500 Subject: [PATCH] eeprom library --- Quad2/Libraries/Quad_EEPROM/storage.cpp | 91 +++++++++++++++++++++++++ Quad2/Libraries/Quad_EEPROM/storage.h | 52 ++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 Quad2/Libraries/Quad_EEPROM/storage.cpp create mode 100644 Quad2/Libraries/Quad_EEPROM/storage.h diff --git a/Quad2/Libraries/Quad_EEPROM/storage.cpp b/Quad2/Libraries/Quad_EEPROM/storage.cpp new file mode 100644 index 0000000..0aa59d2 --- /dev/null +++ b/Quad2/Libraries/Quad_EEPROM/storage.cpp @@ -0,0 +1,91 @@ +/* + * storage.cpp + * + * Created on: Dec 10, 2013 + * Author: Ryler Hockenbury + * + * Read and write from EEPROM + */ + + +void readEEPROM() { + +} + +void writeEEPROM() { + +} + + +float readFloat(int address) { + union floatStore { + byte floatByte[4]; + unsigned short floatUShort[2]; + float floatVal; + } floatOut; + + + for (int i = 0; i < 4; i++) { + floatOut.floatByte[i] = EEPROM.read(address + i); + } + + return floatOut.floatVal; +} + +void writeFloat(float value, int address) { + union floatStore { + byte floatByte[4]; + unsigned short floatUShort[2]; + float floatVal; + } floatIn; + + floatIn.floatVal = value; + + for (int i = 0; i < 4; i++) { + EEPROM.write(address + i, floatIn.floatByte[i]); + } +} + +void updateFloat(float value, int address) { + +} + + + long readLong(int address) { + union longStore { + byte longByte[4]; + unsigned short longUShort[2]; + long longVal; + } longOut; + + for (byte i = 0; i < 4; i++) { + longOut.longByte[i] = EEPROM.read(address + i); + } + + return longOut.longVal; + } + + void writeLong(long value, int address) { + union longStore { + byte longByte[4]; + unsigned short longUShort[2]; + long longVal; + } longIn; + + longIn.longVal = value; + + for (int i = 0; i < 4; i++) { + EEPROM.write(address + i, longIn.longByte[i]); + } + + } + + void updateLong(long vaue, int address) { + + } + + + + + + diff --git a/Quad2/Libraries/Quad_EEPROM/storage.h b/Quad2/Libraries/Quad_EEPROM/storage.h new file mode 100644 index 0000000..91336e7 --- /dev/null +++ b/Quad2/Libraries/Quad_EEPROM/storage.h @@ -0,0 +1,52 @@ +/* + * storage.h + * + * Created on: Dec 10, 2013 + * Author: Ryler Hockenbury + * + * Read and write from EEPROM + */ + +#ifndef STORAGE_h +#define STORAGE_h + +#define EEPROM_START_ADDRESSS 0 +#define EEPROM_END_ADDRESS 1023 + +#define PID_P_ADDRESS 0 +#define PID_I_ADDRESS 4 +#define PID_D_ADDRESS 8 + +#define TAKEOFF_THROTTLE_ADDRESS 5 + +#define RADIO_SMOOTH_FACTOR_ADDRESS 5 +#define MAX_COMMAND_ANGLE_ADDRESS 5 +#define MIN_COMMAND_ANGLE_ADDRESS 5 + + +class Storage { + + public: + + Storage(); + + static void writePidPValue(float value, int address=PID_P_ADDRESS); + static void writePidIValue(float value, int address=PID_I_ADDRESS); + static void writePidDValue(float value, int address=PID_D_ADDRESS); + + //void writeTakeoffThrottleValue(float value, int address); + + static float readPidPValue(int address=PID_P_ADDRESS); + static float readPidIValue(int address=PID_I_ADDRESS); + static float readPidDValue(int address=PID_D_ADDRESS); + + + private: + + +}; + + + + +#endif /* STORAGE_h */