-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'hugo/feature/Add-Afraid-blue-animation' into develop
- Loading branch information
Showing
4 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// + Stage 1 + 2 + 3 + 4 + 5 + 6 + 7 + | ||
// | | | | | | | | | ||
// | |\ | |\ | |-----------|\ | -- Blue | ||
// | /| \ | /| \ | /| | \ | | ||
// | / | \ | / | \ | / | | \ | | ||
// | / | \ | / | \ | / | | \ | | ||
// | / | \| / | \| / | | \ | | ||
// | / | |/ | |/ | | \ | | ||
// | / | | | | | | \ | | ||
// | / | | | | | | \ | | ||
// | / | | | | | | \ | | ||
// | / | | | | | | \ | | ||
// | / | | | | | | \ | | ||
// | / | | | | | | \ | | ||
// |/ | | | | | | \| | ||
// | | | | | | | | | ||
// | | | | | | | | -- Black | ||
|
||
#pragma once | ||
|
||
// ? LCOV_EXCL_START - Exclude from coverage report | ||
|
||
#include "LEDAnimation.h" | ||
|
||
namespace leka::led::animation { | ||
|
||
class AfraidBlue : public interface::LEDAnimation | ||
{ | ||
public: | ||
explicit AfraidBlue(interface::LED &ears, interface::LED &belt) : _ears(ears), _belt(belt) {}; | ||
|
||
void start() final; | ||
void run() final; | ||
void stop() final; | ||
|
||
private: | ||
interface::LED &_ears; | ||
interface::LED &_belt; | ||
uint8_t _step = 0; | ||
uint8_t _stage = 1; | ||
|
||
[[nodiscard]] auto mapStep(uint8_t step) const -> float; | ||
|
||
void stage1(); | ||
void stage2(); | ||
void stage3(); | ||
void stage4(); | ||
void stage5(); | ||
void stage6(); | ||
void stage7(); | ||
|
||
void increaseBrightness(); | ||
void decreaseBrightness(float treshold); | ||
|
||
void turnLedBlack(); | ||
}; | ||
|
||
} // namespace leka::led::animation | ||
|
||
// ? LCOV_EXCL_STOP - Exclude from coverage report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// ? LCOV_EXCL_START - Exclude from coverage report | ||
|
||
#include "AfraidBlue.h" | ||
|
||
#include "MathUtils.h" | ||
|
||
namespace leka::led::animation { | ||
|
||
void AfraidBlue::start() | ||
{ | ||
turnLedBlack(); | ||
} | ||
|
||
void AfraidBlue::stop() | ||
{ | ||
turnLedBlack(); | ||
} | ||
|
||
void AfraidBlue::run() | ||
{ | ||
switch (_stage) { | ||
case 1: | ||
stage1(); | ||
break; | ||
case 2: | ||
stage2(); | ||
break; | ||
case 3: | ||
stage3(); | ||
break; | ||
case 4: | ||
stage4(); | ||
break; | ||
case 5: | ||
stage5(); | ||
break; | ||
case 6: | ||
stage6(); | ||
break; | ||
case 7: | ||
stage7(); | ||
break; | ||
default: | ||
break; | ||
} | ||
_ears.show(); | ||
_belt.show(); | ||
} | ||
|
||
auto AfraidBlue::mapStep(uint8_t step) const -> float | ||
{ | ||
constexpr auto kMaxInputValue = uint8_t {30}; | ||
return utils::math::map(step, uint8_t {0}, kMaxInputValue, 0.F, 1.F); | ||
} | ||
|
||
void AfraidBlue::stage1() | ||
{ | ||
increaseBrightness(); | ||
} | ||
|
||
void AfraidBlue::stage2() | ||
{ | ||
static constexpr auto kTreshold = 0.7F; | ||
decreaseBrightness(kTreshold); | ||
} | ||
|
||
void AfraidBlue::stage3() | ||
{ | ||
increaseBrightness(); | ||
} | ||
|
||
void AfraidBlue::stage4() | ||
{ | ||
static constexpr auto kTreshold = 0.7F; | ||
decreaseBrightness(kTreshold); | ||
} | ||
|
||
void AfraidBlue::stage5() | ||
{ | ||
if (auto pos = mapStep(_step); pos != 1.F) { | ||
RGB color = ColorKit::colorGradient(RGB::black, RGB::pure_blue, pos); | ||
_belt.setColor(color); | ||
_ears.setColor(color); | ||
_step++; | ||
} else { | ||
_step = 0; | ||
_stage++; | ||
} | ||
} | ||
|
||
void AfraidBlue::stage6() | ||
{ | ||
if (auto pos = mapStep(_step); pos != 1.F) { | ||
_belt.setColor(RGB::pure_blue); | ||
_ears.setColor(RGB::pure_blue); | ||
_step++; | ||
} else { | ||
_stage++; | ||
} | ||
} | ||
|
||
void AfraidBlue::stage7() | ||
{ | ||
decreaseBrightness(0.F); | ||
} | ||
|
||
void AfraidBlue::increaseBrightness() | ||
{ | ||
if (auto pos = mapStep(_step); pos != 1.F) { | ||
RGB color = ColorKit::colorGradient(RGB::black, RGB::pure_blue, pos); | ||
_belt.setColor(color); | ||
_ears.setColor(color); | ||
_step++; | ||
} else { | ||
_stage++; | ||
} | ||
} | ||
|
||
void AfraidBlue::decreaseBrightness(float treshold) | ||
{ | ||
if (auto pos = mapStep(_step); pos > treshold) { | ||
RGB color = ColorKit::colorGradient(RGB::black, RGB::pure_blue, pos); | ||
_belt.setColor(color); | ||
_ears.setColor(color); | ||
_step--; | ||
} else { | ||
_stage++; | ||
} | ||
} | ||
|
||
void AfraidBlue::turnLedBlack() | ||
{ | ||
_ears.setColor(RGB::black); | ||
_belt.setColor(RGB::black); | ||
_ears.show(); | ||
_belt.show(); | ||
} | ||
|
||
} // namespace leka::led::animation | ||
|
||
// ? LCOV_EXCL_STOP - Exclude from coverage report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters