I can't retrieve the timestamp from the ADXL355 driver
llzz97 opened this issue · 1 comments
llzz97 commented
This is my code,
#include <iiopp.h>
#include <iostream>
#include <iomanip>
using namespace iiopp;
using namespace std;
static ssize_t _sampleTriggerCB(const struct iio_channel *p_pChannel, void *p_pSrc, size_t p_szBytes, void *p_pData)
{
Channel l_channel(const_cast<iio_channel *>(p_pChannel));
std::string l_strChannelName(l_channel.id().c_str());
cout << "Channel: " << quoted(l_strChannelName) << "\n";
cout << " value: " << quoted(to_string(value(l_channel))) << std::endl;
return 1;
}
static void _triggerEvents()
{
auto l_pContext = create_default_context();
auto l_device(l_pContext->find_device("adxl355"));
auto l_channelAccX(l_device.find_channel("accel_x", false));
l_channelAccX.enable();
auto l_channelAccY(l_device.find_channel("accel_y", false));
l_channelAccY.enable();
auto l_channelAccZ(l_device.find_channel("accel_z", false));
l_channelAccZ.enable();
auto l_channelTemp(l_device.find_channel("temp", false));
l_channelTemp.enable();
auto l_channelTimestamp(l_device.find_channel("timestamp", false));
l_channelTimestamp.enable();
auto l_buff(l_device.create_buffer(1, false));
while (l_buff->for_each(_sampleTriggerCB, nullptr) > 0);
}
int main(int argc, char ** argv)
{
try
{
_triggerEvents();
}
catch (error & e)
{
cerr << "ERROR " << e.code().value() << ": " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
I correctly receive all the other channels, but the timestamp is not working.
Am I doing something wrong?
I'm using version 0.25.
llzz97 commented
I solved it, I was missing the call l_pBuff->refill() before l_buff->for_each.
#include <iiopp.h>
#include <iostream>
#include <iomanip>
using namespace iiopp;
using namespace std;
static ssize_t _sampleTriggerCB(const struct iio_channel *p_pChannel, void *p_pSrc, size_t p_szBytes, void *p_pData)
{
Channel l_channel(const_cast<iio_channel *>(p_pChannel));
std::string l_strChannelName(l_channel.id().c_str());
cout << "Channel: " << quoted(l_strChannelName) << "\n";
cout << " value: " << quoted(to_string(value(l_channel))) << std::endl;
return 1;
}
static void _triggerEvents()
{
auto l_pContext = create_default_context();
auto l_device(l_pContext->find_device("adxl355"));
auto l_channelAccX(l_device.find_channel("accel_x", false));
l_channelAccX.enable();
auto l_channelAccY(l_device.find_channel("accel_y", false));
l_channelAccY.enable();
auto l_channelAccZ(l_device.find_channel("accel_z", false));
l_channelAccZ.enable();
auto l_channelTemp(l_device.find_channel("temp", false));
l_channelTemp.enable();
auto l_channelTimestamp(l_device.find_channel("timestamp", false));
l_channelTimestamp.enable();
auto l_buff(l_device.create_buffer(1, false));
l_buff->refill();
while (l_buff->for_each(_sampleTriggerCB, nullptr) > 0);
}
int main(int argc, char ** argv)
{
try
{
_triggerEvents();
}
catch (error & e)
{
cerr << "ERROR " << e.code().value() << ": " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}