void OnAirGesturesDataValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args) { byte[] value = new byte[args.CharacteristicValue.Length]; DataReader reader = DataReader.FromBuffer(args.CharacteristicValue); reader.ReadBytes(value); if (value.Length > 0) { byte first = value[0]; if (first != 20) { // Air Gestured TAPAirGesture airGesture = TAPAirGestureHelper.intToAirGesture(first); if (this.OnAirGestured != null && airGesture != TAPAirGesture.Undefined) { this.OnAirGestured(this.Identifier, airGesture); } } else if (value.Length > 1) { // State this.isInAirGestureState = value[1] == 1; if (this.OnTapChangedAirGesturesState != null) { this.OnTapChangedAirGesturesState(this.Identifier, value[1] == 1); } } } }
void OnTapDataValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args) { if (this.isInAirGestureState) { if (this.OnAirGestured != null) { byte[] value = new byte[args.CharacteristicValue.Length]; DataReader reader = DataReader.FromBuffer(args.CharacteristicValue); reader.ReadBytes(value); TAPAirGesture airGesture = TAPAirGestureHelper.tapToAirGesture(value[0]); if (airGesture != TAPAirGesture.Undefined) { this.OnAirGestured(this.Identifier, airGesture); } } } else { if (this.OnTapped != null) { byte[] value = new byte[args.CharacteristicValue.Length]; DataReader reader = DataReader.FromBuffer(args.CharacteristicValue); reader.ReadBytes(value); Debug.WriteLine("TAPPED " + value[0]); this.OnTapped(this.Identifier, value[0]); } } }