summaryrefslogtreecommitdiff
path: root/patches/xow/0001-Single-controller-patch.patch
blob: b56270a2460fc09a1bd2a2b5838cc5a3760b168c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 8937ae5e05e64c884b9f8d0736628a596bba6728 Mon Sep 17 00:00:00 2001
From: Kjetil Orbekk <kj@orbekk.com>
Date: Mon, 22 Feb 2021 08:17:49 -0500
Subject: [PATCH] Single controller patch

---
 controller/controller.cpp |  6 ++++++
 controller/controller.h   |  1 +
 dongle/dongle.cpp         | 13 +++++++++----
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/controller/controller.cpp b/controller/controller.cpp
index d138e0c..83640ea 100644
--- a/controller/controller.cpp
+++ b/controller/controller.cpp
@@ -171,6 +171,12 @@ void Controller::initInput(const AnnounceData *announce)
         return;
     }
 
+    if (initialized) {
+        Log::info("HACK: Skip initialization because of reute");
+        return;
+    }
+    initialized = true;
+
     InputDevice::AxisConfig stickConfig = {};
 
     // 16 bits (signed) for the sticks
diff --git a/controller/controller.h b/controller/controller.h
index 5486895..cd11853 100644
--- a/controller/controller.h
+++ b/controller/controller.h
@@ -52,4 +52,5 @@ private:
     InputDevice inputDevice;
 
     uint8_t batteryLevel = 0xff;
+    bool initialized = false;
 };
diff --git a/dongle/dongle.cpp b/dongle/dongle.cpp
index b931ff8..5c5305e 100644
--- a/dongle/dongle.cpp
+++ b/dongle/dongle.cpp
@@ -72,9 +72,13 @@ void Dongle::handleControllerConnect(Bytes address)
         std::placeholders::_1
     );
 
-    controllers[wcid - 1].reset(new Controller(sendPacket));
-
-    Log::info("Controller '%d' connected", wcid);
+    if (controllers[wcid - 1] == nullptr)
+    {
+        controllers[wcid - 1].reset(new Controller(sendPacket));
+        Log::info("Controller '%d' connected", wcid);
+    } else {
+        Log::info("Controller '%d' connected (re-attached)", wcid);
+    }
 }
 
 void Dongle::handleControllerDisconnect(uint8_t wcid)
@@ -93,7 +97,8 @@ void Dongle::handleControllerDisconnect(uint8_t wcid)
         return;
     }
 
-    controllers[wcid - 1].reset();
+    // QQQ: Figure out how to flag protect this.
+    // controllers[wcid - 1].reset();
 
     if (!removeClient(wcid))
     {
-- 
2.29.2