3 kGetSensorReadingID
= 0, // getSensorReading(int *, int *)
4 kGetLEDBrightnessID
= 1, // getLEDBrightness(int, int *)
5 kSetLEDBrightnessID
= 2, // setLEDBrightness(int, int, int *)
6 kSetLEDFadeID
= 3, // setLEDFade(int, int, int, int *)
7 // other firmware-related functions
8 // verifyFirmwareID = 4,
9 // verifyFirmware(int *)
10 // getFirmwareVersionID = 5,
11 // getFirmwareVersion(int *)
12 // other flashing-related functions
17 #include <mach/mach.h>
18 //#include <Carbon/Carbon.h>
19 #include <IOKit/IOKitLib.h>
20 #include <CoreFoundation/CoreFoundation.h>
22 static io_connect_t dataPort
= 0; // shared?
24 io_connect_t
getDataPort(void)
27 io_service_t serviceObject
;
29 if (dataPort
) return dataPort
;
31 // Look up a registered IOService object whose class is AppleLMUController
32 serviceObject
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching("AppleLMUController"));
36 printf("getLightSensors() error: failed to find ambient light sensor\n");
40 // Create a connection to the IOService object
41 kr
= IOServiceOpen(serviceObject
, mach_task_self(), 0, &dataPort
);
42 IOObjectRelease(serviceObject
);
44 if (kr
!= KERN_SUCCESS
)
46 printf("getLightSensors() error: failed to open IoService object\n");
53 void getLightSensors(float *left
, float *right
)
55 IOItemCount scalarInputCount
= 0;
56 IOItemCount scalarOutputCount
= 2;
60 kr
= IOConnectMethodScalarIScalarO(getDataPort(),
67 if (kr
!= KERN_SUCCESS
)
69 //printf("error getting light sensor values\n");
81 #include <IOKit/graphics/IOGraphicsLib.h>
82 #include <ApplicationServices/ApplicationServices.h>
84 float getDisplayBrightness(void)
88 CGDirectDisplayID targetDisplay
;
90 CFStringRef key
= CFSTR(kIODisplayBrightnessKey
);
91 float brightness
= HUGE_VALF
;
93 targetDisplay
= CGMainDisplayID();
94 service
= CGDisplayIOServicePort(targetDisplay
);
96 dErr
= IODisplayGetFloatParameter(service
, kNilOptions
, key
, &brightness
);
101 void setDisplayBrightness(float brightness
)
104 io_service_t service
;
105 CGDirectDisplayID targetDisplay
;
106 CFStringRef key
= CFSTR(kIODisplayBrightnessKey
);
108 targetDisplay
= CGMainDisplayID();
109 service
= CGDisplayIOServicePort(targetDisplay
);
111 dErr
= IODisplaySetFloatParameter(service
, kNilOptions
, key
, brightness
);
115 // Keyboard Brightness
117 float getKeyboardBrightness(void)
121 IOItemCount scalarInputCount
= 1;
122 IOItemCount scalarOutputCount
= 1;
123 SInt32 in_unknown
= 0, out_brightness
;
125 kr
= IOConnectMethodScalarIScalarO(getDataPort(), kGetLEDBrightnessID
,
131 if (kr
!= KERN_SUCCESS
)
133 printf("getKeyboardBrightness() error\n");
142 void setKeyboardBrightness(float in
)
144 static io_connect_t dp
= 0; // shared?
146 IOItemCount scalarInputCount
= 2;
147 IOItemCount scalarOutputCount
= 1;
148 SInt32 in_unknown
= 0, in_brightness
, out_brightness
;
150 in_brightness
= in
* 0xfff;
152 //kr = IOConnectMethodScalarIScalarO(getDataPort(), kSetLEDBrightnessID,
153 kr
= IOConnectMethodScalarIScalarO(dp
, kSetLEDBrightnessID
,
160 if (kr
!= KERN_SUCCESS
)
162 printf("setKeyboardBrightness() error\n");