mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Code clean-up
This commit is contained in:
parent
d669e47704
commit
1a45648146
@ -1,49 +1,17 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
|
|
||||||
#include "hasp_debug.h"
|
|
||||||
|
|
||||||
void eepromWrite(char addr, std::string & data);
|
|
||||||
std::string eepromRead(char addr);
|
|
||||||
|
|
||||||
void eepromSetup()
|
void eepromSetup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if defined(STM32Fxx)
|
||||||
|
eeprom_buffer_fill();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ESP8266 // Don't start at boot, only at write
|
||||||
// EEPROM.begin(1024);
|
// EEPROM.begin(1024);
|
||||||
// debugPrintln("EEPROM: Started Eeprom");
|
// debugPrintln("EEPROM: Started Eeprom");
|
||||||
}
|
}
|
||||||
|
|
||||||
void eepromLoop()
|
void eepromLoop()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void eepromUpdate(uint16_t addr, char ch)
|
|
||||||
{
|
|
||||||
if(EEPROM.read(addr) != ch) {
|
|
||||||
EEPROM.write(addr, ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void eepromWrite(uint16_t addr, std::string & data)
|
|
||||||
{
|
|
||||||
int count = data.length();
|
|
||||||
for(int i = 0; i < count; i++) {
|
|
||||||
eepromUpdate(addr + i, data[i]);
|
|
||||||
}
|
|
||||||
eepromUpdate(addr + count, '\0');
|
|
||||||
// EEPROM.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string eepromRead(uint16_t addr)
|
|
||||||
{
|
|
||||||
char data[1024]; // Max 1024 Bytes
|
|
||||||
int len = 0;
|
|
||||||
unsigned char k;
|
|
||||||
k = EEPROM.read(addr);
|
|
||||||
while(k != '\0' && len < 1023) // Read until null character
|
|
||||||
{
|
|
||||||
k = EEPROM.read(addr + len);
|
|
||||||
if((uint8_t(k) < 32) || (uint8_t(k) > 127)) break; // check for printable ascii, includes '\0'
|
|
||||||
data[len] = k;
|
|
||||||
len++;
|
|
||||||
}
|
|
||||||
return std::string(data);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user