From c0ca4c81d0257c261897acd7b08992b473f917b3 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 20 Apr 2020 21:05:08 +0200 Subject: [PATCH] Make saveing and loading to epprop a user controlled operation --- CMakeCache.txt | 21 ++++++++++++++++++--- W433DataReciver.cpp | 13 ++++++++++++- W433DataReciver.h | 10 +++++----- main.cpp | 23 ++++++++++++++++------- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/CMakeCache.txt b/CMakeCache.txt index 1e71adc..76e0c7e 100644 --- a/CMakeCache.txt +++ b/CMakeCache.txt @@ -20,6 +20,9 @@ AR_AVRDUDE:FILEPATH=/usr/bin/avrdude //Path to a program. AR_AVRSIZE:FILEPATH=/usr/bin/avr-size +//Path to a program. +CMAKE_ADDR2LINE:FILEPATH=/bin/addr2line + //Path to a program. 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. 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. CMAKE_EXE_LINKER_FLAGS:STRING= @@ -150,6 +156,9 @@ CMAKE_PROJECT_NAME:STATIC=rgbcontroller //Path to a program. 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 // during all build types. CMAKE_SHARED_LINKER_FLAGS:STRING= @@ -235,6 +244,8 @@ rgbcontroller_SOURCE_DIR:STATIC=/home/philipp/Programming/avr/RGBcontroller # INTERNAL cache entries ######################## +//ADVANCED property for variable: CMAKE_ADDR2LINE +CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_AR CMAKE_AR-ADVANCED:INTERNAL=1 //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 CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 //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 -CMAKE_CACHE_PATCH_VERSION:INTERNAL=5 +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 //ADVANCED property for variable: CMAKE_COLOR_MAKEFILE CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 //Path to CMake executable. @@ -285,6 +296,8 @@ CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_DLLTOOL +CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 //Path to cache edit program executable. CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake //Executable file format @@ -342,8 +355,10 @@ CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 //ADVANCED property for variable: CMAKE_RANLIB CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_READELF +CMAKE_READELF-ADVANCED:INTERNAL=1 //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 CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG diff --git a/W433DataReciver.cpp b/W433DataReciver.cpp index be62235..8ce999d 100644 --- a/W433DataReciver.cpp +++ b/W433DataReciver.cpp @@ -50,7 +50,18 @@ int8_t W433DataReciver::reciveBit(uint8_t index) 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; + } } diff --git a/W433DataReciver.h b/W433DataReciver.h index ed0676b..fb8f5b1 100644 --- a/W433DataReciver.h +++ b/W433DataReciver.h @@ -23,11 +23,11 @@ private: //constants static constexpr uint8_t CLOCK_DEVIDER = 1; - static constexpr uint16_t LARGE_TIME = 500; - static constexpr uint16_t SMALL_TIME = 125; - static constexpr uint16_t SYNC_TIME = SMALL_TIME; + static constexpr uint16_t LARGE_TIME = 2000; + static constexpr uint16_t SMALL_TIME = 500; + static constexpr uint16_t SYNC_TIME = 800; 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 uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.30; static constexpr uint16_t DISCARD_TIME = SMALL_TIME*0.6; @@ -86,7 +86,7 @@ public: ~W433DataReciver(); static void initTimer(); static void staticInterrupt(); - void waitForReciveIdle(const uint16_t timeoutMs = 2000); + void waitForReciveIdle(const uint16_t timeoutMs = 10000); void interrupt(); #ifdef USE_RINGBUFFER RingBuffer* getRingBuffer(); diff --git a/main.cpp b/main.cpp index d716589..360f399 100644 --- a/main.cpp +++ b/main.cpp @@ -48,10 +48,12 @@ inline static void printHelp(Serial* serial) serial->write_p(PSTR("Available Commands: \n\ help : Show this prompt.\n\ - relay add [id] [name] : Add Wireless Relay.\n\ - relay delete [n] : Delete n'th Relay.\n\ + relay add [id] [name] : Add Wireless Relay. Save to make permant.\n\ + relay delete [n] : Delete n'th Relay. Save to make permant.\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\ erase : Erase epprom.\n\ dump : Dump epprom.\n\ @@ -127,7 +129,6 @@ void relayDispatch(SVector* relays, Pwm16b* auxPwm, c relays->push_back(relay); } writeRelayState(serial, &relays->back(), relays->count()-1); - save(); } 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")); @@ -142,7 +143,6 @@ void relayDispatch(SVector* relays, Pwm16b* auxPwm, c snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", index, relays->at(index).getName()); serial->write(buffer, SNPRINTF_BUFFER_SIZE); relays->erase(index); - save(); } } else if( strcmp(token, "on") == 0 ) @@ -186,7 +186,6 @@ void relayDispatch(SVector* relays, Pwm16b* auxPwm, c serial->write_p(PSTR("now ")); if(strcmp(token, "on") == 0) resendEnabled = true; else resendEnabled = false; - save(); } resendEnabled ? serial->write_p(PSTR("enabled.\n")) : serial->write_p(PSTR("disabled.\n")) ; } @@ -311,11 +310,11 @@ void serialDispatch(Serial* serial, SVector* relays, char* token = strtok(buffer, " \n"); if(strcmp(token, "relay") == 0) { + reciver->waitForReciveIdle(); relayDispatch(relays, auxPwm, strtok(NULL, " \n"), serial); } else if(strcmp(token, "rgb") == 0) { - reciver->waitForReciveIdle(); rgbDispatch(rgbled, strtok(NULL, " \n"), serial); } else if(strcmp(token, "aux") == 0) @@ -342,6 +341,16 @@ void serialDispatch(Serial* serial, SVector* relays, } 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) { for(uint16_t i = 0; i < 1024; i++) EEPROM_write_char(i, 0);