Created
October 11, 2017 17:37
-
-
Save seki/0fd1a9fbde1dfc625b500749cb7712f3 to your computer and use it in GitHub Desktop.
test tool for AB shutter (Bluetooth Remote Shutter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// abs3 | |
// | |
// Created by Masatoshi SEKI on 2017/10/12. | |
// Copyright © 2017年 Masatoshi SEKI. All rights reserved. | |
// | |
#if 0 | |
- Connected to device UUID: C9529529-C937-45B4-B3B6-D1476FFB111B Named: AB Shutter3 | |
- UUID 2A50 Read Value: 0x028A2466820100 | |
- UUID 2A19 Read Value: 0x63 | |
- UUID 2A19 Unsubscribed | |
- UUID 2A19 Unsubscribed | |
- UUID 2A19 Read Value: 0x63 | |
- Disconnected from device UUID: C9529529-C937-45B4-B3B6-D1476FFB111B Named: AB Shutter3 | |
Address: FF-FF-3E-F8-69-12 | |
Random Address: No | |
Services: | |
Paired: Yes | |
Configured: Yes | |
Connected: Yes | |
Vendor ID: 0x248A | |
Product ID: 0x8266 | |
Class of Device: Low Energy | |
AFH: On | |
AFH Map: ffffffff1f | |
RSSI: -51 | |
Role: Central | |
Connection Mode: Active Mode | |
Interval: 0 ms | |
#endif | |
#import <IOKit/hid/IOHIDManager.h> | |
#import <Foundation/Foundation.h> | |
IOHIDManagerRef manager; | |
void cleanUp() { | |
CFRelease(manager); | |
} | |
void SignalHandler(int sigraised) { | |
cleanUp(); | |
exit(0); | |
} | |
void handleInput(void *context, IOReturn result, void *sender, IOHIDValueRef valueRef) { | |
if (result == kIOReturnSuccess) { | |
IOHIDElementRef elementRef = IOHIDValueGetElement(valueRef); | |
uint32_t usage = IOHIDElementGetUsage(elementRef); | |
long value = IOHIDValueGetIntegerValue(valueRef); | |
printf("elementRef: %ux usage: %ud value: %ld\n", (unsigned int)elementRef, usage, value); | |
} else { | |
printf("result: %x\n", result); | |
} | |
} | |
int main(int argc, const char * argv[]) { | |
signal(SIGINT, SignalHandler); | |
manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDManagerOptionNone); | |
NSDictionary* criteria = @{ | |
@kIOHIDDeviceUsagePageKey: @(kHIDPage_GenericDesktop), | |
@kIOHIDDeviceUsageKey: @(kHIDUsage_GD_Keyboard), | |
@kIOHIDVendorIDKey: @(0x248A), | |
@kIOHIDProductIDKey: @(0x8266), | |
}; | |
IOHIDManagerSetDeviceMatching(manager, (__bridge CFDictionaryRef)criteria); | |
IOHIDManagerScheduleWithRunLoop(manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
IOReturn ret = IOHIDManagerOpen(manager, kIOHIDOptionsTypeSeizeDevice); | |
if (ret != kIOReturnSuccess) { | |
printf("Failed to open\n"); | |
} else { | |
IOHIDManagerRegisterInputValueCallback(manager, &handleInput, NULL); | |
} | |
CFRunLoopRun(); | |
cleanUp(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment