1
0

HrReceiver.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using ANT_Managed_Library;
  3. using UnityEngine;
  4. namespace Sensors.ANT
  5. {
  6. public struct HrSensorData
  7. {
  8. public float HeartRate;
  9. }
  10. public class HrReceiver : AwaitDevice
  11. {
  12. private AntChannel backgroundScanChannel;
  13. private AntChannel deviceChannel;
  14. private HrSensorData sensorData;
  15. private bool connected;
  16. public override int DeviceId { get; }
  17. public override bool Connected => connected;
  18. public HrSensorData SensorData => sensorData;
  19. public HrReceiver()
  20. {
  21. }
  22. public HrReceiver(int deviceID)
  23. {
  24. DeviceId = deviceID;
  25. }
  26. public override void Connect(AntDevice device)
  27. {
  28. var channelID = AntManager.Instance.GetFreeChannelID();
  29. deviceChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00,
  30. channelID, (ushort) device.deviceNumber, device.deviceType, device.transType, (byte) device.radiofreq,
  31. (ushort) device.period, false);
  32. connected = true;
  33. deviceChannel.onReceiveData += Data;
  34. deviceChannel.onChannelResponse += ChannelResponse;
  35. deviceChannel.hideRXFAIL = true;
  36. }
  37. //Deal with the received Data
  38. private void Data(byte[] data)
  39. {
  40. sensorData.HeartRate = data[7];
  41. }
  42. private void ChannelResponse(ANT_Response response)
  43. {
  44. }
  45. }
  46. }