Esempio n. 1
0
        protected virtual void OnLightBlueBeanScratch1Measured(LightBlueBeanScratch1EventArgs e)
        {
            EventHandler <LightBlueBeanScratch1EventArgs> handler = LightBlueBeanScratch1_Measured;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 2
0
        // Handle the recieved data from the indication event.
        // IndicationへのConfirmは、受信時点で自動的に行われる。
        void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            string result = string.Empty;

            var data = new byte[args.CharacteristicValue.Length];

            DataReader.FromBuffer(args.CharacteristicValue).ReadBytes(data);

            // パケット構成
            // 0-1: カウンタ(16bit)
            // 2-3: AccX(16bit)

            UInt16 count;
            Int16  accXFiltered;
            Int16  accXRaw;

            if (data.Length >= 2)
            {
                int currentOffset = 0;

                //Read LightBlue Bean Scratch1
                count          = BitConverter.ToUInt16(new byte[] { data[currentOffset], data[currentOffset + 1] }, 0);
                currentOffset += 2;

                accXFiltered   = BitConverter.ToInt16(new byte[] { data[currentOffset], data[currentOffset + 1] }, 0);
                currentOffset += 2;

                accXRaw        = BitConverter.ToInt16(new byte[] { data[currentOffset], data[currentOffset + 1] }, 0);
                currentOffset += 2;


                LightBlueBeanScratch1EventArgs LightBlueBeanScratch1Value = new LightBlueBeanScratch1EventArgs();
                LightBlueBeanScratch1Value.Scratch1 = new LightBlueBeanScratch1Value(count, accXFiltered, accXRaw);
                OnLightBlueBeanScratch1Measured(LightBlueBeanScratch1Value);
            }
        }