#ifndef JOYSTICK_H
#define JOYSTICK_H

#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <stdint.h>
#include "project.h"

//	---------------------
//  js_event
//	---------------------

typedef struct {
	unsigned int	time;		// event timestamp in milliseconds
	short			value;		// value
	unsigned char	type;		// event type
	unsigned char	number;		// axis/button number
} js_event;


//	---------------------
//  js_event
//	---------------------

#define JS_EVENT_BUTTON	0x01	// button pressed/released
#define JS_EVENT_AXIS	0x02	// joystick moved
#define JS_EVENT_INIT	0x80	// initial state of device

//	----------------------------------------------------------------------------
//	joystick
//	----------------------------------------------------------------------------

class joystick : public QThread
{
	Q_OBJECT
public:
	explicit joystick(QObject *parent = 0);
	~joystick();

public:
	void run();
public:
	void pollJoystick();

signals:
	void errorx(int type, int socketError, const QString &message);
	void jsReading(int time, int value, int type, int number);

public slots:
	void stop();

public:
	bool quit;
private:
	QMutex mutex;
	QWaitCondition cond;
	int fd;

};

#endif // JOYSTICK_H
