Make saveing and loading to epprop a user controlled operation

This commit is contained in:
2020-04-20 21:05:08 +02:00
parent 27509e21ee
commit c0ca4c81d0
4 changed files with 51 additions and 16 deletions

View File

@ -20,6 +20,9 @@ AR_AVRDUDE:FILEPATH=/usr/bin/avrdude
//Path to a program. //Path to a program.
AR_AVRSIZE:FILEPATH=/usr/bin/avr-size AR_AVRSIZE:FILEPATH=/usr/bin/avr-size
//Path to a program.
CMAKE_ADDR2LINE:FILEPATH=/bin/addr2line
//Path to a program. //Path to a program.
CMAKE_AR:FILEPATH=/bin/ar CMAKE_AR:FILEPATH=/bin/ar
@ -82,6 +85,9 @@ CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
//Flags used by the C compiler during RELWITHDEBINFO builds. //Flags used by the C compiler during RELWITHDEBINFO builds.
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
//Path to a program.
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND
//Flags used by the linker during all build types. //Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING= CMAKE_EXE_LINKER_FLAGS:STRING=
@ -150,6 +156,9 @@ CMAKE_PROJECT_NAME:STATIC=rgbcontroller
//Path to a program. //Path to a program.
CMAKE_RANLIB:FILEPATH=/bin/ranlib CMAKE_RANLIB:FILEPATH=/bin/ranlib
//Path to a program.
CMAKE_READELF:FILEPATH=/bin/readelf
//Flags used by the linker during the creation of shared libraries //Flags used by the linker during the creation of shared libraries
// during all build types. // during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING= CMAKE_SHARED_LINKER_FLAGS:STRING=
@ -235,6 +244,8 @@ rgbcontroller_SOURCE_DIR:STATIC=/home/philipp/Programming/avr/RGBcontroller
# INTERNAL cache entries # INTERNAL cache entries
######################## ########################
//ADVANCED property for variable: CMAKE_ADDR2LINE
CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_AR //ADVANCED property for variable: CMAKE_AR
CMAKE_AR-ADVANCED:INTERNAL=1 CMAKE_AR-ADVANCED:INTERNAL=1
//This is the directory where this CMakeCache.txt was created //This is the directory where this CMakeCache.txt was created
@ -242,9 +253,9 @@ CMAKE_CACHEFILE_DIR:INTERNAL=/home/philipp/Programming/avr/RGBcontroller
//Major version of cmake used to create the current loaded cache //Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache //Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=15 CMAKE_CACHE_MINOR_VERSION:INTERNAL=16
//Patch version of cmake used to create the current loaded cache //Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=5 CMAKE_CACHE_PATCH_VERSION:INTERNAL=3
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE //ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
//Path to CMake executable. //Path to CMake executable.
@ -285,6 +296,8 @@ CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO //ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_DLLTOOL
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
//Path to cache edit program executable. //Path to cache edit program executable.
CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake
//Executable file format //Executable file format
@ -342,8 +355,10 @@ CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
//ADVANCED property for variable: CMAKE_RANLIB //ADVANCED property for variable: CMAKE_RANLIB
CMAKE_RANLIB-ADVANCED:INTERNAL=1 CMAKE_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_READELF
CMAKE_READELF-ADVANCED:INTERNAL=1
//Path to CMake installation. //Path to CMake installation.
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.15 CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG

View File

@ -50,7 +50,18 @@ int8_t W433DataReciver::reciveBit(uint8_t index)
void W433DataReciver::waitForReciveIdle(const uint16_t timeoutMs) void W433DataReciver::waitForReciveIdle(const uint16_t timeoutMs)
{ {
for(uint16_t i = 0; i < timeoutMs && state != LOOKING_FOR_SYNC; ++i ) _delay_ms(1); uint16_t counter = 0;
while(true)
{
while(counter < timeoutMs && state != LOOKING_FOR_SYNC)
{
_delay_ms(1);
++counter;
}
_delay_ms(500);
counter+=500;
if(state == LOOKING_FOR_SYNC || counter >= timeoutMs) break;
}
} }

View File

@ -23,11 +23,11 @@ private:
//constants //constants
static constexpr uint8_t CLOCK_DEVIDER = 1; static constexpr uint8_t CLOCK_DEVIDER = 1;
static constexpr uint16_t LARGE_TIME = 500; static constexpr uint16_t LARGE_TIME = 2000;
static constexpr uint16_t SMALL_TIME = 125; static constexpr uint16_t SMALL_TIME = 500;
static constexpr uint16_t SYNC_TIME = SMALL_TIME; static constexpr uint16_t SYNC_TIME = 800;
static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.20; static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.20;
static constexpr uint16_t SYNC_END_TIME_TOLERANCE = SYNC_TIME*0.80; static constexpr uint16_t SYNC_END_TIME_TOLERANCE = SYNC_TIME*0.50;
static constexpr uint16_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.30; static constexpr uint16_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.30;
static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.30; static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.30;
static constexpr uint16_t DISCARD_TIME = SMALL_TIME*0.6; static constexpr uint16_t DISCARD_TIME = SMALL_TIME*0.6;
@ -86,7 +86,7 @@ public:
~W433DataReciver(); ~W433DataReciver();
static void initTimer(); static void initTimer();
static void staticInterrupt(); static void staticInterrupt();
void waitForReciveIdle(const uint16_t timeoutMs = 2000); void waitForReciveIdle(const uint16_t timeoutMs = 10000);
void interrupt(); void interrupt();
#ifdef USE_RINGBUFFER #ifdef USE_RINGBUFFER
RingBuffer<RINGBUFFER_LENGTH, uint8_t>* getRingBuffer(); RingBuffer<RINGBUFFER_LENGTH, uint8_t>* getRingBuffer();

View File

@ -48,10 +48,12 @@ inline static void printHelp(Serial* serial)
serial->write_p(PSTR("Available Commands: \n\ serial->write_p(PSTR("Available Commands: \n\
help : Show this prompt.\n\ help : Show this prompt.\n\
relay add [id] [name] : Add Wireless Relay.\n\ relay add [id] [name] : Add Wireless Relay. Save to make permant.\n\
relay delete [n] : Delete n'th Relay.\n\ relay delete [n] : Delete n'th Relay. Save to make permant.\n\
relay [on/off] [nn] : Turn on/off nth relay.\n\ relay [on/off] [nn] : Turn on/off nth relay.\n\
relay resend [on/off] : Turn on/off periodic auto resend.\n\ relay resend [on/off] : Turn on/off periodic auto resend. Save to make permant.\n\
save : Save current state as startup state.\n\
load : load startup state.\n\
state : Get machine readable state.\n\ state : Get machine readable state.\n\
erase : Erase epprom.\n\ erase : Erase epprom.\n\
dump : Dump epprom.\n\ dump : Dump epprom.\n\
@ -127,7 +129,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
relays->push_back(relay); relays->push_back(relay);
} }
writeRelayState(serial, &relays->back(), relays->count()-1); writeRelayState(serial, &relays->back(), relays->count()-1);
save();
} }
else if(relays->remainingCapacity() == 0) serial->write_p(PSTR("Relay storage full.\n")); else if(relays->remainingCapacity() == 0) serial->write_p(PSTR("Relay storage full.\n"));
else serial->write_p(PSTR("Usage: relay add [id] [name]\n [id] being a 16bit binary nummber and [name] an optional string\n")); else serial->write_p(PSTR("Usage: relay add [id] [name]\n [id] being a 16bit binary nummber and [name] an optional string\n"));
@ -142,7 +143,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", index, relays->at(index).getName()); snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", index, relays->at(index).getName());
serial->write(buffer, SNPRINTF_BUFFER_SIZE); serial->write(buffer, SNPRINTF_BUFFER_SIZE);
relays->erase(index); relays->erase(index);
save();
} }
} }
else if( strcmp(token, "on") == 0 ) else if( strcmp(token, "on") == 0 )
@ -186,7 +186,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
serial->write_p(PSTR("now ")); serial->write_p(PSTR("now "));
if(strcmp(token, "on") == 0) resendEnabled = true; if(strcmp(token, "on") == 0) resendEnabled = true;
else resendEnabled = false; else resendEnabled = false;
save();
} }
resendEnabled ? serial->write_p(PSTR("enabled.\n")) : serial->write_p(PSTR("disabled.\n")) ; resendEnabled ? serial->write_p(PSTR("enabled.\n")) : serial->write_p(PSTR("disabled.\n")) ;
} }
@ -311,11 +310,11 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
char* token = strtok(buffer, " \n"); char* token = strtok(buffer, " \n");
if(strcmp(token, "relay") == 0) if(strcmp(token, "relay") == 0)
{ {
reciver->waitForReciveIdle();
relayDispatch(relays, auxPwm, strtok(NULL, " \n"), serial); relayDispatch(relays, auxPwm, strtok(NULL, " \n"), serial);
} }
else if(strcmp(token, "rgb") == 0) else if(strcmp(token, "rgb") == 0)
{ {
reciver->waitForReciveIdle();
rgbDispatch(rgbled, strtok(NULL, " \n"), serial); rgbDispatch(rgbled, strtok(NULL, " \n"), serial);
} }
else if(strcmp(token, "aux") == 0) else if(strcmp(token, "aux") == 0)
@ -342,6 +341,16 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
} }
serial->write_p(PSTR("EOL\n")); serial->write_p(PSTR("EOL\n"));
} }
else if(strcmp(token, "save") == 0)
{
save();
serial->write_p(PSTR("State saved to EEPROM.\n"));
}
else if(strcmp(token, "save") == 0)
{
load();
serial->write_p(PSTR("Loaded state from EEPROM.\n"));
}
else if(strcmp(token, "erase") == 0) else if(strcmp(token, "erase") == 0)
{ {
for(uint16_t i = 0; i < 1024; i++) EEPROM_write_char(i, 0); for(uint16_t i = 0; i < 1024; i++) EEPROM_write_char(i, 0);