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 Waiting animation breathing #516

Merged
merged 2 commits into from
Mar 9, 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
1 change: 1 addition & 0 deletions libs/LedKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ target_sources(LedKit
source/SadCry.cpp
source/Singing.cpp
source/Sleeping.cpp
source/Waiting.cpp
source/WakeUp.cpp
)

Expand Down
60 changes: 60 additions & 0 deletions libs/LedKit/include/internal/Waiting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

// + + + + +
// | Stage 1 | Stage 2 | Stage 3 | Stage 4 |
// | | | | |
// | |-\ | |-\ | --- White
// | -/| -\ | -/| -\ |
// | -/ | -\ | -/ | -\ |
// | -/ | -\ | -/ | -\ |
// | -/ | -\ | -/ | -\ |
// | -/ | -\ | -/ | -\ |
// | -/ | -\ | -/ | -\ |
// | -/ | -\| -/ | -\ |
// | -/ | |/ | -\ |
// | -/ | | | -\ |
// | -/ | | | -\ |
// | -/ | | | -\ |
// | -/ | | | -\ |
// | -/ | | | -\| --- Black
// |/ | | | |
// | | | | |

#pragma once

// ? LCOV_EXCL_START - Exclude from coverage report

#include "LEDAnimation.h"

namespace leka::led::animation {

class Waiting : public interface::LEDAnimation
{
public:
explicit Waiting(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, uint8_t max_input_value) const -> float;

void stage1();
void stage2();
void stage3();
void stage4();

void turnLedBlack();
};

} // namespace leka::led::animation

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

// ? LCOV_EXCL_START - Exclude from coverage report

#include "Waiting.h"

#include "MathUtils.h"

namespace leka::led::animation {

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

void Waiting::stop()
{
turnLedBlack();
}

void Waiting::run()
{
switch (_stage) {
case 1:
stage1();
break;
case 2:
stage2();
break;
case 3:
stage3();
break;
case 4:
stage4();
break;
default:
break;
}
_belt.show();
}

auto Waiting::mapStep(uint8_t step, uint8_t max_input_value) const -> float
{
return utils::math::map(step, uint8_t {0}, max_input_value, 0.F, 1.F);
}

void Waiting::stage1()
{
static constexpr auto kMaxInputValue1 = uint8_t {70};
static constexpr auto kMaxInputValue2 = uint8_t {50};
if (auto pos = mapStep(_step, kMaxInputValue1); pos != 1.F) {
RGB color = ColorKit::colorGradient(RGB::black, RGB::white, pos);
_belt.setColor(color);
_step++;
} else {
_step = kMaxInputValue2;
_stage++;
}
}

void Waiting::stage2()
{
static constexpr auto tresholdDown = 0.3F;
static constexpr auto kMaxInputValue2 = uint8_t {50};
if (auto pos = mapStep(_step, kMaxInputValue2); pos >= tresholdDown) {
RGB color = ColorKit::colorGradient(RGB::black, RGB::white, pos);
_belt.setColor(color);
_step--;
} else {
_stage++;
}
}

void Waiting::stage3()
{
static constexpr auto kMaxInputValue1 = uint8_t {70};
static constexpr auto kMaxInputValue2 = uint8_t {50};
if (auto pos = mapStep(_step, kMaxInputValue2); pos != 1.F) {
RGB color = ColorKit::colorGradient(RGB::black, RGB::white, pos);
_belt.setColor(color);
_step++;
} else {
_step = kMaxInputValue1;
_stage++;
}
}

void Waiting::stage4()
{
static constexpr auto kMaxInputValue1 = uint8_t {70};
if (auto pos = mapStep(_step, kMaxInputValue1); pos != 0.F) {
RGB color = ColorKit::colorGradient(RGB::black, RGB::white, pos);
_belt.setColor(color);
_step--;
} else {
_stage++;
}
}

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

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
7 changes: 6 additions & 1 deletion spikes/lk_led_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "SadCry.h"
#include "Singing.h"
#include "Sleeping.h"
#include "Waiting.h"
#include "WakeUp.h"

using namespace leka;
Expand Down Expand Up @@ -61,8 +62,9 @@ led::animation::LoadingYellow animation_loading_yellow(ears, belt);
led::animation::Sad animation_sad(ears, belt);
led::animation::SadCry animation_sad_cry(ears, belt);
led::animation::Singing animation_singing(ears, belt);
led::animation::WakeUp animation_wake_up(ears, belt);
led::animation::Sleeping animation_sleeping(ears, belt);
led::animation::Waiting animation_waiting(ears, belt);
led::animation::WakeUp animation_wake_up(ears, belt);

HelloWorld hello;

Expand Down Expand Up @@ -123,6 +125,9 @@ auto main() -> int
ledkit.start(animation_wake_up);
rtos::ThisThread::sleep_for(10s);

ledkit.start(animation_waiting);
rtos::ThisThread::sleep_for(10s);

ledkit.stop();
rtos::ThisThread::sleep_for(1s);
}
Expand Down