-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💫 (activity): Add EmotionRecognition activity
- Loading branch information
Showing
3 changed files
with
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
// LCOV_EXCL_START | ||
|
||
#include <optional> | ||
|
||
#include "RFIDKit.h" | ||
#include "ReinforcerKit.h" | ||
#include "include/Emotion.h" | ||
#include "interface/Activity.h" | ||
#include "interface/libs/VideoKit.h" | ||
|
||
namespace leka::activity { | ||
|
||
class EmotionRecognition : public interface::Activity | ||
{ | ||
public: | ||
explicit EmotionRecognition(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); | ||
void launchNextRound(); | ||
|
||
RFIDKit &_rfidkit; | ||
interface::VideoKit &_videokit; | ||
ReinforcerKit &_reinforcerkit; | ||
|
||
static constexpr uint8_t kRoundsNumber = 10; | ||
static constexpr uint8_t kSizeOfEmotionsTable = 5 * 2; | ||
|
||
uint8_t _current_round = 0; | ||
std::optional<Emotion> _current_emotion {}; | ||
std::function<void(const MagicCard &)> _backup_callback {}; | ||
std::array<Emotion, kSizeOfEmotionsTable> _emotions = { | ||
Emotion::anger, Emotion::anger, Emotion::fear, Emotion::fear, Emotion::joy, | ||
Emotion::joy, Emotion::sadness, Emotion::sadness, Emotion::disgust, Emotion::disgust}; | ||
}; | ||
|
||
} // namespace leka::activity | ||
|
||
// LCOV_EXCL_STOP |
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,56 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// LCOV_EXCL_START | ||
|
||
#include "EmotionRecognition.h" | ||
#include <random> | ||
|
||
namespace leka::activity { | ||
|
||
void EmotionRecognition::start() | ||
{ | ||
_current_round = 0; | ||
_current_emotion = {}; | ||
|
||
_backup_callback = _rfidkit.getCallback(); | ||
std::shuffle(_emotions.begin(), _emotions.end(), std::mt19937(static_cast<unsigned int>(time(nullptr)))); | ||
launchNextRound(); | ||
|
||
_rfidkit.onTagActivated([this](const MagicCard &card) { processCard(card); }); | ||
} | ||
|
||
void EmotionRecognition::stop() | ||
{ | ||
_rfidkit.onTagActivated(_backup_callback); | ||
} | ||
|
||
void EmotionRecognition::processCard(const MagicCard &card) | ||
{ | ||
if (card == std::get<0>(_current_emotion->cards) || card == std::get<1>(_current_emotion->cards)) { | ||
_reinforcerkit.playDefault(); | ||
++_current_round; | ||
|
||
if (_current_round == kRoundsNumber) { | ||
_backup_callback(MagicCard::dice_roll); | ||
return; | ||
} | ||
|
||
launchNextRound(); | ||
} else { | ||
_backup_callback(card); | ||
} | ||
} | ||
|
||
void EmotionRecognition::launchNextRound() | ||
{ | ||
_current_emotion = _emotions.at(_current_round); | ||
|
||
auto full_path = "/fs/home/img/id/" + std::string(_current_emotion->id) + ".jpg"; | ||
_videokit.displayImage(full_path); | ||
} | ||
|
||
} // namespace leka::activity | ||
|
||
// LCOV_EXCL_STOP |