-
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.
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
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
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,52 @@ | ||
// 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 FlashNumberCounting : public interface::Activity | ||
{ | ||
public: | ||
explicit FlashNumberCounting(RFIDKit &rfidkit, interface::VideoKit &videokit, ReinforcerKit &reinforcerkit, | ||
interface::LED &led) | ||
: _rfidkit(rfidkit), _videokit(videokit), _reinforcerkit(reinforcerkit), _led(led) {}; | ||
|
||
void start() final; | ||
void stop() final; | ||
|
||
private: | ||
void processCard(const MagicCard &card); | ||
void launchNextRound(); | ||
|
||
RFIDKit &_rfidkit; | ||
interface::VideoKit &_videokit; | ||
ReinforcerKit &_reinforcerkit; | ||
interface::LED &_led; | ||
|
||
static constexpr uint8_t kRoundsNumber = 10; | ||
static constexpr uint8_t kSizeOfColorsTable = 5 * 2; | ||
static constexpr uint8_t kSizeOfFlashNumberTable = 12; | ||
|
||
static constexpr std::array<RGB, kSizeOfColorsTable> _colors = { | ||
RGB::pure_blue, RGB::pure_green, RGB::cyan, RGB::yellow, RGB::magenta, | ||
RGB::pure_blue, RGB::pure_green, RGB::cyan, RGB::yellow, RGB::magenta}; | ||
|
||
uint8_t _current_round = 0; | ||
uint8_t _current_flashes_number = 0; | ||
MagicCard _expected_tag_number = MagicCard::none; | ||
std::function<void(const MagicCard &)> _backup_callback {}; | ||
std::array<uint8_t, kSizeOfFlashNumberTable> _flash_numbers = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6}; | ||
}; | ||
|
||
} // namespace leka::activity | ||
|
||
// LCOV_EXCL_STOP |
70 changes: 70 additions & 0 deletions
70
libs/ActivityKit/source/activities/FlashNumberCounting.cpp
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,70 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// LCOV_EXCL_START | ||
|
||
#include "FlashNumberCounting.h" | ||
#include <random> | ||
|
||
namespace leka::activity { | ||
using namespace std::chrono; | ||
|
||
void FlashNumberCounting::start() | ||
{ | ||
_current_round = 0; | ||
_current_flashes_number = 0; | ||
_expected_tag_number = MagicCard::none; | ||
|
||
_videokit.displayImage("fs/home/img/system/robot-face-smiling-slightly.jpg"); | ||
|
||
_backup_callback = _rfidkit.getCallback(); | ||
std::shuffle(_flash_numbers.begin(), _flash_numbers.end(), std::mt19937(static_cast<unsigned int>(time(nullptr)))); | ||
rtos::ThisThread::sleep_for(2s); | ||
|
||
launchNextRound(); | ||
|
||
_rfidkit.onTagActivated([this](const MagicCard &card) { processCard(card); }); | ||
} | ||
|
||
void FlashNumberCounting::stop() | ||
{ | ||
_rfidkit.onTagActivated(_backup_callback); | ||
} | ||
|
||
void FlashNumberCounting::processCard(const MagicCard &card) | ||
{ | ||
if (card == _expected_tag_number) { | ||
_reinforcerkit.playDefault(); | ||
rtos::ThisThread::sleep_for(1s); | ||
|
||
++_current_round; | ||
|
||
if (_current_round == kRoundsNumber) { | ||
_backup_callback(MagicCard::dice_roll); | ||
return; | ||
} | ||
launchNextRound(); | ||
} else { | ||
_backup_callback(card); | ||
} | ||
} | ||
|
||
void FlashNumberCounting::launchNextRound() | ||
{ | ||
_current_flashes_number = _flash_numbers.at(_current_round); | ||
_expected_tag_number = MagicCard(MagicCard::number_0.getId() + _current_flashes_number); | ||
|
||
for (auto i = 0; i < _current_flashes_number; ++i) { | ||
_led.setColor(_colors.at(_current_round)); | ||
_led.show(); | ||
rtos::ThisThread::sleep_for(400ms); | ||
_led.setColor(RGB::black); | ||
_led.show(); | ||
rtos::ThisThread::sleep_for(500ms); | ||
} | ||
} | ||
|
||
} // namespace leka::activity | ||
|
||
// LCOV_EXCL_STOP |