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