Added the hue and kbbutil utilities
This commit is contained in:
commit
ba13e10b9d
|
@ -0,0 +1,52 @@
|
|||
# Makefile configuration
|
||||
CC = gcc
|
||||
INCLUDE = -framework IOKit
|
||||
CFLAGS = -Wall -Winline -pipe -Wno-unused-label
|
||||
|
||||
LDFLAGS = -L/usr/local/lib $(INCLUDE)
|
||||
|
||||
DEBUG = -g -O0 -DDEBUG
|
||||
RELEASE = -O2
|
||||
|
||||
# Optional debugging
|
||||
ifeq ($(dbg),1)
|
||||
CFLAGS += $(DEBUG)
|
||||
else
|
||||
CFLAGS += $(RELEASE)
|
||||
endif
|
||||
|
||||
# General makefile stuff
|
||||
SRC = kbbutil.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
BINS = $(SRC:.c=)
|
||||
|
||||
all: kbbutil
|
||||
|
||||
kbbutil: kbbutil.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ kbbutil.o $(LDFLAGS) $(LDLIBS)
|
||||
@rm -f $(OBJ)
|
||||
|
||||
.c.o:
|
||||
@echo [CC] $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
@echo "[Clean]"
|
||||
@rm -f $(OBJ) *~ core tags $(BINS)
|
||||
|
||||
tags: $(SRC)
|
||||
@echo [ctags]
|
||||
@ctags $(SRC)
|
||||
|
||||
# root ownership and suid bit is set to enable non-root execution
|
||||
#install: kbbutil
|
||||
# @sudo rm -f $(PREFIX)/bin/kbbutil
|
||||
# @cp -a kbbutil $(PREFIX)/bin/kbbutil
|
||||
# @sudo chown root:root $(PREFIX)/bin/kbbutil
|
||||
# @sudo chmod 4755 $(PREFIX)/bin/kbbutil
|
||||
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
|
@ -0,0 +1,5 @@
|
|||
kbbutil - Simple utility for reading the current brightness level of a MacBook keyboard's backlight, and for setting the brightness level.
|
||||
Theoretically requires OSX 10.5 or newer and any MacBook model past the early non-PowerPC macbooks, however this utility has not been tested on anything other than a MacBook Air 6,1 running OS10.10. Your mileage may vary.
|
||||
|
||||
Using this utility is unlikely to cause any system instability, software or hardware damage, temporary or permanent, however if you use this utility then you do so at your own risk.
|
||||
In the event of data loss, any form of damage or any other undesirable conditions which may be caused in some form by the use of this utility, I shall not be held liable in any form.
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* kbbutil 0.1
|
||||
* A very basic application for controlling the keyboard backlight on OSX-running MacBooks.
|
||||
* Copyright 2014, Matthew Connelly.
|
||||
*/
|
||||
|
||||
// includes {{{
|
||||
#include "kbbutil.h"
|
||||
//}}}
|
||||
|
||||
// variable defs {{{
|
||||
io_connect_t io;
|
||||
uint64_t wtf=0;
|
||||
//}}}
|
||||
|
||||
int getKBBrightness() {//{{{
|
||||
kern_return_t kr;
|
||||
uint32_t c_out=1,c_in=1;
|
||||
uint64_t cbr;
|
||||
kr = IOConnectCallScalarMethod(io,kGetLEDBrightnessID,&wtf,c_in,&cbr,&c_out);
|
||||
if(kr==kIOReturnBusy) {fprintf(stderr,"AppleLMUController IO is busy?\n");return -1;}
|
||||
if(kr!=KERN_SUCCESS) {mach_error("IOKit error: ",kr);exit(kr);}
|
||||
return (int)cbr;
|
||||
}//}}}
|
||||
bool setKBBrightness(int nbr) {//{{{
|
||||
kern_return_t kr;
|
||||
uint32_t c_out=1,c_in=2;
|
||||
uint64_t cbr,sbr[2]={wtf,nbr};
|
||||
kr = IOConnectCallScalarMethod(io,kSetLEDBrightnessID,sbr,c_in,&cbr,&c_out);
|
||||
if(kr==kIOReturnBusy) {fprintf(stderr,"AppleLMUController IO is busy?\n");return false;}
|
||||
if(kr!=KERN_SUCCESS) {mach_error("IOKit error: ",kr);exit(kr);}
|
||||
return true;
|
||||
}//}}}
|
||||
|
||||
int main(int argc, char *argv []) {//{{{
|
||||
kern_return_t kr;
|
||||
io_service_t is;
|
||||
is = IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("AppleLMUController"));
|
||||
if(!is) {fprintf(stderr,"Failed to into AppleLMUController\n");exit(1);}
|
||||
kr = IOServiceOpen(is,mach_task_self(),0,&io);
|
||||
IOObjectRelease(is);
|
||||
if(kr!=KERN_SUCCESS) {mach_error("IOKit error: ",kr);exit(kr);}
|
||||
if(argc==1||(argc==2&&(strcmp(argv[1],"-n")==0||strcmp(argv[1],"--numeric-only")==0))) printf(argc==2? "%i" : "Current keyboard brightness: %i\n",getKBBrightness());
|
||||
else if(argc==2&&((atoi(argv[1])==0&&strcmp(argv[1],"0")==0)||(atoi(argv[1])>0&&atoi(argv[1])<=4091))) setKBBrightness(atoi(argv[1]));
|
||||
else {fprintf(stderr,"Invalid argument. kbbutil must be run either with no arguments, with -n or --numeric-only, or with one argument which is a number between 0 and 4091.\n");exit(1);}
|
||||
return 0;
|
||||
}//}}}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* kbbutil.h - header file for kbbutil.c
|
||||
*/
|
||||
|
||||
// includes {{{
|
||||
#include <mach/mach.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
//}}}
|
||||
|
||||
// prototypes {{{
|
||||
int getKBBrightness(void);
|
||||
bool setKBBrightness(int);
|
||||
enum {
|
||||
kGetSensorReadingID = 0,
|
||||
kGetLEDBrightnessID = 1,
|
||||
kSetLEDBrightnessID = 2,
|
||||
kSetLEDFadeID = 3,
|
||||
};
|
||||
//}}}
|
Loading…
Reference in New Issue