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/Mock LedKit #1206

Merged
merged 7 commits into from
Dec 15, 2022
Merged
1 change: 1 addition & 0 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "FoodRecognition.h"
#include "HelloWorld.h"
#include "LedColorRecognition.h"
#include "LedKit.h"
#include "LedNumberCounting.h"
#include "LogKit.h"
#include "NumberRecognition.h"
Expand Down
22 changes: 22 additions & 0 deletions include/interface/libs/LedKit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "LEDAnimation.h"

namespace leka::interface {

class LedKit
{
public:
virtual ~LedKit() = default;

virtual void init() = 0;
virtual void start(interface::LEDAnimation *animation) = 0;
virtual void run() = 0;
virtual void stop() = 0;
};

} // namespace leka::interface
6 changes: 3 additions & 3 deletions libs/BehaviorKit/include/BehaviorKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#pragma once

#include "LedKit.h"
#include "interface/drivers/Motor.h"
#include "interface/libs/LedKit.h"
#include "interface/libs/VideoKit.h"

namespace leka {

class BehaviorKit
{
public:
explicit BehaviorKit(interface::VideoKit &videokit, LedKit &ledkit, interface::Motor &motor_left,
explicit BehaviorKit(interface::VideoKit &videokit, interface::LedKit &ledkit, interface::Motor &motor_left,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to the PR, but could behaviors depend on motionkit instead of motors? how are motors used here?

interface::Motor &motor_right)
: _videokit(videokit), _ledkit(ledkit), _motor_left(motor_left), _motor_right(motor_right)
{
Expand Down Expand Up @@ -42,7 +42,7 @@ class BehaviorKit

private:
interface::VideoKit &_videokit;
LedKit &_ledkit;
interface::LedKit &_ledkit;
interface::Motor &_motor_left;
interface::Motor &_motor_right;
};
Expand Down
6 changes: 4 additions & 2 deletions libs/BehaviorKit/source/BehaviorKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "rtos/ThisThread.h"

#include "LedKitAnimations.h"

namespace leka {

using namespace std::chrono;
Expand All @@ -29,7 +31,7 @@ void BehaviorKit::launching()

void BehaviorKit::sleeping()
{
_ledkit.start(&LedKit::animation::sleeping);
_ledkit.start(&led::animation::sleeping);
_videokit.playVideoOnce("/fs/home/vid/system/robot-system-sleep-yawn_then_sleep-no_eyebrows.avi");
}

Expand Down Expand Up @@ -74,7 +76,7 @@ void BehaviorKit::chargingFull()

void BehaviorKit::bleConnection(bool with_video)
{
_ledkit.start(&LedKit::animation::ble_connection);
_ledkit.start(&led::animation::ble_connection);
if (with_video) {
_videokit.playVideoOnce("/fs/home/vid/system/robot-system-ble_connection-wink-no_eyebrows.avi");
}
Expand Down
35 changes: 17 additions & 18 deletions libs/BehaviorKit/tests/BehaviorKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,34 @@

#include "BehaviorKit.h"

#include "LedKit.h"
#include "LedKitAnimations.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mocks/leka/CoreLED.h"
#include "mocks/leka/CoreMotor.h"
#include "mocks/leka/LEDAnimation.h"
#include "mocks/leka/LedKit.h"
#include "mocks/leka/VideoKit.h"
#include "stubs/leka/EventLoopKit.h"

using namespace leka;

using ::testing::InSequence;

MATCHER_P(isSameAnimation, expected_animation_type, "")
{
bool is_same = typeid(*expected_animation_type) == typeid(*arg);
return is_same;
}

class BehaviorKitTest : public ::testing::Test
{
protected:
BehaviorKitTest() : behaviorkit(mock_videokit, ledkit, mock_motor_left, mock_motor_right) {};
BehaviorKitTest() : behaviorkit(mock_videokit, mock_ledkit, mock_motor_left, mock_motor_right) {};

// void SetUp() override {}
// void TearDown() override {}

mock::VideoKit mock_videokit {};

mock::CoreLED mock_ears;
mock::CoreLED mock_belt;

stub::EventLoopKit stub_event_loop;

LedKit ledkit {stub_event_loop, mock_ears, mock_belt};

mock::LEDAnimation mock_animation {};
mock::LedKit mock_ledkit {};

mock::CoreMotor mock_motor_left {};
mock::CoreMotor mock_motor_right {};
Expand Down Expand Up @@ -76,6 +73,8 @@ TEST_F(BehaviorKitTest, launching)
TEST_F(BehaviorKitTest, sleeping)
{
EXPECT_CALL(mock_videokit, playVideoOnce);
EXPECT_CALL(mock_ledkit, start(isSameAnimation(&led::animation::sleeping))).Times(1);

behaviorkit.sleeping();
}

Expand All @@ -102,12 +101,16 @@ TEST_F(BehaviorKitTest, batteryBehaviors)
TEST_F(BehaviorKitTest, bleConnectionWhileCharging)
{
EXPECT_CALL(mock_videokit, playVideoOnce).Times(0);
EXPECT_CALL(mock_ledkit, start(isSameAnimation(&led::animation::ble_connection))).Times(1);

behaviorkit.bleConnection(false);
}

TEST_F(BehaviorKitTest, bleConnectionWhileNotCharging)
{
EXPECT_CALL(mock_videokit, playVideoOnce);
EXPECT_CALL(mock_ledkit, start(isSameAnimation(&led::animation::ble_connection))).Times(1);

behaviorkit.bleConnection(true);
}

Expand All @@ -119,12 +122,8 @@ TEST_F(BehaviorKitTest, working)

TEST_F(BehaviorKitTest, stop)
{
auto speed = 0.5;

ledkit.start(&mock_animation);

EXPECT_CALL(mock_ledkit, stop);
EXPECT_CALL(mock_videokit, stopVideo);
EXPECT_CALL(mock_animation, stop).Times(1);
EXPECT_CALL(mock_motor_left, stop());
EXPECT_CALL(mock_motor_right, stop());

Expand Down
76 changes: 11 additions & 65 deletions libs/LedKit/include/LedKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,28 @@

#include "ColorKit.h"
#include "LEDAnimation.h"
HPezz marked this conversation as resolved.
Show resolved Hide resolved
#include "animations/AfraidBlue.h"
#include "animations/AfraidRed.h"
#include "animations/AfraidRedBlue.h"
#include "animations/Amazed.h"
#include "animations/Angry.h"
#include "animations/AngryShort.h"
#include "animations/BleConnection.h"
#include "animations/BlinkGreen.h"
#include "animations/Bubbles.h"
#include "animations/Disgusted.h"
#include "animations/Fire.h"
#include "animations/Fly.h"
#include "animations/Happy.h"
#include "animations/Rainbow.h"
#include "animations/Sad.h"
#include "animations/SadCry.h"
#include "animations/Sick.h"
#include "animations/Singing.h"
#include "animations/Sleeping.h"
#include "animations/Sneeze.h"
#include "animations/SpinBlink.h"
#include "animations/Sprinkles.h"
#include "animations/Underwater.h"
#include "animations/WakeUp.h"
#include "animations/Wink.h"
#include "animations/Yawn.h"
#include "interface/libs/EventLoop.h"
namespace leka {
#include "interface/libs/LedKit.h"

class LedKit
namespace leka {
class LedKit : public interface::LedKit
{
public:
static constexpr auto kNumberOfLedsEars = 2;
static constexpr auto kNumberOfLedsBelt = 20;

LedKit(interface::EventLoop &event_loop, interface::LED &ears, interface::LED &belt)
: _event_loop(event_loop), _ears(ears), _belt(belt) {};

void init();
void start(interface::LEDAnimation *animation);
void run();
void stop();

struct animation {
static inline auto afraid_blue = led::animation::AfraidBlue {};
static inline auto afraid_red = led::animation::AfraidRed {};
static inline auto afraid_red_blue = led::animation::AfraidRedBlue {};
static inline auto amazed = led::animation::Amazed {};
static inline auto angry = led::animation::Angry {};
static inline auto angry_short = led::animation::AngryShort {};
static inline auto blink_green = led::animation::BlinkGreen {};
static inline auto bubbles = led::animation::Bubbles {};
static inline auto ble_connection = led::animation::BleConnection {};
static inline auto disgusted = led::animation::Disgusted {};
static inline auto fire = led::animation::Fire {};
static inline auto fly = led::animation::Fly {};
static inline auto happy = led::animation::Happy {};
static inline auto rainbow = led::animation::Rainbow {};
static inline auto sad = led::animation::Sad {};
static inline auto sad_cry = led::animation::SadCry {};
static inline auto sick = led::animation::Sick {};
static inline auto singing = led::animation::Singing {};
static inline auto sleeping = led::animation::Sleeping {};
static inline auto sneeze = led::animation::Sneeze {};
static inline auto spin_blink = led::animation::SpinBlink {};
static inline auto sprinkles = led::animation::Sprinkles {};
static inline auto underwater = led::animation::Underwater {};
static inline auto wake_up = led::animation::WakeUp {};
static inline auto wink = led::animation::Wink {};
static inline auto yawn = led::animation::Yawn {};
};

struct flags {
static constexpr uint32_t START_LED_ANIMATION_FLAG = (1UL << 1);
};

LedKit(interface::EventLoop &event_loop, interface::LED &ears, interface::LED &belt)
: _event_loop(event_loop), _ears(ears), _belt(belt) {};

void init() final;
void start(interface::LEDAnimation *animation) final;
void run() final;
void stop() final;

HPezz marked this conversation as resolved.
Show resolved Hide resolved
private:
interface::EventLoop &_event_loop;

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

#pragma once

#include "animations/AfraidBlue.h"
#include "animations/AfraidRed.h"
#include "animations/AfraidRedBlue.h"
#include "animations/Amazed.h"
#include "animations/Angry.h"
#include "animations/AngryShort.h"
#include "animations/BleConnection.h"
#include "animations/BlinkGreen.h"
#include "animations/Bubbles.h"
#include "animations/Disgusted.h"
#include "animations/Fire.h"
#include "animations/Fly.h"
#include "animations/Happy.h"
#include "animations/Rainbow.h"
#include "animations/Sad.h"
#include "animations/SadCry.h"
#include "animations/Sick.h"
#include "animations/Singing.h"
#include "animations/Sleeping.h"
#include "animations/Sneeze.h"
#include "animations/SpinBlink.h"
#include "animations/Sprinkles.h"
#include "animations/Underwater.h"
#include "animations/WakeUp.h"
#include "animations/Wink.h"
#include "animations/Yawn.h"

namespace leka::led::animation {

static inline auto afraid_blue = led::animation::AfraidBlue {};
static inline auto afraid_red = led::animation::AfraidRed {};
static inline auto afraid_red_blue = led::animation::AfraidRedBlue {};
static inline auto amazed = led::animation::Amazed {};
static inline auto angry = led::animation::Angry {};
static inline auto angry_short = led::animation::AngryShort {};
static inline auto blink_green = led::animation::BlinkGreen {};
static inline auto bubbles = led::animation::Bubbles {};
static inline auto ble_connection = led::animation::BleConnection {};
static inline auto disgusted = led::animation::Disgusted {};
static inline auto fire = led::animation::Fire {};
static inline auto fly = led::animation::Fly {};
static inline auto happy = led::animation::Happy {};
static inline auto rainbow = led::animation::Rainbow {};
static inline auto sad = led::animation::Sad {};
static inline auto sad_cry = led::animation::SadCry {};
static inline auto sick = led::animation::Sick {};
static inline auto singing = led::animation::Singing {};
static inline auto sleeping = led::animation::Sleeping {};
static inline auto sneeze = led::animation::Sneeze {};
static inline auto spin_blink = led::animation::SpinBlink {};
static inline auto sprinkles = led::animation::Sprinkles {};
static inline auto underwater = led::animation::Underwater {};
static inline auto wake_up = led::animation::WakeUp {};
static inline auto wink = led::animation::Wink {};
static inline auto yawn = led::animation::Yawn {};

}; // namespace leka::led::animation
2 changes: 0 additions & 2 deletions libs/LedKit/tests/LedKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "LedKit.h"

#include "rtos/tests/UNITTESTS/doubles/Thread_stub.h"
HPezz marked this conversation as resolved.
Show resolved Hide resolved

#include "CoreLED.h"
#include "gtest/gtest.h"
#include "mocks/leka/CoreLED.h"
Expand Down
1 change: 0 additions & 1 deletion libs/LedKit/tests/LedKit_test_animations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class LedKitTestAnimations : public ::testing::Test

LedKit ledkit {stub_event_loop, ears, belt};

// mock::LEDAnimation mock_animation {};
mock::Animation mock_animation {};
};

Expand Down
6 changes: 3 additions & 3 deletions libs/ReinforcerKit/include/ReinforcerKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#pragma once

#include <interface/drivers/Motor.h>
#include <interface/libs/LedKit.h>
#include <interface/libs/VideoKit.h>

#include "LedKit.h"
#include "MotionKit.h"

namespace leka {

class ReinforcerKit
{
public:
explicit ReinforcerKit(interface::VideoKit &videokit, LedKit &ledkit, MotionKit &motion_kit)
explicit ReinforcerKit(interface::VideoKit &videokit, interface::LedKit &ledkit, MotionKit &motion_kit)
: _videokit(videokit), _ledkit(ledkit), _motionkit(motion_kit)
{
// nothing do to
Expand All @@ -37,7 +37,7 @@ class ReinforcerKit

private:
interface::VideoKit &_videokit;
LedKit &_ledkit;
interface::LedKit &_ledkit;
MotionKit &_motionkit;
Reinforcer _default_reinforcer = Reinforcer::Rainbow;

Expand Down
Loading