Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. /*
  2. * Apple Macbook Pro LCD backlight control
  3. *
  4. * Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
  5. * Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <sys/io.h>
  25. #include <stdlib.h>
  26.  
  27. void init()
  28. {
  29. if (ioperm(0xB2, 0xB3, 1) < 0)
  30. {
  31. perror("ioperm failed (you should be root).");
  32. exit(2);
  33. }
  34. }
  35.  
  36. int get_current_value()
  37. {
  38. outb(0x03, 0xB3);
  39. outb(0xBF, 0xB2);
  40. char t = inb(0xB3) >> 4;
  41. return t;
  42. }
  43.  
  44. int calculate_new_value(const char *arg)
  45. {
  46. int val, new = atoi(arg);
  47.  
  48. if (arg[0] == '+' || arg[0] == '-')
  49. val = new + get_current_value();
  50. else
  51. val = new;
  52.  
  53. if (val > 15)
  54. val = 15;
  55. else if (val < 1)
  56. val = 1;
  57.  
  58. return val;
  59. }
  60.  
  61. int main(int argc, char** argv)
  62. {
  63. if (argc > 2)
  64. {
  65. printf("Usage:\n");
  66. printf("%s : read current value\n", argv[0]);
  67. printf("%s value : write value [0-15]\n", argv[0]);
  68. exit(1);
  69. }
  70.  
  71. init();
  72.  
  73. if (argc < 2)
  74. {
  75. printf("Current value : %d\n", get_current_value());
  76. exit(0);
  77. }
  78.  
  79. if (argc == 2)
  80. {
  81. int value = calculate_new_value(argv[1]);
  82. outb(0x04 | (value << 4), 0xB3);
  83. outb(0xBF, 0xB2);
  84. printf("new value: %d\n", value);
  85. }
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement