upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bh1749.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 "bh1749.h"
29 
49 namespace upm {
50  class BH1749 {
51  public:
63  BH1749(int bus = 0, int addr = 0x39);
64 
68  virtual ~BH1749();
69 
75  void Enable();
76 
82  void Disable();
83 
89  void CheckWhoAmI();
90 
102  void SensorInit(OPERATING_MODES opMode,
103  MEAS_TIMES measTime,
104  RGB_GAINS rgbGain,
105  IR_GAINS irGain,
106  INT_SOURCES intSource);
107 
114  void SetOperatingMode(OPERATING_MODES opMode);
115 
123  int GetOperatingMode();
124 
131  void SetMeasurementTime(MEAS_TIMES measTime);
132 
139  int GetMeasurementTime();
140 
147  void SetRgbGain(RGB_GAINS rgbGain);
148 
155  int GetRgbGain();
156 
163  void SetIrGain(IR_GAINS irGain);
164 
171  int GetIrGain();
172 
179  void SetIntSource(INT_SOURCES intSource);
180 
187  char GetInterruptSourceChar();
188 
194  void EnableInterrupt();
195 
201  void DisableInterrupt();
202 
208  void ResetInterrupt();
209 
215  bool IsInterrupted();
216 
222  bool IsInterruptEnabled();
223 
231  void SoftReset();
232 
239  void SetThresholdHigh(uint16_t threshold);
240 
247  int GetThresholdHigh();
248 
255  void SetThresholdLow(uint16_t threshold);
256 
263  int GetThresholdLow();
264 
271  uint16_t GetRed();
272 
279  uint16_t GetGreen();
280 
287  uint16_t GetBlue();
288 
295  uint16_t GetIr();
296 
303  uint16_t GetGeen2();
304 
312  std::vector<uint16_t> GetMeasurements();
313 
323  void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
324 
328  void RemoveISR();
329 
336  std::string RegistersDump();
337 
338  private:
339  bh1749_context m_bh1749;
340 
341  /* Disable implicit copy and assignment operators */
342  BH1749(const BH1749 &) = delete;
343  BH1749 &operator=(const BH1749 &) = delete;
344  };
345 }
uint16_t GetBlue()
Gets value of Blue color channel.
Definition: bh1749.cxx:244
void DisableInterrupt()
Disables interrupt mode.
Definition: bh1749.cxx:163
void InstallISR(mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
Installs the ISR to a given GPIO pin.
Definition: bh1749.cxx:282
void RemoveISR()
Removes the ISR if it is installed.
Definition: bh1749.cxx:289
int GetThresholdLow()
Gets threshold low value.
Definition: bh1749.cxx:217
bool IsInterruptEnabled()
Gets interrupt mode status.
Definition: bh1749.cxx:182
The full sensor context.
Definition: bh1749.h:93
char GetInterruptSourceChar()
Gets interrupt source value.
Definition: bh1749.cxx:147
void SetIrGain(IR_GAINS irGain)
Sets IR gain value.
Definition: bh1749.cxx:124
void ResetInterrupt()
Resets interrupt status (clear) to allow new interrupt reads.
Definition: bh1749.cxx:170
void SetMeasurementTime(MEAS_TIMES measTime)
Sets measurement time (ODR)
Definition: bh1749.cxx:92
int GetMeasurementTime()
Gets measurement time (ODR) value.
Definition: bh1749.cxx:99
C API for the bh1749 driver.
RGB_GAINS
RGB gain choices.
Definition: bh1749.h:68
bool IsInterrupted()
Gets interrupt status, whether interrupt is raised or not.
Definition: bh1749.cxx:177
BH1749(int bus=0, int addr=0x39)
Initialize a sensor instance with bus and address.
Definition: bh1749.cxx:39
uint16_t GetGeen2()
Gets value of Green2 color channel.
Definition: bh1749.cxx:262
int GetRgbGain()
Gets RGB gain value.
Definition: bh1749.cxx:115
void SoftReset()
Initiates a software reset to the sensor. All register values will be written to their defaults...
Definition: bh1749.cxx:187
void SetThresholdLow(uint16_t threshold)
Sets threshold low value.
Definition: bh1749.cxx:210
Definition: bh1749.hpp:50
void EnableInterrupt()
Enables interrupt mode.
Definition: bh1749.cxx:156
uint16_t GetGreen()
Gets value of Green color channel.
Definition: bh1749.cxx:235
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
OPERATING_MODES
Operation modes enum for interrupt modes (persistance)
Definition: bh1749.h:49
void SensorInit(OPERATING_MODES opMode, MEAS_TIMES measTime, RGB_GAINS rgbGain, IR_GAINS irGain, INT_SOURCES intSource)
Initializes (writes) configuration values to sensor.
Definition: bh1749.cxx:65
uint16_t GetIr()
Gets value of IR color channel.
Definition: bh1749.cxx:253
std::vector< uint16_t > GetMeasurements()
Gets all channels measurements values.
Definition: bh1749.cxx:271
void SetThresholdHigh(uint16_t threshold)
Sets threshold high value.
Definition: bh1749.cxx:194
IR_GAINS
IR gain choices.
Definition: bh1749.h:76
int GetThresholdHigh()
Gets threshold high value.
Definition: bh1749.cxx:201
void SetRgbGain(RGB_GAINS rgbGain)
Sets RGB gain value.
Definition: bh1749.cxx:108
void SetOperatingMode(OPERATING_MODES opMode)
Sets operating mode (interrupt persistance)
Definition: bh1749.cxx:76
uint16_t GetRed()
Gets value of Red color channel.
Definition: bh1749.cxx:226
MEAS_TIMES
Measuremnt time choices.
Definition: bh1749.h:59
INT_SOURCES
Interrupt source choices.
Definition: bh1749.h:84
void Enable()
Enables RGB color measurement on the sensor.
Definition: bh1749.cxx:51
void CheckWhoAmI()
Check "who am I" register value to identify the sensor.
Definition: bh1749.cxx:32
int GetOperatingMode()
Gets operating mode (interrupt persistance) value.
Definition: bh1749.cxx:83
void SetIntSource(INT_SOURCES intSource)
Sets interrupt source value.
Definition: bh1749.cxx:140
std::string RegistersDump()
Gets a dump of configuration registers as a string.
Definition: bh1749.cxx:294
int GetIrGain()
Gets IR gain value.
Definition: bh1749.cxx:131
virtual ~BH1749()
Close and free sensor.
Definition: bh1749.cxx:46
void Disable()
Disables RGB color measurement on the sensor.
Definition: bh1749.cxx:58