upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bh1792.hpp
1 /*
2 * The MIT License (MIT)
3 *
4 * Author: Assam Boudjelthia
5 * Copyright (c) 2018 Rohm Semiconductor.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 
25 #pragma once
26 
27 #include <vector>
28 #include <string>
29 #include "bh1792.h"
30 
49 namespace upm {
50  class BH1792 {
51  public:
52 
62  BH1792(int bus = 0, int addr = 0x5b);
63 
67  virtual ~BH1792();
68 
74  void CheckWhoAmI();
75 
81  bool IsEnabled();
82 
90  void SoftReset();
91 
98  float GetMeasurementTimeMS();
99 
107  void SetGreenLedsCurrent(uint16_t current);
108 
115  int GetGreenLedsCurrent();
116 
124  void SetIrLedCurrent(uint16_t current);
125 
132  int GetIrLedCurrent();
133 
140  void SetIrThreshold(uint16_t threshold);
141 
148  int GetIrThreshold();
149 
156  int GetFifoSize();
157 
165  void DisableInterrupt();
166 
173  void ClearInterrupt();
174 
180  void StartMeasurement();
181 
189  void StopMeasurement();
190 
198  void RestartMeasurement();
199 
208  std::vector<std::vector<int>> GetFifoData();
209 
216  void DiscardFifoData();
217 
224  std::vector<int> GetGreenData();
225 
232  std::vector<int> GetIrData();
233 
248  void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
249 
264  void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
265 
280  void EnableSingleMode(LED_TYPES led_type, uint16_t current);
281 
291  void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
292  void *isr_args);
293 
302  void InstallISR(int pin, void (*isr)(void *), void *isr_args);
303 
307  void RemoveISR();
308 
315  std::string RegistersDump();
316 
317  private:
318  bh1792_context m_bh1792;
319 
320  /* Disable implicit copy and assignment operators */
321  BH1792(const BH1792 &) = delete;
322  BH1792 &operator=(const BH1792 &) = delete;
323  };
324 }
void RemoveISR()
Removes the ISR if it is installed.
Definition: bh1792.cxx:290
int GetIrLedCurrent()
Gets the green LED current value.
Definition: bh1792.cxx:112
std::string RegistersDump()
Gets a dump of configuration registers as a string.
Definition: bh1792.cxx:295
LED_TYPES
LED light types.
Definition: bh1792.h:68
int GetFifoSize()
Gets the current size of built-in FIFO.
Definition: bh1792.cxx:141
bh1792 sensor context
Definition: bh1792.h:95
std::vector< int > GetGreenData()
Gets the values from using green LED light.
Definition: bh1792.cxx:216
void SetIrThreshold(uint16_t threshold)
Sets interrupt IR threshold value for non-synchronized mode.
Definition: bh1792.cxx:123
C API for the bh1792 driver.
Definition: bh1792.hpp:50
void InstallISR(mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
Installs the ISR to a given GPIO pin.
Definition: bh1792.cxx:276
void EnableSingleMode(LED_TYPES led_type, uint16_t current)
Enables and configures the sensor to use single mode. This sets the sensor to take only one measureme...
Definition: bh1792.cxx:269
float GetMeasurementTimeMS()
Gets the value of measurement time is milli-seconds.
Definition: bh1792.cxx:62
BH1792(int bus=0, int addr=0x5b)
Init the sensor with specific bus and address. Before starting measurement, one of (EnableSyncMode...
Definition: bh1792.cxx:31
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void StartMeasurement()
Starts the measuremnt on sensor or enable the sensor.
Definition: bh1792.cxx:166
bool IsEnabled()
Checks if the measuremnt on sensor is enabled.
Definition: bh1792.cxx:50
void SetIrLedCurrent(uint16_t current)
Sets the IR LED Current value.
Definition: bh1792.cxx:98
virtual ~BH1792()
Close and free sensor.
Definition: bh1792.cxx:38
void DiscardFifoData()
Reads and discard the 32 FIFO entries to reset the WATERMARK interrupt flag.
Definition: bh1792.cxx:209
void SoftReset()
Initiates a software reset to the sensor. All register values will be written to their defaults...
Definition: bh1792.cxx:55
std::vector< std::vector< int > > GetFifoData()
Gets the fifo data of 32 entries and resets the WATERMARK interrupt flag.
Definition: bh1792.cxx:187
int GetIrThreshold()
Gets interrupt IR threshold value.
Definition: bh1792.cxx:130
void StopMeasurement()
Definition: bh1792.cxx:173
void ClearInterrupt()
Clears the interrupt flag allowing more interrupts to be raised.
Definition: bh1792.cxx:159
void DisableInterrupt()
Disables interrupt function. Interrupt is enabled by default on all operation modes, so this have to be called after enabling a specific operation mode.
Definition: bh1792.cxx:152
void CheckWhoAmI()
Check "who am I" register value to identify the sensor.
Definition: bh1792.cxx:43
int GetGreenLedsCurrent()
Gets the green LED current value.
Definition: bh1792.cxx:87
void RestartMeasurement()
Restart the measurement, This function stops measurement, then re-writes the configuration registers ...
Definition: bh1792.cxx:180
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold)
Enabled and configures the sensor to use non-synchronized mode. This mode uses IR_THRESHOLD interrupt...
Definition: bh1792.cxx:262
void EnableSyncMode(uint16_t measFreq, uint16_t green_current)
Enables and configures the sensor to use synchronized mode. This will use the built-in FIFO and raise...
Definition: bh1792.cxx:248
void SetGreenLedsCurrent(uint16_t current)
Sets the green LED Current value.
Definition: bh1792.cxx:73
std::vector< int > GetIrData()
Gets the values from using IR LED light.
Definition: bh1792.cxx:232