You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 line
1.1KB

  1. #include <USBHost_t36.h>
  2. USBHost myusb;
  3. USBHub hub1(myusb);
  4. USBHub hub2(myusb);
  5. AntPlus ant1(myusb);
  6. void setup() {
  7. while (!Serial) ; // wait for Arduino Serial Monitor
  8. Serial.println("Ant+ USB Test");
  9. myusb.begin();
  10. ant1.begin();
  11. ant1.onStatusChange(handleStatusChange);
  12. ant1.onDeviceID(handleDeviceID);
  13. }
  14. void loop() {
  15. myusb.Task();
  16. }
  17. void handleStatusChange(int channel, int status) {
  18. Serial.print("Channel ");
  19. Serial.print(channel);
  20. Serial.print(" status: ");
  21. switch (status) {
  22. case 0: Serial.println("STATUS UNASSIGNED CHANNEL"); break;
  23. case 2: Serial.println("STATUS ASSIGNED CHANNEL"); break;
  24. case 3: Serial.println("STATUS SEARCHING CHANNEL"); break;
  25. case 4: Serial.println("STATUS TRACKING_CHANNEL"); break;
  26. default: Serial.println("UNKNOWN STATUS STATE");
  27. }
  28. }
  29. void handleDeviceID(int channel, int devId, int devType, int transType) {
  30. Serial.print("Device found on channel ");
  31. Serial.print(channel);
  32. Serial.print(": deviceId:");
  33. Serial.print(devId);
  34. Serial.print(", deviceType:");
  35. Serial.print(devType);
  36. Serial.print(", transType:");
  37. Serial.println(transType);
  38. }