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