RaidZeroLib
Coroutine robot framework for VEX V5
Toggle main menu visibility
Loading...
Searching...
No Matches
Device.hpp
1
#pragma once
2
#include <cstdint>
3
4
#include "RaidZeroLib/api/Runtime/Component.hpp"
5
6
namespace
rz
{
7
18
class
Device
:
public
Component
{
19
public
:
20
[[nodiscard]] std::uint8_t
port
() const noexcept {
return
port_; }
21
23
[[nodiscard]]
bool
deviceConnected
() const noexcept {
return
connected_; }
24
26
[[nodiscard]] std::uint32_t
deviceEpoch
() const noexcept {
return
epoch_; }
27
29
static
void
validatePorts
();
30
31
protected
:
33
Device
(std::uint8_t
port
, std::string_view kind);
34
~Device
()
override
;
35
37
virtual
bool
poll
() = 0;
38
40
virtual
void
onConnect
() {}
41
42
private
:
43
Task<>
loop
() final;
44
46
void
refresh();
47
48
std::uint8_t port_;
49
bool
connected_ = false;
50
bool
reportedMissing = false;
51
std::uint32_t epoch_ = 0;
52
53
Device
* nextDevice =
nullptr
;
// intrusive list of all devices, for port validation
54
};
55
56
}
// namespace rz
rz::Component::Component
Component(const Component &)=delete
rz::Component::loop
virtual Task loop()=0
Runs for the whole program; never returns.
rz::Device
Base for anything plugged into a V5 smart port. The only layer that talks to hardware.
Definition
Device.hpp:18
rz::Device::deviceConnected
bool deviceConnected() const noexcept
Whether this tick's read succeeded.
Definition
Device.hpp:23
rz::Device::onConnect
virtual void onConnect()
Applies configuration. Called when the device first connects and after every reconnect.
Definition
Device.hpp:40
rz::Device::validatePorts
static void validatePorts()
Throws std::runtime_error if two devices are constructed on the same port.
rz::Device::port
std::uint8_t port() const noexcept
Definition
Device.hpp:20
rz::Device::deviceEpoch
std::uint32_t deviceEpoch() const noexcept
Increments on every (re)connection.
Definition
Device.hpp:26
rz::Device::~Device
~Device() override
rz::Device::Device
Device(std::uint8_t port, std::string_view kind)
rz::Device::poll
virtual bool poll()=0
Reads the hardware into cached members. Returns false if the read failed (keep old values).
rz::Task
corral::Task< T > Task
Lazy: nothing runs until it is co_awaited.
Definition
Task.hpp:17
rz
Definition
DriverControl.hpp:11
RaidZeroLib
api
Hardware
Device.hpp
Generated by
1.18.0