Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #463 from radiant-player/fix-ddhidlib
Browse files Browse the repository at this point in the history
Replace DDHidLib with custom version from BeardedSpice
  • Loading branch information
jacobwgillespie committed Dec 20, 2015
2 parents 4124218 + 1615865 commit 7576fe6
Show file tree
Hide file tree
Showing 46 changed files with 2,017 additions and 6,016 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file should follow the standards specified on [keepachangelog.com](http://k
This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]
### Fixed
* Fixed a bug introduced in 1.6.0 where Radiant would hang when external HID devices were connected ([#463](https://github.com/radiant-player/radiant-player-mac/pull/463)). Note that there is still an outstanding bug where the headphone play/pause buttons open iTunes in addition to controlling Radiant. That is still being investigated.

## [1.6.1] - 2015-12-20
### Fixed
Expand Down
82 changes: 74 additions & 8 deletions radiant-player-mac.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions radiant-player-mac/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import <IOKit/hidsystem/ev_keymap.h>
#import <WebKit/WebKit.h>
#import <EDStarRating/EDStarRating.h>
#import <DDHidLib/DDHidLib.h>

#import "Notifications/NotificationCenter.h"

Expand Down Expand Up @@ -45,7 +44,8 @@
NSMutableDictionary *_styles;
BOOL _isTall;

NSArray *mikeys;
NSMutableArray *_mikeys;
NSMutableArray *_appleRemotes;

WebView *dummyWebView;
DummyWebViewPolicyDelegate *dummyWebViewDelegate;
Expand Down
44 changes: 31 additions & 13 deletions radiant-player-mac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

#import "AppDelegate.h"
#import "LastFmService.h"
#import "DDHidAppleRemote.h"
#import "DDHidAppleMikey.h"

#import <Sparkle/Sparkle.h>
#import <DDHidLib/DDHidLib.h>

@implementation AppDelegate

Expand Down Expand Up @@ -512,8 +513,8 @@ static CGEventRef event_tap_callback(CGEventTapProxy proxy,

- (void) pressKey:(NSUInteger)keytype
{
[self keyEvent:keytype state:0xA]; // key down
[self keyEvent:keytype state: 0xB]; // key up
[self keyEvent:keytype state:0xA]; // key down
[self keyEvent:keytype state:0xB]; // key up
}

- (void) keyEvent:(NSUInteger)keytype state:(NSUInteger)state
Expand Down Expand Up @@ -541,15 +542,32 @@ - (void) refreshMikeys
{
NSLog(@"Reset Mikeys");

if (mikeys != nil) {
[mikeys makeObjectsPerformSelector:@selector(stopListening) withObject:nil];
if (_mikeys != nil) {
@try {
[_mikeys makeObjectsPerformSelector:@selector(stopListening)];
}
@catch (NSException *exception) {
NSLog(@"Error when stopListening on device: %@", exception);
}
}
@try {
NSArray *mikeys = [DDHidAppleMikey allMikeys];
_mikeys = [NSMutableArray arrayWithCapacity:mikeys.count];
for (DDHidAppleMikey *item in mikeys) {
@try {
[item setDelegate:self];
[item setListenInExclusiveMode:NO];
[item startListening];
[_mikeys addObject:item];
}
@catch (NSException *exception) {
NSLog(@"Error when startListning on device: %@, exception %@", item, exception);
}
}
}
@catch (NSException *exception) {
NSLog(@"Error obtaining HID devices: %@", [exception description]);
}
mikeys = [DDHidAppleMikey allMikeys];
// we want to be the delegate of the mikeys
[mikeys makeObjectsPerformSelector:@selector(setDelegate:) withObject:self];
// start listening to all mikey events
[mikeys makeObjectsPerformSelector:@selector(setListenInExclusiveMode:) withObject:(id)kCFBooleanFalse];
[mikeys makeObjectsPerformSelector:@selector(startListening) withObject:nil];
}

- (void) ddhidAppleMikey:(DDHidAppleMikey *)mikey press:(unsigned)usageId upOrDown:(BOOL)upOrDown
Expand All @@ -569,10 +587,10 @@ - (void) ddhidAppleMikey:(DDHidAppleMikey *)mikey press:(unsigned)usageId upOrDo
withObject:nil waitUntilDone:NO];
break;
case kHIDUsage_GD_SystemMenuUp:
[self pressKey:NX_KEYTYPE_SOUND_UP];
// [self pressKey:NX_KEYTYPE_SOUND_UP];
break;
case kHIDUsage_GD_SystemMenuDown:
[self pressKey:NX_KEYTYPE_SOUND_DOWN];
// [self pressKey:NX_KEYTYPE_SOUND_DOWN];
break;
default:
NSLog(@"Unknown key press seen %d", usageId);
Expand Down
164 changes: 164 additions & 0 deletions radiant-player-mac/DDHidLib/DDHidAppleMikey.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2007 Dave Dribin
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#import "DDHidAppleMikey.h"
#import "DDHidElement.h"
#import "DDHidUsage.h"
#import "DDHidQueue.h"
#import "DDHidEvent.h"
#include <IOKit/hid/IOHIDUsageTables.h>

#define APPLE_MIC_ONLY 1

@interface DDHidAppleMikey (DDHidAppleMikeyDelegate)

- (void) ddhidAppleMikey: (DDHidAppleMikey *) mikey
press: (unsigned) usageId
upOrDown:(BOOL)upOrDown;

@end

@interface DDHidAppleMikey (Private)

- (void) initPressElements: (NSArray *) elements;
- (void) ddhidQueueHasEvents: (DDHidQueue *) hidQueue;

@end

@implementation DDHidAppleMikey

+ (NSArray *) allMikeys;
{
//add mikeys
id a2 = [self allDevicesMatchingUsagePage:12 usageId:1 withClass:self skipZeroLocations:NO];
#if APPLE_MIC_ONLY
a2 = [a2 filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"productName == \"Apple Mikey HID Driver\""]];
#endif

return a2;
}

- (id) initWithDevice: (io_object_t) device error: (NSError **) error_;
{
self = [super initWithDevice: device error: error_];
if (self == nil)
return nil;

mPressElements = [[NSMutableArray alloc] init];
[self initPressElements: [self elements]];

return self;
}

//===========================================================
// dealloc
//===========================================================
- (void) dealloc
{
[mPressElements release];

mPressElements = nil;
[super dealloc];
}

#pragma mark -
#pragma mark Elements

- (NSArray *) pressElements;
{
return mPressElements;
}

- (unsigned) numberOfKeys;
{
return (unsigned)[mPressElements count];
}

- (void) addElementsToQueue: (DDHidQueue *) queue;
{
[queue addElements: mPressElements];
}

#pragma mark -
#pragma mark Asynchronous Notification

- (void) setDelegate: (id) delegate;
{
mDelegate = delegate;
}

- (void) addElementsToDefaultQueue;
{
[self addElementsToQueue: mDefaultQueue];
}

@end

@implementation DDHidAppleMikey (DDHidAppleMikeyDelegate)

- (void) ddhidAppleMikey:(DDHidAppleMikey *)mikey press:(unsigned int)usageId upOrDown:(BOOL)upOrDown
{
if ([mDelegate respondsToSelector: _cmd])
[mDelegate ddhidAppleMikey: mikey press: usageId upOrDown:(BOOL)upOrDown];
}

@end

@implementation DDHidAppleMikey (Private)

- (void) initPressElements: (NSArray *) elements;
{
NSEnumerator * e = [elements objectEnumerator];
DDHidElement * element;
while (element = [e nextObject])
{
// unsigned usagePage = [[element usage] usagePage];
// unsigned usageId = [[element usage] usageId];
// if (usagePage == kHIDPage_KeyboardOrKeypad)
// {
// if ((usageId >= 0x04) && (usageId <= 0xA4) ||
// (usageId >= 0xE0) && (usageId <= 0xE7))
{
[mPressElements addObject: element];
}
// }
NSArray * subElements = [element elements];
if (subElements != nil)
[self initPressElements: subElements];
}
}

- (void) ddhidQueueHasEvents: (DDHidQueue *) hidQueue;
{
DDHidEvent * event;
while ((event = [hidQueue nextEvent]))
{
DDHidElement * element = [self elementForCookie: [event elementCookie]];
unsigned usageId = [[element usage] usageId];
SInt32 value = [event value];
[self ddhidAppleMikey:self press:usageId upOrDown:value==1];
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum DDHidAppleRemoteEventIdentifier
kDDHidRemoteButtonPlay_Sleep,
kDDHidRemoteControl_Switched,
kDDHidRemoteControl_Paired,
kDDHidRemoteButtonPlayPause
};
typedef enum DDHidAppleRemoteEventIdentifier DDHidAppleRemoteEventIdentifier;

Expand Down
Loading

0 comments on commit 7576fe6

Please sign in to comment.