Ejemplo n.º 1
0
        public Localisation()
        {
            InitializeComponent();

            _bleService = BLEService.Instance();

            _isAlarmStarted = false;
            _isStarted      = false;
            _firstTimer     = 0;

            // Init player
            _player = CrossSimpleAudioPlayer.Current;
            _player.Load("bing.mp3");
            _player.Volume = 1;

            MessagingCenter.Subscribe <BLEService>(this, "deviceConnectionLost", (sender) =>
            {
                OnDeviceDisconnected();
            });

            MessagingCenter.Subscribe <BLEService, CharacteristicUpdatedEventArgs>(this, "characteristicUpdated", (sender, args) =>
            {
                OnCharacteristicUpdated(args);
            });
        }
        public Welcome_Confirmation()
        {
            InitializeComponent();

            _isConnected = false;

            _player = CrossSimpleAudioPlayer.Current;
            _player.Load("bing.mp3");
            _player.Volume = 1;

            var ble     = CrossBluetoothLE.Current;
            var adapter = CrossBluetoothLE.Current.Adapter;

            NavigationPage.SetHasNavigationBar(this, false);
            // Subscribe events
            MessagingCenter.Subscribe <BLEService, BLEDevice>(this, "deviceDiscovered", async(sender, bleDevice) =>
            {
                await _bleService.ConnectDeviceAsync(bleDevice);
            });

            MessagingCenter.Subscribe <BLEService>(this, "deviceConnected", (sender) =>
            {
                OnDeviceConnected();
            });

            MessagingCenter.Subscribe <BLEService>(this, "deviceConnectionLost", (sender) =>
            {
                OnDeviceDisconnected();
            });

            MessagingCenter.Subscribe <BLEService>(this, "deviceDisconnected", (sender) =>
            {
                OnDeviceDisconnected();
            });

            MessagingCenter.Subscribe <BLEService, BluetoothStateChangedArgs>(this, "stateChanged", (sender, args) =>
            {
                OnStateChanged(args);
            });

            MessagingCenter.Subscribe <BLEService>(this, "scanTimeoutElapsed", (sender) =>
            {
                OnScanTimeoutElapsed();
            });

            MessagingCenter.Subscribe <BLEService, CharacteristicUpdatedEventArgs>(this, "characteristicUpdated", (sender, args) =>
            {
                OnCharacteristicUpdated(args);
            });

            // Start scan
            _bleService = BLEService.Instance();
            _bleService.TryStartScanning(true);
        }