Play-/Source/ui_qt/unix/InputProviderEvDev.cpp

70 lines
1.4 KiB
C++
Raw Normal View History

2019-08-17 13:51:31 -04:00
#include <cassert>
2018-11-26 13:02:15 -05:00
#include "InputProviderEvDev.h"
#include "string_format.h"
#define PROVIDER_ID 'evdv'
CInputProviderEvDev::CInputProviderEvDev()
2018-11-28 22:32:27 -05:00
: m_GPDL([this](auto a, auto b, auto c, auto d, auto e) { this->OnEvDevInputEvent(a, b, c, d, e); })
2018-11-26 13:02:15 -05:00
{
}
uint32 CInputProviderEvDev::GetId() const
{
return PROVIDER_ID;
}
std::string CInputProviderEvDev::GetTargetDescription(const BINDINGTARGET& target) const
{
return string_format("EvDev: btn-%d", target.keyId);
}
2018-11-28 18:37:31 -05:00
void CInputProviderEvDev::OnEvDevInputEvent(GamePadDeviceId deviceId, int code, int value, int type, const input_absinfo* abs)
{
if(!OnInput) return;
2018-11-28 18:37:31 -05:00
BINDINGTARGET tgt;
tgt.providerId = PROVIDER_ID;
tgt.deviceId = deviceId;
tgt.keyId = code;
2018-11-28 22:32:27 -05:00
if(type == EV_MSC)
2018-11-28 18:37:31 -05:00
{
return;
}
else if(type == EV_KEY)
{
tgt.keyType = BINDINGTARGET::KEYTYPE::BUTTON;
OnInput(tgt, value);
}
else if(type == EV_ABS)
{
int fixedValue = value;
2018-11-28 18:51:38 -05:00
if(abs->flat == 0)
2018-11-28 18:37:31 -05:00
{
2018-11-28 18:51:38 -05:00
//Assuming this is a POVhat
2018-11-28 18:37:31 -05:00
tgt.keyType = BINDINGTARGET::KEYTYPE::POVHAT;
switch(value)
{
case 0:
fixedValue = BINDINGTARGET::POVHAT_MAX;
break;
case 1:
fixedValue = 0;
break;
case -1:
fixedValue = 4;
break;
default:
assert(false);
break;
}
}
else
{
2021-10-12 13:25:10 -04:00
int range = (abs->maximum - abs->minimum);
fixedValue = ((value - abs->minimum) * 255) / range;
2018-11-28 18:37:31 -05:00
tgt.keyType = BINDINGTARGET::KEYTYPE::AXIS;
}
OnInput(tgt, fixedValue);
}
}