Create a gist now

Instantly share code, notes, and snippets.

@seki /main.m
Created Oct 11, 2017

What would you like to do?
test tool for AB shutter (Bluetooth Remote Shutter)
// 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
Paired: Yes
Configured: Yes
Connected: Yes
Vendor ID: 0x248A
Product ID: 0x8266
Class of Device: Low Energy
AFH Map: ffffffff1f
RSSI: -51
Role: Central
Connection Mode: Active Mode
Interval: 0 ms
#import <IOKit/hid/IOHIDManager.h>
#import <Foundation/Foundation.h>
IOHIDManagerRef manager;
void cleanUp() {
void SignalHandler(int sigraised) {
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);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment