From 285457852798cd1738a6f98068c4920d96ebdb98 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 1 May 2020 18:26:48 +0300 Subject: [PATCH] Less ugly hacks --- Cocoa/GBView.m | 2 -- JoyKit/JOYController.h | 1 - JoyKit/JOYController.m | 8 +++++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index d342497..e733731 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -116,7 +116,6 @@ } [[NSNotificationCenter defaultCenter] removeObserver:self]; [lastController setRumbleAmplitude:0]; - [lastController _forceStopPWMThread]; [JOYController unregisterListener:self]; } - (instancetype)initWithCoder:(NSCoder *)coder @@ -303,7 +302,6 @@ if (![self.window isMainWindow]) return; if (controller != lastController) { [lastController setRumbleAmplitude:0]; - [lastController _forceStopPWMThread]; lastController = controller; } diff --git a/JoyKit/JOYController.h b/JoyKit/JOYController.h index 9363e36..9ed7cf7 100644 --- a/JoyKit/JOYController.h +++ b/JoyKit/JOYController.h @@ -35,7 +35,6 @@ static NSString const *JOYHatsEmulateButtonsKey = @"JOYHatsEmulateButtons"; - (NSArray *) hats; - (void)setRumbleAmplitude:(double)amp; - (void)setPlayerLEDs:(uint8_t)mask; -- (void)_forceStopPWMThread; // Hack @property (readonly, getter=isConnected) bool connected; @end diff --git a/JoyKit/JOYController.m b/JoyKit/JOYController.m index 0268054..92662ad 100644 --- a/JoyKit/JOYController.m +++ b/JoyKit/JOYController.m @@ -607,7 +607,12 @@ typedef struct __attribute__((packed)) { - (void)pwmThread { /* TODO: This does not handle correctly the case of having a multi-port controller where more than one controller - uses rumble. */ + uses rumble. At least make sure any sibling controllers don't have their PWM thread running. */ + for (JOYController *controller in [JOYController allControllers]) { + if (controller != self && controller->_device == _device) { + [controller _forceStopPWMThread]; + } + } unsigned rumbleCounter = 0; while (self.connected && !_forceStopPWMThread) { if ([_rumbleElement setValue:rumbleCounter < round(_rumblePWMRatio * PWM_RESOLUTION)]) { @@ -619,6 +624,7 @@ typedef struct __attribute__((packed)) { } } [_rumblePWMThreadLock lock]; + [_rumbleElement setValue:0]; _rumblePWMThreadRunning = false; _forceStopPWMThread = false; [_rumblePWMThreadLock unlock];