Major scoped-enum refactor

This commit is contained in:
Jack Andersen
2015-11-20 15:12:22 -10:00
parent 62fae60042
commit c9edf8dd85
23 changed files with 451 additions and 380 deletions

View File

@@ -11,7 +11,7 @@ extern const DeviceSignature BOO_DEVICE_SIGS[];
bool DeviceSignature::DeviceMatchToken(const DeviceToken& token, const TDeviceSignatureSet& sigSet)
{
if (token.getDeviceType() == DeviceToken::DEVTYPE_GENERICHID)
if (token.getDeviceType() == DeviceToken::DeviceType::GenericHID)
return true;
for (const DeviceSignature* sig : sigSet)
{
@@ -27,7 +27,7 @@ DeviceBase* DeviceSignature::DeviceNew(DeviceToken& token)
DeviceBase* retval = NULL;
/* Early-return for generic HID devices */
if (token.getDeviceType() == DeviceToken::DEVTYPE_GENERICHID)
if (token.getDeviceType() == DeviceToken::DeviceType::GenericHID)
{
retval = new GenericPad(&token);
if (!retval)

View File

@@ -20,14 +20,15 @@ DolphinSmashAdapter::~DolphinSmashAdapter()
static inline EDolphinControllerType parseType(unsigned char status)
{
unsigned char type = status & (DOL_TYPE_NORMAL | DOL_TYPE_WAVEBIRD);
EDolphinControllerType type = EDolphinControllerType(status) &
(EDolphinControllerType::Normal | EDolphinControllerType::Wavebird);
switch (type)
{
case DOL_TYPE_NORMAL:
case DOL_TYPE_WAVEBIRD:
return (EDolphinControllerType)type;
case EDolphinControllerType::Normal:
case EDolphinControllerType::Wavebird:
return type;
default:
return DOL_TYPE_NONE;
return EDolphinControllerType::None;
}
}
@@ -77,12 +78,12 @@ void DolphinSmashAdapter::transferCycle()
DolphinControllerState state;
bool rumble = false;
EDolphinControllerType type = parseState(&state, controller, rumble);
if (type && !(m_knownControllers & 1<<i))
if (type != EDolphinControllerType::None && !(m_knownControllers & 1<<i))
{
m_knownControllers |= 1<<i;
m_callback->controllerConnected(i, type);
}
else if (!type && (m_knownControllers & 1<<i))
else if (type == EDolphinControllerType::None && (m_knownControllers & 1<<i))
{
m_knownControllers &= ~(1<<i);
m_callback->controllerDisconnected(i);

View File

@@ -49,8 +49,8 @@ static const uint8_t defaultReport[35] = {
DualshockPad::DualshockPad(DeviceToken* token)
: DeviceBase(token),
m_callback(nullptr),
m_rumbleRequest(0),
m_rumbleState(0)
m_rumbleRequest(EDualshockMotor::None),
m_rumbleState(EDualshockMotor::None)
{
memcpy(m_report.buf, defaultReport, 35);
}
@@ -96,7 +96,7 @@ void DualshockPad::transferCycle()
if (m_rumbleRequest != m_rumbleState)
{
if (m_rumbleRequest & DS3_MOTOR_LEFT)
if ((m_rumbleRequest & EDualshockMotor::Left) != EDualshockMotor::None)
{
m_report.rumble.leftDuration = m_rumbleDuration[0];
m_report.rumble.leftForce = m_rumbleIntensity[0];
@@ -107,7 +107,7 @@ void DualshockPad::transferCycle()
m_report.rumble.leftForce = 0;
}
if (m_rumbleRequest & DS3_MOTOR_RIGHT)
if ((m_rumbleRequest & EDualshockMotor::Right) != EDualshockMotor::None)
{
m_report.rumble.rightDuration = m_rumbleDuration[0];
m_report.rumble.rightOn = true;
@@ -123,9 +123,9 @@ void DualshockPad::transferCycle()
else
{
if (state.m_reserved5[8] & 0x80)
m_rumbleRequest &= ~DS3_MOTOR_RIGHT;
m_rumbleRequest &= ~EDualshockMotor::Right;
if (state.m_reserved5[7] & 0x01)
m_rumbleRequest &= ~DS3_MOTOR_LEFT;
m_rumbleRequest &= ~EDualshockMotor::Left;
m_rumbleState = m_rumbleRequest;
const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V);
float accXval = -((double)state.m_accelerometer[0] - zeroG);

View File

@@ -243,12 +243,12 @@ public:
{
devImp.m_hidDev = this;
std::unique_lock<std::mutex> lk(m_initMutex);
DeviceToken::TDeviceType dType = token.getDeviceType();
if (dType == DeviceToken::DEVTYPE_USB)
DeviceToken::DeviceType dType = token.getDeviceType();
if (dType == DeviceToken::DeviceType::USB)
m_thread = new std::thread(_threadProcUSBLL, this);
else if (dType == DeviceToken::DEVTYPE_BLUETOOTH)
else if (dType == DeviceToken::DeviceType::Bluetooth)
m_thread = new std::thread(_threadProcBTLL, this);
else if (dType == DeviceToken::DEVTYPE_GENERICHID)
else if (dType == DeviceToken::DeviceType::GenericHID)
m_thread = new std::thread(_threadProcHID, this);
else
{

View File

@@ -34,11 +34,11 @@ class HIDListenerUdev final : public IHIDListener
/* Filter to USB/BT */
const char* dt = udev_device_get_devtype(device);
DeviceToken::TDeviceType type;
DeviceToken::DeviceType type;
if (!strcmp(dt, "usb_device"))
type = DeviceToken::DEVTYPE_USB;
type = DeviceToken::DeviceType::USB;
else if (!strcmp(dt, "bluetooth_device"))
type = DeviceToken::DEVTYPE_BLUETOOTH;
type = DeviceToken::DeviceType::Bluetooth;
else
return;
@@ -82,9 +82,9 @@ class HIDListenerUdev final : public IHIDListener
{
/* Matched-insertion failed; see if generic HID interface is available */
udev_list_entry* devInterfaces = nullptr;
if (type == DeviceToken::DEVTYPE_USB)
if (type == DeviceToken::DeviceType::USB)
devInterfaces = udev_list_entry_get_by_name(attrs, "ID_USB_INTERFACES");
else if (type == DeviceToken::DEVTYPE_BLUETOOTH)
else if (type == DeviceToken::DeviceType::Bluetooth)
devInterfaces = udev_list_entry_get_by_name(attrs, "ID_BLUETOOTH_INTERFACES");
if (devInterfaces)
{
@@ -101,7 +101,7 @@ class HIDListenerUdev final : public IHIDListener
{
const char* hidPath = udev_list_entry_get_name(hidEnt);
if (!listener->m_finder._hasToken(hidPath))
listener->m_finder._insertToken(DeviceToken(DeviceToken::DEVTYPE_GENERICHID,
listener->m_finder._insertToken(DeviceToken(DeviceToken::DeviceType::GenericHID,
vid, pid, manuf, product, hidPath));
}
udev_enumerate_unref(hidEnum);