void ConnectToDevice(AntDevice device)
    {
        AntManager.Instance.CloseBackgroundScanChannel();
        byte channelID = AntManager.Instance.GetFreeChannelID();

        deviceChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, channelID, (ushort)device.deviceNumber, device.deviceType, device.transType, (byte)device.radiofreq, (ushort)device.period, false);
        connected     = true;
        deviceChannel.onReceiveData     += Data;
        deviceChannel.onChannelResponse += ChannelResponse;
        deviceChannel.hideRXFAIL         = true;
    }
Exemple #2
0
        /// <summary>
        /// Called when a sensor is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewSensors_DoubleClick(object sender, EventArgs e)
        {
            AntDevice antDevice = (AntDevice)listViewSensors.SelectedItems[0].Tag;

            _fitnessEquipment = antDevice as FitnessEquipment;

            Wasp wasp = antDevice.GetStrongestWasp();

            wasp.ConnectionEvent += Wasp_ConnectionEvent;;
            wasp.RequestConnection();
        }
Exemple #3
0
        /// <summary>
        /// Format a group box for the device
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args">Arguments, if any</param>
        /// <returns></returns>
        GroupBox CreateDeviceBox(AntDevice dev, EventArgs args)
        {
            GroupBox      gb = null;
            List <string> d  = DeviceFormatter.FormatDevice(dev, args);

            gb = new GroupBox();
            // First item in the list is the ID
            gb.Header = d[0];
            ListView lv = new ListView();

            lv.ItemsSource = d;
            lv.Margin      = new Thickness(5);
            lv.Padding     = new Thickness(5);
            gb.Content     = lv;
            return(gb);
        }
Exemple #4
0
 /// <summary>
 /// Returns a dictionary of data from the device passed in
 /// </summary>
 /// <param name="device">Device sending data</param>
 /// <param name="args">arguments provided</param>
 /// <returns></returns>
 public static List <string> FormatDevice(AntDevice device, EventArgs args)
 {
     try
     {
         object[] parameters = { device, args };
         return((List <string>) typeof(DeviceFormatter).InvokeMember(
                    "Format" + device.DeviceType.ToString(),
                    BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
                    null,
                    null,
                    parameters));
     }
     catch (MissingMethodException)
     {
         return(new List <string> {
             "Unknown device", "Type: " + device.DeviceType.ToString()
         });
     }
 }
Exemple #5
0
        /// <summary>
        /// Format a group box for the device
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args">Arguments, if any</param>
        /// <returns></returns>
        GroupBox CreateDeviceBox(AntDevice dev, EventArgs args)
        {
            GroupBox      gb = null;
            List <string> d  = DeviceFormatter.FormatDevice(dev, args);

            if (d.Count > 0)
            {
                ListView lv = new ListView();
                lv.ItemsSource = d;
                lv.Margin      = new Thickness(5);
                lv.Padding     = new Thickness(5);
                gb             = new GroupBox()
                {
                    Width = 200,
                    // First item in the list is the ID
                    Header  = d[0],
                    Content = lv
                };
            }
            return(gb);
        }
    //Windows and mac
    //If the device is found
    void ReceivedBackgroundScanData(Byte[] data)
    {
        byte deviceType = (data[12]); // extended info Device Type byte

        switch (deviceType)
        {
        case AntplusDeviceType.FitnessEquipment: {
            int  deviceNumber = (data[10]) | data[11] << 8;
            byte transType    = data[13];
            foreach (AntDevice d in scanResult)
            {
                if (d.deviceNumber == deviceNumber && d.transType == transType)         //device already found
                {
                    return;
                }
            }

            Debug.Log("FitnessEquipmentfound " + deviceNumber);

            AntDevice foundDevice = new AntDevice();
            foundDevice.deviceType   = deviceType;
            foundDevice.deviceNumber = deviceNumber;
            foundDevice.transType    = transType;
            foundDevice.period       = 8192;
            foundDevice.radiofreq    = 57;
            foundDevice.name         = "FitnessEquipment(" + foundDevice.deviceNumber + ")";
            scanResult.Add(foundDevice);
            if (autoConnectToFirstSensorFound)
            {
                ConnectToDevice(foundDevice);
            }
            break;
        }

        default: {
            break;
        }
        }
    }
Exemple #7
0
        /// <summary>
        /// Generic handler for ANT message updates
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_AntMessageEvent(object sender, EventArgs e)
        {
            // Find the listview it corresponds to and refresh
            AntDevice dev        = sender as AntDevice;
            string    targetName = string.Format("{0} ID: {1}", dev.DeviceType, dev.ExtendedDeviceNumber);

            try
            {
                GroupBox gb = MainPanel.Children.OfType <GroupBox>().First <GroupBox>(x => x.Header.ToString() == targetName);
                ListView lv = gb.Content as ListView;

                List <string> newData = DeviceFormatter.FormatDevice((AntDevice)sender, e);
                //lv.ItemsSource = null;
                if (newData?.Count > 0)
                {
                    lv.ItemsSource = newData;
                    lv.Items.Refresh();
                }
            }
            catch (Exception)
            {
            }
        }