1 // Copyright 2016 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #ifdef _WIN32
8 #include <windows.h>
9 
10 #include "Common/StringUtil.h"
11 #include "Core/HW/WiimoteCommon/WiimoteHid.h"
12 #include "Core/HW/WiimoteReal/WiimoteReal.h"
13 
14 namespace WiimoteReal
15 {
16 // Different methods to send data Wiimote on Windows depending on OS and Bluetooth Stack
17 enum WinWriteMethod
18 {
19   WWM_WRITE_FILE_LARGEST_REPORT_SIZE,
20   WWM_WRITE_FILE_ACTUAL_REPORT_SIZE,
21   WWM_SET_OUTPUT_REPORT
22 };
23 
24 class WiimoteWindows final : public Wiimote
25 {
26 public:
27   WiimoteWindows(const std::basic_string<TCHAR>& path, WinWriteMethod initial_write_method);
28   ~WiimoteWindows() override;
GetId()29   std::string GetId() const override { return WStringToUTF8(m_devicepath); }
30 
31 protected:
32   bool ConnectInternal() override;
33   void DisconnectInternal() override;
34   bool IsConnected() const override;
35   void IOWakeup() override;
36   int IORead(u8* buf) override;
37   int IOWrite(u8 const* buf, size_t len) override;
38 
39 private:
40   std::basic_string<TCHAR> m_devicepath;  // Unique Wiimote reference
41   HANDLE m_dev_handle;                    // HID handle
42   OVERLAPPED m_hid_overlap_read;          // Overlap handles
43   OVERLAPPED m_hid_overlap_write;
44   WinWriteMethod m_write_method;  // Type of Write Method to use
45 };
46 
47 class WiimoteScannerWindows final : public WiimoteScannerBackend
48 {
49 public:
50   WiimoteScannerWindows();
51   ~WiimoteScannerWindows() override;
52   bool IsReady() const override;
53   void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
54   void Update() override;
55 };
56 }  // namespace WiimoteReal
57 
58 #else
59 #include "Core/HW/WiimoteReal/IODummy.h"
60 namespace WiimoteReal
61 {
62 using WiimoteScannerWindows = WiimoteScannerDummy;
63 }
64 #endif
65