diff options
author | Teddy Wing | 2018-08-16 06:32:51 +0200 |
---|---|---|
committer | Teddy Wing | 2018-08-16 06:55:02 +0200 |
commit | 4e62e8ad7abf833a3d2cb7ddfe01161e91c648ad (patch) | |
tree | cb44d486c46068d6cbcdb8cddb1243e7a6906e0a | |
parent | 9dd1e0b3b2485484fb89de3a924e9e6aacea5609 (diff) | |
download | DomeKey-4e62e8ad7abf833a3d2cb7ddfe01161e91c648ad.tar.bz2 |
HeadphoneKey: Detect 3 headphone button types
Using my previous `NSLog`s, the `usageId`s came out to be 205, 233, 234.
Converted these to hex and looked for corresponding constants in
`/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/hid/IOHIDUsageTables.h`.
Use these constants to figure out which button was presed. Will have to
test other headphones. I'm worried the numbers may change for different
headphones.
Added a `KeyPress` enum that's a lot easier to understand than the
`upOrDown` `BOOL`, whose meaning I completely didn't get until I looked
at the `NSLog` output I had before.
-rw-r--r-- | DomeKey/HeadphoneKey.h | 5 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 17 |
2 files changed, 18 insertions, 4 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 16e74b2..0d4e729 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -9,6 +9,11 @@ #import <Foundation/Foundation.h> #import <DDHidLib/DDHidAppleMikey.h> +typedef enum KeyPress : BOOL { + KeyPressDown = YES, + KeyPressUp = NO +} KeyPress; + @interface HeadphoneKey : NSObject { NSArray *_mikeys; } diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index c01d2c5..0593173 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -28,10 +28,19 @@ press:(unsigned)usageId upOrDown:(BOOL)upOrDown { - NSLog(@"Clicked"); - NSLog(@"%d", usageId); - NSLog(@"%@", mikey); - NSLog(@"%d", upOrDown); + if (upOrDown == KeyPressUp) { + switch (usageId) { + case kHIDUsage_Csmr_PlayOrPause: + NSLog(@"Middle"); + break; + case kHIDUsage_Csmr_VolumeIncrement: + NSLog(@"Top"); + break; + case kHIDUsage_Csmr_VolumeDecrement: + NSLog(@"Bottom"); + break; + } + } } @end |