infrared_custom_event.h 1.5 KB

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