Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/rfid/allow-deep-sleep' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 4, 2024
2 parents f1298d8 + 22d8ce7 commit 53d1a4f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions drivers/CoreRFIDReader/include/CoreRFIDReaderCR95HF.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class CoreRFIDReaderCR95HF : public interface::RFIDReader
auto getTag() -> rfid::Tag & final;
void onTagReadable() final;

void enableDeepSleep() final;
void disableDeepSleep() final;

private:
void _receiveResponseFromTag();

Expand Down
10 changes: 10 additions & 0 deletions drivers/CoreRFIDReader/source/CoreRFIDReaderCR95HF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ void CoreRFIDReaderCR95HF::onTagReadable()
_on_tag_readable(_tag);
}

void CoreRFIDReaderCR95HF::enableDeepSleep()
{
_serial.enableDeepSleep();
}

void CoreRFIDReaderCR95HF::disableDeepSleep()
{
_serial.disableDeepSleep();
}

} // namespace leka
14 changes: 14 additions & 0 deletions drivers/CoreRFIDReader/tests/CoreRFIDReaderCR95HF_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,17 @@ TEST_F(CoreRFIDReaderTest, getTag)

EXPECT_EQ(tag.data, expected_values);
}

TEST_F(CoreRFIDReaderTest, enableDeepSleep)
{
EXPECT_CALL(mockBufferedSerial, enableDeepSleep());

reader.enableDeepSleep();
}

TEST_F(CoreRFIDReaderTest, disableDeepSleep)
{
EXPECT_CALL(mockBufferedSerial, disableDeepSleep());

reader.disableDeepSleep();
}
4 changes: 3 additions & 1 deletion include/interface/drivers/RFIDReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <functional>
#include <span>

#include "DeepSleepEnabled.h"

namespace leka {

namespace rfid {
Expand Down Expand Up @@ -43,7 +45,7 @@ namespace rfid {

namespace interface {

class RFIDReader
class RFIDReader : public interface::DeepSleepEnabled
{
public:
virtual ~RFIDReader() = default;
Expand Down
6 changes: 5 additions & 1 deletion libs/RFIDKit/include/RFIDKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

#include "ISO14443A.h"
#include "MagicCard.h"
#include "interface/drivers/DeepSleepEnabled.h"
#include "interface/drivers/RFIDReader.h"

namespace leka {

class RFIDKit
class RFIDKit : public interface::DeepSleepEnabled
{
public:
explicit RFIDKit(interface::RFIDReader &rfid_reader) : _rfid_reader(rfid_reader) {};
Expand All @@ -23,6 +24,9 @@ class RFIDKit
[[nodiscard]] auto getCallback() const -> const std::function<void(const MagicCard &)> &;
[[nodiscard]] auto getLastMagicCardActivated() const -> const MagicCard &;

void enableDeepSleep() final;
void disableDeepSleep() final;

private:
interface::RFIDReader &_rfid_reader;
MagicCard _card = MagicCard::none;
Expand Down
10 changes: 10 additions & 0 deletions libs/RFIDKit/source/RFIDKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ void RFIDKit::onTagActivated(std::function<void(const MagicCard &_card)> const &
return _card;
}

void RFIDKit::enableDeepSleep()
{
_rfid_reader.enableDeepSleep();
}

void RFIDKit::disableDeepSleep()
{
_rfid_reader.disableDeepSleep();
}

} // namespace leka
14 changes: 14 additions & 0 deletions libs/RFIDKit/tests/RFIDKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,17 @@ TEST_F(RFIDKitTest, getLastMagicCardActivated)

EXPECT_EQ(rfid_kit.getLastMagicCardActivated(), MagicCard::emergency_stop);
}

TEST_F(RFIDKitTest, enableDeepSleep)
{
EXPECT_CALL(mock_reader, enableDeepSleep());

rfid_kit.enableDeepSleep();
}

TEST_F(RFIDKitTest, disableDeepSleep)
{
EXPECT_CALL(mock_reader, disableDeepSleep());

rfid_kit.disableDeepSleep();
}
3 changes: 3 additions & 0 deletions tests/unit/mocks/mocks/leka/CoreRFIDReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class CoreRFIDReader : public interface::RFIDReader
MOCK_METHOD(void, onTagReadable, (), (override));
MOCK_METHOD(void, registerOnTagDetectedCallback, (const std::function<void()> &), (override));
MOCK_METHOD(void, registerOnTagReadableCallback, (const std::function<void(rfid::Tag &)> &), (override));

MOCK_METHOD(void, enableDeepSleep, (), (override));
MOCK_METHOD(void, disableDeepSleep, (), (override));
};

} // namespace leka::mock

0 comments on commit 53d1a4f

Please sign in to comment.