• Welcome to PiBoSo Official Forum. Please login or sign up.
 

[Solved] Input plugin - can't get it to work.

Started by adskdn0, February 23, 2014, 04:55:10 PM

Previous topic - Next topic

adskdn0

February 23, 2014, 04:55:10 PM Last Edit: March 18, 2014, 12:10:59 AM by adskdn0
Hello!
I'm going to connect custom input controller, so trying to use input plugin.
DLL is renamed to dli and put to plugins folder.
It is loaded ok and methods Startup(), GetControllerInfo(), GetControllerData(), ... are called by GPBikes, so everything seems OK except controller is not visible in calibration dialog in game settings, and some strange axis name with corrupt symbols get assigned to axis.
And it don't work. Tested on beta3 and beta4.
And also wanted to propose using one standard plugin interface for telemetry and input and.. what can be next. Having different dlls is a little bit inconvenient if you need to use telemetry and input at the same time...


#include "gpb_plugin.h"
#include "GPBInput.h"
#include "stdafx.h"

/*
If compiled as C++, extern "C" must be added to declaration of functions to export

X+ is right, Y+ is top and Z+ is forward.
*/
ServOutData servOutData;
ServInData servInData;

SControllerInfo_t ctrInfo;
SControllerData_t ctrData;

EXPORT int Version()
{
return 2;
}

/* called when software is started. If return value is not 0, the plugin is disabled */
EXPORT int Startup()
{
ServOpen(27004);

strcpy((char*)&ctrInfo.m_szName, "OvfCtr");
strcpy((char*)&ctrInfo.m_szUUID, "ee72a6ac-0e2a-459b-882e-a122eb634e4d");/* universally unique identifier */
ctrInfo.m_iID = 136; /* internal unique ID */
ctrInfo.m_iNumAxis = 6; /* number of axis */
//short m_aaiAxisRange[6][3]; /* min, max and center value of each axis */
for(int i=0; i < 6; i++)
{
//ctrInfo.m_aaiAxisRange[i][0] = -32768;
//ctrInfo.m_aaiAxisRange[i][1] = 32767;
//ctrInfo.m_aaiAxisRange[i][2] = 0;
ctrInfo.m_aaiAxisRange[i][0] = 0;
ctrInfo.m_aaiAxisRange[i][1] = 128;
ctrInfo.m_aaiAxisRange[i][2] = 128;
}
//char m_iNumSliders; /* number of sliders */
//short m_aiSliderRange[6]; /* max value of each slider */
//char m_iNumButtons; /* number of buttons */
//char m_iNumPOV; /* number of POVs */
//char m_iNumDials; /* number of dials */
//char m_aiDialRange[8]; /* max value of dials */
return 0;
}

/* called when software is closed */
EXPORT void Shutdown()
{
ServClose();
}

/* called every rendering frame. This function is optional */
EXPORT void Update()
{

}

/* called when a control is queried */
EXPORT void Reset()
{
}

int dbgControllers = 1;
/* called every few seconds to support hot plugging. The return value is the number of active controllers */
EXPORT int GetNumControllers()
{
return dbgControllers;
}

/* _iIndex is the 0 based controller index. _psInfo must be filled with controller info */
EXPORT int GetControllerInfo(int _iIndex,SControllerInfo_t *_psInfo)
{
if(_iIndex == 0)
{
_psInfo = &ctrInfo;
}

return 0;
}

/* _iID is the unique controller ID. _psData must be filled with controller data */
EXPORT int GetControllerData(int _iID, SControllerData_t *_psData)
{
//if(_iID == ctrInfo.m_iID)
{
ServGetData(&servInData);
for(int i=0; i < 6; i++)
ctrData.m_aiAxis[i] = servInData.axes[i];

_psData = &ctrData;
}

return 0;
}

PiBoSo

February 23, 2014, 06:26:14 PM #1 Last Edit: February 23, 2014, 06:36:28 PM by PiBoSo
Input plugin controllers are not shown in calibration, because they are supposed to be already calibrated.
Could you please write the corrupt symbols assigned to axis?
Please make sure that the unused inputs are set to 0 ( m_iNumSliders, m_iNumButtons, ... ).
Is the _iID parameter of GetControllerData the correct one?
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

adskdn0

February 23, 2014, 07:58:39 PM #2 Last Edit: February 23, 2014, 08:15:16 PM by adskdn0
Y.re right, problem is with _iID.
Looks like corrupt symbols was when i've commented out 'if(_iID == ctrInfo.m_iID)'  in GetControllerData() to see what happens. With this line uncommented there are no symbols or other problems, but _iID passed to GetControllerData() is wrong.

It takes 2 values, most of the time -2147024891 and sometimes 79495860 (in beta3), 73854004 (in beta4b).
Looks like SControllerInfo_t data is inited correctly, please, see screenshot

https://docs.google.com/file/d/0B33SqqrJ31baMkJFajF5c080VHM/edit

Maybe calling convention?
Functions are exported as
#define EXPORT  extern "C" __declspec (dllexport)

Or potentially it could be structure alignment.

PiBoSo


Please make sure that structure packing is 8 bytes, and that "char" of strings is single-byte.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

adskdn0

Now structures are definitely 8 byte aligned with pragma. Nothing have changed.
I can send vs project I'm debugging if there is nothing else I can try to get it working.

adskdn0

March 17, 2014, 11:15:31 PM #5 Last Edit: March 17, 2014, 11:40:09 PM by adskdn0
Figured out what the problem with parameters was.

EXPORT int GetControllerData(int _iID, SControllerData_t *_psData)
{
if(_iID == ctrInfo.m_iID)
{
//ServGetData(&servInData);
//for(int i=0; i < 6; i++)
// ctrData.m_aiAxis[i] = servInData.axes[i];
ctrData.m_aiAxis[0] = sin(dbg_rad+= 0.01F) * 32000;
//_psData = &ctrData;                                 <<<< WRONG
memcpy(_psData, &ctrData, sizeof(SControllerData_t));//<<< OK
}

return 0;
}


Now everything works.

PiBoSo

Quote from: adskdn0 on March 17, 2014, 11:15:31 PM
Figured out what the problem with parameters was.

EXPORT int GetControllerData(int _iID, SControllerData_t *_psData)
{
if(_iID == ctrInfo.m_iID)
{
//ServGetData(&servInData);
//for(int i=0; i < 6; i++)
// ctrData.m_aiAxis[i] = servInData.axes[i];
ctrData.m_aiAxis[0] = sin(dbg_rad+= 0.01F) * 32000;
//_psData = &ctrData;                                 <<<< WRONG
memcpy(_psData, &ctrData, sizeof(SControllerData_t));//<<< OK
}

return 0;
}


Now everything works.

Great to know that the problem is solved.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".