(Infoboxize.) |
Limneoselias (talk | contribs) |
||
Line 37: | Line 37: | ||
void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) { | void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) { | ||
if (IOHIDEventGetType(event)== | if (IOHIDEventGetType(event)==kIOHIDEventTypeProximity){ // Proximity Event Received | ||
int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField) | int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldProximityDetectionMask); // Get the value of the ProximityChanged Field (0 or 64) | ||
// Call dimScreen on SpringBoard to simulate the original proximity effect, or use a reaction of your choice | // Call dimScreen on SpringBoard to simulate the original proximity effect, or use a reaction of your choice | ||
Line 86: | Line 86: | ||
printf("HID Event system should now be running. Hit enter to quit any time.\n"); | printf("HID Event system should now be running. Hit enter to quit any time.\n"); | ||
getchar(); | getchar(); | ||
int resetInterval=0; | |||
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &resetInterval)); | |||
IOHIDEventSystemClose(system, NULL); | IOHIDEventSystemClose(system, NULL); | ||
CFRelease(system); | CFRelease(system); |
Revision as of 11:47, 4 June 2011
AppleProxShim | |
IOService | |
---|---|
Kernel Extension | IOHIDFamily |
Parent Service | AppleCT700 |
IOProviderClass | AppleARMIICDevice |
Primary Usage Page | 65280 |
Primary Usage | 8 |
AppleProxShim is the IOHIDService that controls the device's proximity sensor. By default, this service is enabled only from within applications that have called the high-level method -[UIApplication setProximitySensingEnabled:].
You can intercept the service to manually enable the proximity sensor and assign a callback action for the proximity events, even when on SpringBoard.
To turn on the sensor, you need to change the service's default ReportInterval from 0 to a higher number. For more information about IOHID, see IOHIDFamily
General characteristics
HIDServiceSupport | Yes |
---|---|
Default ReportInterval | 0 |
Example
#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>
void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
if (IOHIDEventGetType(event)==kIOHIDEventTypeProximity){ // Proximity Event Received
int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldProximityDetectionMask); // Get the value of the ProximityChanged Field (0 or 64)
// Call dimScreen on SpringBoard to simulate the original proximity effect, or use a reaction of your choice
int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort();
void (*_SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");
BOOL dim = proximityValue == 0 ? NO : YES;
_SBDimScreen(port,dim);
}
}
int main () {
// Create and open an event system.
IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
// set the PrimaryUsagePage and PrimaryUsage that the AppleProxShim service uses
int page = 65280;
int usage = 8;
// Create a dictionary to match the service with
CFNumberRef nums[2];
CFStringRef keys[2];
keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Get the total of matching services with the above criteria
CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(system, dict, 0, 0, 0,0);
// Get the service
IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
int interval = 1 ;
// Set an interval of 1 , to activate the sensor
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
printf("HID Event system should now be running. Hit enter to quit any time.\n");
getchar();
int resetInterval=0;
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &resetInterval));
IOHIDEventSystemClose(system, NULL);
CFRelease(system);
return 0;
}
Note
The lockscreen has its own Dim Timer, so when in lockscreen the SBDimScreen event will only dim it, but will not undim. Test in SpringBoard, unlocked, for better results.
References
- Headers for IOHID: http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid
|