Exemple #1
0
        public BluetoothProfileActivator(IBluetoothService bluetoothService,
                                         IPersonalizationSettings personalizationSettings,
                                         ISchedulerProvider schedulerProvider,
                                         ILoggerFactory loggerFactory)
        {
            _bluetoothService        = bluetoothService;
            _personalizationSettings = personalizationSettings;
            _schedulerProvider       = schedulerProvider;
            _logger             = loggerFactory.CreateLogger(GetType());
            _bluetoothEventLoop = _schedulerProvider.CreateEventLoopScheduler("BluetoothActivator");
            _logger.Verbose("BluetoothProfileActivator.ctor();");

            _profileActivated = _bluetoothService.IdentitiesActivated(_bluetoothEventLoop)
                                .Retry()
                                .Repeat()
                                .Log(_logger, "IdentitiesActivated")
                                .Select(Translate)
                                .Publish();

            //HACK: Avoid work in the ctor. Can be smart here using SelectMany on the IsEnabled + Connecting when ProfileActivated is subscribed to. -LC
            if (_bluetoothService.IsSupported && IsEnabled)
            {
                _connection.Disposable = _profileActivated.Connect();
            }
        }
Exemple #2
0
        public static async Task SyncBandWithCloud(CancellationTokenSource token_for_logic)
        {
            IBluetoothService ibs = DependencyService.Get <IBluetoothService>().CreateBluetoothService();
            int bt = ibs.EnableBluetooth();

            if (bt > 0) // if we actually turned on the bluetooth
            {
                await Task.Delay(90000, token_for_logic.Token);
            }
            else // if bluetooth was already turned on
            {
                ibs.DisableBluetooth();
                await Task.Delay(30000, token_for_logic.Token); // wait for 30 seconds

                bt = ibs.EnableBluetooth();
                await Task.Delay(90000, token_for_logic.Token); // wait for 90 seconds
            }
            ibs.DisableBluetooth();
            await Task.Delay(30000, token_for_logic.Token); // wait for 30 seconds

            bt = ibs.EnableBluetooth();                     // enable bluetooth for the second time
            await Task.Delay(90000, token_for_logic.Token); // wait for 90 seconds

            ibs.DisableBluetooth();                         // disable bluetooth at the end
            return;
        }
 public IphoneViewModel(IBluetoothService bluetoothService, ISensorDataService sensorDataService, IUserDialogs userDialogs, IDataLoggingService dataLoggingService, IDeviceSlotService deviceSlotService, IMvxLog log)
     : base(bluetoothService, sensorDataService, userDialogs, dataLoggingService, deviceSlotService, log)
 {
     BluetoothViewModel         = new BluetoothViewModel(bluetoothService, deviceSlotService, userDialogs, log);
     VitalSignsMonitorViewModel = new VitalSignsMonitorViewModel(bluetoothService, sensorDataService, deviceSlotService, userDialogs, log);
     //_dataLoggingService.Open();
 }
Exemple #4
0
        private async void BtDeviceConnected(object sender, EventArgs.BTDeviceEventArgs e)
        {
            if (e.Device != null)
            {
                Console.WriteLine($"Connected to device : {e.Device.Id.ToString()}");
                IBluetoothService contactTracingService = await e.Device.GetServiceAsync(EyC19CTService.EyCtServiceUuid);

                if (contactTracingService != null)
                {
                    Console.WriteLine("Discovered the contact tracing service");

                    IBluetoothGattCharacteristic identityCharacteristic = await contactTracingService.GetCharacteristicAsync(EyC19CTService.IdentityCharacteristicUuid);

                    if (identityCharacteristic != null)
                    {
                        byte[] result = await identityCharacteristic.ReadAsync();

                        var str = System.Text.Encoding.Default.GetString(result);
                        Console.WriteLine($"Found Idenity Characterictic : {str}");
                        int rssi = await e.Device.ReadRssiAsync();

                        Console.WriteLine($"RSSI : {rssi}");
                    }
                }
            }
        }
Exemple #5
0
 // Main View Model that connects the subviews
 public MainViewModel(IBluetoothService bluetoothService, ISensorDataService sensorDataService, IUserDialogs userDialogs, IDataLoggingService dataLoggingService, IDeviceSlotService deviceSlotService, IMvxLog log)
     : base(bluetoothService, sensorDataService, userDialogs, dataLoggingService, deviceSlotService, log)
 {
     BluetoothViewModel         = new BluetoothViewModel(bluetoothService, deviceSlotService, userDialogs, log);
     DownloadViewModel          = new DownloadViewModel(bluetoothService, deviceSlotService, dataLoggingService, userDialogs, log);
     VitalSignsMonitorViewModel = new VitalSignsMonitorViewModel(bluetoothService, sensorDataService, deviceSlotService, userDialogs, log);
 }
        public MainPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
            : base(navigationService, pageDialogService)
        {
            Title             = "Main Page";
            PrintMessage      = "";
            _blueToothService = DependencyService.Get <IBluetoothService>();
            _printer          = new Printer();
            BindDeviceList();

            PrintCommand = new DelegateCommand(async() =>
            {
                if (String.IsNullOrEmpty(SelectedDevice))
                {
                    await PageDialogService.DisplayAlertAsync("Please select a Bluetooh Printer...", null, "Ok");
                }
                else
                {
                    _printer.MyPrinter = SelectedDevice;
                    if (String.IsNullOrEmpty(PrintMessage))
                    {
                        await PageDialogService.DisplayAlertAsync("Field to Print can not be empty...", null, "Ok");
                    }
                    else
                    {
                        await _printer.Reset();
                        await _printer.SetAlignCenter();
                        await _printer.WriteLine($"Normal: {PrintMessage}");
                        await _printer.LineFeed();
                        await _printer.BoldOn();
                        await _printer.WriteLine($"Bold: {PrintMessage}");
                        await _printer.BoldOff();
                        await _printer.LineFeed();
                        await _printer.WriteLine_Big($"Grande: \n{PrintMessage}");
                        await _printer.LineFeed();
                        await _printer.SetUnderLine($"Subrayado: {PrintMessage}");
                        await _printer.LineFeed();
                        await _printer.SetAlignRight();
                        await _printer.WriteLine_Bold("Negrito en la Derecha:");
                        await _printer.BoldOn();
                        await _printer.WriteLine_Bigger($"G1: {PrintMessage}", 1);
                        await _printer.BoldOff();
                        await _printer.WriteLine_Bold("Underline...");
                        await _printer.SetUnderLineOn();
                        await _printer.WriteLine_Bigger($"G2: {PrintMessage}", 2);
                        await _printer.WriteLine_Bigger($"G3: {PrintMessage}", 3);
                        await _printer.SetUnderLineOff();
                        await _printer.LineFeed(2);
                        await _printer.SetAlignCenter();
                        await _printer.WriteLine_Bold("Texto Reverse...");
                        await _printer.SetReverseOn();
                        await _printer.WriteLine_Bigger($"Reverse: {PrintMessage}", 1);
                        await _printer.SetReverseOff();
                        await _printer.WriteLine_Bigger($"Not Reverse: {PrintMessage}", 1);
                        await _printer.LineFeed(3);
                        await _printer.Reset();
                    }
                }
            });
        }
 public BluetoothDevice(IBluetoothDeviceInfo deviceInfo, IBluetoothService bluetoothService, ISchedulerProvider schedulerProvider)
 {
     _deviceInfo          = deviceInfo;
     _bluetoothService    = bluetoothService;
     _schedulerProvider   = schedulerProvider;
     _pairDeviceCommand   = new DelegateCommand(PairDevice, () => !Status.IsProcessing && !IsAuthenticated);
     _removeDeviceCommand = new DelegateCommand(RemoveDevice, () => !Status.IsProcessing && _deviceInfo.IsAuthenticated);
 }
 public BluetoothDevice(IBluetoothDeviceInfo deviceInfo, IBluetoothService bluetoothService, ISchedulerProvider schedulerProvider)
 {
     _deviceInfo = deviceInfo;
     _bluetoothService = bluetoothService;
     _schedulerProvider = schedulerProvider;
     _pairDeviceCommand = new DelegateCommand(PairDevice, () => !Status.IsProcessing && !IsAuthenticated);
     _removeDeviceCommand = new DelegateCommand(RemoveDevice, () => !Status.IsProcessing && _deviceInfo.IsAuthenticated);
 }
Exemple #9
0
 public PairingService(INFCService nfcService, IBfService bfService, ISettingsService settingsService, IBluetoothService bluetoothService)
 {
     this.nfcService       = nfcService;
     this.bfService        = bfService;
     this.settingsService  = settingsService;
     this.bluetoothService = bluetoothService;
     aes = new AesManaged();
 }
        public BluetoothPageViewModel(IBluetoothService bluetoothService, INavigationService navigationService, IUserInteraction userInteraction)
        {
            _bluetoothService  = bluetoothService;
            _navigationService = navigationService;
            _userInteraction   = userInteraction;

            SendCommand = ReactiveCommand.Create(async() => await _bluetoothService.WriteAsync("Test"));
        }
Exemple #11
0
 public DeviceViewModel(SensorDevice device, MvxNotifyPropertyChanged parentViewModel, IBluetoothService bluetoothService, IDeviceSlotService deviceSlotService, IUserDialogs userDialogs, IMvxLog log)
 {
     _device            = device;
     _parentViewModel   = parentViewModel;
     _bluetoothService  = bluetoothService;
     _deviceSlotService = deviceSlotService;
     _userDialogs       = userDialogs;
     _log = log;
 }
        public App()
        {
            InitializeComponent();

            DependencyService.Register <MockDataStore>();
            MainPage = new AppShell();

            rfidService      = DependencyService.Get <IRfidService>();
            bluetoothService = DependencyService.Get <IBluetoothService>();
        }
Exemple #13
0
        public DeviceManagerService(IBluetoothService bluetoothService, IFileManager fileManager)
        {
            _bluetoothService = bluetoothService;

            this.fileManager = fileManager;
            bluetoothService.DeviceDiscovered        += BluetoothServiceOnDeviceDiscovered;
            bluetoothService.DeviceDiscoveryComplete += BluetoothServiceDeviceDiscoveryComplete;
            bluetoothService.DeviceRemoved           += BluetoothService_DeviceRemoved;
            bluetoothService.SignalStrengthUpdated   += BluetoothService_SignalStrengthUpdated;
        }
Exemple #14
0
        public async Task ConnectAsync()
        {
            _device = await _bluetoothAdapter.GetDeviceAsync(BluetoothAddress);

            _service = await _device.GetServiceAsync(new Guid(_bluetoothServiceGuid));

            _characteristic = await _service.GetCharacteristicAsync(new Guid(_bluetoothCharacteristicGuid));

            _logger?.LogDebug("Connected");
        }
Exemple #15
0
        public Phx42DeviceService(IBluetoothService bluetoothService, IDevice device, IFileManager fileManager)
        {
            _bluetoothService = bluetoothService;
            _device           = device;
            _fileManager      = fileManager;

            PhxProperties = new Dictionary <string, string>();

            SerialNumber = device.Name;
            MacAddress   = device.Address;
        }
        public RemoteService(
            IBluetoothService socketService,
            IDispatcherService dispatcherService,
            IPlatformService platformService)
        {
            _bluetoothService  = socketService;
            _dispatcherService = dispatcherService;
            _platformService   = platformService;
            _remoteSystems     = new List <RomeRemoteSystem>();

            CommandReceived = OnCommandReceivedAsync;
        }
        public MainPageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Xamarin.Forms.DependencyService.Register <IBluetoothService>();

            bluetoothService = (DependencyService.Get <IBluetoothService>());
            bluetoothService.Init();


            ShowDeviceNameAlert = new DelegateCommand <string>(alertDeviceName);
            Title = "Main Page";
        }
        public ItemsPageViewModel()
        {
            this.DeviceList  = new ObservableCollection <BluetoothDevice>();
            this.ServiceList = new ObservableCollection <BluetoothDeviceService>();
            this.ServiceCharateristicsList = new ObservableCollection <BluetoothServiceCharateristics>();

#if DEBUG
            this.BluetoothService = new BluetoothWrapper_Dummy();
#else
            //Connect to real bluetooth wrapper
#endif
        }
Exemple #19
0
        public Task DisconnectAsync()
        {
            _characteristic = null;
            _service?.Dispose();
            _service = null;
            _device?.Dispose();
            _device = null;

            _logger?.LogDebug("Disconnected");

            return(Task.CompletedTask);
        }
        public ItemsPageViewModel()
        {
            this.DeviceList = new ObservableCollection<BluetoothDevice>();
            this.ServiceList = new ObservableCollection<BluetoothDeviceService>();
            this.ServiceCharateristicsList = new ObservableCollection<BluetoothServiceCharateristics>();

            #if DEBUG
            this.BluetoothService = new BluetoothWrapper_Dummy();
            #else
            //Connect to real bluetooth wrapper
            #endif
        }
        public WelcomePageViewModel(INavigationService navigation, IBluetoothService bluetoothService)
        {
            BluetoothCommand = ReactiveCommand.CreateFromTask(async() =>
                                                              await navigation.PushAsync <BluetoothPageViewModel>());

            IngredientsCommand = ReactiveCommand.CreateFromTask(async() =>
                                                                await navigation.PushAsync <ShowIngredientsPageViewModel>());

            IngredientsCommand.ThrownExceptions.Subscribe(ex => throw ex);

            DrinksCommand = ReactiveCommand.CreateFromTask(async() =>
                                                           await navigation.PushAsync <DrinksPageViewModel>());
        }
Exemple #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UHMS.Core.ViewModels.VitalSignsMonitorViewModel"/> class.
        /// </summary>
        /// <param name="sensorDataService">Sensor data service.</param>
        /// <param name="userDialogs">User dialogs.</param>
        /// <param name="log">Log.</param>
        public VitalSignsMonitorViewModel(IBluetoothService bluetoothService, ISensorDataService sensorDataService, IDeviceSlotService deviceSlotService,
                                          IUserDialogs userDialogs, IMvxLog log)
        {
            _bluetoothService  = bluetoothService;
            _sensorDataService = sensorDataService;
            _deviceSlotService = deviceSlotService;
            _userDialogs       = userDialogs;
            _log = log;

            InitializeGraphs();
            AttatchBluetoothEventHandlers();
            InsertSlots();
        }
Exemple #23
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="navService">Navigation service instance resolved by DI.</param>
        /// <param name="dispatcherService">Dispatcher service instance resolved by DI.</param>
        public VMMainPage(INavigationService navService, IDispatcherService dispatcherService,
                          ISettingsService settingsService, IApiService apiService, INFCService nfcService,
                          IBluetoothService bluetoothService, IBfService bfService, IPairingService pairingService, IUxService uxService)
        {
            this.navService        = navService;
            this.settingsService   = settingsService;
            this.dispatcherService = dispatcherService;
            this.apiService        = apiService;
            this.nfcService        = nfcService;
            this.bluetoothService  = bluetoothService;
            this.bfService         = bfService;
            this.pairingService    = pairingService;
            this.uxService         = uxService;

            this.setAsBusyCommand                    = new DelegateCommand <bool>(SetAsBusyExecte);
            this.logOutCommand                       = new DelegateCommand(LogOutExecute);
            this.navigateToSecureEmailCommand        = new DelegateCommand(NavigateToSecureEmailExecute);
            this.navigateToShareSecureMessageCommand = new DelegateCommand(NavigateToShareSecureMessageExecute);
            this.startNfcPairingCommand              = new DelegateCommand(StartNfcPairingExecute);
            this.navigateToAboutCommand              = new DelegateCommand(NavigateToAboutExecute);
            this.addressChooserCommand               = new DelegateCommand(AddressChooserExecute);
            this.sendSecureEmailCommand              = new DelegateCommand(SendSecureEmailExecute, SendSecureEmailCanExecute);
            this.shareSecureMessageCommand           = new DelegateCommand(ShareSecureMessageExecute, ShareSecureMessageCanExecute);
            this.publishMessageCommand               = new DelegateCommand(PublishMessageExecute, PublishMessageCanExecute);
            this.writeToTagCommand                   = new DelegateCommand(WriteToTagExecute, WriteToTagCanExecute);
            this.encryptSecureNoteCommand            = new DelegateCommand(EncryptSecureNoteExecute, EncryptSecureNoteCanExecute);
            this.clearLogCommand                     = new DelegateCommand(ClearLogExecute);
            this.navigateToInstructionsCommand       = new DelegateCommand(NavigateToInstructionsExecite);
            this.pairDeviceCommand                   = new DelegateCommand(PairDeviceExecute, PairDeviceCanExecute);
            //this.pairDeviceCommand = new DelegateCommand(PairDeviceExecute);

            if (this.nfcService.ConnectDefaultProximityDevice())
            {
                this.nfcService.DeviceArrived             += nfcService_DeviceArrived;
                this.nfcService.DeviceLeft                += nfcService_DeviceLeft;
                this.nfcService.MessageReceivedCompleted  += nfcService_MessageReceivedCompleted;
                this.nfcService.MessagePublishedCompleted += nfcService_MessagePublishedCompleted;
                this.nfcService.SubscribeToMessage("WriteableTag");
                this.nfcService.SubscribeToMessage("NDEF");
                this.nfcService.SubscribeToMessage("NDEF:Unknown");
                this.nfcService.SubscribeToMessage("WindowsMime");
            }
            else
            {
                uxService.ShowToastNotification("Error", AppResources.NoNfcError);
                LogMessage(AppResources.NoNfcError, NfcLogItem.ERROR_ICON);
            }

            contacts   = new Contacts();
            myIdentity = (string)settingsService.Get("email");
        }
        public DrinksPageViewModel(
            IDrinkRecipesRepository drinkRecipeRepository,
            INavigationService navigationService,
            IBluetoothService bluetoothService,
            IUserInteraction userInteraction)
        {
            _drinkRecipeRepository = drinkRecipeRepository;
            _bluetoothService      = bluetoothService;
            _navigationService     = navigationService;
            _userInteraction       = userInteraction;

            AddRecipeCommand = ReactiveCommand.CreateFromTask(async _ =>
                                                              await _navigationService.PushAsync <AddDrinkRecipePageViewModel>());
        }
Exemple #25
0
 public BaseViewModel(IBluetoothService bluetoothService,
                      ISensorDataService sensorDataService,
                      IUserDialogs userDialogs,
                      IDataLoggingService dataLoggingService,
                      IDeviceSlotService deviceSlotService,
                      IMvxLog log)
 {
     _userDialogs       = userDialogs;
     _bluetoothService  = bluetoothService;
     _sensorDataService = sensorDataService;
     _deviceSlotService = deviceSlotService;
     _log = log;
     _dataLoggingService = dataLoggingService;
 }
Exemple #26
0
        public SlotViewModel(DeviceSlot slot, IDeviceSlotService deviceSlotService, IMvxLog log)
        {
            _bluetoothService  = Mvx.Resolve <IBluetoothService>();
            _deviceSlotService = deviceSlotService;
            _userDialogs       = Mvx.Resolve <IUserDialogs>();
            _log = log;

            _slot = slot;

            _deviceSlotService.DeviceAdded         += SubscribeToUpdates;
            _deviceSlotService.DeviceWillBeRemoved += UnsubscribeToUpdates;
            _deviceSlotService.SessionInfoChanged  += UpdateSessionStatus;
            _deviceSlotService.BatteryInfoChanged  += UpdateBatteryStatus;
        }
Exemple #27
0
        public ScanViewModel()
        {
            rfidService      = DependencyService.Get <IRfidService>();
            bluetoothService = DependencyService.Get <IBluetoothService>();

            Title = "Scan";

            ScanCommand      = new Command(Scan);
            PlaySoundCommand = new Command(PlaySound);

            MessagingCenter.Subscribe <string, string>(this, "Scan", (sender, arg) =>
            {
                Scan();
            });
        }
Exemple #28
0
 public BluetoothSetupViewModel(IBluetoothService bluetoothService, IBluetoothProfileActivator bluetoothProfileActivator, ISchedulerProvider schedulerProvider)
 {
     _bluetoothService          = bluetoothService;
     _bluetoothProfileActivator = bluetoothProfileActivator;
     _schedulerProvider         = schedulerProvider;
     _roDevices             = new ReadOnlyObservableCollection <IBluetoothDevice>(_devices);
     _scanForDevicesCommand = new DelegateCommand(ScanForDevices, CanScanForDevices);
     _status = ViewModelStatus.Error(Resources.Bluetooth_NoDevices_RequiresScan);
     _bluetoothProfileActivator.PropertyChanges(bs => bs.IsEnabled)
     .Subscribe(_ =>
     {
         OnPropertyChanged("IsEnabled");
         _scanForDevicesCommand.RaiseCanExecuteChanged();
     });
 }
 public BluetoothSetupViewModel(IBluetoothService bluetoothService, IBluetoothProfileActivator bluetoothProfileActivator, ISchedulerProvider schedulerProvider)
 {
     _bluetoothService = bluetoothService;
     _bluetoothProfileActivator = bluetoothProfileActivator;
     _schedulerProvider = schedulerProvider;
     _roDevices = new ReadOnlyObservableCollection<IBluetoothDevice>(_devices);
     _scanForDevicesCommand = new DelegateCommand(ScanForDevices, CanScanForDevices);
     _status = ViewModelStatus.Error(Resources.Bluetooth_NoDevices_RequiresScan);
     _bluetoothProfileActivator.PropertyChanges(bs => bs.IsEnabled)
                      .Subscribe(_ =>
                                     {
                                         OnPropertyChanged("IsEnabled");
                                         _scanForDevicesCommand.RaiseCanExecuteChanged();
                                     });               
                          
 }
        public BluetoothProfileActivator(IBluetoothService bluetoothService,
            IPersonalizationSettings personalizationSettings,
            ISchedulerProvider schedulerProvider,
            ILoggerFactory loggerFactory)
        {
            _bluetoothService = bluetoothService;
            _personalizationSettings = personalizationSettings;
            _schedulerProvider = schedulerProvider;
            _logger = loggerFactory.CreateLogger(GetType());
            _bluetoothEventLoop = _schedulerProvider.CreateEventLoopScheduler("BluetoothActivator");
            _logger.Verbose("BluetoothProfileActivator.ctor();");

            _profileActivated = _bluetoothService.IdentitiesActivated(_bluetoothEventLoop)
                .Retry()
                .Repeat()
                .Log(_logger, "IdentitiesActivated")
                .Select(Translate)
                .Publish();

            //HACK: Avoid work in the ctor. Can be smart here using SelectMany on the IsEnabled + Connecting when ProfileActivated is subscribed to. -LC
            if (_bluetoothService.IsSupported && IsEnabled)
                _connection.Disposable = _profileActivated.Connect();
        }
Exemple #31
0
 public static void InitApp(IBluetoothService implementedBluetoothService, IMessageService implementedMessageService)
 {
     BluetoothService = implementedBluetoothService;
     MessageService   = implementedMessageService;
 }
Exemple #32
0
 public BleReader(IBluetoothService bluetoothService)
 {
     _bluetoothService = bluetoothService;
 }
        private BluetoothImpl()
        {
            try
            {
                if (PlatformUtils.IsWindows && SettingsProvider.Instance.UseBluetoothWinRT &&
                    PlatformUtils.IsWindowsContractsSdkSupported)
                {
                    Log.Debug("BluetoothImpl: Using WinRT.BluetoothService");
                    _backend = new Bluetooth.WindowsRT.BluetoothService();
                }
#if WindowsNoARM
                else if (PlatformUtils.IsWindows)
                {
                    Log.Debug("BluetoothImpl: Using Windows.BluetoothService");
                    _backend = new Bluetooth.Windows.BluetoothService();
                }
#else
                else if (PlatformUtils.IsWindows && PlatformUtils.IsWindowsContractsSdkSupported)
                {
                    Log.Debug("BluetoothImpl: Using WinRT.BluetoothService (ARM)");
                    _backend = new Bluetooth.WindowsRT.BluetoothService();
                }
#endif
                else if (PlatformUtils.IsLinux)
                {
                    Log.Debug("BluetoothImpl: Using Linux.BluetoothService");
                    _backend = new Bluetooth.Linux.BluetoothService();
                }
                else
                {
                    Log.Warning("BluetoothImpl: Using Dummy.BluetoothService");
                    _backend = new Dummy.BluetoothService();
                }
            }
            catch (PlatformNotSupportedException)
            {
                Log.Error("BluetoothImpl: Critical error while preparing bluetooth backend");
                Log.Error("BluetoothImpl: Backend swapped out with non-functional dummy object in order to prevent crash");
                _backend = new Dummy.BluetoothService();
            }

            _cancelSource = new CancellationTokenSource();
            _loop         = Task.Run(DataConsumerLoop, _cancelSource.Token);

            _backend.Connecting          += (sender, args) => Connecting?.Invoke(this, EventArgs.Empty);
            _backend.NewDataAvailable    += OnNewDataAvailable;
            _backend.NewDataAvailable    += (sender, bytes) => NewDataReceived?.Invoke(this, bytes);
            _backend.BluetoothErrorAsync += (sender, exception) => OnBluetoothError(exception);

            _backend.RfcommConnected += (sender, args) => Task.Run(async() =>
                                                                   await Task.Delay(150).ContinueWith((_) =>
            {
                if (RegisteredDeviceValid)
                {
                    Connected?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    Log.Error("BluetoothImpl: Suppressing Connected event, device not properly registered");
                }
            }));

            _backend.Disconnected += (sender, reason) =>
            {
                if (!SuppressDisconnectionEvents)
                {
                    Disconnected?.Invoke(this, reason);
                }
            };

            MessageReceived += SPPMessageHandler.Instance.MessageReceiver;
        }
Exemple #34
0
 public App(IBluetoothService bluetoothService)
 {
     _bluetoothService = bluetoothService;
     InitializeComponent();
     MainPage = new MainPage(bluetoothService);
 }