RaidZeroLib
Coroutine robot framework for VEX V5
Toggle main menu visibility
Loading...
Searching...
No Matches
SimulationSensor.hpp
1
#pragma once
2
#include <cstdint>
3
4
#include "RaidZeroLib/api/Hardware/Sensor.hpp"
5
6
namespace
rz
{
7
9
template
<
class
T>
10
class
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
rz::Sensor::Sensor
Sensor()=default
rz::SimulationSensor
A sensor whose reading and connection are set directly, for tests.
Definition
SimulationSensor.hpp:10
rz::SimulationSensor::raw
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
rz::SimulationSensor::connected
bool connected() const override
Definition
SimulationSensor.hpp:23
rz::SimulationSensor::reconnect
void reconnect(T value)
Reconnects, optionally with a new reading (as if the device power-cycled).
Definition
SimulationSensor.hpp:17
rz::SimulationSensor::epoch
std::uint32_t epoch() const override
Increments every time the source reconnects. Readings across a reconnect are not comparable.
Definition
SimulationSensor.hpp:27
rz::SimulationSensor::disconnect
void disconnect()
Definition
SimulationSensor.hpp:14
rz::SimulationSensor::set
void set(T value)
Definition
SimulationSensor.hpp:12
rz
Definition
DriverControl.hpp:11
RaidZeroLib
impl
Simulation
Hardware
SimulationSensor.hpp
Generated by
1.18.0