Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado committed Feb 24, 2022
1 parent 70681c9 commit b3fede6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/jled_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ class TJLed {
// functional header is not available for AVR. That means we can only use
// lambdas without captures. As a workaround, we allow an additional void*
// pointer to be passed, which can point to arbitrary data.
typedef void (*FinallyCallback)(B& led, void* data);
typedef void (*FinallyCallback)(B& led, void* data); // NOLINT

// Call Update and when the effect is finished, call the provided function
// f, which gets a reference to this JLed object and an optional data
// pointer. Use e.g. to reconfigure & restart after an effect was played.
bool UpdateAndFinally(FinallyCallback f, void* data=nullptr) {
bool UpdateAndFinally(FinallyCallback f, void* data = nullptr) {
if (!IsRunning()) {
return false;
}
Expand Down
23 changes: 13 additions & 10 deletions test/test_jled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ TEST_CASE("FadeOffEvaluator evaluates to expected brightness curve", "[jled]") {
}

TEST_CASE(
"BreatheEvaluator evaluates to flattened bell curve distributed brightness curve",
"BreatheEvaluator evaluates to flattened bell curve distributed brightness "
"curve",
"[jled]") {
const auto eval = BreatheBrightnessEvaluator(1000, 2000, 500);
REQUIRE(1000+2000+500 == eval.Period());
REQUIRE(1000 + 2000 + 500 == eval.Period());
const std::map<uint32_t, uint8_t> test_values = {
{0, 0}, {500, 68}, {1000, 255}, {2000, 255}, {3000, 255}, {3250, 68}, {3499, 0}, {3500, 0}};
{0, 0}, {500, 68}, {1000, 255}, {2000, 255},
{3000, 255}, {3250, 68}, {3499, 0}, {3500, 0}};

for (const auto &x : test_values) {
REQUIRE((int)x.second == (int)eval.Eval(x.first));
Expand Down Expand Up @@ -393,26 +395,28 @@ TEST_CASE("Update returns true while updating, else false", "[jled]") {
REQUIRE_FALSE(jled.Update());
}

TEST_CASE("UpdateAndFinally triggers the callback once on the last iteration", "[jled]") {
TEST_CASE("UpdateAndFinally triggers the callback once on the last iteration",
"[jled]") {
TestJLed jled = TestJLed(10).Blink(1, 1);

int cbCalled = 0;
auto cb = [] (TestJLed&, void* p) {
auto cb = [](TestJLed &, void *p) {
// gets &cbCalled passed in as void* p
(*(int*)p)++;
int *pCbCalled = (static_cast<int*>(p));
(*pCbCalled)++;
};

jled.Hal().SetMillis(0);
REQUIRE(jled.UpdateAndFinally(cb, &cbCalled));
REQUIRE( cbCalled == 0 );
REQUIRE(cbCalled == 0);

jled.Hal().SetMillis(1);
REQUIRE(!jled.UpdateAndFinally(cb, &cbCalled));
REQUIRE( cbCalled == 1 );
REQUIRE(cbCalled == 1);

jled.Hal().SetMillis(2);
REQUIRE(!jled.UpdateAndFinally(cb, &cbCalled));
REQUIRE( cbCalled == 1 );
REQUIRE(cbCalled == 1);
}

TEST_CASE("After Reset() the effect can be restarted", "[jled]") {
Expand Down Expand Up @@ -562,4 +566,3 @@ TEST_CASE("scaling a value with factor 31 returns original value", "[scale5]") {
REQUIRE(127 == jled::scale5(127, 31));
REQUIRE(255 == jled::scale5(255, 31));
}

0 comments on commit b3fede6

Please sign in to comment.