mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
bh17xx: minor documentation and formatting updates, added rohm to vendor groups
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -30,276 +30,276 @@ using namespace upm;
|
||||
|
||||
BH1792::BH1792(int bus, int addr) : m_bh1792(bh1792_init(bus, addr))
|
||||
{
|
||||
if(!m_bh1792)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_init() failed");
|
||||
if(!m_bh1792)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_init() failed");
|
||||
}
|
||||
|
||||
BH1792::~BH1792()
|
||||
{
|
||||
bh1792_close(m_bh1792);
|
||||
bh1792_close(m_bh1792);
|
||||
}
|
||||
|
||||
void BH1792::CheckWhoAmI()
|
||||
{
|
||||
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_check_who_am_i() failed");
|
||||
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_check_who_am_i() failed");
|
||||
}
|
||||
|
||||
bool BH1792::IsEnabled()
|
||||
{
|
||||
return bh1792_is_enabled(m_bh1792);
|
||||
return bh1792_is_enabled(m_bh1792);
|
||||
}
|
||||
|
||||
void BH1792::SoftReset()
|
||||
{
|
||||
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_soft_reset() failed");
|
||||
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_soft_reset() failed");
|
||||
}
|
||||
|
||||
float BH1792::GetMeasurementTimeMS()
|
||||
{
|
||||
float meas_time;
|
||||
float meas_time;
|
||||
|
||||
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_meas_time_ms() failed");
|
||||
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_meas_time_ms() failed");
|
||||
|
||||
return meas_time;
|
||||
return meas_time;
|
||||
}
|
||||
|
||||
void BH1792::SetGreenLedsCurrent(uint16_t current)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t status;
|
||||
|
||||
status = bh1792_set_green_leds_current(m_bh1792, current);
|
||||
if(status == UPM_ERROR_OUT_OF_RANGE) {
|
||||
throw std::range_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_green_leds_current() failed, current not in range");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_green_leds_current() failed");
|
||||
}
|
||||
status = bh1792_set_green_leds_current(m_bh1792, current);
|
||||
if(status == UPM_ERROR_OUT_OF_RANGE) {
|
||||
throw std::range_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_green_leds_current() failed, current not in range");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_green_leds_current() failed");
|
||||
}
|
||||
}
|
||||
|
||||
int BH1792::GetGreenLedsCurrent()
|
||||
{
|
||||
uint8_t current;
|
||||
uint8_t current;
|
||||
|
||||
if(bh1792_get_green_leds_current(m_bh1792, ¤t) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_green_leds_current() failed");
|
||||
if(bh1792_get_green_leds_current(m_bh1792, ¤t) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_green_leds_current() failed");
|
||||
|
||||
return (int)current;
|
||||
return (int)current;
|
||||
}
|
||||
|
||||
void BH1792::SetIrLedCurrent(uint16_t current)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t status;
|
||||
|
||||
status = bh1792_set_ir_led_current(m_bh1792, current);
|
||||
if(status == UPM_ERROR_OUT_OF_RANGE) {
|
||||
throw std::range_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_led_current() failed, current not in range");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_led_current() failed");
|
||||
}
|
||||
status = bh1792_set_ir_led_current(m_bh1792, current);
|
||||
if(status == UPM_ERROR_OUT_OF_RANGE) {
|
||||
throw std::range_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_led_current() failed, current not in range");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_led_current() failed");
|
||||
}
|
||||
}
|
||||
|
||||
int BH1792::GetIrLedCurrent()
|
||||
{
|
||||
uint8_t current;
|
||||
uint8_t current;
|
||||
|
||||
if(bh1792_get_ir_led_current(m_bh1792, ¤t) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_led_current() failed");
|
||||
if(bh1792_get_ir_led_current(m_bh1792, ¤t) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_led_current() failed");
|
||||
|
||||
return (int)current;
|
||||
return (int)current;
|
||||
}
|
||||
|
||||
void BH1792::SetIrThreshold(uint16_t threshold)
|
||||
{
|
||||
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_threshold() failed");
|
||||
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_set_ir_threshold() failed");
|
||||
}
|
||||
|
||||
int BH1792::GetIrThreshold()
|
||||
{
|
||||
uint16_t threshold;
|
||||
uint16_t threshold;
|
||||
|
||||
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_threshold() failed");
|
||||
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_threshold() failed");
|
||||
|
||||
return (int)threshold;
|
||||
return (int)threshold;
|
||||
}
|
||||
|
||||
int BH1792::GetFifoSize()
|
||||
{
|
||||
uint8_t size;
|
||||
uint8_t size;
|
||||
|
||||
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_fifo_size() failed");
|
||||
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_fifo_size() failed");
|
||||
|
||||
return (int)size;
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
void BH1792::DisableInterrupt()
|
||||
{
|
||||
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_disable_interrupt() failed");
|
||||
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_disable_interrupt() failed");
|
||||
}
|
||||
|
||||
void BH1792::ClearInterrupt()
|
||||
{
|
||||
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_clear_interrupt() failed");
|
||||
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_clear_interrupt() failed");
|
||||
}
|
||||
|
||||
void BH1792::StartMeasurement()
|
||||
{
|
||||
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_start_measurement() failed");
|
||||
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_start_measurement() failed");
|
||||
}
|
||||
|
||||
void BH1792::StopMeasurement()
|
||||
{
|
||||
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_stop_measurement() failed");
|
||||
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_stop_measurement() failed");
|
||||
}
|
||||
|
||||
void BH1792::RestartMeasurement()
|
||||
{
|
||||
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_restart_measurement() failed");
|
||||
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_restart_measurement() failed");
|
||||
}
|
||||
|
||||
std::vector<std::vector<int>> BH1792::GetFifoData()
|
||||
{
|
||||
uint16_t fifo_off[FIFO_WATERMARK], fifo_on[FIFO_WATERMARK];
|
||||
uint16_t fifo_off[FIFO_WATERMARK], fifo_on[FIFO_WATERMARK];
|
||||
|
||||
if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_fifo_data() failed");
|
||||
|
||||
std::vector<int> item;
|
||||
std::vector<std::vector<int>> result;
|
||||
item.reserve(2);
|
||||
result.reserve(FIFO_WATERMARK);
|
||||
for(int i = 0; i < FIFO_WATERMARK; i++) {
|
||||
item.clear();
|
||||
item.push_back(fifo_off[i]);
|
||||
item.push_back(fifo_on[i]);
|
||||
result.push_back(item);
|
||||
}
|
||||
if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_fifo_data() failed");
|
||||
|
||||
return result;
|
||||
std::vector<int> item;
|
||||
std::vector<std::vector<int>> result;
|
||||
item.reserve(2);
|
||||
result.reserve(FIFO_WATERMARK);
|
||||
for(int i = 0; i < FIFO_WATERMARK; i++) {
|
||||
item.clear();
|
||||
item.push_back(fifo_off[i]);
|
||||
item.push_back(fifo_on[i]);
|
||||
result.push_back(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void BH1792::DiscardFifoData()
|
||||
{
|
||||
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_discard_fifo_data() failed");
|
||||
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_discard_fifo_data() failed");
|
||||
}
|
||||
|
||||
std::vector<int> BH1792::GetGreenData()
|
||||
{
|
||||
uint16_t green_off, green_on;
|
||||
uint16_t green_off, green_on;
|
||||
|
||||
if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_green_data() failed");
|
||||
if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_green_data() failed");
|
||||
|
||||
std::vector<int> result;
|
||||
result.reserve(2);
|
||||
result.push_back(green_off);
|
||||
result.push_back(green_on);
|
||||
std::vector<int> result;
|
||||
result.reserve(2);
|
||||
result.push_back(green_off);
|
||||
result.push_back(green_on);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<int> BH1792::GetIrData()
|
||||
{
|
||||
uint16_t ir_off, ir_on;
|
||||
uint16_t ir_off, ir_on;
|
||||
|
||||
if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_data() failed");
|
||||
if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_get_ir_data() failed");
|
||||
|
||||
std::vector<int> result;
|
||||
result.reserve(2);
|
||||
result.push_back(ir_off);
|
||||
result.push_back(ir_on);
|
||||
std::vector<int> result;
|
||||
result.reserve(2);
|
||||
result.push_back(ir_off);
|
||||
result.push_back(ir_on);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void BH1792::EnableSyncMode(uint16_t measFreq, uint16_t green_current)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t status;
|
||||
|
||||
status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
|
||||
if(status == UPM_ERROR_INVALID_PARAMETER) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_sync_mode() failed, invalid measurement frequncy");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_sync_mode() failed");
|
||||
}
|
||||
status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
|
||||
if(status == UPM_ERROR_INVALID_PARAMETER) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_sync_mode() failed, invalid measurement frequncy");
|
||||
} else if(status != UPM_SUCCESS) {
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_sync_mode() failed");
|
||||
}
|
||||
}
|
||||
|
||||
void BH1792::EnableNonSyncMode(uint16_t ir_current, uint16_t threshold)
|
||||
{
|
||||
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_non_sync_mode() failed");
|
||||
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_non_sync_mode() failed");
|
||||
}
|
||||
|
||||
void BH1792::EnableSingleMode(LED_TYPES led_type, uint16_t current)
|
||||
{
|
||||
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_single_mode() failed");
|
||||
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_enable_single_mode() failed");
|
||||
}
|
||||
|
||||
void BH1792::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
|
||||
{
|
||||
if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_install_isr() failed");
|
||||
if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_install_isr() failed");
|
||||
}
|
||||
|
||||
void BH1792::InstallISR(int pin, void (*isr)(void *), void *isr_args)
|
||||
{
|
||||
if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_install_isr_falling_edge() failed");
|
||||
if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_install_isr_falling_edge() failed");
|
||||
}
|
||||
|
||||
void BH1792::RemoveISR()
|
||||
{
|
||||
bh1792_remove_isr(m_bh1792);
|
||||
bh1792_remove_isr(m_bh1792);
|
||||
}
|
||||
|
||||
std::string BH1792::RegistersDump()
|
||||
{
|
||||
char dump[255];
|
||||
std::string dumpStr;
|
||||
char dump[255];
|
||||
std::string dumpStr;
|
||||
|
||||
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_registers_dump() failed");
|
||||
dumpStr = dump;
|
||||
return dumpStr;
|
||||
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
"bh1792_registers_dump() failed");
|
||||
dumpStr = dump;
|
||||
return dumpStr;
|
||||
}
|
||||
|
@ -37,19 +37,11 @@ extern "C"
|
||||
#include "bh1792glc_registers.h"
|
||||
|
||||
/**
|
||||
* @brief C API for the bh1792 Heart Rate sensor driver
|
||||
* @defgroup bh1792 libupm-bh1792
|
||||
* @ingroup ROHM i2c medical
|
||||
*/
|
||||
/**
|
||||
* @file bh1792.h
|
||||
* @library bh1792
|
||||
* @sensor bh1792
|
||||
* @comname Heart Rate Sensor
|
||||
* @type medical
|
||||
* @man ROHM
|
||||
* @con i2c
|
||||
* @brief C API for the bh1792 driver
|
||||
*
|
||||
* @brief C API for the bh1792 Heart Rate sensor driver
|
||||
* @include bh1792.c
|
||||
*/
|
||||
|
||||
#define ONE_SEC_IN_MIRCO_SEC 1000000
|
||||
@ -61,40 +53,40 @@ extern "C"
|
||||
* and single modes.
|
||||
*/
|
||||
typedef enum {
|
||||
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
|
||||
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
|
||||
} MEAS_MODES;
|
||||
|
||||
/**
|
||||
* @brief LED light types
|
||||
*/
|
||||
typedef enum {
|
||||
GREEN,
|
||||
IR
|
||||
GREEN,
|
||||
IR
|
||||
} LED_TYPES;
|
||||
|
||||
/**
|
||||
* @brief Interrupt modes of the sensor
|
||||
*/
|
||||
typedef enum {
|
||||
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
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief Operations modes available with the sensor
|
||||
*/
|
||||
typedef enum {
|
||||
SYNCHRONIZED,
|
||||
NON_SYNCHRONIZED,
|
||||
SINGLE_GREEN,
|
||||
SINGLE_IR
|
||||
SYNCHRONIZED,
|
||||
NON_SYNCHRONIZED,
|
||||
SINGLE_GREEN,
|
||||
SINGLE_IR
|
||||
} OP_MODES;
|
||||
|
||||
/**
|
||||
@ -102,26 +94,26 @@ typedef enum {
|
||||
*/
|
||||
typedef struct _bh1792_context
|
||||
{
|
||||
mraa_i2c_context i2c;
|
||||
mraa_gpio_context interrupt;
|
||||
bool enabled;
|
||||
bool isrEnabled;
|
||||
OP_MODES op_mode;
|
||||
pthread_t sync_thread;
|
||||
bool sync_thread_alive;
|
||||
LED_TYPES led_type;
|
||||
INTERRUPT_MODES interrupt_mode;
|
||||
uint16_t meas_freq;
|
||||
uint8_t green_current;
|
||||
uint8_t ir_current;
|
||||
uint16_t threshold;
|
||||
mraa_i2c_context i2c;
|
||||
mraa_gpio_context interrupt;
|
||||
bool enabled;
|
||||
bool isrEnabled;
|
||||
OP_MODES op_mode;
|
||||
pthread_t sync_thread;
|
||||
bool sync_thread_alive;
|
||||
LED_TYPES led_type;
|
||||
INTERRUPT_MODES interrupt_mode;
|
||||
uint16_t meas_freq;
|
||||
uint8_t green_current;
|
||||
uint8_t ir_current;
|
||||
uint16_t threshold;
|
||||
} *bh1792_context;
|
||||
|
||||
/**
|
||||
* @brief Init the sensor with specific bus and address. Before starting
|
||||
* measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode,
|
||||
* measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode,
|
||||
* or bh1792_enable_single_mode) have to be called.
|
||||
*
|
||||
*
|
||||
* @param bus I2C bus number
|
||||
* @param addr I2C sensor address
|
||||
* @return context of initialized sensor
|
||||
@ -130,14 +122,14 @@ bh1792_context bh1792_init(int bus, int addr);
|
||||
|
||||
/**
|
||||
* @brief Close and free sensor context
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
*/
|
||||
void bh1792_close(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Check "who am I" register value to identify the sensor
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -145,7 +137,7 @@ upm_result_t bh1792_check_who_am_i(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Checks if the measuremnt on sensor is enabled
|
||||
*
|
||||
*
|
||||
* @param The sensor context
|
||||
* @return True if measurement is enabled, or false otherwise
|
||||
*/
|
||||
@ -155,7 +147,7 @@ bool bh1792_is_enabled(bh1792_context dev);
|
||||
* @brief Initiates a software reset to the sensor. All register values will
|
||||
* be written to their defaults, thus intended operation mode need to be
|
||||
* enabled.
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -163,7 +155,7 @@ upm_result_t bh1792_soft_reset(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Gets the value of measurement time is milli-seconds
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param meas_time_ms Float pointer to store value of measurement time
|
||||
* @return UPM result
|
||||
@ -172,7 +164,7 @@ upm_result_t bh1792_get_meas_time_ms(bh1792_context dev, float *meas_time);
|
||||
|
||||
/**
|
||||
* @brief Sets the green LED Current value
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @return UPM result
|
||||
@ -181,7 +173,7 @@ upm_result_t bh1792_set_green_leds_current(bh1792_context dev, uint8_t current);
|
||||
|
||||
/**
|
||||
* @brief Gets the green LED current value
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param current Pointer to store the read current value
|
||||
* @return UPM result
|
||||
@ -190,7 +182,7 @@ upm_result_t bh1792_get_green_leds_current(bh1792_context dev, uint8_t *current)
|
||||
|
||||
/**
|
||||
* @brief Sets the IR LED Current value
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @return UPM result
|
||||
@ -199,7 +191,7 @@ upm_result_t bh1792_set_ir_led_current(bh1792_context dev, uint8_t current);
|
||||
|
||||
/**
|
||||
* @brief Gets the IR LED current value
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param current Pointer to store the read current value
|
||||
* @return UPM result
|
||||
@ -208,7 +200,7 @@ upm_result_t bh1792_get_ir_led_current(bh1792_context dev, uint8_t *current);
|
||||
|
||||
/**
|
||||
* @brief Sets interrupt ir threshold value for non-synchronized mode
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @param threshold Value to be written, range 0-65536
|
||||
* @return UPM result
|
||||
@ -217,7 +209,7 @@ upm_result_t bh1792_set_ir_threshold(bh1792_context dev, uint16_t threshold);
|
||||
|
||||
/**
|
||||
* @brief Gets interrupt ir threshold value
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @param threshold Pointer (uint16_t) to write value
|
||||
* @return UPM result
|
||||
@ -226,7 +218,7 @@ upm_result_t bh1792_get_ir_threshold(bh1792_context dev, uint16_t *threshold);
|
||||
|
||||
/**
|
||||
* @brief Gets the current size of built-in FIFO
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param count The pointer to store the size
|
||||
* @return UPM result
|
||||
@ -235,9 +227,9 @@ upm_result_t bh1792_get_fifo_size(bh1792_context dev, uint8_t *count);
|
||||
|
||||
/**
|
||||
* @brief Disables interrupt function. Interrupt is enabled by default on all
|
||||
* operation modes, so this have to be called after enabling a specific
|
||||
* operation modes, so this have to be called after enabling a specific
|
||||
* operation mode
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -245,7 +237,7 @@ upm_result_t bh1792_disable_interrupt(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Clears the interrupt flag allowing more interrupts to be raised
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -253,7 +245,7 @@ upm_result_t bh1792_clear_interrupt(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Starts the measuremnt on sensor or enable the sensor
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -263,7 +255,7 @@ upm_result_t bh1792_start_measurement(bh1792_context dev);
|
||||
* @breif 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().
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -273,7 +265,7 @@ upm_result_t bh1792_stop_measurement(bh1792_context dev);
|
||||
* @brief Restart the measurement, This function stops measurement, then
|
||||
* re-writes the configuration registers again and start measurement with same
|
||||
* configuration.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -282,19 +274,19 @@ upm_result_t bh1792_restart_measurement(bh1792_context dev);
|
||||
/**
|
||||
* @brief Gets the fifo data of 32 entries and resets the WATERMARK interrupt
|
||||
* flag.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param fifo_led_off Array/Pointer to store 32 entries of fifo LED_OFF data
|
||||
* @param fifo_led_on Array/Pointer to store 32 entries of fifo LED_ON data
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_get_fifo_data(bh1792_context dev, uint16_t fifo_led_off[],
|
||||
uint16_t fifo_led_on[]);
|
||||
uint16_t fifo_led_on[]);
|
||||
|
||||
/**
|
||||
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
|
||||
* interrupt flag.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @return UPM result
|
||||
*/
|
||||
@ -302,34 +294,34 @@ upm_result_t bh1792_discard_fifo_data(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Gets the values from using green LED light
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param green_led_off Pointer to store the reading value of LED_OFF
|
||||
* @param green_led_on Pointer to store the reading value of LED_ON
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_get_green_data(bh1792_context dev, uint16_t *green_led_off,
|
||||
uint16_t *green_led_on);
|
||||
uint16_t *green_led_on);
|
||||
|
||||
/**
|
||||
* @brief Gets the values from using IR LED light
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param ir_led_off Pointer to store the reading value of LED_OFF
|
||||
* @param ir_led_on Pointer to store the reading value of LED_ON
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
|
||||
uint16_t *ir_led_on);
|
||||
uint16_t *ir_led_on);
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
*
|
||||
* You need to call bh1792_start_measurement() after this.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param meas_freq Measurement frequncy mode, valid values 32, 64, 128, 256,
|
||||
* 1024
|
||||
@ -337,45 +329,45 @@ upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_enable_sync_mode(bh1792_context dev, uint16_t meas_freq,
|
||||
uint8_t green_current);
|
||||
uint8_t green_current);
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
*
|
||||
* You need to call bh1792_start_measurement() after this.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param ir_current The IR LED current value
|
||||
* @param threshold The IR LED interrupt threshold value
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_enable_non_sync_mode(bh1792_context dev, uint8_t ir_current,
|
||||
uint16_t threshold);
|
||||
uint16_t threshold);
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
*
|
||||
* You need to call bh1792_start_measurement() after this. If you need to get
|
||||
* continuous values, clear interrupt and bh1792_start_measurement()
|
||||
* continuously.
|
||||
*
|
||||
*
|
||||
* @param dev The sensor context
|
||||
* @param led_type LED light type to use, takes GREEN or IR values
|
||||
* @param current The chosen led_type current value
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
|
||||
uint8_t current);
|
||||
uint8_t current);
|
||||
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
|
||||
* @param pin GPIO pin number
|
||||
@ -384,11 +376,11 @@ upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
|
||||
int pin, void (*isr)(void *), void *isr_args);
|
||||
int pin, void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @param pin GPIO pin number
|
||||
* @param isr Pointer to ISR function
|
||||
@ -396,18 +388,18 @@ upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t bh1792_install_isr_falling_edge(bh1792_context dev, int pin,
|
||||
void (*isr)(void *), void *isr_args);
|
||||
void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Removes the ISR if it is installed
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
*/
|
||||
void bh1792_remove_isr(bh1792_context dev);
|
||||
void bh1792_remove_isr(bh1792_context dev);
|
||||
|
||||
/**
|
||||
* @brief Gets a dump of configuration registers as a string
|
||||
*
|
||||
*
|
||||
* @param dev Sensor context
|
||||
* @param dump Pointer of char to save dump string
|
||||
* @return UPM result
|
||||
|
@ -29,294 +29,296 @@
|
||||
#include "bh1792.h"
|
||||
|
||||
/**
|
||||
* @brief C++ API for the bh1792 Heart Rate sensor driver
|
||||
* @brief BH1792 Heart Rate Sensor
|
||||
* @defgroup bh1792 libupm-bh1792
|
||||
* @ingroup ROHM i2c medical
|
||||
* @ingroup rohm i2c medical
|
||||
*/
|
||||
/**
|
||||
* @library bh1792
|
||||
* @sensor bh1792
|
||||
* @comname Heart Rate Sensor
|
||||
* @type medical
|
||||
* @man ROHM
|
||||
* @man rohm
|
||||
* @con i2c
|
||||
*
|
||||
* @brief C++ API for the bh1792 driver
|
||||
*
|
||||
* @snippet bh1792.cxx Interesting
|
||||
*/
|
||||
|
||||
namespace upm {
|
||||
class BH1792 {
|
||||
public:
|
||||
class BH1792 {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Init the sensor with specific bus and address. Before
|
||||
* starting measurement, one of (EnableSyncMode, EnableNonSyncMode,
|
||||
* or EnableSingleMode) has to be called.
|
||||
*
|
||||
* @param bus I2C bus number
|
||||
* @param addr I2C sensor address
|
||||
* @throws std::runtime_error on initialization failure
|
||||
*/
|
||||
BH1792(int bus = 0, int addr = 0x5b);
|
||||
/**
|
||||
* @brief Init the sensor with specific bus and address. Before
|
||||
* starting measurement, one of (EnableSyncMode, EnableNonSyncMode,
|
||||
* or EnableSingleMode) has to be called.
|
||||
*
|
||||
* @param bus I2C bus number
|
||||
* @param addr I2C sensor address
|
||||
* @throws std::runtime_error on initialization failure
|
||||
*/
|
||||
BH1792(int bus = 0, int addr = 0x5b);
|
||||
|
||||
/**
|
||||
* @brief Close and free sensor
|
||||
*/
|
||||
virtual ~BH1792();
|
||||
/**
|
||||
* @brief Close and free sensor
|
||||
*/
|
||||
virtual ~BH1792();
|
||||
|
||||
/**
|
||||
* @brief Check "who am I" register value to identify the sensor
|
||||
*
|
||||
* @throws std::runtime_error if this value is incorrect
|
||||
*/
|
||||
void CheckWhoAmI();
|
||||
/**
|
||||
* @brief Check "who am I" register value to identify the sensor
|
||||
*
|
||||
* @throws std::runtime_error if this value is incorrect
|
||||
*/
|
||||
void CheckWhoAmI();
|
||||
|
||||
/**
|
||||
* @brief Checks if the measuremnt on sensor is enabled
|
||||
*
|
||||
* @return True if measurement is enabled, or false otherwise
|
||||
*/
|
||||
bool IsEnabled();
|
||||
/**
|
||||
* @brief Checks if the measuremnt on sensor is enabled
|
||||
*
|
||||
* @return True if measurement is enabled, or false otherwise
|
||||
*/
|
||||
bool IsEnabled();
|
||||
|
||||
/**
|
||||
* @brief Initiates a software reset to the sensor. All register values
|
||||
* will be written to their defaults, thus intended operation mode need
|
||||
* to be enabled.
|
||||
*
|
||||
* @throws std::runtime_error if software reset fails
|
||||
*/
|
||||
void SoftReset();
|
||||
/**
|
||||
* @brief Initiates a software reset to the sensor. All register values
|
||||
* will be written to their defaults, thus intended operation mode need
|
||||
* to be enabled.
|
||||
*
|
||||
* @throws std::runtime_error if software reset fails
|
||||
*/
|
||||
void SoftReset();
|
||||
|
||||
/**
|
||||
* @brief Gets the value of measurement time is milli-seconds
|
||||
*
|
||||
* @return measurement time float in milli-seconds
|
||||
* @throws std::runtime_error if reading measurement time fails
|
||||
*/
|
||||
float GetMeasurementTimeMS();
|
||||
/**
|
||||
* @brief Gets the value of measurement time is milli-seconds
|
||||
*
|
||||
* @return measurement time float in milli-seconds
|
||||
* @throws std::runtime_error if reading measurement time fails
|
||||
*/
|
||||
float GetMeasurementTimeMS();
|
||||
|
||||
/**
|
||||
* @brief Sets the green LED Current value
|
||||
*
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @throws std::runtime_error if setting current fails
|
||||
* @throws std::range_error if current value out of range
|
||||
*/
|
||||
void SetGreenLedsCurrent(uint16_t current);
|
||||
/**
|
||||
* @brief Sets the green LED Current value
|
||||
*
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @throws std::runtime_error if setting current fails
|
||||
* @throws std::range_error if current value out of range
|
||||
*/
|
||||
void SetGreenLedsCurrent(uint16_t current);
|
||||
|
||||
/**
|
||||
* @brief Gets the green LED current value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetGreenLedsCurrent();
|
||||
/**
|
||||
* @brief Gets the green LED current value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetGreenLedsCurrent();
|
||||
|
||||
/**
|
||||
* @brief Sets the IR LED Current value
|
||||
*
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @throws std::runtime_error if setting current fails
|
||||
* @throws std::range_error if current value out of range
|
||||
*/
|
||||
void SetIrLedCurrent(uint16_t current);
|
||||
/**
|
||||
* @brief Sets the IR LED Current value
|
||||
*
|
||||
* @param current The current value, accepted values are between 0-63
|
||||
* @throws std::runtime_error if setting current fails
|
||||
* @throws std::range_error if current value out of range
|
||||
*/
|
||||
void SetIrLedCurrent(uint16_t current);
|
||||
|
||||
/**
|
||||
* @brief Gets the green LED current value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetIrLedCurrent();
|
||||
/**
|
||||
* @brief Gets the green LED current value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetIrLedCurrent();
|
||||
|
||||
/**
|
||||
* @brief Sets interrupt IR threshold value for non-synchronized mode
|
||||
*
|
||||
* @param threshold Value to be written, range 0-65536
|
||||
* @throws std::runtime_error if setting threshold fails
|
||||
*/
|
||||
void SetIrThreshold(uint16_t threshold);
|
||||
/**
|
||||
* @brief Sets interrupt IR threshold value for non-synchronized mode
|
||||
*
|
||||
* @param threshold Value to be written, range 0-65536
|
||||
* @throws std::runtime_error if setting threshold fails
|
||||
*/
|
||||
void SetIrThreshold(uint16_t threshold);
|
||||
|
||||
/**
|
||||
* @brief Gets interrupt IR threshold value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetIrThreshold();
|
||||
/**
|
||||
* @brief Gets interrupt IR threshold value
|
||||
*
|
||||
* @return Green LED used current
|
||||
* @throws std::runtime_error if reading current fails
|
||||
*/
|
||||
int GetIrThreshold();
|
||||
|
||||
/**
|
||||
* @brief Gets the current size of built-in FIFO
|
||||
*
|
||||
* @return Number of entries store in FIFO
|
||||
* @throws std::runtime_error if reading size fails
|
||||
*/
|
||||
int GetFifoSize();
|
||||
/**
|
||||
* @brief Gets the current size of built-in FIFO
|
||||
*
|
||||
* @return Number of entries store in FIFO
|
||||
* @throws std::runtime_error if reading size fails
|
||||
*/
|
||||
int GetFifoSize();
|
||||
|
||||
/**
|
||||
* @brief Disables interrupt function. Interrupt is enabled by default
|
||||
* on all operation modes, so this have to be called after enabling a
|
||||
* specific operation mode
|
||||
*
|
||||
* @throws std::runtime_error if setting interrupt disable bits fails
|
||||
*/
|
||||
void DisableInterrupt();
|
||||
/**
|
||||
* @brief Disables interrupt function. Interrupt is enabled by default
|
||||
* on all operation modes, so this have to be called after enabling a
|
||||
* specific operation mode
|
||||
*
|
||||
* @throws std::runtime_error if setting interrupt disable bits fails
|
||||
*/
|
||||
void DisableInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Clears the interrupt flag allowing more interrupts to be
|
||||
* raised
|
||||
*
|
||||
* @throws std::runtime_error if clearing interrupt fails
|
||||
*/
|
||||
void ClearInterrupt();
|
||||
/**
|
||||
* @brief Clears the interrupt flag allowing more interrupts to be
|
||||
* raised
|
||||
*
|
||||
* @throws std::runtime_error if clearing interrupt fails
|
||||
*/
|
||||
void ClearInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Starts the measuremnt on sensor or enable the sensor
|
||||
*
|
||||
* @throws std::runtime_error if starting measurement fails
|
||||
*/
|
||||
void StartMeasurement();
|
||||
/**
|
||||
* @brief Starts the measuremnt on sensor or enable the sensor
|
||||
*
|
||||
* @throws std::runtime_error if starting measurement fails
|
||||
*/
|
||||
void StartMeasurement();
|
||||
|
||||
/**
|
||||
* @breif Stops the measurement by setting the software reset bit. This
|
||||
* function will reset all config registers. To resume from previous
|
||||
* configuration call RestartMeasurement().
|
||||
*
|
||||
* @throws std::runtime_error if disabling measurement fails
|
||||
*/
|
||||
void StopMeasurement();
|
||||
/**
|
||||
* @breif Stops the measurement by setting the software reset bit. This
|
||||
* function will reset all config registers. To resume from previous
|
||||
* configuration call RestartMeasurement().
|
||||
*
|
||||
* @throws std::runtime_error if disabling measurement fails
|
||||
*/
|
||||
void StopMeasurement();
|
||||
|
||||
/**
|
||||
* @brief Restart the measurement, This function stops measurement,
|
||||
* then re-writes the configuration registers again and start
|
||||
* measurement with same configuration.
|
||||
*
|
||||
* @throws std::runtime_error if restarting measurement fails
|
||||
*/
|
||||
void RestartMeasurement();
|
||||
/**
|
||||
* @brief Restart the measurement, This function stops measurement,
|
||||
* then re-writes the configuration registers again and start
|
||||
* measurement with same configuration.
|
||||
*
|
||||
* @throws std::runtime_error if restarting measurement fails
|
||||
*/
|
||||
void RestartMeasurement();
|
||||
|
||||
/**
|
||||
* @brief Gets the fifo data of 32 entries and resets the WATERMARK
|
||||
* interrupt flag.
|
||||
*
|
||||
* @return vector of values of the retrieved FIFO values, which are
|
||||
* vectors containing 2 values each (led off, led_on)
|
||||
* @throws std::runtime_error if reading FIFO data fails
|
||||
*/
|
||||
std::vector<std::vector<int>> GetFifoData();
|
||||
/**
|
||||
* @brief Gets the fifo data of 32 entries and resets the WATERMARK
|
||||
* interrupt flag.
|
||||
*
|
||||
* @return vector of values of the retrieved FIFO values, which are
|
||||
* vectors containing 2 values each (led off, led_on)
|
||||
* @throws std::runtime_error if reading FIFO data fails
|
||||
*/
|
||||
std::vector<std::vector<int>> GetFifoData();
|
||||
|
||||
/**
|
||||
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
|
||||
* interrupt flag.
|
||||
*
|
||||
* @throws std::runtime_error if reading FIFO data fails
|
||||
*/
|
||||
void DiscardFifoData();
|
||||
/**
|
||||
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
|
||||
* interrupt flag.
|
||||
*
|
||||
* @throws std::runtime_error if reading FIFO data fails
|
||||
*/
|
||||
void DiscardFifoData();
|
||||
|
||||
/**
|
||||
* @brief Gets the values from using green LED light
|
||||
*
|
||||
* @return vector of values (led off, led on) of green led values
|
||||
* @throws std::runtime_error if reading green data fails
|
||||
*/
|
||||
std::vector<int> GetGreenData();
|
||||
/**
|
||||
* @brief Gets the values from using green LED light
|
||||
*
|
||||
* @return vector of values (led off, led on) of green led values
|
||||
* @throws std::runtime_error if reading green data fails
|
||||
*/
|
||||
std::vector<int> GetGreenData();
|
||||
|
||||
/**
|
||||
* @brief Gets the values from using IR LED light
|
||||
*
|
||||
* @return vector of values (led off, led on) of IR led values
|
||||
* @throws std::runtime_error if reading IR data fails
|
||||
*/
|
||||
std::vector<int> GetIrData();
|
||||
/**
|
||||
* @brief Gets the values from using IR LED light
|
||||
*
|
||||
* @return vector of values (led off, led on) of IR led values
|
||||
* @throws std::runtime_error if reading IR data fails
|
||||
*/
|
||||
std::vector<int> GetIrData();
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this.
|
||||
*
|
||||
* @param measFreq Measurement frequncy mode, valid values 32, 64, 128,
|
||||
* 256, 1024
|
||||
* @param green_current Green LED current value
|
||||
* @throws std::runtime_error if enabling synchronized mode fails
|
||||
* @throws std::invalid_argument if measurement frequency is invalid
|
||||
*/
|
||||
void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this.
|
||||
*
|
||||
* @param measFreq Measurement frequncy mode, valid values 32, 64, 128,
|
||||
* 256, 1024
|
||||
* @param green_current Green LED current value
|
||||
* @throws std::runtime_error if enabling synchronized mode fails
|
||||
* @throws std::invalid_argument if measurement frequency is invalid
|
||||
*/
|
||||
void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this.
|
||||
*
|
||||
* @param ir_current The IR LED current value
|
||||
* @param threshold The IR LED interrupt threshold value
|
||||
*
|
||||
* @throws std::runtime_error if enabling non-synchronized mode fails
|
||||
*/
|
||||
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this.
|
||||
*
|
||||
* @param ir_current The IR LED current value
|
||||
* @param threshold The IR LED interrupt threshold value
|
||||
*
|
||||
* @throws std::runtime_error if enabling non-synchronized mode fails
|
||||
*/
|
||||
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this. If you need to get
|
||||
* continuous values, clear interrupt and StartMeasurement()
|
||||
* continuously.
|
||||
*
|
||||
* @param led_type LED light type to use, takes GREEN or IR (0 or 1)
|
||||
* @param current The chosen led_type current value
|
||||
* @throws std::runtime_error if enabling single mode fails
|
||||
*/
|
||||
void EnableSingleMode(LED_TYPES led_type, uint16_t current);
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* You need to call StartMeasurement() after this. If you need to get
|
||||
* continuous values, clear interrupt and StartMeasurement()
|
||||
* continuously.
|
||||
*
|
||||
* @param led_type LED light type to use, takes GREEN or IR (0 or 1)
|
||||
* @param current The chosen led_type current value
|
||||
* @throws std::runtime_error if enabling single mode fails
|
||||
*/
|
||||
void EnableSingleMode(LED_TYPES led_type, uint16_t current);
|
||||
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
|
||||
* @param pin GPIO pin number
|
||||
* @param isr Pointer to ISR function
|
||||
* @param isr_args Arguments to pass the ISR function
|
||||
* @throws std::runtime_error if installing ISR fails
|
||||
*/
|
||||
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
|
||||
void *isr_args);
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
|
||||
* @param pin GPIO pin number
|
||||
* @param isr Pointer to ISR function
|
||||
* @param isr_args Arguments to pass the ISR function
|
||||
* @throws std::runtime_error if installing ISR fails
|
||||
*/
|
||||
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
|
||||
void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
* @param pin GPIO pin number
|
||||
* @param isr Pointer to ISR function
|
||||
* @param isr_args Arguments to pass the ISR function
|
||||
* @throws std::runtime_error if installing ISR fails
|
||||
*/
|
||||
void InstallISR(int pin, void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Removes the ISR if it is installed
|
||||
*/
|
||||
void RemoveISR();
|
||||
/**
|
||||
* @brief Installs the ISR to a given GPIO pin
|
||||
*
|
||||
* @param pin GPIO pin number
|
||||
* @param isr Pointer to ISR function
|
||||
* @param isr_args Arguments to pass the ISR function
|
||||
* @throws std::runtime_error if installing ISR fails
|
||||
*/
|
||||
void InstallISR(int pin, void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Gets a dump of configuration registers as a string
|
||||
*
|
||||
* @return string of dumped registers
|
||||
* @throws std::runtime_error if reading one of the registers fails
|
||||
*/
|
||||
std::string RegistersDump();
|
||||
/**
|
||||
* @brief Removes the ISR if it is installed
|
||||
*/
|
||||
void RemoveISR();
|
||||
|
||||
private:
|
||||
bh1792_context m_bh1792;
|
||||
/**
|
||||
* @brief Gets a dump of configuration registers as a string
|
||||
*
|
||||
* @return string of dumped registers
|
||||
* @throws std::runtime_error if reading one of the registers fails
|
||||
*/
|
||||
std::string RegistersDump();
|
||||
|
||||
/* Disable implicit copy and assignment operators */
|
||||
BH1792(const BH1792 &) = delete;
|
||||
BH1792 &operator=(const BH1792 &) = delete;
|
||||
};
|
||||
private:
|
||||
bh1792_context m_bh1792;
|
||||
|
||||
/* Disable implicit copy and assignment operators */
|
||||
BH1792(const BH1792 &) = delete;
|
||||
BH1792 &operator=(const BH1792 &) = delete;
|
||||
};
|
||||
}
|
@ -19,30 +19,30 @@
|
||||
"Specifications": {
|
||||
"Supply Voltage (VDD)": {
|
||||
"unit": "V",
|
||||
"min": 2.5,
|
||||
"typical": 3.0,
|
||||
"min": 2.5,
|
||||
"typical": 3.0,
|
||||
"max": 3.6
|
||||
},
|
||||
"Terminal Input Voltage": {
|
||||
"unit": "V",
|
||||
"min": 0.7,
|
||||
"max": 5.5
|
||||
},
|
||||
"Supply Current": {
|
||||
"Terminal Input Voltage": {
|
||||
"unit": "V",
|
||||
"min": 0.7,
|
||||
"max": 5.5
|
||||
},
|
||||
"Supply Current": {
|
||||
"unit": "uA",
|
||||
"min": 0.8,
|
||||
"max": 200
|
||||
},
|
||||
"LED Supply Current": {
|
||||
"unit": "mA",
|
||||
"typical": 1.4,
|
||||
"max": 3.0
|
||||
},
|
||||
"Standby Mode Current": {
|
||||
"unit": "uA",
|
||||
"typical": 0.8,
|
||||
"max": 1.5
|
||||
},
|
||||
},
|
||||
"LED Supply Current": {
|
||||
"unit": "mA",
|
||||
"typical": 1.4,
|
||||
"max": 3.0
|
||||
},
|
||||
"Standby Mode Current": {
|
||||
"unit": "uA",
|
||||
"typical": 0.8,
|
||||
"max": 1.5
|
||||
},
|
||||
"Operating Temperature": {
|
||||
"unit": "°C",
|
||||
"min": -20,
|
||||
|
Reference in New Issue
Block a user