DUDS
Distributed Update of Data from Something
APDS9301.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2018 Jeff Jackowski
9  */
10 #ifndef APDS9301_HPP
11 #define APDS9301_HPP
12 
15 #include <duds/data/Quantity.hpp>
16 
17 namespace duds { namespace hardware { namespace devices { namespace instruments {
18 
27 
36 class APDS9301 : boost::noncopyable {
40  std::unique_ptr<duds::hardware::interface::Smbus> com;
44  float actualPeriod;
50  float scale;
54  std::uint16_t broad, ir;
55  struct {
59  unsigned int hGain : 1;
63  unsigned int integTime : 2;
64  };
71  void startOrStop(int val);
72 public:
81  APDS9301(std::unique_ptr<duds::hardware::interface::Smbus> &c);
86  ~APDS9301();
96  void init(float integration, bool hGain);
102  void suspend();
109  void resume();
116  float period() const {
117  return actualPeriod;
118  }
123  bool highGain() const {
124  return hGain;
125  }
130  void sample();
135  duds::data::Quantity maxIrradiance() const;
144  duds::data::Quantity irradiance() const;
148  std::uint16_t brightnessCount() const {
149  return broad;
150  }
159  duds::data::Quantity irradianceIr() const;
163  std::uint16_t brightnessIrCount() const {
164  return ir;
165  }
173  duds::data::Quantity illuminance() const;
174 };
175 
176 } } } }
177 
178 #endif // #ifndef APDS9301_HPP
A container for a value and a unit to better describe the value.
Definition: Quantity.hpp:37
Base class for all APDS9301 specific errors.
Definition: APDS9301.hpp:22
std::unique_ptr< duds::hardware::interface::Smbus > com
The SMBus communication interface.
Definition: APDS9301.hpp:40
unsigned int hGain
High gain (16x) flag.
Definition: APDS9301.hpp:59
float period() const
Returns the sampling period configured for the device.
Definition: APDS9301.hpp:116
An invalid integration time was specified.
Definition: APDS9301.hpp:26
std::uint16_t brightnessIrCount() const
The value reported by the device for the infrared brightness.
Definition: APDS9301.hpp:163
float actualPeriod
Configured integration time.
Definition: APDS9301.hpp:44
The base type for errors from devices.
A quick try at supporting APDS9301 brightness sensor; will change significantly in the future...
Definition: APDS9301.hpp:36
float scale
Multiplier applied to the sample results to account for different integration times and gain setting ...
Definition: APDS9301.hpp:50
unsigned int integTime
Integration time value used in device configuration register.
Definition: APDS9301.hpp:63
std::uint16_t brightnessCount() const
The value reported by the device for the broad spectrum brightness.
Definition: APDS9301.hpp:148
bool highGain() const
Returns true if the device has been configured to use its 16x gain function by a previous call to ini...
Definition: APDS9301.hpp:123