123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef LIGHT_H_
  2. #define LIGHT_H_
  3. #include "config.h"
  4. #include "helpers.h"
  5. #include <stdbool.h>
  6. #include <sys/types.h>
  7. #include <dirent.h>
  8. #include <linux/limits.h>
  9. #define LIGHT_YEAR "2012-2018"
  10. #define LIGHT_AUTHOR "Fredrik Haikarainen"
  11. #define ASSERT_SET(t, v) \
  12. if (v) { \
  13. fprintf(stderr, t " cannot be used more than once.\n"); \
  14. return false; \
  15. } \
  16. v = true;
  17. #define ASSERT_CMDSET() ASSERT_SET("Commands", cmd_set)
  18. #define ASSERT_TARGETSET() ASSERT_SET("Targets", target_set)
  19. #define ASSERT_FIELDSET() ASSERT_SET("Fields", field_set)
  20. #define ASSERT_CTRLSET() ASSERT_SET("Controllers", ctrl_set)
  21. #define ASSERT_VALSET() ASSERT_SET("Values", val_set)
  22. typedef enum {
  23. LIGHT_BRIGHTNESS = 0,
  24. LIGHT_MAX_BRIGHTNESS,
  25. LIGHT_MIN_CAP,
  26. LIGHT_SAVERESTORE
  27. } light_field_t;
  28. typedef enum {
  29. LIGHT_BACKLIGHT = 0,
  30. LIGHT_KEYBOARD
  31. } light_target_t;
  32. typedef enum {
  33. LIGHT_AUTO = 0,
  34. LIGHT_SPECIFY
  35. } light_ctrl_mode_t;
  36. typedef enum {
  37. LIGHT_GET = 0,
  38. LIGHT_SET,
  39. LIGHT_ADD,
  40. LIGHT_SUB,
  41. LIGHT_PRINT_HELP, /* Prints help and exits */
  42. LIGHT_PRINT_VERSION, /* Prints version info and exits */
  43. LIGHT_LIST_CTRL,
  44. LIGHT_RESTORE,
  45. LIGHT_SAVE
  46. } light_cmd_t;
  47. typedef enum {
  48. LIGHT_RAW = 0,
  49. LIGHT_PERCENT
  50. } light_val_mode_t;
  51. typedef struct {
  52. /* Cache file prefix */
  53. char prefix[NAME_MAX + 1];
  54. /* Which controller to use */
  55. light_ctrl_mode_t ctrl;
  56. char ctrl_name[NAME_MAX + 1];
  57. /* What to do with the controller */
  58. light_cmd_t cmd;
  59. light_val_mode_t val_mode;
  60. unsigned long val_raw; /* The specified value in raw mode */
  61. double val_percent; /* The specified value in percent */
  62. light_target_t target;
  63. light_field_t field;
  64. /* Cache data */
  65. bool has_cached_brightness_max;
  66. unsigned long cached_brightness_max;
  67. } light_ctx_t;
  68. /* -- Global variable holding the settings for the current run -- */
  69. light_ctx_t ctx;
  70. bool light_initialize (int argc, char **argv);
  71. bool light_execute (void);
  72. void light_free (void);
  73. bool light_ctrl_list (void);
  74. bool light_ctrl_probe (char *controller, size_t len);
  75. bool light_ctrl_exist (char const *controller);
  76. bool light_ctrl_get_brightness (char const *controller, unsigned long *v);
  77. bool light_ctrl_set_brightness (char const *controller, unsigned long v);
  78. bool light_ctrl_get_brightness_max (char const *controller, unsigned long *v);
  79. bool light_ctrl_get_cap_min (char const *controller, bool *hasMinCap, unsigned long *minCap);
  80. bool light_ctrl_set_cap_min (char const *controller, unsigned long val);
  81. bool light_ctrl_save_brightness (char const *controller, unsigned long val);
  82. bool light_ctrl_restore_brightness (char const *controller);
  83. #endif /* LIGHT_H_ */