Example #1
0
        public void ATTClientAttributeValueEvent(object sender, Bluegiga.BLE.Events.ATTClient.AttributeValueEventArgs e)
        {
            // check for a new value from the connected peripheral's heart rate measurement attribute
            if (e.connection == GetConnectionHandle() && e.atthandle == att_handle_measurement)
            {
                aX = (e.value[1] * 256 + e.value[2]) * accelerometerFSR / Math.Pow(2, 16);
                aY = (e.value[3] * 256 + e.value[4]) * accelerometerFSR / Math.Pow(2, 16);
                aZ = (e.value[5] * 256 + e.value[6]) * accelerometerFSR / Math.Pow(2, 16);
                gX = (e.value[7] * 256 + e.value[8]) * gyroFSR / Math.Pow(2, 16);
                gY = (e.value[9] * 256 + e.value[10]) * gyroFSR / Math.Pow(2, 16);
                gZ = (e.value[11] * 256 + e.value[12]) * gyroFSR / Math.Pow(2, 16);
                AccelerationValue    = new Acceleration(aX, aY, aZ);
                AngularvelocityValue = new AngularVelocity(gX, gY, gZ);
                double x0 = aX * aX + aY * aY + aZ * aZ;

                if (x0 - x1 > 290)
                {
                    if (originalStep < 0)
                    {
                        originalStep = step;
                    }
                    currentStep = step - originalStep;

                    PedometerValue = new PedometerData(step, calorie, distance, duration, currentStep);
                    step           = step + 1;
                }
                x1 = x0;
            }
        }
Example #2
0
        public WindowsGem(string address)
        {
            _last             = Quaternion.identity;
            reference         = Quaternion.identity;
            _lastAcceleration = Vector3.zero;
            State             = GemState.Disconnected;
            Pedometer         = new PedometerData();

            string[] str       = address.Split(':');
            var      addrBytes = new byte[str.Length];

            for (int i = 0; i < addrBytes.Length; i++)
            {
                addrBytes[i] = Byte.Parse(str[i], System.Globalization.NumberStyles.HexNumber);
            }

            this.address    = addrBytes;
            this.addressStr = address;

            State = GemState.Disconnected;

            onCombinedDataRecieved = new NativeWrapper.gemOnCombinedDataReceived(CombinedDataReceived);
            NativeWrapper.gemSetOnCombinedData(addrBytes, onCombinedDataRecieved);

            onPedometerDataRecieved = new NativeWrapper.gemOnPedometerReceived(PedometerDataReceived);
            NativeWrapper.gemSetOnPedometerData(addrBytes, onPedometerDataRecieved);

            onTapDataRecieved = new NativeWrapper.gemOnTapDataReceived(TapDataReceived);
            NativeWrapper.gemSetOnTapData(addrBytes, onTapDataRecieved);

            onStateChanged = new NativeWrapper.gemOnStateChanged(StateChanged);
            NativeWrapper.gemSetOnStateChanged(addrBytes, onStateChanged);
        }
Example #3
0
        private void PedometerDataReceived(uint steps, float walktime)
        {
            PedometerData pedometer = new PedometerData();

            pedometer.Steps    = (int)steps;
            pedometer.WalkTime = walktime;

            Pedometer = pedometer;
        }
Example #4
0
        public void ATTClientAttributeValueEvent(object sender, Bluegiga.BLE.Events.ATTClient.AttributeValueEventArgs e)
        {
            String log = String.Format("ble_evt_attclient_attribute_value: connection={0}, atthandle={1}, type={2}, value=[ {3}]" + Environment.NewLine,
                                       e.connection,
                                       e.atthandle,
                                       e.type,
                                       ByteArrayToHexString(e.value)
                                       );

            Console.Write(log);

            // check for a new value from the connected peripheral's heart rate measurement attribute
            if (e.connection == GetConnectionHandle() && e.atthandle == att_handle_rx)
            {
                if (e.value[0] == SIPP_02_CMD_11_REALTIME)
                {
                    step     = e.value[1] << 16 & 0xff0000 | e.value[2] << 8 & 0xff00 | e.value[3] & 0xff;
                    calorie  = e.value[7] << 16 & 0xff0000 | e.value[8] << 8 & 0xff00 | e.value[9] & 0xff;
                    distance = e.value[10] << 16 & 0xff0000 | e.value[11] << 8 & 0xff00 | e.value[12] & 0xff;
                    duration = e.value[13] << 8 & 0xff00 | e.value[14] & 0xff;
                    if (originalStep < 0)
                    {
                        originalStep = step;
                    }
                    currentStep    = step - originalStep;
                    PedometerValue = new PedometerData(step, calorie, distance, duration, currentStep);

                    // display actual measurement
                    Console.WriteLine(String.Format("Step: {0},  Calore: {1} K, Distance: {2} meter, Duration: {3} minute", step, calorie, distance, duration) + Environment.NewLine);
                }
                else if (e.value[0] == SIPP_02_CMD_09_READ_DATA)
                {
                    if (e.value[1] == 0x00)
                    {
                        step    = e.value[6] << 16 & 0xff0000 | e.value[7] << 8 & 0xff00 | e.value[8] & 0xff;
                        calorie = e.value[12] << 16 & 0xff0000 | e.value[13] << 8 & 0xff00 | e.value[14] & 0xff;

                        if (originalStep < 0)
                        {
                            originalStep = step;
                        }
                        currentStep = step - originalStep;
                    }
                    else if (e.value[1] == 0x01)
                    {
                        distance = e.value[6] << 16 & 0xff0000 | e.value[7] << 8 & 0xff00 | e.value[8] & 0xff;
                        duration = e.value[9] << 8 & 0xff00 | e.value[10] & 0xff;

                        PedometerValue = new PedometerData(step, calorie, distance, duration, currentStep);
                        // display actual measurement
                        Console.WriteLine(String.Format("Step: {0},  Calore: {1} K, Distance: {2} meter, Duration: {3} minute", step, calorie, distance, duration) + Environment.NewLine);
                    }
                }
            }
        }
Example #5
0
        public void ATTClientAttributeValueEvent(object sender, Bluegiga.BLE.Events.ATTClient.AttributeValueEventArgs e)
        {
            // check for a new value from the connected peripheral's heart rate measurement attribute
            if (e.connection == GetConnectionHandle() && e.atthandle == att_handle_measurement)
            {
                aX = BitConverter.ToInt16(e.value, 0) * accelerometerFSR / Math.Pow(2, 16);
                aY = BitConverter.ToInt16(e.value, 2) * accelerometerFSR / Math.Pow(2, 16);
                aZ = BitConverter.ToInt16(e.value, 4) * accelerometerFSR / Math.Pow(2, 16);
                gX = BitConverter.ToInt16(e.value, 6) * gyroFSR / Math.Pow(2, 16);
                gY = BitConverter.ToInt16(e.value, 8) * gyroFSR / Math.Pow(2, 16);
                gZ = BitConverter.ToInt16(e.value, 10) * gyroFSR / Math.Pow(2, 16);
                AccelerationValue    = new Acceleration(aX, aY, aZ);
                AngularvelocityValue = new AngularVelocity(gX, gY, gZ);
                double x0 = aX * aX + aY * aY + aZ * aZ;
                if (x0 < (this.threshold * this.threshold))
                {
                    if (x1 > 0)
                    {
                        x1 = 0;
                    }

                    return;
                }

                if (x0 - x1 > (this.threshold * this.threshold))
                {
                    if (originalStep < 0)
                    {
                        originalStep = step;
                    }
                    currentStep = step - originalStep;

                    PedometerValue = new PedometerData(step, calorie, distance, duration, currentStep);
                    step           = step + 1;
                }
                x1 = x0;
            }
        }