46 bool rc =
driver->Connect();
55 LOG_INFO(
"Error: cannot find Joystick device.");
64 return driver->Disconnect();
69 char propName[16] = {0}, propLabel[16] = {0};
74 int nAxis =
driver->getNumOfAxes();
75 int nJoysticks =
driver->getNumOfJoysticks();
76 int nButtons =
driver->getNumrOfButtons();
86 for (
int i = 0; i < nJoysticks * 2; i += 2)
88 snprintf(propName, 16,
"JOYSTICK_%d", i / 2 + 1);
89 snprintf(propLabel, 16,
"Joystick %d", i / 2 + 1);
97 for (
int i = 0; i < nAxis; i++)
99 snprintf(propName, 16,
"AXIS_%d", i + 1);
100 snprintf(propLabel, 16,
"Axis %d", i + 1);
111 for (
int i = 0; i < nButtons; i++)
113 snprintf(propName, 16,
"BUTTON_%d", i + 1);
114 snprintf(propLabel, 16,
"Button %d", i + 1);
153 snprintf(buf, 8,
"%d",
driver->getVersion());
156 snprintf(buf, 8,
"%d",
driver->getNumOfJoysticks());
159 snprintf(buf, 8,
"%d",
driver->getNumOfAxes());
162 snprintf(buf, 8,
"%d",
driver->getNumrOfButtons());
167 for (
int i = 0; i <
driver->getNumOfJoysticks(); i++)
187 for (
int i = 0; i <
driver->getNumOfJoysticks(); i++)
266 joystick->joystickEvent(joystick_n, mag, angle);
271 joystick->buttonEvent(button_n, value);
284 LOGF_DEBUG(
"joystickEvent[%d]: %g @ %g", joystick_n, mag, angle);
302 LOGF_DEBUG(
"axisEvent[%d]: %d", axis_n, value);
305 if (std::abs(value) <=
DeadZoneN[axis_n].value)
323 LOGF_DEBUG(
"buttonEvent[%d]: %s", button_n, value > 0 ?
"On" :
"Off");
const char * getDeviceName() const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void addDebugControl()
Add Debug control to the driver.
The JoyStickDriver class provides basic functionality to read events from supported game pads under L...
The JoyStick class provides an INDI driver that displays event data from game pads....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
ISwitchVectorProperty ButtonSP
static void buttonHelper(int button_n, int value)
virtual bool Disconnect() override
Disconnect from device.
INumberVectorProperty AxisNP
std::unique_ptr< JoyStickDriver > driver
static void joystickHelper(int joystick_n, double mag, double angle)
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual const char * getDefaultName() override
ITextVectorProperty PortTP
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
static void axisHelper(int axis_n, int value)
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void joystickEvent(int joystick_n, double mag, double angle)
INumberVectorProperty DeadZoneNP
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
INumberVectorProperty * JoyStickNP
void axisEvent(int axis_n, int value)
ITextVectorProperty JoystickInfoTP
void buttonEvent(int button_n, int value)
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUSaveConfigText(FILE *fp, const ITextVectorProperty *tvp)
Add a text vector property value to the configuration file.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#define LOGF_DEBUG(fmt,...)
std::unique_ptr< JoyStick > joystick(new JoyStick())
const char * DEVICE_PORT
Device serial (or bluetooth) connection port. The default value on Linux is /dev/ttyUSB0 while on Mac...
Number vector property descriptor.