Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hugo/feature/Add Reinforcers animations #560

Merged
merged 5 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/LedKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ target_sources(LedKit
source/Amazed.cpp
source/Angry.cpp
source/AngryShort.cpp
source/BlinkGreen.cpp
source/Bubbles.cpp
source/Disgusted.cpp
source/Fire.cpp
source/Fly.cpp
source/Happy.cpp
source/LedKit.cpp
source/LoadingGreen.cpp
source/LoadingOrange.cpp
source/LoadingRed.cpp
source/LoadingYellow.cpp
source/Rainbow.cpp
source/Sad.cpp
source/SadCry.cpp
source/Sick.cpp
source/Singing.cpp
source/Sleeping.cpp
source/Sneeze.cpp
source/SpinBlink.cpp
source/Sprinkles.cpp
source/Underwater.cpp
source/Waiting.cpp
source/WakeUp.cpp
Expand Down
58 changes: 58 additions & 0 deletions libs/LedKit/include/internal/BlinkGreen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

// 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 +
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | |----| | | |----| | | |----| | | |----| | | |----| | --- Green1
// ----| | | |----| | | |----| | | |----| | | |----| | | | --- Green2
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// |----| |----| |----| |----| |----| |----| |----| |----| |----| |----| --- Black
// | | | | | | | | | | | | | | | | | | | |

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class BlinkGreen : public interface::LEDAnimation
{
public:
explicit BlinkGreen(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 = 0;

[[nodiscard]] auto mapStep(uint8_t step) const -> float;

void stagesBlack();
void stagesGreen1();
void stagesGreen2();

void turnLedBlack();
};

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
37 changes: 37 additions & 0 deletions libs/LedKit/include/internal/Fire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class Fire : public interface::LEDAnimation
{
public:
explicit Fire(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;
uint8_t _wave_tail_index = 0;

void stageWaves();
[[nodiscard]] auto getFireColor(uint8_t index) const -> RGB;

void turnLedBlack();
};

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
37 changes: 37 additions & 0 deletions libs/LedKit/include/internal/Rainbow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class Rainbow : public interface::LEDAnimation
{
public:
explicit Rainbow(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;
uint8_t _rainbow_tail_index = 0;

void stagesRainbow();
[[nodiscard]] auto getRainbowColor(uint8_t index) const -> RGB;

void turnLedBlack();
};

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
57 changes: 57 additions & 0 deletions libs/LedKit/include/internal/SpinBlink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

// 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 +
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// |----| |----| |----| |----| |----| |----| |----| |----| |----| |----| Ears Magenta
// ----| |----| |----| |----| |----| |----| |----| |----| |----| |----| | Ears Cyan
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | | | |
// ----| |----| |----| |----| |----| |----| |----| |----| |----| |----| | Belt Magenta
// |----| |----| |----| |----| |----| |----| |----| |----| |----| |----| Belt Cyan
// | | | | | | | | | | | | | | | | | | | |

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class SpinBlink : public interface::LEDAnimation
{
public:
explicit SpinBlink(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 = 0;

[[nodiscard]] auto mapStep(uint8_t step) const -> float;

void stagesBeltCyan();
void stagesBeltMagenta();

void turnLedBlack();
};

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
37 changes: 37 additions & 0 deletions libs/LedKit/include/internal/Sprinkles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class Sprinkles : public interface::LEDAnimation
{
public:
explicit Sprinkles(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;
uint8_t _wave_tail_index = 0;

void moveWave(uint8_t &wave_tail_index);
[[nodiscard]] auto getSprinklesColor() const -> RGB;

void turnLedBlack();
};

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
99 changes: 99 additions & 0 deletions libs/LedKit/source/BlinkGreen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

// ? LCOV_EXCL_START - Exclude from coverage report

#include "BlinkGreen.h"

#include "MathUtils.h"

namespace leka::led::animation {

static constexpr auto green1 = RGB {0, 170, 0};
static constexpr auto green2 = RGB {0, 255, 80};

void BlinkGreen::start()
{
turnLedBlack();
}

void BlinkGreen::stop()
{
turnLedBlack();
_step = 0;
_stage = 0;
}

void BlinkGreen::run()
{
static constexpr auto kLastStage = uint8_t {41};
auto is_green2_stage = [this] { return (_stage % 4) == 0; };
auto is_green1_stage = [this] { return (_stage % 2) == 0; };
if (_stage > kLastStage) {
return;
}
if (is_green2_stage()) {
stagesGreen2();
} else if (is_green1_stage()) {
stagesGreen1();
} else {
stagesBlack();
}
_belt.show();
_ears.show();
}

auto BlinkGreen::mapStep(uint8_t step) const -> float
{
static constexpr auto kInputMaxValue = uint8_t {6};
return utils::math::map(step, uint8_t {0}, kInputMaxValue, 0.F, 1.F);
}

void BlinkGreen::stagesBlack()
{
if (auto pos = mapStep(_step); pos != 1.F) {
_belt.setColor(RGB::black);
_ears.setColor(RGB::black);
++_step;
} else {
_step = 0;
++_stage;
}
}

void BlinkGreen::stagesGreen1()
{
if (auto pos = mapStep(_step); pos != 1.F) {
_belt.setColor(green1);
_ears.setColor(green1);
++_step;
} else {
_step = 0;
++_stage;
}
}

void BlinkGreen::stagesGreen2()
{
if (auto pos = mapStep(_step); pos != 1.F) {
_belt.setColor(green2);
_ears.setColor(green2);
++_step;
} else {
_step = 0;
++_stage;
}
}

void BlinkGreen::turnLedBlack()
{
_ears.setColor(RGB::black);
_belt.setColor(RGB::black);
_ears.show();
_belt.show();
}

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
Loading