|  | @@ -31,7 +31,7 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
 | 
	
		
			
			| 31 | 31 |  
 | 
	
		
			
			| 32 | 32 |    unsigned long specLen = 0;
 | 
	
		
			
			| 33 | 33 |  
 | 
	
		
			
			| 34 |  | -  while((currFlag = getopt(argc, argv, "HhVGSAULIObmcas:prv:")) != -1)
 | 
	
		
			
			|  | 34 | +  while((currFlag = getopt(argc, argv, "HhVGSAULIObmckas:prv:")) != -1)
 | 
	
		
			
			| 35 | 35 |    {
 | 
	
		
			
			| 36 | 36 |      switch(currFlag)
 | 
	
		
			
			| 37 | 37 |      {
 | 
	
	
		
			
			|  | @@ -87,6 +87,9 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
 | 
	
		
			
			| 87 | 87 |          ASSERT_TARGETSET();
 | 
	
		
			
			| 88 | 88 |          light_Configuration.target = LIGHT_MIN_CAP;
 | 
	
		
			
			| 89 | 89 |          break;
 | 
	
		
			
			|  | 90 | +      case 'k':
 | 
	
		
			
			|  | 91 | +	      ASSERT_TARGETSET();
 | 
	
		
			
			|  | 92 | +	      light_Configuration.target = LIGHT_KEYBOARD;
 | 
	
		
			
			| 90 | 93 |  
 | 
	
		
			
			| 91 | 94 |        /* -- Controller selection -- */
 | 
	
		
			
			| 92 | 95 |        case 'a':
 | 
	
	
		
			
			|  | @@ -201,11 +204,12 @@ void light_printHelp(){
 | 
	
		
			
			| 201 | 204 |    printf("  -L:\t\tList controllers\n");
 | 
	
		
			
			| 202 | 205 |    printf("  -I:\t\tRestore brightness\n");
 | 
	
		
			
			| 203 | 206 |    printf("  -O:\t\tSave brightness\n\n");
 | 
	
		
			
			| 204 |  | -  
 | 
	
		
			
			|  | 207 | +
 | 
	
		
			
			| 205 | 208 |    printf("Targets (can not be used in conjunction):\n");
 | 
	
		
			
			| 206 | 209 |    printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
 | 
	
		
			
			| 207 | 210 |    printf("  -m:\t\tMaximum brightness\n  \t\tUsed with [G]\n\n");
 | 
	
		
			
			| 208 | 211 |    printf("  -c:\t\tMinimum cap\n  \t\tUsed with [GS]\n");
 | 
	
		
			
			|  | 212 | +  printf("  -k:\t\tSet keyboard brightness instead of display brightness \n \t\tUsed with [GSAU]");
 | 
	
		
			
			| 209 | 213 |    printf("  \t\tG returns null if no minimum cap is set.\n\n");
 | 
	
		
			
			| 210 | 214 |  
 | 
	
		
			
			| 211 | 215 |    printf("Controller selection (can not be used in conjunction):\n");
 | 
	
	
		
			
			|  | @@ -215,7 +219,7 @@ void light_printHelp(){
 | 
	
		
			
			| 215 | 219 |    printf("Value modes (can not be used in conjunction):\n");
 | 
	
		
			
			| 216 | 220 |    printf("  -p:\t\tInterpret <value> as, and output values in, percent. (default)\n");
 | 
	
		
			
			| 217 | 221 |    printf("  -r:\t\tInterpret <value> as, and output values in, raw mode.\n\n");
 | 
	
		
			
			| 218 |  | -  
 | 
	
		
			
			|  | 222 | +
 | 
	
		
			
			| 219 | 223 |    printf("Other:\n");
 | 
	
		
			
			| 220 | 224 |    printf("  -v:\t\tSets the verbosity level, (needs argument).\n  \t\t0: Only outputs read values.\n  \t\t1: Read values, Errors.\n  \t\t2: Read values, Errors, Warnings.\n  \t\t3: Read values, Errors, Warnings, Notices.\n\n");
 | 
	
		
			
			| 221 | 225 |  }
 | 
	
	
		
			
			|  | @@ -275,7 +279,7 @@ LIGHT_BOOL light_initialize(int argc, char** argv)
 | 
	
		
			
			| 275 | 279 |      LIGHT_ERR("selected controller is not valid, make sure this application is run as root.");
 | 
	
		
			
			| 276 | 280 |      return FALSE;
 | 
	
		
			
			| 277 | 281 |    }
 | 
	
		
			
			| 278 |  | -  
 | 
	
		
			
			|  | 282 | +
 | 
	
		
			
			| 279 | 283 |  
 | 
	
		
			
			| 280 | 284 |    return TRUE;
 | 
	
		
			
			| 281 | 285 |  }
 | 
	
	
		
			
			|  | @@ -285,7 +289,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 285 | 289 |    unsigned long rawCurr; /* The current brightness, in raw mode */
 | 
	
		
			
			| 286 | 290 |    double    percentCurr; /* The current brightness, in percent  */
 | 
	
		
			
			| 287 | 291 |    unsigned long  rawMax; /* The max brightness, in percent      */
 | 
	
		
			
			| 288 |  | -  
 | 
	
		
			
			|  | 292 | +
 | 
	
		
			
			| 289 | 293 |    unsigned long  rawSetP; /* The final value to be set, in raw mode, when setting with percent */
 | 
	
		
			
			| 290 | 294 |    unsigned long  rawAddP; /* The final value to be set, in raw mode, when adding with percent */
 | 
	
		
			
			| 291 | 295 |    unsigned long  rawSubP; /* The final value to be set, in raw mode, when subtracting with percent */
 | 
	
	
		
			
			|  | @@ -351,7 +355,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 351 | 355 |  
 | 
	
		
			
			| 352 | 356 |    /* -- Secondly, calculate the rest of the values (Clamp them here as well!) */
 | 
	
		
			
			| 353 | 357 |    percentCurr = LIGHT_CLAMP( ((double)rawCurr) /  ((double)rawMax) * 100 , 0.00, 100.00 );
 | 
	
		
			
			| 354 |  | -  percentMinCap = LIGHT_CLAMP( ((double)minCap) / ((double)rawMax) * 100 , 0.00, 100.00 );  
 | 
	
		
			
			|  | 358 | +  percentMinCap = LIGHT_CLAMP( ((double)minCap) / ((double)rawMax) * 100 , 0.00, 100.00 );
 | 
	
		
			
			| 355 | 359 |  
 | 
	
		
			
			| 356 | 360 |    rawSetP     = LIGHT_CLAMP( ((unsigned long) (light_Configuration.specifiedValuePercent * ((double)rawMax) ) / 100) , minCap, rawMax );
 | 
	
		
			
			| 357 | 361 |    rawAddP     = LIGHT_CLAMP( ((unsigned long) ( (percentCurr + light_Configuration.specifiedValuePercent) * ((double)rawMax)) / 100) , minCap, rawMax );
 | 
	
	
		
			
			|  | @@ -365,7 +369,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 365 | 369 |  
 | 
	
		
			
			| 366 | 370 |    rawSetR     = LIGHT_CLAMP( light_Configuration.specifiedValueRaw , minCap, rawMax );
 | 
	
		
			
			| 367 | 371 |    rawAddR     = LIGHT_CLAMP( rawCurr + light_Configuration.specifiedValueRaw , minCap, rawMax );
 | 
	
		
			
			| 368 |  | -  
 | 
	
		
			
			|  | 372 | +
 | 
	
		
			
			| 369 | 373 |    if(light_Configuration.specifiedValueRaw > rawCurr){
 | 
	
		
			
			| 370 | 374 |      rawSubR     = LIGHT_CLAMP(0, minCap, rawMax)
 | 
	
		
			
			| 371 | 375 |    }else{
 | 
	
	
		
			
			|  | @@ -374,7 +378,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 374 | 378 |  
 | 
	
		
			
			| 375 | 379 |    minCapP     = LIGHT_CLAMP(((unsigned long) (light_Configuration.specifiedValuePercent * ((double)rawMax) ) / 100), 0, rawMax);
 | 
	
		
			
			| 376 | 380 |    minCapR     = LIGHT_CLAMP( light_Configuration.specifiedValueRaw, 0, rawMax );
 | 
	
		
			
			| 377 |  | -  
 | 
	
		
			
			|  | 381 | +
 | 
	
		
			
			| 378 | 382 |    /* Handle get operations */
 | 
	
		
			
			| 379 | 383 |    if(light_Configuration.operationMode == LIGHT_GET)
 | 
	
		
			
			| 380 | 384 |    {
 | 
	
	
		
			
			|  | @@ -390,6 +394,12 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 390 | 394 |          break;
 | 
	
		
			
			| 391 | 395 |        case LIGHT_SAVERESTORE:
 | 
	
		
			
			| 392 | 396 |          break;
 | 
	
		
			
			|  | 397 | +      case LIGHT_KEYBOARD:
 | 
	
		
			
			|  | 398 | +        (light_Configuration.valueMode == LIGHT_RAW) ? printf("%lu\n", rawCurr) : printf("%.2f\n", percentCurr);
 | 
	
		
			
			|  | 399 | +        break;
 | 
	
		
			
			|  | 400 | +      case LIGHT_KEYBOARD_MAX_BRIGHTNESS:
 | 
	
		
			
			|  | 401 | +        (light_Configuration.valueMode == LIGHT_RAW) ? printf("%lu\n", rawMax) : printf("100.00\n"); /* <- I know how stupid it is but it might just make someones life easier */
 | 
	
		
			
			|  | 402 | +        break;
 | 
	
		
			
			| 393 | 403 |      }
 | 
	
		
			
			| 394 | 404 |  
 | 
	
		
			
			| 395 | 405 |      return TRUE;
 | 
	
	
		
			
			|  | @@ -397,7 +407,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 397 | 407 |  
 | 
	
		
			
			| 398 | 408 |    /* Handle set/add/sub operations */
 | 
	
		
			
			| 399 | 409 |    if(light_Configuration.operationMode == LIGHT_SET ||
 | 
	
		
			
			| 400 |  | -     light_Configuration.operationMode == LIGHT_ADD || 
 | 
	
		
			
			|  | 410 | +     light_Configuration.operationMode == LIGHT_ADD ||
 | 
	
		
			
			| 401 | 411 |       light_Configuration.operationMode == LIGHT_SUB)
 | 
	
		
			
			| 402 | 412 |    {
 | 
	
		
			
			| 403 | 413 |  
 | 
	
	
		
			
			|  | @@ -426,7 +436,7 @@ LIGHT_BOOL light_execute()
 | 
	
		
			
			| 426 | 436 |        /* All good? Return true. */
 | 
	
		
			
			| 427 | 437 |        return TRUE;
 | 
	
		
			
			| 428 | 438 |  
 | 
	
		
			
			| 429 |  | -    }else if(light_Configuration.target == LIGHT_BRIGHTNESS){
 | 
	
		
			
			|  | 439 | +    }else if(light_Configuration.target == LIGHT_BRIGHTNESS || light_Configuration.target == LIGHT_KEYBOARD){
 | 
	
		
			
			| 430 | 440 |        /* Handle brightness writing */
 | 
	
		
			
			| 431 | 441 |  
 | 
	
		
			
			| 432 | 442 |        /* Point our writevalue according to configuration */
 | 
	
	
		
			
			|  | @@ -516,7 +526,7 @@ LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET type, char **buffe
 | 
	
		
			
			| 516 | 526 |    }
 | 
	
		
			
			| 517 | 527 |  
 | 
	
		
			
			| 518 | 528 |    memset(returner, '\0', 256);
 | 
	
		
			
			| 519 |  | -  
 | 
	
		
			
			|  | 529 | +
 | 
	
		
			
			| 520 | 530 |    switch(type)
 | 
	
		
			
			| 521 | 531 |    {
 | 
	
		
			
			| 522 | 532 |      case LIGHT_BRIGHTNESS:
 | 
	
	
		
			
			|  | @@ -531,6 +541,12 @@ LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET type, char **buffe
 | 
	
		
			
			| 531 | 541 |      case LIGHT_SAVERESTORE:
 | 
	
		
			
			| 532 | 542 |        spfVal = sprintf(returner, "/etc/light/save/%s", controller);
 | 
	
		
			
			| 533 | 543 |        break;
 | 
	
		
			
			|  | 544 | +    case LIGHT_KEYBOARD:
 | 
	
		
			
			|  | 545 | +      spfVal = sprintf(returner, "/sys/class/leds/%s/brightness", controller);
 | 
	
		
			
			|  | 546 | +      break;
 | 
	
		
			
			|  | 547 | +    case LIGHT_KEYBOARD_MAX_BRIGHTNESS:
 | 
	
		
			
			|  | 548 | +      spfVal = sprintf(returner, "/sys/class/leds/%s/max_brightness", controller);
 | 
	
		
			
			|  | 549 | +      break;
 | 
	
		
			
			| 534 | 550 |    }
 | 
	
		
			
			| 535 | 551 |  
 | 
	
		
			
			| 536 | 552 |    if(spfVal < 0)
 | 
	
	
		
			
			|  | @@ -551,12 +567,12 @@ LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v)
 | 
	
		
			
			| 551 | 567 |    char *brightnessPath = NULL;
 | 
	
		
			
			| 552 | 568 |    LIGHT_BOOL readVal = FALSE;
 | 
	
		
			
			| 553 | 569 |  
 | 
	
		
			
			| 554 |  | -  if(!light_genPath(controller, LIGHT_BRIGHTNESS, &brightnessPath))
 | 
	
		
			
			|  | 570 | +  if(!light_genPath(controller, light_Configuration.target, &brightnessPath))
 | 
	
		
			
			| 555 | 571 |    {
 | 
	
		
			
			| 556 | 572 |      LIGHT_ERR("could not generate path to brightness file");
 | 
	
		
			
			| 557 | 573 |      return FALSE;
 | 
	
		
			
			| 558 | 574 |    }
 | 
	
		
			
			| 559 |  | -
 | 
	
		
			
			|  | 575 | +  LIGHT_NOTE(brightnessPath)
 | 
	
		
			
			| 560 | 576 |    readVal = light_readULong( brightnessPath , v);
 | 
	
		
			
			| 561 | 577 |    free(brightnessPath);
 | 
	
		
			
			| 562 | 578 |  
 | 
	
	
		
			
			|  | @@ -574,7 +590,17 @@ LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v)
 | 
	
		
			
			| 574 | 590 |    char *maxPath;
 | 
	
		
			
			| 575 | 591 |    LIGHT_BOOL readVal = FALSE;
 | 
	
		
			
			| 576 | 592 |  
 | 
	
		
			
			| 577 |  | -  if(!light_genPath(controller, LIGHT_MAX_BRIGHTNESS, &maxPath))
 | 
	
		
			
			|  | 593 | +  LIGHT_TARGET target;
 | 
	
		
			
			|  | 594 | +  if(light_Configuration.target == LIGHT_KEYBOARD)
 | 
	
		
			
			|  | 595 | +  {
 | 
	
		
			
			|  | 596 | +    target = LIGHT_KEYBOARD_MAX_BRIGHTNESS;
 | 
	
		
			
			|  | 597 | +  }
 | 
	
		
			
			|  | 598 | +  else
 | 
	
		
			
			|  | 599 | +  {
 | 
	
		
			
			|  | 600 | +    target = LIGHT_MAX_BRIGHTNESS;
 | 
	
		
			
			|  | 601 | +  }
 | 
	
		
			
			|  | 602 | +
 | 
	
		
			
			|  | 603 | +  if(!light_genPath(controller, target, &maxPath))
 | 
	
		
			
			| 578 | 604 |    {
 | 
	
		
			
			| 579 | 605 |      LIGHT_ERR("could not generate path to maximum brightness file");
 | 
	
		
			
			| 580 | 606 |      return FALSE;
 | 
	
	
		
			
			|  | @@ -603,7 +629,7 @@ LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v)
 | 
	
		
			
			| 603 | 629 |    char *brightnessPath = NULL;
 | 
	
		
			
			| 604 | 630 |    LIGHT_BOOL writeVal = FALSE;
 | 
	
		
			
			| 605 | 631 |  
 | 
	
		
			
			| 606 |  | -  if(!light_genPath(controller, LIGHT_BRIGHTNESS, &brightnessPath))
 | 
	
		
			
			|  | 632 | +  if(!light_genPath(controller, light_Configuration.target, &brightnessPath))
 | 
	
		
			
			| 607 | 633 |    {
 | 
	
		
			
			| 608 | 634 |      LIGHT_ERR("could not generate path to brightness file");
 | 
	
		
			
			| 609 | 635 |      return FALSE;
 | 
	
	
		
			
			|  | @@ -627,6 +653,7 @@ LIGHT_BOOL light_controllerAccessible(char const *controller)
 | 
	
		
			
			| 627 | 653 |  
 | 
	
		
			
			| 628 | 654 |    if(!light_getBrightness(controller, &dummy))
 | 
	
		
			
			| 629 | 655 |    {
 | 
	
		
			
			|  | 656 | +    LIGHT_NOTE(controller)
 | 
	
		
			
			| 630 | 657 |      LIGHT_WARN("could not read controllers brightness file, so controller is not accessible")
 | 
	
		
			
			| 631 | 658 |      return FALSE;
 | 
	
		
			
			| 632 | 659 |    }
 | 
	
	
		
			
			|  | @@ -637,7 +664,7 @@ LIGHT_BOOL light_controllerAccessible(char const *controller)
 | 
	
		
			
			| 637 | 664 |      return FALSE;
 | 
	
		
			
			| 638 | 665 |    }
 | 
	
		
			
			| 639 | 666 |  
 | 
	
		
			
			| 640 |  | -  if(!light_genPath(controller, LIGHT_BRIGHTNESS, &brightnessPath))
 | 
	
		
			
			|  | 667 | +  if(!light_genPath(controller, light_Configuration.target, &brightnessPath))
 | 
	
		
			
			| 641 | 668 |    {
 | 
	
		
			
			| 642 | 669 |      LIGHT_ERR("could not generate path to brightness file");
 | 
	
		
			
			| 643 | 670 |      return FALSE;
 | 
	
	
		
			
			|  | @@ -661,9 +688,13 @@ LIGHT_BOOL light_iterateControllers()
 | 
	
		
			
			| 661 | 688 |    if(light_iteratorDir == NULL)
 | 
	
		
			
			| 662 | 689 |    {
 | 
	
		
			
			| 663 | 690 |      light_iteratorDir = opendir("/sys/class/backlight");
 | 
	
		
			
			|  | 691 | +    if(light_Configuration.target == LIGHT_KEYBOARD)
 | 
	
		
			
			|  | 692 | +    {
 | 
	
		
			
			|  | 693 | +      light_iteratorDir = opendir("/sys/class/leds");
 | 
	
		
			
			|  | 694 | +    }
 | 
	
		
			
			| 664 | 695 |      if(light_iteratorDir == NULL)
 | 
	
		
			
			| 665 | 696 |      {
 | 
	
		
			
			| 666 |  | -      LIGHT_ERR("could not open /sys/class/backlight directory");
 | 
	
		
			
			|  | 697 | +      LIGHT_ERR("could not open backlight or leds directory");
 | 
	
		
			
			| 667 | 698 |        return FALSE;
 | 
	
		
			
			| 668 | 699 |      }
 | 
	
		
			
			| 669 | 700 |    }
 | 
	
	
		
			
			|  | @@ -706,7 +737,7 @@ LIGHT_BOOL light_getBestController(char *controller)
 | 
	
		
			
			| 706 | 737 |  
 | 
	
		
			
			| 707 | 738 |      if(light_getMaxBrightness(light_currentController, &currVal))
 | 
	
		
			
			| 708 | 739 |      {
 | 
	
		
			
			| 709 |  | -      
 | 
	
		
			
			|  | 740 | +
 | 
	
		
			
			| 710 | 741 |        if(light_controllerAccessible(light_currentController))
 | 
	
		
			
			| 711 | 742 |        {
 | 
	
		
			
			| 712 | 743 |          if(currVal > bestValYet)
 | 
	
	
		
			
			|  | @@ -747,7 +778,7 @@ LIGHT_BOOL light_getBestController(char *controller)
 | 
	
		
			
			| 747 | 778 |  LIGHT_BOOL light_getMinCap(char const * controller, LIGHT_BOOL * hasMinCap, unsigned long * minCap)
 | 
	
		
			
			| 748 | 779 |  {
 | 
	
		
			
			| 749 | 780 |   char * mincapPath = NULL;
 | 
	
		
			
			| 750 |  | - 
 | 
	
		
			
			|  | 781 | +
 | 
	
		
			
			| 751 | 782 |   if(!light_genPath(controller, LIGHT_MIN_CAP, &mincapPath))
 | 
	
		
			
			| 752 | 783 |   {
 | 
	
		
			
			| 753 | 784 |      LIGHT_ERR("could not generate path to minimum cap file");
 |