fix comments and variable names
This commit is contained in:
parent
bd424b78d1
commit
6d6ea9606e
@ -1,15 +1,21 @@
|
|||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
|
||||||
bool alreadyWrittenAblock = false;//false
|
// The start address for the controller data
|
||||||
uint8_t EEMEM currentFanSpeedAddress = 0x30;
|
uint8_t EEMEM startAddressController = 0x00;
|
||||||
uint8_t EEMEM fanControllerStartAddress = 0x00;
|
|
||||||
|
|
||||||
|
// Where the writing of the fans points start
|
||||||
|
uint8_t EEMEM startAddressFan1 = 0x30;
|
||||||
|
uint8_t EEMEM startAddressFan2 = 0x60;
|
||||||
|
|
||||||
uint8_t EEMEM fanSpeedStartAddress = 0x30;
|
// The placement for the next datapoint form the fans.
|
||||||
|
uint8_t EEMEM currentAddressFan1 = 0x30;
|
||||||
|
uint8_t EEMEM currentAddressFan2 = 0x60;
|
||||||
|
|
||||||
|
// Checks if its written a struct in the memmory space.
|
||||||
|
bool alreadyWrittenABlock = false;
|
||||||
|
|
||||||
|
// Checks if the EEPROM memory is ready to be written in.
|
||||||
void checkEEpromIsReady(){
|
void checkEEpromIsReady(){
|
||||||
printf("checking eeprom");
|
|
||||||
while(1){
|
while(1){
|
||||||
if (eeprom_is_ready()){
|
if (eeprom_is_ready()){
|
||||||
break;
|
break;
|
||||||
@ -21,22 +27,28 @@ void checkEEpromIsReady(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Takes inn a struct by the form of config_t
|
||||||
|
// Checks if the eeprom is ready to be written in
|
||||||
|
// Checks if it has been written information at the address
|
||||||
|
// If true, the infromation is replaced with the intaken struct
|
||||||
|
// else the intaken struct is written at the address.
|
||||||
void WriteStructInEEPROM(config_t writeStruct){
|
void WriteStructInEEPROM(config_t writeStruct){
|
||||||
uint8_t structSize;
|
uint8_t structSize;
|
||||||
structSize = sizeof(writeStruct);
|
structSize = sizeof(writeStruct);
|
||||||
|
|
||||||
//check if eeprom_is_ready()
|
|
||||||
checkEEpromIsReady();
|
checkEEpromIsReady();
|
||||||
|
|
||||||
if (alreadyWrittenAblock){
|
if (alreadyWrittenABlock){
|
||||||
eeprom_update_block((void*) &writeStruct,(void*) &fanControllerStartAddress, structSize);
|
eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize);
|
||||||
}else{
|
}else{
|
||||||
eeprom_write_block((void*)&writeStruct,(void*) &fanControllerStartAddress, structSize);
|
eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize);
|
||||||
alreadyWrittenAblock = true;//true
|
alreadyWrittenABlock = true;
|
||||||
//reurn something
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads the memory block at the address 0x00
|
||||||
|
// returns a struct in form of config_t
|
||||||
config_t ReadStructInEEPROM(){
|
config_t ReadStructInEEPROM(){
|
||||||
//is eeprom ready??
|
//is eeprom ready??
|
||||||
config_t readStruct;
|
config_t readStruct;
|
||||||
@ -44,26 +56,50 @@ config_t ReadStructInEEPROM(){
|
|||||||
|
|
||||||
checkEEpromIsReady();
|
checkEEpromIsReady();
|
||||||
|
|
||||||
eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize);
|
eeprom_read_block((void *) &readStruct,(void*) &startAddressController, structsize);
|
||||||
return readStruct;
|
return readStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteFanSpeedInEEPROM(uint8_t fanSpeed){
|
// Takes inn a dataPoint and what data set it belongs to
|
||||||
|
// checks if EEPROM is ready
|
||||||
|
// If the dataset is 1, the datapoint is written at the address.
|
||||||
|
// If the dataset is 2 its written at another point.
|
||||||
|
void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){
|
||||||
|
|
||||||
checkEEpromIsReady();
|
checkEEpromIsReady();
|
||||||
|
if (data == 1){
|
||||||
eeprom_write_byte(currentFanSpeedAddress, fanSpeed);
|
eeprom_write_byte(currentAddressFan1, dataPoint);
|
||||||
currentFanSpeedAddress++;
|
currentAddressFan1++;
|
||||||
}
|
} else if (data == 2){
|
||||||
|
eeprom_write_byte(currentAddressFan2, dataPoint);
|
||||||
void ReadFanSpeedInfo(){
|
currentAddressFan2++;
|
||||||
uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress;
|
} else{
|
||||||
uint8_t fanSpeedIterate = 0;
|
// error???
|
||||||
|
;
|
||||||
checkEEpromIsReady();
|
}
|
||||||
|
}
|
||||||
for (uint8_t i = 0; i <len; i++){
|
|
||||||
fanSpeedIterate = eeprom_read_byte(i);
|
// Reads all the datapoints to the choosen data.
|
||||||
printf("Fanspeed nr %u : %u", i, fanSpeedIterate);
|
// it writes the data points in the USART stream.
|
||||||
|
void ReadDataPointSpeedInfo(uint8_t data){
|
||||||
|
uint8_t dataPoint = 0;
|
||||||
|
|
||||||
|
if (data == 1){
|
||||||
|
uint8_t len = currentAddressFan1 - startAddressFan1;
|
||||||
|
|
||||||
|
checkEEpromIsReady();
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i <len; i++){
|
||||||
|
dataPoint = eeprom_read_byte(i);
|
||||||
|
printf("Fanspeed nr %u : %u", i, dataPoint);
|
||||||
|
}
|
||||||
|
} else if (data == 2){
|
||||||
|
uint8_t len = currentAddressFan2 - startAddressFan2;
|
||||||
|
checkEEpromIsReady();
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i <len; i++){
|
||||||
|
dataPoint = eeprom_read_byte(i);
|
||||||
|
printf("Fanspeed nr %u : %u", i, dataPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,16 +21,25 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Struct for information on the controller.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t fanSpeed;
|
uint8_t fanSpeed;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
|
// Check if EEPROM is ready to be written in
|
||||||
void checkEEpromIsReady();
|
void checkEEpromIsReady();
|
||||||
|
|
||||||
|
// Writes a struct in EEPROM
|
||||||
void WriteStructInEEPROM(config_t writeStruct);
|
void WriteStructInEEPROM(config_t writeStruct);
|
||||||
|
|
||||||
|
// Read data from EEPROM and return it as a controller struct
|
||||||
config_t ReadStructInEEPROM();
|
config_t ReadStructInEEPROM();
|
||||||
void WriteFanSpeedInEEPROM(uint8_t fanSpeed);
|
|
||||||
void ReadFanSpeedInfo();
|
// Writes a datapoint in EEPROM
|
||||||
|
void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data);
|
||||||
|
|
||||||
|
// Reads all the dataPoints form EEPROM
|
||||||
|
void ReadDataPointSpeedInfo(uint8_t data);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user