Skip to content

Commit

Permalink
Trying to solve repeated start/stop use events in short periods
Browse files Browse the repository at this point in the history
Probably the user is keeping the card a little bit too long on the box, so I added a configuration settings with 2s default value to disable RFID readings.
  • Loading branch information
PBrunot committed Aug 11, 2024
1 parent e092868 commit b633f4d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
3 changes: 3 additions & 0 deletions conf/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ namespace fabomatic
/// @brief Minimum time to confirm by long tap maintenance
static constexpr auto LONG_TAP_DURATION{10s};

/// @brief Disabled RFID reading after a successfull read for X seconds.
static constexpr auto DELAY_BETWEEN_SWEEPS{2s};

} // namespace conf::machine

/// @brief Debug settings
Expand Down
2 changes: 2 additions & 0 deletions include/BaseRfidWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace fabomatic
virtual auto readCardSerial() const -> std::optional<card::uid_t> = 0;
virtual auto selfTest() const -> bool = 0;
virtual auto reset() const -> void = 0;

virtual auto setDisabledUntil(fabomatic::Tasks::time_point t) -> void = 0;
};
} // namespace fabomatic
#endif // BASERFIDWRAPPER_HPP_
1 change: 0 additions & 1 deletion include/BoardLogic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ namespace fabomatic
FabBackend server;
std::optional<std::reference_wrapper<BaseRFIDWrapper>> rfid{std::nullopt}; // Configured at runtime
std::optional<std::reference_wrapper<LCDWrapper>> lcd{std::nullopt}; // Configured at runtime
bool ready_for_a_new_card{true};
bool led_status{false};

Machine machine;
Expand Down
5 changes: 4 additions & 1 deletion include/RFIDWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace fabomatic
{
private:
std::unique_ptr<Driver> driver;
std::optional<fabomatic::Tasks::time_point> disabledUntil;

public:
RFIDWrapper();
Expand Down Expand Up @@ -46,14 +47,16 @@ namespace fabomatic

[[nodiscard]] auto getUid() const -> card::uid_t override;

[[nodiscard]] auto setDisabledUntil(fabomatic::Tasks::time_point delay) -> void override;

/// @brief Returns the driver object for testing/simulation
Driver &getDriver();

RFIDWrapper(const RFIDWrapper &) = delete; // copy constructor
RFIDWrapper &operator=(const RFIDWrapper &x) = delete; // copy assignment
RFIDWrapper(RFIDWrapper &&) = delete; // move constructor
RFIDWrapper &operator=(RFIDWrapper &&) = delete; // move assignment
~RFIDWrapper() override{}; // Default destructor
~RFIDWrapper() override {}; // Default destructor
};
} // namespace fabomatic

Expand Down
9 changes: 1 addition & 8 deletions src/BoardLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ namespace fabomatic
{
ESP_LOGD(TAG, "New card present");

if (!ready_for_a_new_card)
{
return;
}
ready_for_a_new_card = false;

if (machine.isFree())
{
// machine is free
Expand Down Expand Up @@ -557,12 +551,11 @@ namespace fabomatic
if (result)
{
onNewCard(result.value());
rfid.setDisabledUntil(Tasks::arduinoNow() + conf::machine::DELAY_BETWEEN_SWEEPS);
}
return;
}

// No new card present
ready_for_a_new_card = true;
if (machine.isFree())
{
changeStatus(Status::MachineFree);
Expand Down
21 changes: 20 additions & 1 deletion src/RFIDWrapper.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace fabomatic
{
/// @brief Constructor
template <typename Driver>
RFIDWrapper<Driver>::RFIDWrapper() : driver{std::make_unique<Driver>()} {};
RFIDWrapper<Driver>::RFIDWrapper() : driver{std::make_unique<Driver>()}, disabledUntil{std::nullopt} {};

/// @brief indicates if a new card is present in the RFID chip antenna area
/// @return true if a new card is present
Expand All @@ -24,15 +24,34 @@ namespace fabomatic
if (conf::debug::ENABLE_LOGS && result)
ESP_LOGD(TAG, "isNewCardPresent=%d", result);

if (disabledUntil && disabledUntil > fabomatic::Tasks::arduinoNow())
{
ESP_LOGD(TAG, "isNewCardPresent is disabled");
return false;
}

return result;
}

template <typename Driver>
[[nodiscard]] auto RFIDWrapper<Driver>::setDisabledUntil(fabomatic::Tasks::time_point delay) -> void
{
this->disabledUntil = delay;
}

/// @brief tries to read the card serial number
/// @return true if successfull, result can be read with getUid()
template <typename Driver>
auto RFIDWrapper<Driver>::readCardSerial() const -> std::optional<card::uid_t>
{
const auto &result = driver->PICC_ReadCardSerial();

if (disabledUntil && disabledUntil > fabomatic::Tasks::arduinoNow())
{
ESP_LOGD(TAG, "readCardSerial is disabled");
return std::nullopt;
}

if (result)
{
return getUid();
Expand Down

0 comments on commit b633f4d

Please sign in to comment.