Skip to content

Commit

Permalink
🚸 (BlinkOnCharge): Improve animation
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Dec 15, 2022
1 parent fe7e073 commit cf4a918
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
7 changes: 7 additions & 0 deletions libs/LedKit/include/animations/BlinkOnCharge.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class BlinkOnCharge : public interface::LEDAnimation
uint8_t _step = 0;
uint8_t _stage = 0;

void stage0();
void stage1();
void stage2();

void increaseBrightness(uint8_t max, RGB color);
void decreaseBrightness(uint8_t max, RGB color);

void turnLedBlack();
};

Expand Down
71 changes: 64 additions & 7 deletions libs/LedKit/source/animations/BlinkOnCharge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,77 @@ void BlinkOnCharge::stop()

void BlinkOnCharge::run()
{
const auto kStageDurationEarsOn = uint8_t {20};

if (_ears == nullptr || _belt == nullptr) {
return;
}

if (_stage < kStageDurationEarsOn) {
_ears->setColor(RGB::pure_green);
_ears->show();
} else {
switch (_stage) {
case 0:
stage0();
break;
case 1:
stage1();
break;

case 2:
stage2();
break;

default:
_stage = 0;
break;
}
_ears->show();
}

void BlinkOnCharge::stage0()
{
increaseBrightness(20, RGB::pure_green);
}

void BlinkOnCharge::stage1()
{
decreaseBrightness(20, RGB::pure_green);
}

void BlinkOnCharge::stage2()
{
static constexpr auto kMaxEarsOffDuration = uint8_t {100};
if (_step < kMaxEarsOffDuration) {
turnLedBlack();
++_step;
} else {
_step = 0;
++_stage;
}
}

void BlinkOnCharge::increaseBrightness(uint8_t max, RGB color)
{
static const auto kMaxInputValue = max;
if (auto pos = utils::normalizeStep(_step, kMaxInputValue); pos != 1.F) {
RGB color_gradient = ColorKit::colorGradient(RGB::black, color, pos);
_ears->setColor(color_gradient);
++_step;

} else {
_step = 0;
++_stage;
}
}

void BlinkOnCharge::decreaseBrightness(uint8_t max, RGB color)
{
static const auto kMaxInputValue = max;
if (auto pos = utils::normalizeStep(kMaxInputValue - _step, max); pos != 0) {
RGB color_gradient = ColorKit::colorGradient(RGB::black, color, pos);
_ears->setColor(color_gradient);
++_step;

++_stage;
} else {
_step = 0;
++_stage;
}
}

void BlinkOnCharge::turnLedBlack()
Expand Down

0 comments on commit cf4a918

Please sign in to comment.