34#ifndef _OPENLCB_VELOCITY_HXX_
35#define _OPENLCB_VELOCITY_HXX_
51#define MPH_FACTOR 0.44704f
uint16_t float16_t
This type represents how velocity is seen on the wire (16 bit float).
int singles2halfp(void *target, const void *source, int numel)
Converts an IEEE single (float) to a half-precision (float16).
#define MPH_FACTOR
Conversion factor for MPH.
int halfp2singles(void *target, const void *source, int numel)
Converts an half-precision (float16) to an IEEE single (float).
This class provides a mechanism for working with velocity in different forms.
Velocity()
Default constructor.
float speed() const
Return the speed independent of direction.
void set_dcc_28(uint8_t value)
Set the speed from DCC 28 speed step format.
void reverse()
Set the direction to reverse.
~Velocity()
Destructor does nothing.
bool operator==(const Velocity &v) const
Overloaded equals equals operator.
Velocity operator/(const Velocity &v) const
Overloaded division operator.
Velocity & operator+=(const Velocity &v)
Overloaded addition equals operator.
Velocity & operator*=(const Velocity &v)
Overloaded multiplication equals operator.
Velocity(double value)
Basic constructor.
float velocity
Floating point representation of velocity.
float mph() const
Convert the native meters/sec representation into mile per hour.
Velocity(const Velocity &old_velocity)
Copy constructor.
bool isnan() const
Checks whether the speed is unknown.
@ FORWARD
forward direction
@ REVERSE
reverse direction
Velocity(float value)
Basic constructor.
Velocity operator+(const Velocity &v) const
Overloaded addition operator.
void set_wire(float16_t value)
Set the value based on the wire version of velocity.
Velocity & operator/=(const Velocity &v)
Overloaded division equals operator.
Velocity & operator++()
Overloaded pre-increement operator.
void forward()
Set the direction to forward.
static float zero_adjust(float value, float old)
Adjust for a math result of negative 0.
Velocity(float16_t value)
Constructor that takes the 16 bit wire format.
bool operator!=(const Velocity &v) const
Overloaded not equals operator.
void set_mph(float mph)
Sets the speed value from a given mph value.
uint8_t get_dcc_28()
Get the speed in DCC 28 speed step format.
bool direction() const
Return the direction independent of speed.
Velocity & operator=(const Velocity &v)
Overloaded equals operator.
void set_dcc_128(uint8_t value)
Set the speed from DCC 128 speed step format.
float16_t get_wire() const
Get a wire version of the velocity.
Velocity(int value)
Basic constructor.
Velocity & operator-=(const Velocity &v)
Overloaded subtraction equals operator.
Velocity & operator--()
Overloaded pre-decreement operator.
Velocity operator*(const Velocity &v) const
Overloaded multiplication operator.
uint8_t get_dcc_128()
Get the speed in DCC 128 speed step format.
void set_dcc_14(uint8_t value)
Set the speed from DCC 14 speed step format.
uint8_t get_dcc_14()
Get the speed in DCC 14 speed step format.
Velocity operator-(const Velocity &v) const
Overloaded subtraction operator.
Velocity(unsigned int value)
Basic constructor.