Merge pull request #7101 from lioncash/ios
WiimoteDevice: Minor changes
This commit is contained in:
commit
fca6d80740
|
@ -339,7 +339,7 @@ void BluetoothEmu::Update()
|
||||||
// Create ACL connection
|
// Create ACL connection
|
||||||
if (m_HCIEndpoint && (m_ScanEnable & HCI_PAGE_SCAN_ENABLE))
|
if (m_HCIEndpoint && (m_ScanEnable & HCI_PAGE_SCAN_ENABLE))
|
||||||
{
|
{
|
||||||
for (auto& wiimote : m_WiiMotes)
|
for (const auto& wiimote : m_WiiMotes)
|
||||||
{
|
{
|
||||||
if (wiimote.EventPagingChanged(m_ScanEnable))
|
if (wiimote.EventPagingChanged(m_ScanEnable))
|
||||||
SendEventRequestConnection(wiimote);
|
SendEventRequestConnection(wiimote);
|
||||||
|
@ -524,7 +524,7 @@ bool BluetoothEmu::SendEventConnectionComplete(const bdaddr_t& _bd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called from Update() after ScanEnable has been enabled.
|
// This is called from Update() after ScanEnable has been enabled.
|
||||||
bool BluetoothEmu::SendEventRequestConnection(WiimoteDevice& _rWiiMote)
|
bool BluetoothEmu::SendEventRequestConnection(const WiimoteDevice& _rWiiMote)
|
||||||
{
|
{
|
||||||
SQueuedEvent Event(sizeof(SHCIEventRequestConnection), 0);
|
SQueuedEvent Event(sizeof(SHCIEventRequestConnection), 0);
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ private:
|
||||||
bool SendEventInquiryResponse();
|
bool SendEventInquiryResponse();
|
||||||
bool SendEventInquiryComplete();
|
bool SendEventInquiryComplete();
|
||||||
bool SendEventRemoteNameReq(const bdaddr_t& _bd);
|
bool SendEventRemoteNameReq(const bdaddr_t& _bd);
|
||||||
bool SendEventRequestConnection(WiimoteDevice& _rWiiMote);
|
bool SendEventRequestConnection(const WiimoteDevice& _rWiiMote);
|
||||||
bool SendEventConnectionComplete(const bdaddr_t& _bd);
|
bool SendEventConnectionComplete(const bdaddr_t& _bd);
|
||||||
bool SendEventReadClockOffsetComplete(u16 _connectionHandle);
|
bool SendEventReadClockOffsetComplete(u16 _connectionHandle);
|
||||||
bool SendEventConPacketTypeChange(u16 _connectionHandle, u16 _packetType);
|
bool SendEventConPacketTypeChange(u16 _connectionHandle, u16 _packetType);
|
||||||
|
|
|
@ -56,7 +56,7 @@ WiimoteDevice::WiimoteDevice(Device::BluetoothEmu* host, int number, bdaddr_t bd
|
||||||
{
|
{
|
||||||
INFO_LOG(IOS_WIIMOTE, "Wiimote: #%i Constructed", number);
|
INFO_LOG(IOS_WIIMOTE, "Wiimote: #%i Constructed", number);
|
||||||
|
|
||||||
m_ConnectionState = (ready) ? CONN_READY : CONN_INACTIVE;
|
m_ConnectionState = ready ? ConnectionState::Ready : ConnectionState::Inactive;
|
||||||
m_ConnectionHandle = 0x100 + number;
|
m_ConnectionHandle = 0x100 + number;
|
||||||
memset(m_LinkKey, 0xA0 + number, HCI_KEY_SIZE);
|
memset(m_LinkKey, 0xA0 + number, HCI_KEY_SIZE);
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ void WiimoteDevice::DoState(PointerWrap& p)
|
||||||
|
|
||||||
p.Do(m_ConnectionState);
|
p.Do(m_ConnectionState);
|
||||||
|
|
||||||
p.Do(m_HIDControlChannel_Connected);
|
p.Do(m_hid_control_channel.connected);
|
||||||
p.Do(m_HIDControlChannel_ConnectedWait);
|
p.Do(m_hid_control_channel.connected_wait);
|
||||||
p.Do(m_HIDControlChannel_Config);
|
p.Do(m_hid_control_channel.config);
|
||||||
p.Do(m_HIDControlChannel_ConfigWait);
|
p.Do(m_hid_control_channel.config_wait);
|
||||||
p.Do(m_HIDInterruptChannel_Connected);
|
p.Do(m_hid_interrupt_channel.connected);
|
||||||
p.Do(m_HIDInterruptChannel_ConnectedWait);
|
p.Do(m_hid_interrupt_channel.connected_wait);
|
||||||
p.Do(m_HIDInterruptChannel_Config);
|
p.Do(m_hid_interrupt_channel.config);
|
||||||
p.Do(m_HIDInterruptChannel_ConfigWait);
|
p.Do(m_hid_interrupt_channel.config_wait);
|
||||||
|
|
||||||
p.Do(m_BD);
|
p.Do(m_BD);
|
||||||
p.Do(m_ConnectionHandle);
|
p.Do(m_ConnectionHandle);
|
||||||
|
@ -130,55 +130,55 @@ void WiimoteDevice::DoState(PointerWrap& p)
|
||||||
|
|
||||||
bool WiimoteDevice::LinkChannel()
|
bool WiimoteDevice::LinkChannel()
|
||||||
{
|
{
|
||||||
if (m_ConnectionState != CONN_LINKING)
|
if (m_ConnectionState != ConnectionState::Linking)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// try to connect L2CAP_PSM_HID_CNTL
|
// try to connect L2CAP_PSM_HID_CNTL
|
||||||
if (!m_HIDControlChannel_Connected)
|
if (!m_hid_control_channel.connected)
|
||||||
{
|
{
|
||||||
if (m_HIDControlChannel_ConnectedWait)
|
if (m_hid_control_channel.connected_wait)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_HIDControlChannel_ConnectedWait = true;
|
m_hid_control_channel.connected_wait = true;
|
||||||
SendConnectionRequest(0x0040, L2CAP_PSM_HID_CNTL);
|
SendConnectionRequest(0x0040, L2CAP_PSM_HID_CNTL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to config L2CAP_PSM_HID_CNTL
|
// try to config L2CAP_PSM_HID_CNTL
|
||||||
if (!m_HIDControlChannel_Config)
|
if (!m_hid_control_channel.config)
|
||||||
{
|
{
|
||||||
if (m_HIDControlChannel_ConfigWait)
|
if (m_hid_control_channel.config_wait)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_HIDControlChannel_ConfigWait = true;
|
m_hid_control_channel.config_wait = true;
|
||||||
SendConfigurationRequest(0x0040);
|
SendConfigurationRequest(0x0040);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to connect L2CAP_PSM_HID_INTR
|
// try to connect L2CAP_PSM_HID_INTR
|
||||||
if (!m_HIDInterruptChannel_Connected)
|
if (!m_hid_interrupt_channel.connected)
|
||||||
{
|
{
|
||||||
if (m_HIDInterruptChannel_ConnectedWait)
|
if (m_hid_interrupt_channel.connected_wait)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_HIDInterruptChannel_ConnectedWait = true;
|
m_hid_interrupt_channel.connected_wait = true;
|
||||||
SendConnectionRequest(0x0041, L2CAP_PSM_HID_INTR);
|
SendConnectionRequest(0x0041, L2CAP_PSM_HID_INTR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to config L2CAP_PSM_HID_INTR
|
// try to config L2CAP_PSM_HID_INTR
|
||||||
if (!m_HIDInterruptChannel_Config)
|
if (!m_hid_interrupt_channel.config)
|
||||||
{
|
{
|
||||||
if (m_HIDInterruptChannel_ConfigWait)
|
if (m_hid_interrupt_channel.config_wait)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_HIDInterruptChannel_ConfigWait = true;
|
m_hid_interrupt_channel.config_wait = true;
|
||||||
SendConfigurationRequest(0x0041);
|
SendConfigurationRequest(0x0041);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOG(IOS_WIIMOTE, "ConnectionState CONN_LINKING -> CONN_COMPLETE");
|
DEBUG_LOG(IOS_WIIMOTE, "ConnectionState CONN_LINKING -> CONN_COMPLETE");
|
||||||
m_ConnectionState = CONN_COMPLETE;
|
m_ConnectionState = ConnectionState::Complete;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -195,9 +195,9 @@ bool WiimoteDevice::LinkChannel()
|
||||||
//
|
//
|
||||||
void WiimoteDevice::Activate(bool ready)
|
void WiimoteDevice::Activate(bool ready)
|
||||||
{
|
{
|
||||||
if (ready && (m_ConnectionState == CONN_INACTIVE))
|
if (ready && (m_ConnectionState == ConnectionState::Inactive))
|
||||||
{
|
{
|
||||||
m_ConnectionState = CONN_READY;
|
m_ConnectionState = ConnectionState::Ready;
|
||||||
}
|
}
|
||||||
else if (!ready)
|
else if (!ready)
|
||||||
{
|
{
|
||||||
|
@ -209,7 +209,7 @@ void WiimoteDevice::Activate(bool ready)
|
||||||
void WiimoteDevice::EventConnectionAccepted()
|
void WiimoteDevice::EventConnectionAccepted()
|
||||||
{
|
{
|
||||||
DEBUG_LOG(IOS_WIIMOTE, "ConnectionState %x -> CONN_LINKING", m_ConnectionState);
|
DEBUG_LOG(IOS_WIIMOTE, "ConnectionState %x -> CONN_LINKING", m_ConnectionState);
|
||||||
m_ConnectionState = CONN_LINKING;
|
m_ConnectionState = ConnectionState::Linking;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteDevice::EventDisconnect()
|
void WiimoteDevice::EventDisconnect()
|
||||||
|
@ -217,30 +217,21 @@ void WiimoteDevice::EventDisconnect()
|
||||||
// Send disconnect message to plugin
|
// Send disconnect message to plugin
|
||||||
Wiimote::ControlChannel(m_ConnectionHandle & 0xFF, 99, nullptr, 0);
|
Wiimote::ControlChannel(m_ConnectionHandle & 0xFF, 99, nullptr, 0);
|
||||||
|
|
||||||
m_ConnectionState = CONN_INACTIVE;
|
m_ConnectionState = ConnectionState::Inactive;
|
||||||
// Clear channel flags
|
// Clear channel flags
|
||||||
ResetChannels();
|
ResetChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WiimoteDevice::EventPagingChanged(u8 _pageMode)
|
bool WiimoteDevice::EventPagingChanged(u8 page_mode) const
|
||||||
{
|
{
|
||||||
if ((m_ConnectionState == CONN_READY) && (_pageMode & HCI_PAGE_SCAN_ENABLE))
|
return (m_ConnectionState == ConnectionState::Ready) && (page_mode & HCI_PAGE_SCAN_ENABLE);
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteDevice::ResetChannels()
|
void WiimoteDevice::ResetChannels()
|
||||||
{
|
{
|
||||||
// reset connection process
|
// reset connection process
|
||||||
m_HIDControlChannel_Connected = false;
|
m_hid_control_channel = {};
|
||||||
m_HIDControlChannel_Config = false;
|
m_hid_interrupt_channel = {};
|
||||||
m_HIDInterruptChannel_Connected = false;
|
|
||||||
m_HIDInterruptChannel_Config = false;
|
|
||||||
m_HIDControlChannel_ConnectedWait = false;
|
|
||||||
m_HIDControlChannel_ConfigWait = false;
|
|
||||||
m_HIDInterruptChannel_ConnectedWait = false;
|
|
||||||
m_HIDInterruptChannel_ConfigWait = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -425,9 +416,9 @@ void WiimoteDevice::ReceiveConnectionResponse(u8 _Ident, u8* _pData, u32 _Size)
|
||||||
|
|
||||||
// update state machine
|
// update state machine
|
||||||
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
||||||
m_HIDControlChannel_Connected = true;
|
m_hid_control_channel.connected = true;
|
||||||
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
||||||
m_HIDInterruptChannel_Connected = true;
|
m_hid_interrupt_channel.connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteDevice::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size)
|
void WiimoteDevice::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size)
|
||||||
|
@ -501,9 +492,9 @@ void WiimoteDevice::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size)
|
||||||
|
|
||||||
// update state machine
|
// update state machine
|
||||||
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
||||||
m_HIDControlChannel_Connected = true;
|
m_hid_control_channel.connected = true;
|
||||||
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
||||||
m_HIDInterruptChannel_Connected = true;
|
m_hid_interrupt_channel.connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteDevice::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size)
|
void WiimoteDevice::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size)
|
||||||
|
@ -521,9 +512,9 @@ void WiimoteDevice::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u32 _Siz
|
||||||
SChannel& rChannel = m_Channel[rsp->scid];
|
SChannel& rChannel = m_Channel[rsp->scid];
|
||||||
|
|
||||||
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
if (rChannel.PSM == L2CAP_PSM_HID_CNTL)
|
||||||
m_HIDControlChannel_Config = true;
|
m_hid_control_channel.config = true;
|
||||||
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
else if (rChannel.PSM == L2CAP_PSM_HID_INTR)
|
||||||
m_HIDInterruptChannel_Config = true;
|
m_hid_interrupt_channel.config = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiimoteDevice::ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size)
|
void WiimoteDevice::ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size)
|
||||||
|
|
|
@ -30,8 +30,8 @@ public:
|
||||||
// ugly Host handling....
|
// ugly Host handling....
|
||||||
// we really have to clean all this code
|
// we really have to clean all this code
|
||||||
|
|
||||||
bool IsConnected() const { return m_ConnectionState == CONN_COMPLETE; }
|
bool IsConnected() const { return m_ConnectionState == ConnectionState::Complete; }
|
||||||
bool IsInactive() const { return m_ConnectionState == CONN_INACTIVE; }
|
bool IsInactive() const { return m_ConnectionState == ConnectionState::Inactive; }
|
||||||
bool LinkChannel();
|
bool LinkChannel();
|
||||||
void ResetChannels();
|
void ResetChannels();
|
||||||
void Activate(bool ready);
|
void Activate(bool ready);
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
|
|
||||||
void EventConnectionAccepted();
|
void EventConnectionAccepted();
|
||||||
void EventDisconnect();
|
void EventDisconnect();
|
||||||
bool EventPagingChanged(u8 _pageMode);
|
bool EventPagingChanged(u8 page_mode) const;
|
||||||
|
|
||||||
const bdaddr_t& GetBD() const { return m_BD; }
|
const bdaddr_t& GetBD() const { return m_BD; }
|
||||||
const uint8_t* GetClass() const { return uclass; }
|
const uint8_t* GetClass() const { return uclass; }
|
||||||
|
@ -53,23 +53,26 @@ public:
|
||||||
const u8* GetLinkKey() const { return m_LinkKey; }
|
const u8* GetLinkKey() const { return m_LinkKey; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum ConnectionState
|
enum class ConnectionState
|
||||||
{
|
{
|
||||||
CONN_INACTIVE = -1,
|
Inactive = -1,
|
||||||
CONN_READY,
|
Ready,
|
||||||
CONN_LINKING,
|
Linking,
|
||||||
CONN_COMPLETE
|
Complete
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct HIDChannelState
|
||||||
|
{
|
||||||
|
bool connected = false;
|
||||||
|
bool connected_wait = false;
|
||||||
|
bool config = false;
|
||||||
|
bool config_wait = false;
|
||||||
|
};
|
||||||
|
|
||||||
ConnectionState m_ConnectionState;
|
ConnectionState m_ConnectionState;
|
||||||
|
|
||||||
bool m_HIDControlChannel_Connected = false;
|
HIDChannelState m_hid_control_channel;
|
||||||
bool m_HIDControlChannel_ConnectedWait = false;
|
HIDChannelState m_hid_interrupt_channel;
|
||||||
bool m_HIDControlChannel_Config = false;
|
|
||||||
bool m_HIDControlChannel_ConfigWait = false;
|
|
||||||
bool m_HIDInterruptChannel_Connected = false;
|
|
||||||
bool m_HIDInterruptChannel_ConnectedWait = false;
|
|
||||||
bool m_HIDInterruptChannel_Config = false;
|
|
||||||
bool m_HIDInterruptChannel_ConfigWait = false;
|
|
||||||
|
|
||||||
// STATE_TO_SAVE
|
// STATE_TO_SAVE
|
||||||
bdaddr_t m_BD;
|
bdaddr_t m_BD;
|
||||||
|
@ -95,7 +98,7 @@ private:
|
||||||
typedef std::map<u32, SChannel> CChannelMap;
|
typedef std::map<u32, SChannel> CChannelMap;
|
||||||
CChannelMap m_Channel;
|
CChannelMap m_Channel;
|
||||||
|
|
||||||
bool DoesChannelExist(u16 _SCID) { return m_Channel.find(_SCID) != m_Channel.end(); }
|
bool DoesChannelExist(u16 scid) const { return m_Channel.find(scid) != m_Channel.end(); }
|
||||||
void SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLength, u8* _pCommandData);
|
void SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLength, u8* _pCommandData);
|
||||||
|
|
||||||
void SignalChannel(u8* _pData, u32 _Size);
|
void SignalChannel(u8* _pData, u32 _Size);
|
||||||
|
|
Loading…
Reference in New Issue