7const int8_t kNotAnInterrupt = -1;
8const float kMillisecondsInSecond = 1000.0;
9const float kMillimetersInMeter = 1000.0;
17 unsigned long pulsesPerMeter)
18 : mPulsesPerMeterRatio{ pulsesPerMeter > 0 ? static_cast<float>(pulsesPerMeter) / 100.0F
20 , mMillimetersPerPulse{ pulsesPerMeter > 0
21 ? kMillimetersInMeter / static_cast<float>(pulsesPerMeter)
24 , kSensorAttached{ mRuntime.pinToInterrupt(pulsePin) != kNotAnInterrupt }
47 return dt > 0 ? kMillisecondsInSecond * mMillimetersPerPulse /
static_cast<float>(dt) : 0.0F;
52 return kSensorAttached;
volatile unsigned long mPulsesCounter
volatile unsigned long mPreviousPulse
DirectionlessOdometer(Runtime &runtime, uint8_t pulsePin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed but not direction.
bool isAttached() const override
Returns whether the sensor has been properly attached.
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
virtual void reset()
Resets the total travelled distance and speed to 0
volatile unsigned long mDt
const float mPulsesPerMeterRatio
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
virtual void update()
Conducts the distance and speed measurements.
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
A callback to be invoked.
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
virtual int getRisingEdgeMode() const =0
Get the rising edge constant for setting an interrupt.
virtual void enableInterrupts()=0
Enable interrupts.
virtual int8_t pinToInterrupt(uint8_t pin)=0
Gets the interrupt number of the specified pin, equivalent of digitalPinToInterrupt in Arduino.
virtual void setPinDirection(uint8_t pin, uint8_t direction)=0
Set pin direction, equivalent of pinMode in Arduino.
virtual void disableInterrupts()=0
Disable interrupts.
virtual uint8_t getInputState() const =0
Get the runtime-specific value representing an INPUT pin state.
virtual void setInterrupt(uint8_t pin, InterruptCallback callback, int mode)=0
Enables an external hardware interrupt and provides a callback, equivalent to attachInterrupt in Ardu...
virtual unsigned long currentTimeMicros()=0
Gets the amount of microseconds since the microcontroller started running, equivalent of micros in Ar...
const unsigned long kMinimumPulseGap
const unsigned long kDefaultPulsesPerMeter