RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
rz::Device Class Referenceabstract

Base for anything plugged into a V5 smart port. The only layer that talks to hardware. More...

#include <Device.hpp>

Inheritance diagram for rz::Device:
rz::Component rz::InertialSensor rz::MotorDevice rz::RotationSensor

Public Member Functions

std::uint8_t port () const noexcept
bool deviceConnected () const noexcept
 Whether this tick's read succeeded.
std::uint32_t deviceEpoch () const noexcept
 Increments on every (re)connection.
Public Member Functions inherited from rz::Component
 Component (const Component &)=delete
Component & operator= (const Component &)=delete
 Component (Component &&)=delete
Component & operator= (Component &&)=delete
virtual ~Component ()
std::string_view name () const noexcept
 Used in log and error messages.

Static Public Member Functions

static void validatePorts ()
 Throws std::runtime_error if two devices are constructed on the same port.
Static Public Member Functions inherited from rz::Component
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.

Protected Member Functions

 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.
Protected Member Functions inherited from rz::Component
 Component (std::string_view name)

Detailed Description

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.

Constructor & Destructor Documentation

◆ Device()

rz::Device::Device ( std::uint8_t port,
std::string_view kind )
protected
Parameters
kindHuman-readable device type, used as the component name in log messages (e.g. "RotationSensor").

◆ ~Device()

rz::Device::~Device ( )
overrideprotected

Member Function Documentation

◆ 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: