upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Macros | Typedefs | Enumerations
Include dependency graph for bh1792.h:

API Description

/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <signal.h>
#include "bh1792.h"
#include <sys/time.h>
#include "upm_utilities.h"
bool isStopped;
#define SENSOR_ADDR 0x5b
#define I2C_BUS 0
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_data(void *args)
{
uint16_t led_on[32], led_off[32];
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
if(bh1792_get_fifo_data(dev, led_off, led_on) == UPM_SUCCESS) {
printf("\nFIFO data:\n");
for(int i = 0; i < 32; i++)
printf("%d: off: %d, on: %d\n", i, led_off[i], led_on[i]);
printf("timestamp %ld sec, %ld nsec\n", now.tv_sec, now.tv_nsec);
}
}
int main(int argc, char **argv)
{
float meas_time;
signal(SIGINT, signal_int_handler);
bh1792_context dev = bh1792_init(I2C_BUS, SENSOR_ADDR);
if (!dev) {
printf("bh1792_init() failed.\n");
return -1;
}
printf("Software reset\n");
bh1792_enable_sync_mode(dev, 256, 32);
bh1792_install_isr(dev, MRAA_GPIO_EDGE_FALLING, 33, &print_data, dev);
bh1792_get_meas_time_ms(dev, &meas_time);
printf("Heart beat sensor data\n");
while(!isStopped) {
usleep(meas_time * 1000);
}
return 0;
}

Go to the source code of this file.

Data Structures

struct  _bh1792_context
 bh1792 sensor context More...
 

Functions

bh1792_context bh1792_init (int bus, int addr)
 Init the sensor with specific bus and address. Before starting measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode, or bh1792_enable_single_mode) have to be called. More...
 
void bh1792_close (bh1792_context dev)
 Close and free sensor context. More...
 
upm_result_t bh1792_check_who_am_i (bh1792_context dev)
 Check "who am I" register value to identify the sensor. More...
 
bool bh1792_is_enabled (bh1792_context dev)
 Checks if the measuremnt on sensor is enabled. More...
 
upm_result_t bh1792_soft_reset (bh1792_context dev)
 Initiates a software reset to the sensor. All register values will be written to their defaults, thus intended operation mode need to be enabled. More...
 
upm_result_t bh1792_get_meas_time_ms (bh1792_context dev, float *meas_time)
 Gets the value of measurement time is milli-seconds. More...
 
upm_result_t bh1792_set_green_leds_current (bh1792_context dev, uint8_t current)
 Sets the green LED Current value. More...
 
upm_result_t bh1792_get_green_leds_current (bh1792_context dev, uint8_t *current)
 Gets the green LED current value. More...
 
upm_result_t bh1792_set_ir_led_current (bh1792_context dev, uint8_t current)
 Sets the IR LED Current value. More...
 
upm_result_t bh1792_get_ir_led_current (bh1792_context dev, uint8_t *current)
 Gets the IR LED current value. More...
 
upm_result_t bh1792_set_ir_threshold (bh1792_context dev, uint16_t threshold)
 Sets interrupt ir threshold value for non-synchronized mode. More...
 
upm_result_t bh1792_get_ir_threshold (bh1792_context dev, uint16_t *threshold)
 Gets interrupt ir threshold value. More...
 
upm_result_t bh1792_get_fifo_size (bh1792_context dev, uint8_t *count)
 Gets the current size of built-in FIFO. More...
 
upm_result_t bh1792_disable_interrupt (bh1792_context dev)
 Disables interrupt function. Interrupt is enabled by default on all operation modes, so this have to be called after enabling a specific operation mode. More...
 
upm_result_t bh1792_clear_interrupt (bh1792_context dev)
 Clears the interrupt flag allowing more interrupts to be raised. More...
 
upm_result_t bh1792_start_measurement (bh1792_context dev)
 Starts the measuremnt on sensor or enable the sensor. More...
 
upm_result_t bh1792_stop_measurement (bh1792_context dev)
 
upm_result_t bh1792_restart_measurement (bh1792_context dev)
 Restart the measurement, This function stops measurement, then re-writes the configuration registers again and start measurement with same configuration. More...
 
upm_result_t bh1792_get_fifo_data (bh1792_context dev, uint16_t fifo_led_off[], uint16_t fifo_led_on[])
 Gets the fifo data of 32 entries and resets the WATERMARK interrupt flag. More...
 
upm_result_t bh1792_discard_fifo_data (bh1792_context dev)
 Reads and discard the 32 FIFO entries to reset the WATERMARK interrupt flag. More...
 
upm_result_t bh1792_get_green_data (bh1792_context dev, uint16_t *green_led_off, uint16_t *green_led_on)
 Gets the values from using green LED light. More...
 
upm_result_t bh1792_get_ir_data (bh1792_context dev, uint16_t *ir_led_off, uint16_t *ir_led_on)
 Gets the values from using IR LED light. More...
 
upm_result_t bh1792_enable_sync_mode (bh1792_context dev, uint16_t meas_freq, uint8_t green_current)
 Enables and configures the sensor to use synchronized mode. This will use the built-in FIFO and raises a WATERMARK interrupt when FIFO size reaches 32 entries. To clear that interrupt flag FIFO must be read or discarded. This mode uses only green LED. More...
 
upm_result_t bh1792_enable_non_sync_mode (bh1792_context dev, uint8_t ir_current, uint16_t threshold)
 Enabled and configures the sensor to use non-synchronized mode. This mode uses IR_THRESHOLD interrupt, it will raise an interrupt if IR LED ON value is equal or greater than the threshold value. Interrupt must be cleared before receiving new interrupts. This mode uses only IR LED. More...
 
upm_result_t bh1792_enable_single_mode (bh1792_context dev, LED_TYPES led_type, uint8_t current)
 Enables and configures the sensor to use single mode. This sets the sensor to take only one measurement and raise an interrupt after measurement is finished. Interrupt flags has to be cleared to recieved new interrupts. This mode uses both green and IR LEDs. More...
 
upm_result_t bh1792_install_isr (bh1792_context dev, mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
 Installs the ISR to a given GPIO pin. More...
 
upm_result_t bh1792_install_isr_falling_edge (bh1792_context dev, int pin, void(*isr)(void *), void *isr_args)
 Installs the ISR to a given GPIO pin. More...
 
void bh1792_remove_isr (bh1792_context dev)
 Removes the ISR if it is installed. More...
 
upm_result_t bh1792_registers_dump (bh1792_context dev, char *dump)
 Gets a dump of configuration registers as a string. More...
 

Macros

#define ONE_SEC_IN_MIRCO_SEC   1000000
 
#define FIFO_WATERMARK   32
 
#define LED_CURRENT_MAX   63
 

Typedefs

typedef struct _bh1792_contextbh1792_context
 bh1792 sensor context
 

Enumerations

enum  MEAS_MODES {
  MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ, MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ, MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ, MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ,
  MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ, MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE, MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE
}
 Measurement modes, for synchronized time modes, non synchronized and single modes.
 
enum  LED_TYPES { GREEN, IR }
 LED light types.
 
enum  INTERRUPT_MODES { WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK, IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD, ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE }
 Interrupt modes of the sensor.
 
enum  OP_MODES { SYNCHRONIZED, NON_SYNCHRONIZED, SINGLE_GREEN, SINGLE_IR }
 Operations modes available with the sensor.
 

Function Documentation

bh1792_context bh1792_init ( int  bus,
int  addr 
)
Parameters
busI2C bus number
addrI2C sensor address
Returns
context of initialized sensor

Here is the call graph for this function:

void bh1792_close ( bh1792_context  dev)
Parameters
devSensor context

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_check_who_am_i ( bh1792_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

bool bh1792_is_enabled ( bh1792_context  dev)
Parameters
Thesensor context
Returns
True if measurement is enabled, or false otherwise

Here is the caller graph for this function:

upm_result_t bh1792_soft_reset ( bh1792_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_meas_time_ms ( bh1792_context  dev,
float *  meas_time 
)
Parameters
devThe sensor context
meas_time_msFloat pointer to store value of measurement time
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_set_green_leds_current ( bh1792_context  dev,
uint8_t  current 
)
Parameters
devThe sensor context
currentThe current value, accepted values are between 0-63
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_green_leds_current ( bh1792_context  dev,
uint8_t *  current 
)
Parameters
devThe sensor context
currentPointer to store the read current value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_set_ir_led_current ( bh1792_context  dev,
uint8_t  current 
)
Parameters
devThe sensor context
currentThe current value, accepted values are between 0-63
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_ir_led_current ( bh1792_context  dev,
uint8_t *  current 
)
Parameters
devThe sensor context
currentPointer to store the read current value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_set_ir_threshold ( bh1792_context  dev,
uint16_t  threshold 
)
Parameters
devSensor context
thresholdValue to be written, range 0-65536
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_ir_threshold ( bh1792_context  dev,
uint16_t *  threshold 
)
Parameters
devSensor context
thresholdPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_fifo_size ( bh1792_context  dev,
uint8_t *  count 
)
Parameters
devThe sensor context
countThe pointer to store the size
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_disable_interrupt ( bh1792_context  dev)
Parameters
devThe sensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_clear_interrupt ( bh1792_context  dev)
Parameters
devThe sensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_start_measurement ( bh1792_context  dev)
Parameters
devThe sensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_stop_measurement ( bh1792_context  dev)

Stops the measurement by setting the software reset bit. This function will reset all config registers. To resume from previous configuration call bh1792_restart_measurement().

Parameters
devThe sensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_restart_measurement ( bh1792_context  dev)
Parameters
devThe sensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_get_fifo_data ( bh1792_context  dev,
uint16_t  fifo_led_off[],
uint16_t  fifo_led_on[] 
)
Parameters
devThe sensor context
fifo_led_offArray/Pointer to store 32 entries of fifo LED_OFF data
fifo_led_onArray/Pointer to store 32 entries of fifo LED_ON data
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_discard_fifo_data ( bh1792_context  dev)
Parameters
devThe sensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_green_data ( bh1792_context  dev,
uint16_t *  green_led_off,
uint16_t *  green_led_on 
)
Parameters
devThe sensor context
green_led_offPointer to store the reading value of LED_OFF
green_led_onPointer to store the reading value of LED_ON
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_get_ir_data ( bh1792_context  dev,
uint16_t *  ir_led_off,
uint16_t *  ir_led_on 
)
Parameters
devThe sensor context
ir_led_offPointer to store the reading value of LED_OFF
ir_led_onPointer to store the reading value of LED_ON
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1792_enable_sync_mode ( bh1792_context  dev,
uint16_t  meas_freq,
uint8_t  green_current 
)

You need to call bh1792_start_measurement() after this.

Parameters
devThe sensor context
meas_freqMeasurement frequncy mode, valid values 32, 64, 128, 256, 1024
green_currentGreen LED current value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_enable_non_sync_mode ( bh1792_context  dev,
uint8_t  ir_current,
uint16_t  threshold 
)

You need to call bh1792_start_measurement() after this.

Parameters
devThe sensor context
ir_currentThe IR LED current value
thresholdThe IR LED interrupt threshold value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_enable_single_mode ( bh1792_context  dev,
LED_TYPES  led_type,
uint8_t  current 
)

You need to call bh1792_start_measurement() after this. If you need to get continuous values, clear interrupt and bh1792_start_measurement() continuously.

Parameters
devThe sensor context
led_typeLED light type to use, takes GREEN or IR values
currentThe chosen led_type current value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_install_isr ( bh1792_context  dev,
mraa_gpio_edge_t  edge,
int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
devSensor context
edgeEdge type to raise ISR with, of type mraa_gpio_edge_t
pinGPIO pin number
isrPointer to ISR function
isr_argsArguments to pass the ISR function
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1792_install_isr_falling_edge ( bh1792_context  dev,
int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
devSensor context
pinGPIO pin number
isrPointer to ISR function
isr_argsArguments to pass the ISR function
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void bh1792_remove_isr ( bh1792_context  dev)
Parameters
devSensor context

Here is the caller graph for this function:

upm_result_t bh1792_registers_dump ( bh1792_context  dev,
char *  dump 
)
Parameters
devSensor context
dumpPointer of char to save dump string
Returns
UPM result

Here is the caller graph for this function: