Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
AppleISL29003: Difference between revisions - iPhone Development Wiki

AppleISL29003: Difference between revisions

From iPhone Development Wiki
mNo edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
=== Ambient Light Sensor ===
AppleCT700 (formerly AppleISL29003 ) is the IOHIDService that controls the device's Ambient Light Sensor (ALS). It is generally used to detect the incoming light level in Lux units, so the device can automatically adjust screen brightness, if the option is enabled.  
AppleCT700 (formerly AppleISL29003 ) is the IOHIDService that controls the device's Ambient Light Sensor ( ALS ). It is generally used to detect the incoming light level in Lux units, so the device can automatically adjust screen brightness, if the option is enabled.  
   
   
You can intercept the service to start getting lux level reports and assign a callback action.
You can intercept the service to start getting lux level reports and assign a callback action.
Line 7: Line 6:


=== General characteristics ===
=== General characteristics ===
{| class="wikitable"
{| class="wikitable"
! CFBundleIdentifier
! CFBundleIdentifier
Line 23: Line 23:
#include <stdio.h>
#include <stdio.h>


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) == kIOHIDEventTypeAmbientLightSensor) { // Ambient Light Sensor Event
  if (IOHIDEventGetType(event)==12){ // Ambient Light Sensor Event
int luxValue = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorLevel); // lux Event Field
int channel0 = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorRawChannel0); // ch0 Event Field
int luxValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)786432); // lux Event Field
int channel1 = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorRawChannel1); // ch1 Event Field
int channel0=IOHIDEventGetIntegerValue(event, (IOHIDEventField)786433); // ch0 Event Field
 
int channel1=IOHIDEventGetIntegerValue(event, (IOHIDEventField)786434); // ch1 Event Field
NSLog(@"IOHID: ALS Sensor: Lux : %d  ch0 : %d  ch1 : %d", luxValue, channel0, channel1);
// lux==0 : no light, lux==1000+ almost direct sunlight
    NSLog(@"IOHID: ALS Sensor: Lux : %d  ch0 : %d  ch1 : %d",luxValue,channel0,channel1);
}
    // lux==0 : no light, lux==1000+ almost direct sunlight
  }  
}
}


    
    


int main () {
int main(int argc, char **argv) {
  // Create and open an event system.
// Create and open an event system.
  IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);


  // Set the PrimaryUsagePage and PrimaryUsage for the Ambient Light Sensor Service  
// Set the PrimaryUsagePage and PrimaryUsage for the Ambient Light Sensor Service  
  int page = 0xff00;
int page = 0xff00;
  int usage = 4;
int usage = 4;
  // Create a dictionary to match the service with
// Create a dictionary to match the service with
  CFNumberRef nums[2];
CFStringRef keys[2];
  CFStringRef keys[2];
CFNumberRef nums[2];
  keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
  keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
  nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
  nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
    
    
    
    
  CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    
    
  // Get all services matching the above criteria
// Get all services matching the above criteria
  CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(system, dict, 0, 0, 0,0);
CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(system, dict, 0, 0, 0,0);
    
    
    
    
  // Get the service
// Get the service
  IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
  int interval = 1 ;
int interval = 1 ;


  // set the ReportInterval of ALS service to something faster than the default (5428500)
// set the ReportInterval of ALS service to something faster than the default (5428500)
  IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
    
    
  IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
  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 defaultInterval=5428500;
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &defaultInterval));
   
   
  IOHIDEventSystemClose(system, NULL);
IOHIDEventSystemClose(system, NULL);
  CFRelease(system);
CFRelease(system);
  return 0;
return 0;
}</source>
}</source>


== External links ==


== References ==
* [http://en.wikipedia.org/wiki/Lux Lux definition].
<references/>
* [http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid Headers for IOHID].
* Lux definition : http://en.wikipedia.org/wiki/Lux
 
* Headers for IOHID: http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid


{{occlass|library=IOKit.framework|navbox=1}}
{{occlass|library=IOKit.framework|navbox=1}}

Latest revision as of 04:26, 25 October 2014

AppleCT700 (formerly AppleISL29003 ) is the IOHIDService that controls the device's Ambient Light Sensor (ALS). It is generally used to detect the incoming light level in Lux units, so the device can automatically adjust screen brightness, if the option is enabled.

You can intercept the service to start getting lux level reports and assign a callback action.

To make the reporting interval of the ALS sensor more effective, you need to change the service's default ReportInterval from 5428500 to a lower number. For more information about IOHID, see IOHIDFamily.

General characteristics

CFBundleIdentifier com.apple.driver.AppleIntegratedProxALSSensor
HIDServiceSupport Yes
Default ReportInterval 5428500

Example

#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>

void handle_event(void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
	if (IOHIDEventGetType(event) == kIOHIDEventTypeAmbientLightSensor) { // Ambient Light Sensor Event
		int luxValue = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorLevel); // lux Event Field
		int channel0 = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorRawChannel0); // ch0 Event Field
		int channel1 = IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldAmbientLightSensorRawChannel1); // ch1 Event Field

		NSLog(@"IOHID: ALS Sensor: Lux : %d  ch0 : %d   ch1 : %d", luxValue, channel0, channel1);
		// lux==0 : no light, lux==1000+ almost direct sunlight				
	}
}

  

int main(int argc, char **argv) {
	// Create and open an event system.
	IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);

	// Set the PrimaryUsagePage and PrimaryUsage for the Ambient Light Sensor Service 
	int page = 0xff00;
	int usage = 4;
	
	// Create a dictionary to match the service with
	CFStringRef keys[2];
	CFNumberRef nums[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 all services matching 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 the ReportInterval of ALS service to something faster than the default (5428500)
	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 defaultInterval=5428500;
	IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &defaultInterval));
 
	IOHIDEventSystemClose(system, NULL);
	CFRelease(system);
	return 0;
}

External links