RBE1001Lib
Rangefinder.h
Go to the documentation of this file.
1 #pragma once
2 #include "Arduino.h"
3 #include "freertos/FreeRTOS.h"
4 #include "freertos/task.h"
5 #include "freertos/semphr.h"
6 #define MAX_POSSIBLE_INTERRUPT_RANGEFINDER 4
7 
21 class Rangefinder {
22 public:
23  Rangefinder();
31  void attach(int trigger, int echo);
35  static int numberOfFinders;
39  static bool timoutThreadStarted;
43  static int pingIndex;
47  static bool forceFire;
51  portMUX_TYPE synch = portMUX_INITIALIZER_UNLOCKED;
55  int echoPin;
63  volatile unsigned long startTime;
67  volatile unsigned long roundTripTime;
86  float getDistanceCM();
90  static void checkTimeout();
96  static void fire();
102  void sensorISR();
106  static int getTimeoutState();
107 
108 
109 };
static int pingIndex
Definition: Rangefinder.h:43
float getDistanceCM()
get the distance of an object from the sensor in centimeters
static int getTimeoutState()
Function used by the timeout check thread to determine if this object has timed out.
Definition: Rangefinder.cpp:40
static Rangefinder * list[MAX_POSSIBLE_INTERRUPT_RANGEFINDER]
list of attached rangefinders
Definition: Rangefinder.h:80
int triggerPin
Definition: Rangefinder.h:59
void sensorISR()
The method called from the ISR indicating the echo pin changed state.
Definition: Rangefinder.cpp:82
static bool timoutThreadStarted
Definition: Rangefinder.h:39
long getRoundTripTimeMicroSeconds()
get the time of latest round trip in microseconds
Rangefinder objects wrap a FreeRTOS thread with pin change interrupts to read trigger/echo style ultr...
Definition: Rangefinder.h:21
#define MAX_POSSIBLE_INTERRUPT_RANGEFINDER
Definition: Rangefinder.h:6
static bool forceFire
Definition: Rangefinder.h:47
volatile unsigned long startTime
Definition: Rangefinder.h:63
static void checkTimeout()
check the current state of timeout and fire if its time to do so
Definition: Rangefinder.cpp:44
static int numberOfFinders
Definition: Rangefinder.h:35
void attach(int trigger, int echo)
Attach 2 pins to be used as triger and echo.
Definition: Rangefinder.cpp:92
static void fire()
fire a strobe of the trig pin
Definition: Rangefinder.cpp:66
volatile unsigned long roundTripTime
Definition: Rangefinder.h:67
portMUX_TYPE synch
Definition: Rangefinder.h:51