123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef LIGHT_H
  2. #define LIGHT_H
  3. #include "helpers.h"
  4. #include <sys/types.h>
  5. #include <dirent.h>
  6. #include <linux/limits.h>
  7. #define LIGHT_VER_MAJOR 0
  8. #define LIGHT_VER_MINOR 10
  9. #define LIGHT_VER_TYPE "beta"
  10. #define LIGHT_YEAR 2014
  11. #define LIGHT_AUTHOR "Fredrik Haikarainen"
  12. #define ASSERT_SET(t,v) \
  13. if(v)\
  14. {\
  15. fprintf(stderr, t" arguments can not be used in conjunction.\n");\
  16. return FALSE;\
  17. }\
  18. v = TRUE;
  19. #define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
  20. #define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
  21. #define ASSERT_FIELDSET() ASSERT_SET("Field", fieldSet)
  22. #define ASSERT_CTRLSET() ASSERT_SET("Controller", ctrlSet)
  23. #define ASSERT_VALSET() ASSERT_SET("Value", valSet)
  24. typedef enum LIGHT_FIELD {
  25. LIGHT_BRIGHTNESS = 0,
  26. LIGHT_MAX_BRIGHTNESS,
  27. LIGHT_MIN_CAP,
  28. LIGHT_SAVERESTORE
  29. } LIGHT_FIELD;
  30. typedef enum LIGHT_TARGET {
  31. LIGHT_BACKLIGHT = 0,
  32. LIGHT_KEYBOARD
  33. } LIGHT_TARGET;
  34. typedef enum LIGHT_CTRL_MODE {
  35. LIGHT_AUTO = 0,
  36. LIGHT_SPECIFY
  37. } LIGHT_CTRL_MODE;
  38. typedef enum LIGHT_OP_MODE {
  39. LIGHT_GET = 0,
  40. LIGHT_SET,
  41. LIGHT_ADD,
  42. LIGHT_SUB,
  43. LIGHT_PRINT_HELP, /* Prints help and exits */
  44. LIGHT_PRINT_VERSION, /* Prints version info and exits */
  45. LIGHT_LIST_CTRL,
  46. LIGHT_RESTORE,
  47. LIGHT_SAVE
  48. } LIGHT_OP_MODE;
  49. typedef enum LIGHT_VAL_MODE {
  50. LIGHT_RAW = 0,
  51. LIGHT_PERCENT
  52. } LIGHT_VAL_MODE;
  53. typedef struct light_runtimeArguments_s {
  54. /* Which controller to use */
  55. LIGHT_CTRL_MODE controllerMode;
  56. char specifiedController[NAME_MAX + 1];
  57. /* What to do with the controller */
  58. LIGHT_OP_MODE operationMode;
  59. LIGHT_VAL_MODE valueMode;
  60. unsigned long specifiedValueRaw; /* The specified value in raw mode */
  61. double specifiedValuePercent; /* The specified value in percent */
  62. LIGHT_TARGET target;
  63. LIGHT_FIELD field;
  64. /* Cache data */
  65. LIGHT_BOOL hasCachedMaxBrightness;
  66. unsigned long cachedMaxBrightness;
  67. } light_runtimeArguments, *light_runtimeArguments_p;
  68. /* -- Global variable holding the settings for the current run -- */
  69. light_runtimeArguments light_Configuration;
  70. /* Sets default values for the configuration */
  71. void light_defaultConfig();
  72. /* Parses the program arguments and sets the configuration accordingly (unsanitized) */
  73. LIGHT_BOOL light_parseArguments(int argc, char** argv);
  74. /* Prints a header if verbosity level > 0 */
  75. void light_printVersion(void);
  76. /* Prints help regardless of verbosity level */
  77. void light_printHelp(void);
  78. /* -- SECTION: Main code -- */
  79. /* Initializes the application */
  80. LIGHT_BOOL light_initialize(int argc, char** argv);
  81. /* Does the work */
  82. LIGHT_BOOL light_execute(void);
  83. /* Frees up resources */
  84. void light_free();
  85. /* SECTION: Controller functionality */
  86. /* WARNING: `buffer` HAS to be freed by the user if not null once returned!
  87. * Size is always NAME_MAX + 1 */
  88. LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET target, LIGHT_FIELD type, char **buffer);
  89. LIGHT_BOOL light_validControllerName(char const *controller);
  90. LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v);
  91. LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v);
  92. LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v);
  93. LIGHT_BOOL light_controllerAccessible(char const *controller);
  94. /* WARNING: `controller` HAS to be at most NAME_MAX, otherwise fails */
  95. LIGHT_BOOL light_getBestController(char *controller);
  96. LIGHT_BOOL light_getMinCap(char const *controller, LIGHT_BOOL *hasMinCap, unsigned long *minCap);
  97. LIGHT_BOOL light_setMinCap(char const *controller, unsigned long v);
  98. LIGHT_BOOL light_listControllers();
  99. LIGHT_BOOL light_saveBrightness(char const *controller, unsigned long v);
  100. LIGHT_BOOL light_restoreBrightness(char const *controller);
  101. #endif /* LIGHT_H */