You can access the photosensitive sensor using IOService, from the IOKit library. The name of the light sensor is "AppleLMUController". Here is a good example: a light sensor . Simply put, get the service as follows: 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 that will contain KERN_SUCCESS
if the method does not work. Also, do not forget to free the service object using IOObjectRelease(service);
EDIT: On the other hand, IOConnectMethodScalarIScalarO()
seems deprecated. Use instead:
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. Keep in mind that not all MacBooks work this way: in my mid-15th year of 2010, both values ββare the same, since the light sensor is in the iSight camera.
source share