infrared_custom_event.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. InfraredCustomEventTypeRpcLoaded,
  16. };
  17. #pragma pack(push, 1)
  18. typedef union {
  19. uint32_t packed_value;
  20. struct {
  21. uint16_t type;
  22. int16_t value;
  23. } content;
  24. } InfraredCustomEvent;
  25. #pragma pack(pop)
  26. static inline uint32_t infrared_custom_event_pack(uint16_t type, int16_t value) {
  27. InfraredCustomEvent event = {.content = {.type = type, .value = value}};
  28. return event.packed_value;
  29. }
  30. static inline void
  31. infrared_custom_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
  32. InfraredCustomEvent event = {.packed_value = packed_value};
  33. if(type) *type = event.content.type;
  34. if(value) *value = event.content.value;
  35. }
  36. static inline uint16_t infrared_custom_event_get_type(uint32_t packed_value) {
  37. uint16_t type;
  38. infrared_custom_event_unpack(packed_value, &type, NULL);
  39. return type;
  40. }
  41. static inline int16_t infrared_custom_event_get_value(uint32_t packed_value) {
  42. int16_t value;
  43. infrared_custom_event_unpack(packed_value, NULL, &value);
  44. return value;
  45. }