RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
SimulationSensor.hpp
1#pragma once
2#include <cstdint>
3
4#include "RaidZeroLib/api/Hardware/Sensor.hpp"
5
6namespace rz {
7
9template <class T>
10class SimulationSensor final : public Sensor<T> {
11 public:
12 void set(T value) { reading = value; }
13
14 void disconnect() { isConnected = false; }
15
17 void reconnect(T value) {
18 reading = value;
19 isConnected = true;
20 ++connectionEpoch;
21 }
22
23 [[nodiscard]] bool connected() const override { return isConnected; }
24
25 protected:
26 [[nodiscard]] T raw() const override { return reading; }
27 [[nodiscard]] std::uint32_t epoch() const override { return connectionEpoch; }
28
29 private:
30 T reading{};
31 bool isConnected = true;
32 std::uint32_t connectionEpoch = 0;
33};
34
35} // namespace rz
Sensor()=default
A sensor whose reading and connection are set directly, for tests.
Definition SimulationSensor.hpp:10
T raw() const override
This tick's reading from the source; the last good value while disconnected. May restart after a reco...
Definition SimulationSensor.hpp:26
bool connected() const override
Definition SimulationSensor.hpp:23
void reconnect(T value)
Reconnects, optionally with a new reading (as if the device power-cycled).
Definition SimulationSensor.hpp:17
std::uint32_t epoch() const override
Increments every time the source reconnects. Readings across a reconnect are not comparable.
Definition SimulationSensor.hpp:27
void disconnect()
Definition SimulationSensor.hpp:14
void set(T value)
Definition SimulationSensor.hpp:12
Definition DriverControl.hpp:11