#include <stdio.h>
#include <signal.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)
{
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
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);
if (!dev) {
printf("bh1792_init() failed.\n");
return -1;
}
printf("Software reset\n");
printf("Heart beat sensor data\n");
while(!isStopped) {
usleep(meas_time * 1000);
}
return 0;
}
|
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...
|
|
|
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.
|
|