Firmware SDK
twr_hc_sr04

Driver for HC-SR04 ultrasonic range sensor. More...

Typedefs

typedef struct twr_hc_sr04_t twr_hc_sr04_t
 HC-SR04 instance.
 

Enumerations

enum  twr_hc_sr04_event_t {
  TWR_HC_SR04_EVENT_ERROR = 0,
  TWR_HC_SR04_EVENT_UPDATE = 1
}
 
enum  twr_hc_sr04_echo_t {
  TWR_HC_SR04_ECHO_P5 = TWR_GPIO_P5,
  TWR_HC_SR04_ECHO_P8 = TWR_GPIO_P8
}
 

Functions

void twr_hc_sr04_init_sensor_module (twr_hc_sr04_t *self)
 Initialize HC-SR04 for sensor module. More...
 
void twr_hc_sr04_init (twr_hc_sr04_t *self, twr_gpio_channel_t trig, twr_hc_sr04_echo_t echo)
 Initialize HC-SR04. More...
 
void twr_hc_sr04_set_event_handler (twr_hc_sr04_t *self, void(*event_handler)(twr_hc_sr04_t *, twr_hc_sr04_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_hc_sr04_set_update_interval (twr_hc_sr04_t *self, twr_tick_t interval)
 Set measurement interval. More...
 
bool twr_hc_sr04_measure (twr_hc_sr04_t *self)
 Start measurement manually. More...
 
bool twr_hc_sr04_get_distance_millimeter (twr_hc_sr04_t *self, float *millimeter)
 Get measured distance in millimeters. More...
 

Detailed Description

Driver for HC-SR04 ultrasonic range sensor.

Enumeration Type Documentation

◆ twr_hc_sr04_event_t

Enumerator
TWR_HC_SR04_EVENT_ERROR 

Error event.

TWR_HC_SR04_EVENT_UPDATE 

Update event.

Definition at line 12 of file twr_hc_sr04.h.

Function Documentation

◆ twr_hc_sr04_get_distance_millimeter()

bool twr_hc_sr04_get_distance_millimeter ( twr_hc_sr04_t self,
float *  millimeter 
)

Get measured distance in millimeters.

Parameters
[in]selfInstance
[out]millimeterPointer to variable where result will be stored
Returns
true When value is valid
false When value is invalid

Definition at line 190 of file twr_hc_sr04.c.

Here is the call graph for this function:

◆ twr_hc_sr04_init()

void twr_hc_sr04_init ( twr_hc_sr04_t self,
twr_gpio_channel_t  trig,
twr_hc_sr04_echo_t  echo 
)

Initialize HC-SR04.

Parameters
[in]selfInstance
[in]echoPin
[in]trigPin

Definition at line 19 of file twr_hc_sr04.c.

Referenced by twr_hc_sr04_init_sensor_module().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_hc_sr04_init_sensor_module()

void twr_hc_sr04_init_sensor_module ( twr_hc_sr04_t self)

Initialize HC-SR04 for sensor module.

Parameters
[in]selfInstance

Definition at line 14 of file twr_hc_sr04.c.

Here is the call graph for this function:

◆ twr_hc_sr04_measure()

bool twr_hc_sr04_measure ( twr_hc_sr04_t self)

Start measurement manually.

Parameters
[in]selfInstance
Returns
true On success
false When other measurement is in progress

Definition at line 114 of file twr_hc_sr04.c.

Referenced by twr_hc_sr04_get_distance_millimeter(), and twr_hc_sr04_set_update_interval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_hc_sr04_set_event_handler()

void twr_hc_sr04_set_event_handler ( twr_hc_sr04_t self,
void(*)(twr_hc_sr04_t *, twr_hc_sr04_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]selfInstance
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 92 of file twr_hc_sr04.c.

◆ twr_hc_sr04_set_update_interval()

void twr_hc_sr04_set_update_interval ( twr_hc_sr04_t self,
twr_tick_t  interval 
)

Set measurement interval.

Parameters
[in]selfInstance
[in]intervalMeasurement interval

Definition at line 98 of file twr_hc_sr04.c.

Here is the call graph for this function: