You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
// squeeky door laptop hinge haha
|
|
//
|
|
// lmutracker.mm
|
|
//
|
|
// clang -o lmutracker lmutracker.mm -framework IOKit -framework CoreFoundation
|
|
////
|
|
// mplayer -ss 00:00:01.90 -endpos 00:00:02.90 door.mp3
|
|
//
|
|
// via:https://stackoverflow.com/questions/17625495/how-do-you-programmatically-access-the-ambient-light-sensor-on-mac-os-x-10-5
|
|
|
|
|
|
#include <mach/mach.h>
|
|
#import <IOKit/IOKitLib.h>
|
|
#import <CoreFoundation/CoreFoundation.h>
|
|
|
|
static double updateInterval = 0; //0 means only run once
|
|
static io_connect_t dataPort = 0;
|
|
|
|
void updateTimerCallBack(CFRunLoopTimerRef timer, void *info) {
|
|
kern_return_t kr;
|
|
uint32_t outputs = 2;
|
|
uint64_t values[outputs];
|
|
|
|
kr = IOConnectCallMethod(dataPort, 0, nil, 0, nil, 0, values, &outputs, nil, 0);
|
|
if (kr == KERN_SUCCESS) {
|
|
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%8lld", values[0]);
|
|
//return;
|
|
exit(0); // exit program after getting value!
|
|
}
|
|
|
|
if (kr == kIOReturnBusy) {
|
|
return;
|
|
}
|
|
|
|
mach_error("I/O Kit error:", kr);
|
|
exit(kr);
|
|
}
|
|
|
|
int main(void) {
|
|
kern_return_t kr;
|
|
io_service_t serviceObject;
|
|
CFRunLoopTimerRef updateTimer;
|
|
|
|
serviceObject = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController"));
|
|
if (!serviceObject) {
|
|
fprintf(stderr, "failed to find ambient light sensors\n");
|
|
exit(1);
|
|
}
|
|
|
|
kr = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);
|
|
IOObjectRelease(serviceObject);
|
|
if (kr != KERN_SUCCESS) {
|
|
mach_error("IOServiceOpen:", kr);
|
|
exit(kr);
|
|
}
|
|
|
|
setbuf(stdout, NULL);
|
|
printf("%8ld", 0L);
|
|
|
|
updateTimer = CFRunLoopTimerCreate(kCFAllocatorDefault,
|
|
CFAbsoluteTimeGetCurrent() + updateInterval, updateInterval,
|
|
0, 0, updateTimerCallBack, NULL);
|
|
CFRunLoopAddTimer(CFRunLoopGetCurrent(), updateTimer, kCFRunLoopDefaultMode);
|
|
CFRunLoopRun();
|
|
|
|
exit(0);
|
|
}
|