I realize there is not any public documentation about the use of the isight light sensor, however programs such as ShadowBook (shown here) are able to access the the brightness data and I was simply wondering if anyone has been able to achieve a similar result and know how to access this sensor? Thanks!
1 Answers
You can access the light sensor with IOService, from the IOKit library. The name for the light sensor is "AppleLMUController". Here's a good example: light sensor.
Simply put, get the service like this: io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController"));
Then, connect to the service using:
io_connect_t port = 0;
IOServiceOpen(service, mach_task_self(), 0, &port);
Get the light levels using: IOConnectMethodScalarIScalarO(port, 0, 0, 2, &left, &right);
Where left
and right
are integers that now hold the light levels of the sensors.
Note that many IOService methods return a kern_return_t
variable, which will hold KERN_SUCCESS
, unless the method failed. Also be sure to release the service object using IOObjectRelease(service);
EDIT: On second thought, IOConnectMethodScalarIScalarO()
appears to be deprecated.
Instead, use:
uint32_t outputs = 2;
uint64_t values[outputs];
IOConnectCallMethod(port, 0, nil, 0, nil, 0, values , &outputs, nil, 0);
The left and right values will be stored in values[0]
and values[1]
respectively. Be aware that not all MacBooks work this way: on my mid 2010 15'' pro, both values are the same, as the light sensor is in the iSight camera.

- 21,988
- 13
- 81
- 109

- 2,569
- 1
- 15
- 14
-
how would I return a log for those values? `NSLog(@"right %f", values);`? how would I format left/right? – Grant Wilkinson Apr 10 '12 at 04:13
-
one more quick question it seems to be called once when my application starts but how can I continually call it? Tried to use a timer to recall the method but it doesnt update the value – Grant Wilkinson Apr 10 '12 at 04:24
-
1To log, `NSLog(@"Left:%i, Right:%i", (int)values[0], (int)values[1]);` would be sufficient. I think using `values` as an array will fix your problem with the numbers not updating. If not, I can send you a quick example I made. – wquist Apr 10 '12 at 20:03
-
The log is working fine now thank you, but if it woulndt be too much trouble as you already have it made it would be of great help if you could zip it up to me. grant@wilkinson-family.com thank you very much! – Grant Wilkinson Apr 11 '12 at 00:05
-
Thanks you ver much for posting the code!. is this code works for iOS also? – AshokPolu Oct 27 '16 at 10:02