main.c 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 * 1;
  20. cfg.cy_crit = 250;
  21. cfg.cy_suppress_time = fs * 1;
  22. if (jump_rope_count_device_init(&dev, &cfg) != 0)
  23. abort();
  24. while (scanf("%f%f%f%f%f%f%f",
  25. &packet.gx, &packet.gy, &packet.gz,
  26. &packet.ax, &packet.ay, &packet.az,
  27. &packet.cy) == 7) {
  28. ret = process_packet(&dev, &packet, &result);
  29. if (ret != 0)
  30. abort();
  31. if (result == RESULT_INACTIVE) {
  32. if (count > 1)
  33. printf("%d\n", count - 1);
  34. count = 0;
  35. } else if (result == RESULT_TRIGGERED)
  36. count += 1;
  37. }
  38. if (count > 1)
  39. printf("%d\n", count - 1);
  40. return 0;
  41. }
  42. /* vim: set ts=8 sw=8 sts=8 noet: */