Beispiel #1
0
    public void Onclick_Close()
    {
        if (hrChannel)
        {
            hrChannel.onChannelResponse -= OnChannelResponse;
            hrChannel.Close();
            CancelInvoke("HRMTransmit");
            hrChannel = null;
        }
        if (speedChannel)
        {
            speedChannel.onReceiveData -= ReceivedSpeedAntData;
            speedChannel.Close();
            speedChannel = null;
        }
        if (backgroundScanChannel)
        {
            backgroundScanChannel.onReceiveData     -= ReceivedBackgroundScanData;
            backgroundScanChannel.onChannelResponse -= OnChannelResponse;
            backgroundScanChannel.Close();
            backgroundScanChannel = null;
        }

        StopCoroutine("Reconnect");
    }
Beispiel #2
0
    void ReceivedBackgroundScanData(Byte[] data)
    {
        byte deviceType = (data[12]);         // extended info Device Type byte

        //use the Extended Message Formats to identify nodes

        switch (deviceType)
        {
        case AntplusDeviceType.FitnessEquipment:
        {
            backgroundScanChannel.Close();
            deviceNumber = (ushort)((data[10]) | data[11] << 8);

            transType = data[13];
            Debug.Log("found FEC trainer, opening channel, device number is " + deviceNumber);

            FECChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, 1, deviceNumber, 17, transType, 57, 8192, false);
            FECChannel.onReceiveData += FECData;
            FECChannel.hideRXFAIL     = true;
            break;
        }

        default:
        {
            break;
        }
        }
    }
Beispiel #3
0
 public void Onclick_Start_BackgroundScan()
 {
     init_Device();
     backgroundScanChannel = AntManager.Instance.OpenBackgroundScanChannel(0);
     backgroundScanChannel.onReceiveData     += ReceivedBackgroundScanData;
     backgroundScanChannel.onChannelResponse += OnChannelResponse;
 }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            Debug.Log("init device and start background scan");
            AntManager.Instance.Init();
            backgroundScanChannel = AntManager.Instance.OpenBackgroundScanChannel(0);
            backgroundScanChannel.onReceiveData += ReceivedBackgroundScanData;
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            Debug.Log("setting resistance to 0 %");
            byte[] pageToSend = new byte[8] {
                0x30, 0xFF, 0xFF, 0xFF, 0xFF, 4, 55, 0
            };
            FECChannel.sendAcknowledgedData(pageToSend);
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
            Debug.Log("setting resistance to 100 %");
            byte[] pageToSend = new byte[8] {
                0x30, 0xFF, 0xFF, 0xFF, 0xFF, 4, 55, 200
            };                                                                           //unit is 0.50%
            FECChannel.sendAcknowledgedData(pageToSend);
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            Debug.Log("setting resistance to 75 %");
            byte[] pageToSend = new byte[8] {
                0x30, 0xFF, 0xFF, 0xFF, 0xFF, 4, 55, 150
            };                                                                                       //unit is 0.50%
            FECChannel.sendAcknowledgedData(pageToSend);
        }
    }
Beispiel #5
0
    public AntChannel OpenContinuousScanChannel(byte radioFreq, byte USBDeviceNum = 0)
    {
        AntChannel channel = this.gameObject.AddComponent <AntChannel>();

        channel.ConfigureContinuousScan(0x00, radioFreq, USBDeviceNum);
        return(channel);
    }
    void ReceivedBackgroundScanData(Byte[] data)
    {
        byte deviceType = (data[12]); // extended info Device Type byte

        //use the Extended Message Formats to identify nodes

        switch (deviceType)
        {
        case AntplusDeviceType.BikeSpeed:
        {
            BikeDisplay b = new BikeDisplay();
            bikeDisplayList.Add(b);
            b.deviceNumber = (data[10]) | data[11] << 8;
            lastChannelUsed++;
            AntChannel speedChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, (byte)lastChannelUsed, 0, 123, 0, 57, 8118, false);         //bike speed Display
            speedChannel.onReceiveData += b.GetSpeed;
            speedChannel.hideRXFAIL     = true;
            Debug.Log("found bike speed #" + bikeDisplayList.Count);

            break;
        }

        default:
        {
            break;
        }
        }
    }
Beispiel #7
0
    public AntChannel OpenBackgroundScanChannel(byte userChannel)
    {
        AntChannel channel = this.gameObject.AddComponent <AntChannel>();

        channelList.Add(channel);
        channel.ConfigureScan(userChannel);
        return(channel);
    }
Beispiel #8
0
    public AntChannel OpenChannel(ANT_ReferenceLibrary.ChannelType channelType, byte userChannel, ushort deviceNum, byte deviceType, byte transType, byte radioFreq, ushort channelPeriod, bool pairing)
    {
        AntChannel channel = this.gameObject.AddComponent <AntChannel>();

        channelList.Add(channel);
        channel.ConfigureAnt(channelType, userChannel, deviceNum, deviceType, transType, radioFreq, channelPeriod, pairing);
        return(channel);
    }
Beispiel #9
0
 void CloseBackgroundScan()
 {
     nScanRequest--;
     if (nScanRequest == 0)
     {
         backgroundScanChannel.Close();
         backgroundScanChannel = null;
         Debug.Log("all devices connected, closing background scan channel");
     }
 }
    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;
    }
Beispiel #11
0
    public void Onclick_Init_HRSensor()
    {
        init_Device();

        //call the ConfigureAnt method for a master channel with the correct ANT speed display settings
        //found in ANT_Device_Profile_Heart_Rate_Monitor.pdf on thisisant.com
        //using channel 1
        hrChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Master_Transmit_0x10, 1, 255, 120, 0, 57, 8070, false); //hr sensor
        hrChannel.onChannelResponse += OnChannelResponse;

        InvokeRepeating("HRMTransmit", 1, 1 / 4f); // let's fake a HRM by updating a HR beat every 1/4 second
    }
Beispiel #12
0
    public void Onclick_Init_SpeedDisplay()
    {
        init_Device();

        //call the ConfigureAnt method for a slave channel with the correct ANT speed display settings
        //found in ANT+_Device_Profile_-_Bicycle_Speed_and_Cadence_2.0.pdf on thisisant.com
        //using channel 2
        //note: collision is a normal behaviour searching for a master.

        speedChannel = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, 2, 0, 123, 0, 57, 8118, false); //bike speed Display
        speedChannel.onChannelResponse += OnChannelResponse;
        speedChannel.onReceiveData     += ReceivedSpeedAntData;
    }
Beispiel #13
0
    // Use this for initialization
    void Start()
    {
        if (AntManager.Instance.device == null)
        {
            AntManager.Instance.Init();
            //  AntManager.Instance.onDeviceResponse += OnDeviceResponse;
            //  AntManager.Instance.onSerialError += OnSerialError; //if usb dongle is unplugged for example
        }

        AntChannel scanChannel = AntManager.Instance.OpenContinuousScanChannel(57);

        // scanChannel.onChannelResponse += OnChannelResponse;
        scanChannel.onReceiveData += ReceiveContinuouScanData;
    }
Beispiel #14
0
    public AntChannel OpenBackgroundScanChannel(byte userChannel, byte USBDeviceNum = 0)
    {
        nScanRequest++;
        if (backgroundScanChannel) //if a background Scan channel already exist
        {
            return(backgroundScanChannel);
        }

        channelIDUsed[USBDeviceNum, userChannel] = true;
        backgroundScanChannel = this.gameObject.AddComponent <AntChannel>();
        channelList.Add(backgroundScanChannel);
        backgroundScanChannel.ConfigureScan(userChannel, USBDeviceNum);

        return(backgroundScanChannel);
    }
Beispiel #15
0
    void Start()
    {
        //INIT HR Display on usb device 0 and 1
        init_Device(0);
        AntChannel c = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, 0, 0, 120, 0, 57, 8070, false, 0);

        c.onChannelResponse += OnChannelResponse;
        c.onReceiveData     += USB0;
        c.hideRXFAIL         = true;

        init_Device(1);
        AntChannel d = AntManager.Instance.OpenChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, 0, 0, 120, 0, 57, 8070, false, 1);

        d.onChannelResponse += OnChannelResponse;
        d.onReceiveData     += USB1;
        d.hideRXFAIL         = true;
    }
    //Start a background Scan to find the device
    public void StartScan()
    {
        Debug.Log("Looking for ANT + Speed sensor");
#if UNITY_ANDROID && !UNITY_EDITOR
        //java:  connect_speed(String gameobjectName, float wheel, boolean useAndroidUI, boolean skipPreferredSearch, int deviceID)
        AndroidJNI.AttachCurrentThread();
        using (AndroidJavaClass javaClass = new AndroidJavaClass("com.ant.plugin.Ant_Connector")) {
            using (AndroidJavaObject activity = javaClass.GetStatic <AndroidJavaObject>("mContext")) {
                activity.Call("connect_speed", this.gameObject.name, wheelCircumference, useAndroidUI, skipPreferredSearch, deviceID);
            }
        }
#else
        AntManager.Instance.Init();
        scanResult            = new List <AntDevice>();
        backgroundScanChannel = AntManager.Instance.OpenBackgroundScanChannel(0);
        backgroundScanChannel.onReceiveData += ReceivedBackgroundScanData;
#endif
    }
 void StartScan()
 {
     Debug.Log("starting scan");
     backgroundScanChannel = AntManager.Instance.OpenBackgroundScanChannel(0);
     backgroundScanChannel.onReceiveData += ReceivedBackgroundScanData;
 }