Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/feature/Add-ChooseReinforcer-activity' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Sep 22, 2022
2 parents 9df8f93 + 182f2a1 commit 279f8aa
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "rtos/Thread.h"

#include "ActivityKit.h"
#include "ChooseReinforcer.h"
#include "CoreBattery.h"
#include "CoreBufferedSerial.h"
#include "CoreDMA2D.hpp"
Expand Down Expand Up @@ -334,6 +335,7 @@ namespace activities {
namespace internal {

auto display_tag = leka::activity::DisplayTags(rfidkit, display::videokit);
auto choose_reinforcer = leka::activity::ChooseReinforcer(rfidkit, display::videokit, reinforcerkit);
auto number_recognition = leka::activity::NumberRecognition(rfidkit, display::videokit, reinforcerkit);
auto picto_color_recognition = leka::activity::PictoColorRecognition(rfidkit, display::videokit, reinforcerkit);
auto led_color_recognition =
Expand All @@ -343,6 +345,7 @@ namespace activities {

inline const std::unordered_map<MagicCard, interface::Activity *> activities {
{MagicCard::number_10, &internal::display_tag},
{MagicCard::number_0, &internal::choose_reinforcer},
{MagicCard::number_1, &internal::number_recognition},
{MagicCard::number_2, &internal::picto_color_recognition},
{MagicCard::number_3, &internal::led_color_recognition},
Expand Down
1 change: 1 addition & 0 deletions libs/ActivityKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_sources(ActivityKit
source/activities/NumberRecognition.cpp
source/activities/PictoColorRecognition.cpp
source/activities/LedColorRecognition.cpp
source/activities/ChooseReinforcer.cpp
)

target_link_libraries(ActivityKit
Expand Down
37 changes: 37 additions & 0 deletions libs/ActivityKit/include/activities/ChooseReinforcer.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

#include "RFIDKit.h"
#include "ReinforcerKit.h"
#include "interface/Activity.h"
#include "interface/libs/VideoKit.h"

namespace leka::activity {

class ChooseReinforcer : public interface::Activity
{
public:
explicit ChooseReinforcer(RFIDKit &rfidkit, interface::VideoKit &videokit, ReinforcerKit &reinforcerkit)
: _rfidkit(rfidkit), _videokit(videokit), _reinforcerkit(reinforcerkit) {};

void start() final;
void stop() final;

private:
void processCard(const MagicCard &card);

RFIDKit &_rfidkit;
interface::VideoKit &_videokit;
ReinforcerKit &_reinforcerkit;

std::function<void(const MagicCard &)> _backup_callback {};
};

} // namespace leka::activity

// LCOV_EXCL_STOP
56 changes: 56 additions & 0 deletions libs/ActivityKit/source/activities/ChooseReinforcer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

// LCOV_EXCL_START

#include "ChooseReinforcer.h"

namespace leka::activity {

void ChooseReinforcer::start()
{
_videokit.displayImage("fs/home/img/system/robot-face-smiling-slightly.jpg");

_backup_callback = _rfidkit.getCallback();

_rfidkit.onTagActivated([this](const MagicCard &card) { processCard(card); });
}

void ChooseReinforcer::processCard(const MagicCard &card)
{
switch (card.getId()) {
case (MagicCard::reinforcer_1_blink_green.getId()):
_reinforcerkit.setDefaultReinforcer(ReinforcerKit::Reinforcer::BlinkGreen);
_reinforcerkit.playDefault();
break;
case (MagicCard::reinforcer_2_spin_blink.getId()):
_reinforcerkit.setDefaultReinforcer(ReinforcerKit::Reinforcer::SpinBlink);
_reinforcerkit.playDefault();
break;
case (MagicCard::reinforcer_3_fire.getId()):
_reinforcerkit.setDefaultReinforcer(ReinforcerKit::Reinforcer::Fire);
_reinforcerkit.playDefault();
break;
case (MagicCard::reinforcer_4_sprinkles.getId()):
_reinforcerkit.setDefaultReinforcer(ReinforcerKit::Reinforcer::Sprinkles);
_reinforcerkit.playDefault();
break;
case (MagicCard::reinforcer_5_rainbow.getId()):
_reinforcerkit.setDefaultReinforcer(ReinforcerKit::Reinforcer::Rainbow);
_reinforcerkit.playDefault();
break;
default:
_backup_callback(card);
break;
}
}

void ChooseReinforcer::stop()
{
_rfidkit.onTagActivated(_backup_callback);
}

} // namespace leka::activity

// LCOV_EXCL_STOP
2 changes: 1 addition & 1 deletion libs/RFIDKit/include/MagicCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct MagicCard {

explicit constexpr MagicCard(const rfid::Tag &tag) : _tag(tag) {}

[[nodiscard]] auto getId() const -> uint16_t
[[nodiscard]] constexpr auto getId() const -> uint16_t
{
auto high = _tag.data.at(id_high_byte_index);
auto low = _tag.data.at(id_low_byte_index);
Expand Down

0 comments on commit 279f8aa

Please sign in to comment.