Skip to content

Commit

Permalink
allow pointer types in TJLedSequence (#73)
Browse files Browse the repository at this point in the history
This change is needed for the MicroPython port in order to operate also on
an array of JLed* pointers, when the JLedSequence class is defined as
TJLedSequence<JLed*>.

bump platformio ver in ci to 5.1.1
  • Loading branch information
jandelgado committed Jun 19, 2021
1 parent 0672dc0 commit 6ebb7fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: install tools
run: |
pip install platformio==5.0.3
pip install platformio==5.1.1
sudo apt-get update && sudo apt-get install -y lcov
- name: run tests
Expand All @@ -54,4 +54,3 @@ jobs:

- name: build examples
run: make ci

1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ framework = arduino
build_flags = -Isrc
src_filter = +<../../src/> +<./>
upload_protocol=stlink
debug_speed=auto

[env:esp8266]
platform = espressif8266
Expand Down
9 changes: 6 additions & 3 deletions src/jled_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ class TJLed {
uint16_t delay_after_ = 0; // delay after each repetition
};

template<typename T> T* ptr(T &obj) {return &obj;} // NOLINT
template<typename T> T* ptr(T *obj) {return obj;}

// a group of JLed objects which can be controlled simultanously, in parallel
// or sequentially.
template <typename T>
Expand All @@ -458,7 +461,7 @@ class TJLedSequence {
bool UpdateParallel() {
auto result = false;
for (auto i = 0u; i < n_; i++) {
result |= leds_[i].Update();
result |= ptr(leds_[i])->Update();
}
return result;
}
Expand All @@ -469,15 +472,15 @@ class TJLedSequence {
if (cur_ >= n_) {
return false;
}
if (!leds_[cur_].Update()) {
if (!ptr(leds_[cur_])->Update()) {
return ++cur_ < n_;
}
return true;;
}

void ResetLeds() {
for (auto i = 0u; i < n_; i++) {
leds_[i].Reset();
ptr(leds_[i])->Reset();
}
}

Expand Down

0 comments on commit 6ebb7fc

Please sign in to comment.