Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/feature/Add-Sneeze-animation' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Mar 9, 2022
2 parents 914ac37 + 9370253 commit 719839a
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/LedKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target_sources(LedKit
source/Sick.cpp
source/Singing.cpp
source/Sleeping.cpp
source/Sneeze.cpp
source/Waiting.cpp
source/WakeUp.cpp
source/Wink.cpp
Expand Down
46 changes: 46 additions & 0 deletions libs/LedKit/include/internal/Sneeze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 Sneeze : public interface::LEDAnimation
{
public:
explicit Sneeze(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 _sneeze_position = 0;

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

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

void sneezeFromRight();
void sneezeFromLeft();

void turnLedBlack();
};

} // namespace leka::led::animation

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

// ? LCOV_EXCL_START - Exclude from coverage report

#include "Sneeze.h"

#include "MathUtils.h"

namespace leka::led::animation {

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

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

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

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

void Sneeze::stage1()
{
if (auto pos = mapStep(_step); pos != 1.F) {
++_step;
} else {
_step = 0;
++_stage;
}
}

void Sneeze::stage2()
{
static constexpr auto green_sick = RGB {0x10, 0xF0, 0x30};

static constexpr auto kNumberOfLedsBelt = uint8_t {20};
_belt.setColorAtIndex(_sneeze_position, green_sick);
_belt.setColorAtIndex(kNumberOfLedsBelt - (_sneeze_position + 1), green_sick);
++_sneeze_position;
if (_sneeze_position > kNumberOfLedsBelt / 6) {
++_stage;
}
}

void Sneeze::stage3()
{
static constexpr auto green_sick = RGB {0x10, 0xF0, 0x30};

static constexpr auto kNumberOfLedsBelt = uint8_t {20};
if (auto pos = mapStep(_step); pos != 1.F) {
RGB color = ColorKit::colorGradient(RGB::black, green_sick, pos);
_belt.setColorAtIndex(_sneeze_position, color);
_belt.setColorAtIndex(kNumberOfLedsBelt - (_sneeze_position + 1), color);
++_step;
} else {
++_stage;
}
}

void Sneeze::stage4()
{
static constexpr auto kNumberOfLedsBelt = uint8_t {20};
_belt.setColorAtIndex(_sneeze_position, RGB::black);
_belt.setColorAtIndex(kNumberOfLedsBelt - (_sneeze_position + 1), RGB::black);
--_sneeze_position;
if (_sneeze_position == 0) {
++_stage;
}
}

void Sneeze::stage5()
{
static constexpr auto kNumberOfLedsBelt = uint8_t {20};
_belt.setColorAtIndex(_sneeze_position, RGB::black);
_belt.setColorAtIndex(kNumberOfLedsBelt - (_sneeze_position + 1), RGB::black);
++_stage;
}

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

} // namespace leka::led::animation

// ? LCOV_EXCL_STOP - Exclude from coverage report
5 changes: 5 additions & 0 deletions spikes/lk_led_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Sick.h"
#include "Singing.h"
#include "Sleeping.h"
#include "Sneeze.h"
#include "Waiting.h"
#include "WakeUp.h"
#include "Wink.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ led::animation::SadCry animation_sad_cry(ears, belt);
led::animation::Sick animation_sick {ears, belt};
led::animation::Singing animation_singing(ears, belt);
led::animation::Sleeping animation_sleeping(ears, belt);
led::animation::Sneeze animation_sneeze {ears, belt};
led::animation::Waiting animation_waiting(ears, belt);
led::animation::WakeUp animation_wake_up(ears, belt);
led::animation::Wink animation_wink {ears, belt};
Expand Down Expand Up @@ -143,6 +145,9 @@ auto main() -> int
ledkit.start(animation_wink);
rtos::ThisThread::sleep_for(10s);

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

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

0 comments on commit 719839a

Please sign in to comment.