From a2b434752c33f389738dd602cf21ea3302f45275 Mon Sep 17 00:00:00 2001 From: Toshik Date: Thu, 9 Jul 2020 23:38:07 +0300 Subject: [PATCH] Restructure library and make it usable in Platformio Fix compilation errors due to Ticker library was updated --- .gitignore | 5 ++++ .vscode/extensions.json | 7 ++++++ {example/blink => examples}/blink/blink.ino | 0 platformio.ini | 23 +++++++++++++++++++ .../TickerScheduler.cpp | 6 ++--- TickerScheduler.h => src/TickerScheduler.h | 10 ++++---- 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json rename {example/blink => examples}/blink/blink.ino (100%) create mode 100644 platformio.ini rename TickerScheduler.cpp => src/TickerScheduler.cpp (91%) rename TickerScheduler.h => src/TickerScheduler.h (87%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0f0d740 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/example/blink/blink/blink.ino b/examples/blink/blink.ino similarity index 100% rename from example/blink/blink/blink.ino rename to examples/blink/blink.ino diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..3fd8969 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,23 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = examples/blink +lib_dir = . + +[env:esp8266] +platform = espressif8266 +board = esp01 +framework = arduino + +[env:megaatmega2560] +platform = atmelavr +board = megaatmega2560 +framework = arduino diff --git a/TickerScheduler.cpp b/src/TickerScheduler.cpp similarity index 91% rename from TickerScheduler.cpp rename to src/TickerScheduler.cpp index b3badc2..af47ffa 100644 --- a/TickerScheduler.cpp +++ b/src/TickerScheduler.cpp @@ -19,13 +19,13 @@ TickerScheduler::~TickerScheduler() this->size = 0; } -void TickerScheduler::handleTickerFlag(volatile bool * flag) +void TickerScheduler::handleTickerFlag(bool * flag) { if (!*flag) *flag = true; } -void TickerScheduler::handleTicker(tscallback_t f, void * arg, volatile bool * flag) +void TickerScheduler::handleTicker(tscallback_t f, void * arg, bool * flag) { if (*flag) { @@ -81,7 +81,7 @@ bool TickerScheduler::enable(uint8_t i) if (i >= this->size || !this->items[i].is_used) return false; - volatile bool * flag = &this->items[i].flag; + bool * flag = &this->items[i].flag; this->items[i].t.attach_ms(this->items[i].period, TickerScheduler::handleTickerFlag, flag); return true; diff --git a/TickerScheduler.h b/src/TickerScheduler.h similarity index 87% rename from TickerScheduler.h rename to src/TickerScheduler.h index 237ea67..708ba2e 100644 --- a/TickerScheduler.h +++ b/src/TickerScheduler.h @@ -48,7 +48,7 @@ class Ticker #include #endif -void tickerFlagHandle(volatile bool * flag); +void tickerFlagHandle(bool * flag); #ifdef _GLIBCXX_FUNCTIONAL typedef std::function tscallback_t; @@ -59,11 +59,11 @@ typedef void(*tscallback_t)(void*); struct TickerSchedulerItem { Ticker t; - volatile bool flag = false; + bool flag = false; tscallback_t cb; void * cb_arg; uint32_t period; - volatile bool is_used = false; + bool is_used = false; }; class TickerScheduler @@ -72,8 +72,8 @@ class TickerScheduler uint8_t size; TickerSchedulerItem *items = NULL; - void handleTicker(tscallback_t, void *, volatile bool * flag); - static void handleTickerFlag(volatile bool * flag); + void handleTicker(tscallback_t, void *, bool * flag); + static void handleTickerFlag(bool * flag); public: TickerScheduler(uint8_t size);