PDA

View Full Version : How to simultaneously read and transfer all joystick values to a usb port



Arpitgarg
11th March 2011, 07:51
Hi, i am emulating joystick, so far i am able to read joystick values and display them on screen, but i want to send them to another computer using tcp socket. I am able to create a socket but can any one tell me how can i gather all the values and send them to tcp socket

Joystick reader



#include "mainwindow.h"
#include "ui_mainwindow.h"



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer* timer = new QTimer(this);
joystick = new Joystick();
connect(timer, SIGNAL(timeout()), this, SLOT(updateForm()));
connect(ui->btnConnect,SIGNAL(clicked()),this, SLOT(joyConnect()));
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::joyConnect()
{
if(joystick->init(joyAccess->text().toAscii()) > -1)
{
ui->btnConnect->setText("Connected");
timer->start();
}

}
void MainWindow::updateForm()
{
ui->lcd1->display(joystick->getAxis(0));
ui->lcd2->display(joystick->getAxis(1));
ui->lcd3->display(joystick->getAxis(2));
ui->lcd4->display(joystick->getAxis(3));


if(joystick->getButton(0) > 0)
ui->label_1->setText("UP");
else
ui->label_1->setText(" Axis1");

if(joystick->getButton(1) > 0)
ui->label_2->setText("Down");
else
ui->label_2->setText(" Axis2");


if(joystick->getButton(2) > 0)
ui->label_3->setText("UP");
else
ui->label_3->setText(" Axis3");


if(joystick->getButton(3) > 0)
ui->label_4->setText("UP");
else
ui->label_4->setText(" Axis4");

}

Arpitgarg
11th March 2011, 17:03
Hi everybody
i am new to Qt.I am trying to emulate joystick so far i am able to read joystik value and display it.i want to simulataneous gather all(4) the values and send ot to a port.

I am reading joystick values using getAxis().
I will appreciate any help from ur side.

stampede
11th March 2011, 17:19
There is similar thread already : link (http://www.qtcentre.org/threads/39560-Joystick-Reader?highlight=joystick). Aren't you the same person ? ;)
If not, then well, Qt does not offer any usb-port access methods, you'll need to implement it on your own. On windows, maybe you could use libusb (http://sourceforge.net/apps/trac/libusb-win32/wiki) ?

wysota
12th March 2011, 00:14
If you are able to read all the values then what's exactly the problem?

ChrisW67
12th March 2011, 00:27
Aren't you the same person ?
Or perhaps two people in the same class at school with the same homework assignment.

Arpitgarg
12th March 2011, 14:05
Well I want to send all the values simultaneously to tcp socket, and I am not able to figure out how??.

SixDegrees
12th March 2011, 14:18
You call socket.write(). See the documentation.

wysota
12th March 2011, 15:19
And the same IP? Doubtful. Users merged, merging threads.

Arpitgarg
12th March 2011, 21:42
Well, may be I wasn't clear last time, the problem is how to gather all the values together .

wysota
12th March 2011, 22:25
What do you mean "together"?

ChrisW67
12th March 2011, 23:07
Well, may be I wasn't clear last time, the problem is how to gather all the values together .
The clarity hasn't changed much.

You can store joystick values in a QVector, QList, some user-defined structure with appropriate streaming operators if needed, or just send them one at a time. There is no QBundleOfJoystickValues class to rely on, and there is no universal right way to bundle data. If the receiver imposes a certain format then you should send your data in that format.