Skip to content

Commit

Permalink
eeprom library
Browse files Browse the repository at this point in the history
  • Loading branch information
rhockenbury committed Dec 11, 2013
1 parent ea3f237 commit 46a414a
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
91 changes: 91 additions & 0 deletions Quad2/Libraries/Quad_EEPROM/storage.cpp
Original file line number Diff line number Diff line change
@@ -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) {

}






52 changes: 52 additions & 0 deletions Quad2/Libraries/Quad_EEPROM/storage.h
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 46a414a

Please sign in to comment.