api.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef PWRTRAY_API_H_
  2. #define PWRTRAY_API_H_
  3. #include <stdint.h>
  4. #include <netinet/in.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define PT_SOCK_DIR "/var/run/pwrtray"
  9. #define PT_SOCKET PT_SOCK_DIR "/socket"
  10. //#define PT_PACKED __attribute__((__packed__))
  11. #define PT_PACKED
  12. enum {
  13. PTREQ_PING = 0x0,
  14. PTREQ_WANT_NOTIFY,
  15. PTREQ_XEVREP,
  16. /* Backlight controls */
  17. PTREQ_BL_GETSTATE = 0x100,
  18. PTREQ_BL_SETBRIGHTNESS,
  19. PTREQ_BL_AUTODIM,
  20. /* Battery controls */
  21. PTREQ_BAT_GETSTATE = 0x200,
  22. /* Notifications */
  23. PTNOTI_SRVDOWN = 0xF00,
  24. PTNOTI_BL_CHANGED,
  25. PTNOTI_BAT_CHANGED,
  26. };
  27. /* (struct pt_message *)->bat_stat.flags */
  28. #define PT_BAT_FLG_ONAC (1 << 0) /* On AC */
  29. #define PT_BAT_FLG_ACUNKNOWN (1 << 1) /* AC status unknown */
  30. #define PT_BAT_FLG_CHARGING (1 << 2) /* Currently charging */
  31. #define PT_BAT_FLG_CHUNKNOWN (1 << 3) /* Charging status unknown */
  32. /* (struct pt_message *)->bl_stat.flags */
  33. #define PT_BL_FLG_AUTODIM (1 << 0) /* Auto dimming enabled */
  34. #define PT_BL_FLG_AUTODIM_AC (1 << 1) /* Auto dimming enabled on AC */
  35. /* (struct pt_message *)->bl_autodim.flags */
  36. #define PT_AUTODIM_FLG_ENABLE (1 << 0) /* Auto dimming enable */
  37. #define PT_AUTODIM_FLG_ENABLE_AC (1 << 1) /* Auto dimming enable on AC */
  38. /* (struct pt_message *)->flags */
  39. #define PT_FLG_REPLY (1 << 0) /* This is a reply to a previous message */
  40. #define PT_FLG_OK (1 << 1) /* There was no error */
  41. #define PT_FLG_ENABLE (1 << 2) /* Generic boolean flag */
  42. struct pt_message {
  43. uint16_t id;
  44. uint16_t flags;
  45. union {
  46. struct { /* Backlight / LCD state */
  47. uint32_t flags;
  48. int32_t min_brightness;
  49. int32_t max_brightness;
  50. int32_t brightness_step;
  51. int32_t brightness;
  52. } PT_PACKED bl_stat;
  53. struct { /* Set backlight */
  54. int32_t brightness;
  55. } PT_PACKED bl_set;
  56. struct { /* Autodim controls */
  57. uint32_t flags;
  58. int32_t max_percent;
  59. } PT_PACKED bl_autodim;
  60. struct { /* Battery state */
  61. uint32_t flags;
  62. int32_t min_level;
  63. int32_t max_level;
  64. int32_t level;
  65. } PT_PACKED bat_stat;
  66. struct { /* Error code (only for PT_FLG_REPLY) */
  67. int32_t code;
  68. } PT_PACKED error;
  69. } PT_PACKED;
  70. } PT_PACKED;
  71. #ifdef __cplusplus
  72. } /* extern "C" */
  73. #endif
  74. #endif /* PWRTRAY_API_H_ */