This is the flow of my program.
void HID_PnP::PollUSB()
{
buf[0] = 0x00;
memset((void*)&buf[2], 0x00, sizeof(buf) - 2);
if (isConnected == false) {
device = hid_open(0x04D8, 0x003F, NULL);
if (device) {
isConnected = true;
hid_set_nonblocking(device, true);
timer->start(1000); //check every two seconds
}
}
else {
if (hid_write(device, buf, sizeof(buf)) == -1)
{
CloseDevice();
return;
}
if(hid_read(device, buf, sizeof(buf)) == -1)
{
CloseDevice();
return;
}
}
QByteArray usb_data
(reinterpret_cast<char
*>
(buf
),
sizeof(buf
));
hid_comm_update(usb_data, isConnected);
}
void HID_PnP::PollUSB()
{
buf[0] = 0x00;
memset((void*)&buf[2], 0x00, sizeof(buf) - 2);
if (isConnected == false) {
device = hid_open(0x04D8, 0x003F, NULL);
if (device) {
isConnected = true;
hid_set_nonblocking(device, true);
timer->start(1000); //check every two seconds
}
}
else {
if (hid_write(device, buf, sizeof(buf)) == -1)
{
CloseDevice();
return;
}
if(hid_read(device, buf, sizeof(buf)) == -1)
{
CloseDevice();
return;
}
}
QByteArray usb_data(reinterpret_cast<char*>(buf), sizeof(buf));
hid_comm_update(usb_data, isConnected);
}
To copy to clipboard, switch view to plain text mode
{
ui->setupUi(this);
plugNPlay = new HID_PnP();
connect(plugNPlay,
SIGNAL(hid_comm_update
(QByteArray,
bool)),
this,
SLOT(update_gui
(QByteArray,
bool)));
Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form)
{
ui->setupUi(this);
plugNPlay = new HID_PnP();
connect(plugNPlay, SIGNAL(hid_comm_update(QByteArray,bool)), this, SLOT(update_gui(QByteArray,bool)));
To copy to clipboard, switch view to plain text mode
void Form
::update_gui(QByteArray usb_data,
bool isConnected
) {
if(isConnected){
std::string message(usb_data.constData(), 60); //usb_data.length()
QString latitude
= qmessage.
mid(0,
21);
QString longitude
= qmessage.
mid(23,
25);
QString lat_mid
= qmessage.
mid(0,
18);
QString lon_mid
= qmessage.
mid(23,
21);
double lat = lat_mid.toDouble();
double lon = lon_mid.toDouble();
qDebug() << usb_data;
ui
->textEdit
->append
("| " + QTime::currentTime().
toString("<i>hh:mm:ss</i>") + " | <b>Latitude:</b> " + latitude + " <b>Longtitude:</b> " +longitude + " <b>Height:</b> " + height);
void Form::update_gui(QByteArray usb_data, bool isConnected)
{
if(isConnected){
std::string message(usb_data.constData(), 60); //usb_data.length()
QString qmessage = QString::fromStdString(message);
QString latitude = qmessage.mid(0,21);
QString longitude = qmessage.mid(23,25);
QString height = qmessage.mid(50);
QString lat_mid = qmessage.mid(0,18);
QString lon_mid = qmessage.mid(23,21);
double lat = lat_mid.toDouble();
double lon = lon_mid.toDouble();
qDebug() << usb_data;
ui->textEdit->append("| " + QTime::currentTime().toString("<i>hh:mm:ss</i>") + " | <b>Latitude:</b> "
+ latitude + " <b>Longtitude:</b> " +longitude + " <b>Height:</b> " + height);
To copy to clipboard, switch view to plain text mode
I need the lat and lon variables to store a double acquired from a string.
Bookmarks