DUDS
Distributed Update of Data from Something
ISL29125.cpp
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) 2017 Jeff Jackowski
9  */
13 
14 namespace duds { namespace hardware { namespace devices { namespace instruments {
15 
16 ISL29125::ISL29125(std::unique_ptr<duds::hardware::interface::I2c> &c) :
17 com(std::move(c)) {
18  // make conversation to read input so it can be reused
19  // address -- green
20  input.addOutputVector() << (std::int8_t)9;
21  // read in 6 bytes
23 }
24 
26  suspend();
27 }
28 
29 void ISL29125::init(bool wide) {
30  // remake the initialization conversation
31  initialize.clear();
33  // address -- config
34  (std::int8_t)1 <<
35  // config byte -- run, set range
36  (std::int8_t)(0x5 | (wide ? 0x8 : 0));
37  com->converse(initialize);
38 }
39 
42  conv.addOutputVector() <<
43  // address -- config
44  (std::int8_t)1 <<
45  // config byte -- stop
46  (std::int8_t)0;
47  com->converse(conv);
48 }
49 
51  if (initialize.empty()) {
53  }
54  com->converse(initialize);
55 }
56 
58  // get input
59  com->converse(input);
60  // parse input
62  // the device uses a peculiar ordering
63  ex >> g >> r >> b;
64 }
65 
66 } } } }
void init(bool wide=true)
Configures for continuous 16-bit sampling of all colors.
Definition: ISL29125.cpp:29
void clear()
Makes the conversation empty.
std::unique_ptr< duds::hardware::interface::I2c > com
The I2C communication interface.
Definition: ISL29125.hpp:28
ConversationVector & addInputVector(std::size_t len)
Creates a new ConversationVector for fixed length input and initializes it with the given length...
Header for ConversationExtractor; includes all other conversation related header files.
ISL29125(std::unique_ptr< duds::hardware::interface::I2c > &c)
Prepares to communicate with the device, but does not initalize the device.
Definition: ISL29125.cpp:16
duds::hardware::interface::Conversation initialize
Output used to initialize the device.
Definition: ISL29125.hpp:32
void suspend()
Suspends operation by putting the device into a low-power mode.
Definition: ISL29125.cpp:40
STL namespace.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
std::uint16_t b
Blue brightness.
Definition: ISL29125.hpp:48
An attempt was made to use a device prior to running a required initialization step.
std::uint16_t g
Green brightness.
Definition: ISL29125.hpp:44
static std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > conv
String converter; UTF-8 to/from UTF-32.
Definition: BppFont.cpp:165
void sample()
The device takes about 101ms to produce a 16-bit sample per color.
Definition: ISL29125.cpp:57
std::uint16_t r
Red brightness.
Definition: ISL29125.hpp:40
ConversationVector & addOutputVector()
Creates a new ConversationVector for output and returns it for modification.
void resume()
Resumes operation after a call to suspend().
Definition: ISL29125.cpp:50
Extracts data from a Conversation without modifying the Conversation or copying from it...
duds::hardware::interface::Conversation input
Used to read in the sampled data.
Definition: ISL29125.hpp:36
bool empty() const
Returns true if the conversation has no parts.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48
Represents a two-way conversation with a device.