infrared_custom_event.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stddef.h>
  4. enum InfraredCustomEventType {
  5. // Reserve first 100 events for button types and indexes, starting from 0
  6. InfraredCustomEventTypeReserved = 100,
  7. InfraredCustomEventTypeMenuSelected,
  8. InfraredCustomEventTypeTransmitStarted,
  9. InfraredCustomEventTypeTransmitStopped,
  10. InfraredCustomEventTypeSignalReceived,
  11. InfraredCustomEventTypeTextEditDone,
  12. InfraredCustomEventTypePopupClosed,
  13. InfraredCustomEventTypeButtonSelected,
  14. InfraredCustomEventTypeBackPressed,
  15. InfraredCustomEventTypeRpcLoad,
  16. InfraredCustomEventTypeRpcExit,
  17. InfraredCustomEventTypeRpcButtonPress,
  18. InfraredCustomEventTypeRpcButtonRelease,
  19. InfraredCustomEventTypeRpcSessionClose,
  20. };
  21. #pragma pack(push, 1)
  22. typedef union {
  23. uint32_t packed_value;
  24. struct {
  25. uint16_t type;
  26. int16_t value;
  27. } content;
  28. } InfraredCustomEvent;
  29. #pragma pack(pop)
  30. static inline uint32_t infrared_custom_event_pack(uint16_t type, int16_t value) {
  31. InfraredCustomEvent event = {.content = {.type = type, .value = value}};
  32. return event.packed_value;
  33. }
  34. static inline void
  35. infrared_custom_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
  36. InfraredCustomEvent event = {.packed_value = packed_value};
  37. if(type) *type = event.content.type;
  38. if(value) *value = event.content.value;
  39. }
  40. static inline uint16_t infrared_custom_event_get_type(uint32_t packed_value) {
  41. uint16_t type;
  42. infrared_custom_event_unpack(packed_value, &type, NULL);
  43. return type;
  44. }
  45. static inline int16_t infrared_custom_event_get_value(uint32_t packed_value) {
  46. int16_t value;
  47. infrared_custom_event_unpack(packed_value, NULL, &value);
  48. return value;
  49. }