Base for anything plugged into a V5 smart port. The only layer that talks to hardware.
More...
#include <Device.hpp>
|
| static void | validatePorts () |
| | Throws std::runtime_error if two devices are constructed on the same port.
|
| static Task | runAll () |
| | Runs the loop of every component constructed so far, in construction order, until cancelled. rz::robot runs it; tests without rz::robot run it alongside their script.
|
|
| | Device (std::uint8_t port, std::string_view kind) |
| | ~Device () override |
| virtual bool | poll ()=0 |
| | Reads the hardware into cached members. Returns false if the read failed (keep old values).
|
| virtual void | onConnect () |
| | Applies configuration. Called when the device first connects and after every reconnect.
|
| | Component (std::string_view name) |
Base for anything plugged into a V5 smart port. The only layer that talks to hardware.
- A component that polls its hardware at tickStarted(), so every reading is this tick's by sensorsUpdated(). It is only polled while rz::robot (or Component::runAll()) runs.
- A failed read keeps the last good values and marks the device disconnected (logged once).
- onConnect() applies configuration on the first connection and again after every reconnect, since devices lose their settings when they power-cycle.
- Constructors only store configuration, so devices can be globals in any file.
◆ Device()
| rz::Device::Device |
( |
std::uint8_t | port, |
|
|
std::string_view | kind ) |
|
protected |
- Parameters
-
| kind | Human-readable device type, used as the component name in log messages (e.g. "RotationSensor"). |
◆ ~Device()
◆ deviceConnected()
| bool rz::Device::deviceConnected |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Whether this tick's read succeeded.
◆ deviceEpoch()
| std::uint32_t rz::Device::deviceEpoch |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Increments on every (re)connection.
◆ onConnect()
| virtual void rz::Device::onConnect |
( |
| ) |
|
|
inlineprotectedvirtual |
Applies configuration. Called when the device first connects and after every reconnect.
◆ poll()
| virtual bool rz::Device::poll |
( |
| ) |
|
|
protectedpure virtual |
Reads the hardware into cached members. Returns false if the read failed (keep old values).
◆ port()
| std::uint8_t rz::Device::port |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ validatePorts()
| void rz::Device::validatePorts |
( |
| ) |
|
|
static |
Throws std::runtime_error if two devices are constructed on the same port.
The documentation for this class was generated from the following file: