Skip to content

Commit

Permalink
Restructure library and make it usable in Platformio
Browse files Browse the repository at this point in the history
Fix compilation errors due to Ticker library was updated
  • Loading branch information
Toshik committed Jul 9, 2020
1 parent 80f9351 commit a2b4347
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
File renamed without changes.
23 changes: 23 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions TickerScheduler.cpp → src/TickerScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions TickerScheduler.h → src/TickerScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Ticker
#include <functional>
#endif

void tickerFlagHandle(volatile bool * flag);
void tickerFlagHandle(bool * flag);

#ifdef _GLIBCXX_FUNCTIONAL
typedef std::function<void(void*)> tscallback_t;
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit a2b4347

Please sign in to comment.