light.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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" arguments cannot be used in conjunction.\n"); \
  14. return false; \
  15. } \
  16. v = true;
  17. #define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
  18. #define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
  19. #define ASSERT_FIELDSET() ASSERT_SET("Field", fieldSet)
  20. #define ASSERT_CTRLSET() ASSERT_SET("Controller", ctrlSet)
  21. #define ASSERT_VALSET() ASSERT_SET("Value", valSet)
  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 light_runtimeArguments_s {
  52. /* Which controller to use */
  53. light_ctrl_mode_t controllerMode;
  54. char specifiedController[NAME_MAX + 1];
  55. /* What to do with the controller */
  56. light_cmd_t operationMode;
  57. light_val_mode_t valueMode;
  58. unsigned long specifiedValueRaw; /* The specified value in raw mode */
  59. double specifiedValuePercent; /* The specified value in percent */
  60. light_target_t target;
  61. light_field_t field;
  62. /* Cache data */
  63. bool hasCachedMaxBrightness;
  64. unsigned long cachedMaxBrightness;
  65. } light_runtimeArguments, *light_runtimeArguments_p;
  66. /* -- Global variable holding the settings for the current run -- */
  67. light_runtimeArguments light_Configuration;
  68. /* Sets default values for the configuration */
  69. void light_defaultConfig();
  70. /* Parses the program arguments and sets the configuration accordingly (unsanitized) */
  71. bool light_parseArguments(int argc, char **argv);
  72. /* Prints a header if verbosity level > 0 */
  73. void light_printVersion(void);
  74. /* Prints help regardless of verbosity level */
  75. void light_printHelp(void);
  76. /* -- SECTION: Main code -- */
  77. /* Initializes the application */
  78. bool light_initialize(int argc, char **argv);
  79. /* Does the work */
  80. bool light_execute(void);
  81. /* Frees up resources */
  82. void light_free();
  83. /* SECTION: Controller functionality */
  84. /* WARNING: `buffer` HAS to be freed by the user if not null once returned!
  85. * Size is always NAME_MAX + 1 */
  86. bool light_genPath(char const *controller, light_target_t target, light_field_t type, char **buffer);
  87. bool light_validControllerName(char const *controller);
  88. bool light_getBrightness(char const *controller, unsigned long *v);
  89. bool light_getMaxBrightness(char const *controller, unsigned long *v);
  90. bool light_setBrightness(char const *controller, unsigned long v);
  91. bool light_controllerAccessible(char const *controller);
  92. /* WARNING: `controller` HAS to be at most NAME_MAX, otherwise fails */
  93. bool light_getBestController(char *controller);
  94. bool light_getMinCap(char const *controller, bool * hasMinCap, unsigned long *minCap);
  95. bool light_setMinCap(char const *controller, unsigned long v);
  96. bool light_listControllers();
  97. bool light_saveBrightness(char const *controller, unsigned long v);
  98. bool light_restoreBrightness(char const *controller);
  99. #endif /* LIGHT_H_ */