Outputs data from a APDS9301 on stdout.
#include <iostream>
#include <thread>
#include <iomanip>
#include <assert.h>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/program_options.hpp>
constexpr int valw = 8;
bool quit = false;
try {
);
std::cout.precision(6);
do {
std::this_thread::sleep_for(std::chrono::seconds(1));
assert(visB.
unit == chku);
assert(irB.
unit == chku);
std::cout <<
"Visible: " << std::setw(10) << visB.
value <<
"W/m2 IR: " <<
std::setw(10) << irB.
value <<
"W/m2 Illuminance: " << std::setw(10) <<
ill.
value <<
" lux" << std::endl;
} while (!quit);
} catch (...) {
std::cerr << "Program failed in runtest(): " <<
boost::current_exception_diagnostic_information() << std::endl;
}
int main(int argc, char *argv[])
try {
std::string i2cpath;
float inttime;
int i2caddr;
bool hgain = false;
{
boost::program_options::options_description optdesc(
"Options for APDS9301 test"
);
optdesc.add_options()
(
"help,h",
"Show this help message"
)
(
"smbdev,i",
boost::program_options::value<std::string>(&i2cpath)->
default_value("/dev/i2c-1"),
"Specify Smbus device file"
)
(
"smbaddr,a",
boost::program_options::value<int>(&i2caddr)->
default_value(0x39),
"Specify Smbus device address"
)
(
"integrate,e",
boost::program_options::value<float>(&inttime)->
default_value(0.014f),
"Maximum integration time"
)
(
"highgain,g",
"Use high gain (16x)"
)
;
boost::program_options::variables_map vm;
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, optdesc),
vm
);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << "Test program for light meter APDS9301\n" << argv[0]
<< " [options]\n" << optdesc << std::endl;
return 0;
}
if (vm.count("highgain")) {
hgain = true;
}
}
std::unique_ptr<duds::hardware::interface::Smbus> smb(
)
);
meter.
init(inttime, hgain);
std::cout <<
"Integration period is " << meter.
period() <<
" seconds.\n" std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2));
std::thread doit(runtest, std::ref(meter));
std::cin.get();
quit = true;
doit.join();
} catch (...) {
std::cerr << "Program failed in main(): " <<
boost::current_exception_diagnostic_information() << std::endl;
return 1;
}