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.
 
 
 

56 lines
1.0 KiB

  1. #include "backlight.h"
  2. #include "stdint.h"
  3. #include "stdio.h"
  4. #include "stdlib.h"
  5. #ifndef BACKLIGHT_DEVICE
  6. #define BACKLIGHT_DEVICE "amdgpu_bl0"
  7. #endif
  8. const char* device_brightness = "/sys/class/backlight/" BACKLIGHT_DEVICE "/brightness";
  9. const char* device_max_brightness = "/sys/class/backlight/" BACKLIGHT_DEVICE "/max_brightness";
  10. /**
  11. * 获取最大亮度值
  12. * */
  13. int backlight_get_max()
  14. {
  15. FILE* fp = fopen(device_max_brightness, "r");
  16. if (fp == NULL)
  17. return -1;
  18. char str[10];
  19. fgets(str, 10, fp);
  20. fclose(fp);
  21. return atoi(str);
  22. }
  23. /**
  24. * 获取当前亮度值
  25. * */
  26. int backlight_get_current()
  27. {
  28. FILE* fp = fopen(device_brightness, "r");
  29. if (fp == NULL)
  30. return -1;
  31. char str[10];
  32. fgets(str, 10, fp);
  33. fclose(fp);
  34. return atoi(str);
  35. }
  36. /**
  37. * 设置当前亮度值
  38. * */
  39. void backlight_set_current(int val)
  40. {
  41. FILE* fp = fopen(device_brightness, "w");
  42. if (fp == NULL)
  43. return;
  44. char str[10];
  45. int len = snprintf(str, 10, "%d", val);
  46. fputs(str, fp);
  47. fclose(fp);
  48. }