From 4c945af1b409abe308d49495e386ae4cc8e31ab5 Mon Sep 17 00:00:00 2001 From: Csaba Nagy Date: Fri, 17 Apr 2015 21:51:28 +0200 Subject: [PATCH 1/4] Update platform.txt Quoting the serial.port will enable esptool to work for dev/tty devices with spaces in their name. Like in OSX: `/dev/tty.wch ch341 USB=>RS232 fa130`. Without quote the esptool fails silently since it only parses the `/dev/tty.wch`. --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index 505bfea89..3490ef416 100644 --- a/platform.txt +++ b/platform.txt @@ -91,5 +91,5 @@ tools.esptool.path={runtime.ide.path}/hardware/tools/esp8266 tools.esptool.upload.protocol=esp tools.esptool.upload.params.verbose=-vv tools.esptool.upload.params.quiet= -tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp {serial.port} -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin" +tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin" From 8ac5d70b7080722258bd2cdac1e177da5da4ede7 Mon Sep 17 00:00:00 2001 From: Bundit J Date: Sat, 18 Apr 2015 15:33:45 +0700 Subject: [PATCH 2/4] Add get and put functions to EEPROM As available in http://www.arduino.cc/en/Reference/EEPROM --- libraries/EEPROM/EEPROM.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libraries/EEPROM/EEPROM.h b/libraries/EEPROM/EEPROM.h index 0c7068d1c..c51f759b7 100644 --- a/libraries/EEPROM/EEPROM.h +++ b/libraries/EEPROM/EEPROM.h @@ -35,6 +35,27 @@ class EEPROMClass void commit(); void end(); + template T &get(int address, T &t) + { + if (address < 0 || address >= _size) + return t; + + uint8_t *ptr = (uint8_t*) &t; + for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count]; + return t; + } + + template const T &put(int address, const T &t) + { + if (address < 0 || address >= _size) + return t; + + const uint8_t *ptr = (const uint8_t*) &t; + for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++; + _dirty = true; + return t; + } + protected: uint8_t* _data; size_t _size; From 2adda59b6da3cd4b088dfa9d45c0b4eddbc1b186 Mon Sep 17 00:00:00 2001 From: Bundit J Date: Sat, 18 Apr 2015 16:08:36 +0700 Subject: [PATCH 3/4] Add get and put functions to EEPROM As available in http://www.arduino.cc/en/Reference/EEPROM --- libraries/EEPROM/EEPROM.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/EEPROM/EEPROM.h b/libraries/EEPROM/EEPROM.h index c51f759b7..961ff8b08 100644 --- a/libraries/EEPROM/EEPROM.h +++ b/libraries/EEPROM/EEPROM.h @@ -37,7 +37,7 @@ class EEPROMClass template T &get(int address, T &t) { - if (address < 0 || address >= _size) + if (address < 0 || address + sizeof(T) > _size) return t; uint8_t *ptr = (uint8_t*) &t; @@ -47,7 +47,7 @@ class EEPROMClass template const T &put(int address, const T &t) { - if (address < 0 || address >= _size) + if (address < 0 || address + sizeof(T) > _size) return t; const uint8_t *ptr = (const uint8_t*) &t; From 5a4c4c34277138c4d012e81fb42e8ba027a11c27 Mon Sep 17 00:00:00 2001 From: Bundit J Date: Sat, 18 Apr 2015 22:48:04 +0700 Subject: [PATCH 4/4] Use memcpy instead of loop --- libraries/EEPROM/EEPROM.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/EEPROM/EEPROM.h b/libraries/EEPROM/EEPROM.h index 961ff8b08..52de83909 100644 --- a/libraries/EEPROM/EEPROM.h +++ b/libraries/EEPROM/EEPROM.h @@ -24,6 +24,7 @@ #include #include +#include class EEPROMClass { @@ -41,7 +42,7 @@ class EEPROMClass return t; uint8_t *ptr = (uint8_t*) &t; - for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count]; + memcpy(ptr, _data + address, sizeof(T)); return t; } @@ -51,7 +52,7 @@ class EEPROMClass return t; const uint8_t *ptr = (const uint8_t*) &t; - for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++; + memcpy(_data + address, ptr, sizeof(T)); _dirty = true; return t; }