input_dump.c 904 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "flipper_v2.h"
  2. #include <stdio.h>
  3. typedef union {
  4. unsigned int packed;
  5. InputState state;
  6. } InputDump;
  7. static void state_cb(const void* value, void* ctx) {
  8. InputDump dump = {.packed = 0};
  9. dump.state = *(InputState*)value;
  10. printf("state: %02x\n", dump.packed);
  11. }
  12. static void event_cb(const void* value, void* ctx) {
  13. const InputEvent* event = value;
  14. printf("event: %02x %s\n", event->input, event->state ? "pressed" : "released");
  15. }
  16. void application_input_dump(void* p) {
  17. // open record
  18. ValueManager* state_record = furi_open("input_state");
  19. furi_check(state_record);
  20. subscribe_pubsub(&state_record->pubsub, state_cb, NULL);
  21. PubSub* event_record = furi_open("input_events");
  22. furi_check(event_record);
  23. subscribe_pubsub(event_record, event_cb, NULL);
  24. printf("Example app [input dump]\n");
  25. for(;;) {
  26. delay(100);
  27. }
  28. }