main.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <jump_rope_count_device.h>
  4. const int fs = 50;
  5. int main()
  6. {
  7. struct jump_rope_count_config cfg;
  8. struct jump_rope_count_device dev;
  9. struct sensor_packet packet;
  10. int count = 0, ret;
  11. enum jump_rope_count_result result;
  12. cfg.lg = 0.5;
  13. cfg.hg = 1.5;
  14. cfg.la = 4.0;
  15. cfg.ha = 6.0;
  16. cfg.lgz = -1.5;
  17. cfg.hgz = 2;
  18. cfg.a_g_window = 100;
  19. cfg.cy_window = fs * 0.1;
  20. cfg.cy_crit = 200;
  21. cfg.cy_suppress_time = fs * 0.2;
  22. cfg.wait_time = fs * 1;
  23. if (jump_rope_count_device_init(&dev, &cfg) != 0)
  24. abort();
  25. while (scanf("%f%f%f%f%f%f%f",
  26. &packet.gx, &packet.gy, &packet.gz,
  27. &packet.ax, &packet.ay, &packet.az,
  28. &packet.cy) == 7) {
  29. ret = process_packet(&dev, &packet, &result);
  30. if (ret != 0)
  31. abort();
  32. if (result == RESULT_INACTIVE) {
  33. if (count > 1)
  34. printf("%d\n", count - 1);
  35. count = 0;
  36. } else if (result == RESULT_TRIGGERED)
  37. count += 1;
  38. }
  39. if (count > 1)
  40. printf("%d\n", count - 1);
  41. return 0;
  42. }
  43. /* vim: set ts=8 sw=8 sts=8 noet: */