Beispiel #1
0
 public App(IBluetoothManager bluetoothManager, ILocalStorageManager localStorageManager)
 {
     Instance = this;
     PlatformSpecificManagers.BluetoothManager = bluetoothManager;
     PlatformSpecificManagers.LocalStorageManager = localStorageManager;
     MainPage = new Biketimer.Views.Slideout.SlideoutNavigation();
 }
 public BluetoothHelper()
 {
     _Manager = BluetoothManager.Instance;
     //_Myexception = new ExceptionHandler();
     //PrinterCentral = new PrinterHelper();
     GloVa.DevicesDiscovered = new List <RemoteDevice>();
 }
Beispiel #3
0
        public void Initialize()
        {
            ListDevices = new ObservableCollection <BTDevice>();

            IBluetoothManager btMan = DependencyService.Get <IBluetoothManager>();
            var listBTDevices       = btMan.GetBondedDevices();

            if (listBTDevices != null && listBTDevices.Count > 0)
            {
                foreach (var device in listBTDevices)
                {
                    Device = new BTDevice
                    {
                        Name    = device.Name,
                        UUID    = device.UUID,
                        Address = device.Address
                    };
                    ListDevices.Add(Device);
                }
            }
            else
            {
                lbl1 = "Bluetoothデバイスがありません。";
            }
        }
        public KeyManagementPageViewModel(KeyVendorUser user, IBluetoothManager bluetooth)
        {
            _bluetooth = bluetooth;
            _user      = user;

            KeyList = "";
        }
Beispiel #5
0
 public ManufacturerNameStringCharacteristicBuilder(IBluetoothManager bluetoothManager)
 {
     _Builder = bluetoothManager.NewGattCharacteristicBuilder();
     _Builder.SetUuid(CHARACTERISTIC_MANUFACTURER_NAME)
     .SetPermissions(PERMISSIONS)
     .SetProperties(PROPERTIES);
 }
Beispiel #6
0
 public RfcommServerPage()
 {
     BluetoothManager = DependencyService.Get <IManagerManager>().BluetoothManager;
     ServiceProviders = new ObservableCollection <IRfcommServiceProvider>();
     InitializeComponent();
     ProviderListView.ItemsSource = ServiceProviders;
 }
Beispiel #7
0
        public static async Task <bool> TurnOnBluetoothAsync(
            this IBluetoothManager bluetooth, uint timeout, uint delay)
        {
            return(await Task.Run(async() =>
            {
                if (!bluetooth.IsBluetoothOn)
                {
                    bluetooth.IsBluetoothOn = true;

                    for (int i = 0; i *delay < timeout; i++)
                    {
                        if (!bluetooth.IsBluetoothOn)
                        {
                            await Task.Delay((int)delay);
                        }
                        else
                        {
                            break;
                        }

                        Debug.WriteLine("turning BT on...");
                    }
                }

                return bluetooth.IsBluetoothOn;
            }));
        }
Beispiel #8
0
        public static async Task <BluetoothDevice> FindBluetoothDeviceByAddressAsync(
            this IBluetoothManager bluetooth, string address, uint delay)
        {
            return(await Task.Run(async() =>
            {
                await bluetooth.StartDeviceDiscoveryAsync(1000, delay);

                while (bluetooth.IsDiscovering)
                {
                    foreach (var device in bluetooth.DeviceList)
                    {
                        if (device.Address == address)
                        {
                            bluetooth.StopDiscovering();
                            return new BluetoothDevice()
                            {
                                Name = device.Name, Address = device.Address
                            };
                        }
                    }

                    Debug.WriteLine("looking fot device with address...");
                    await Task.Delay((int)delay);
                }

                return null;
            }));
        }
Beispiel #9
0
        public static async Task <bool> StartDeviceDiscoveryAsync(
            this IBluetoothManager bluetooth, uint timeout, uint delay)
        {
            return(await Task.Run(async() =>
            {
                if (!bluetooth.IsDiscovering)
                {
                    bluetooth.StartDiscovering();

                    for (int i = 0; i *delay < timeout; i++)
                    {
                        if (!bluetooth.IsDiscovering)
                        {
                            await Task.Delay((int)delay);
                        }
                        else
                        {
                            break;
                        }

                        Debug.WriteLine("starting BT discovering...");
                    }
                }

                return bluetooth.IsDiscovering;
            }));
        }
Beispiel #10
0
        public static async Task <bool> CreateConnectionAsync(
            this IBluetoothManager bluetooth, uint timeout, uint delay)
        {
            return(await Task.Run(async() =>
            {
                if (!bluetooth.IsConnected)
                {
                    bluetooth.OpenConnection();

                    for (int i = 0; i *delay < timeout; i++)
                    {
                        if (!bluetooth.IsConnected)
                        {
                            await Task.Delay((int)delay);
                        }
                        else
                        {
                            break;
                        }

                        Debug.WriteLine("trying to connect...");
                    }
                }

                return bluetooth.IsConnected;
            }));
        }
Beispiel #11
0
        public static async Task <bool> BondWithBluetoothDeviceAsync(
            this IBluetoothManager bluetooth, string address, int timeout, uint delay)
        {
            return(await Task.Run(async() =>
            {
                if (!bluetooth.IsBonded)
                {
                    bluetooth.CreateBond(address);

                    for (int i = 0; i *delay < timeout; i++)
                    {
                        if (!bluetooth.IsBonded)
                        {
                            await Task.Delay((int)delay);
                        }
                        else
                        {
                            break;
                        }

                        Debug.WriteLine("trying to bond...");
                    }
                }

                return bluetooth.IsBonded;
            }));
        }
Beispiel #12
0
        public BluetoothDeviceListPage()
        {
            bluetoothManager    = DependencyService.Get <IBluetoothManager>();
            bluetoothDeviceList = new ObservableCollection <IBluetoothDevice>();
            resetDeviceList();
            ListView bluetoothDeviceListView = new ListView();

            bluetoothDeviceListView.ItemSelected += onDeviceSelected;
            bluetoothDeviceListView.ItemsSource   = bluetoothDeviceList;
            bluetoothDeviceListView.ItemTemplate  = new DataTemplate(typeof(BluetoothDeviceCell));

            qrCodeConnectButton          = new Button();
            qrCodeConnectButton.Text     = "QRCode";
            qrCodeConnectButton.Clicked += onQRCodeConnectClicked;

            scanDevicesButton          = new Button();
            scanDevicesButton.Clicked += (object sender, EventArgs e) =>
            {
                resetDeviceList();
                bluetoothManager.SearchForBlutoothDevices();
            };
            bluetoothManager.onDiscoveryStarted  += onDiscoveryStarted;
            bluetoothManager.onDevicesFound      += onDevicesFound;
            bluetoothManager.onDiscoveryFinished += onDiscoveryFinished;
            scanDevicesButton.Text = "Scan Devices";
            Content = new StackLayout
            {
                Children =
                {
                    qrCodeConnectButton,
                    scanDevicesButton,
                    bluetoothDeviceListView
                }
            };
        }
        public KeyVendorTerminal(IBluetoothManager bluetoothManager)
        {
            _bluetoothManager = bluetoothManager;

            SplittingEnabled = true;
            PartLenght       = 20;
            TimeToReadPart   = 200;
        }
 public RfcommRXConnectionGroup(IBluetoothManager bluetoothManager, RXConnectionManager connectionManager)
 {
     BluetoothManager = bluetoothManager;
     Listener         = new RfcommAdvertiseRXListener(this);
     //Scanner = new RfcommRXScanner(this);
     Scanner           = new RfcommFromAttRXScanner(this);
     ConnectionManager = connectionManager;
 }
Beispiel #15
0
        public BatteryServiceWrapper(IBluetoothManager bluetoothManager)
        {
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            builder.SetUuid(BATTERY_SERVICE_UUID).SetServiceType(GattServiceType.Primary);
            BatteryLevelCharacteristicWrapper = new BatteryLevelCharacteristicWrapper(bluetoothManager);
            builder.AddCharacteristics(BatteryLevelCharacteristicWrapper.GattServerCharacteristic);
            GattServerService = builder.Build();
        }
 public ClientRfcommServiceWrapper(IBluetoothManager bluetoothManager)
 {
     BluetoothManager             = bluetoothManager;
     AddressCharacteristicWrapper = new ClientRfcommAddressCharacteristicWrapper(this);
     GattServerService            = BluetoothManager.NewGattServiceBuilder()
                                    .SetUuid(Constants.ClientRfcommServiceGuid)
                                    .AddCharacteristics(AddressCharacteristicWrapper.GattServerCharacteristic)
                                    .Build();
 }
Beispiel #17
0
 public BleDeviceSelectorWindow(IBluetoothManager bluetoothManager, ConnectionProfile connectionProfile)
 {
     BluetoothManager     = bluetoothManager;
     ConnectionProfile    = connectionProfile;
     ScanResultItemSource = new ObservableCollection <BleDeviceViewModel>();
     InitializeComponent();
     DeviceListView.ItemsSource = ScanResultItemSource;
     IsVisibleChanged          += BleDeviceSelectorWindow_IsVisibleChanged;
 }
Beispiel #18
0
        public LogPageViewModel(KeyVendorUser user, IBluetoothManager bluetooth)
        {
            _bluetooth = bluetooth;
            _user      = user;

            LogList = new ObservableCollection <LogInfo>();
            Indexer = 0;

            GetLogAsync(Indexer);
        }
 public RXRfcommServiceProvider(IBluetoothManager bluetoothManager, RfcommServiceProvider win10Provider)
 {
     BluetoothManager                    = bluetoothManager;
     Win10RfcommServiceProvider          = win10Provider;
     RfcommConnectionList                = new List <RXRFCommConnection>();
     RfcommServiceProviderSocketListener = new StreamSocketListener();
     RfcommServiceProviderSocketListener.ConnectionReceived += RfcommServiceProviderSocketListener_ConnectionReceived;
     RfcommServiceProviderSocketListener.BindServiceNameAsync("{" + ServiceId.ToString().ToUpper() + "}", SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication).AsTask().Wait();
     InitializeServiceSdpAttributes(Win10RfcommServiceProvider, "TestService");
 }
        public GyroscopeServiceWrapper(IBluetoothManager bluetoothManager)
        {
            BluetoothManager = bluetoothManager;
            AngularVelocityCharacteristicWrapper = new GyroscopeAngularVelocityCharacteristicWrapper(this);
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            GattServerService = builder.SetUuid(Constant.GyroscopeServiceGuid)
                                .AddCharacteristics(AngularVelocityCharacteristicWrapper.GattServerCharacteristic)
                                .Build();
        }
Beispiel #21
0
        public ClientCharacteristicConfigurationDescriptorWrapper(IBluetoothManager bluetoothManager)
        {
            _ClientConfigurations = new Dictionary <IBluetoothDevice, Configuration>();
            var builder = bluetoothManager.NewGattDescriptorBuilder();

            builder.SetUuid(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID).SetPermissions(PERMISSIONS);
            GattServerDescriptor          = builder.Build();
            GattServerDescriptor.OnRead  += _OnRead;
            GattServerDescriptor.OnWrite += _OnWrite;
        }
        public KeepNotifyingCharacteristicWrapper(IBluetoothManager bluetoothManager)
        {
            ClientCharacteristicConfigurationDescriptorWrapper = new ClientCharacteristicConfigurationDescriptorWrapper(bluetoothManager);
            IGattCharacteristicBuilder builder = bluetoothManager.NewGattCharacteristicBuilder();

            builder.SetUuid(UUID).SetPermissions(PERMISSIONS).SetProperties(PROPERTIES);
            builder.AddDescriptors(ClientCharacteristicConfigurationDescriptorWrapper.GattServerDescriptor);
            GattServerCharacteristic         = builder.Build();
            GattServerCharacteristic.OnRead += _OnRead;
        }
Beispiel #23
0
        public VendingPageViewModel(KeyVendorUser user, IBluetoothManager bluetooth)
        {
            _bluetooth = bluetooth;
            _user      = user;

            IsToolbarVisible = _user.HasAdminRights;
            KeyList          = new ObservableCollection <string>();

            GetKeyListAsync();
        }
        public ConnectionPageViewModel(KeyVendorUser user, IBluetoothManager bluetooth)
        {
            _user      = user;
            _bluetooth = bluetooth;

            ButtonText = TextConstants.ButtonStartRefreshing;
            DeviceList = _bluetooth.DeviceList;

            StartRefreshingAsync();
        }
Beispiel #25
0
        public RfcommSettingPage()
        {
            InitializeComponent();
            IManagerManager managerManager = DependencyService.Get <IManagerManager>();

            BluetoothManager = managerManager.BluetoothManager;
            var rxConnManager = managerManager.RXConnectionManager;
            RfcommRXConnectionGroup rfcommConnectionGroup = new RfcommRXConnectionGroup(BluetoothManager, rxConnManager);

            rxConnManager.AddConnectionGroup(rfcommConnectionGroup);
        }
Beispiel #26
0
        public TestServiceWrapper(IBluetoothManager bluetoothManager)
        {
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            builder.SetUuid(SERVICE_UUID).SetServiceType(GattServiceType.Primary);
            TestCharacteristicWrapper          = new TestCharacteristicWrapper(bluetoothManager);
            KeepNotifyingCharacteristicWrapper = new KeepNotifyingCharacteristicWrapper(bluetoothManager);
            builder.AddCharacteristics(TestCharacteristicWrapper.GattServerCharacteristic);
            builder.AddCharacteristics(KeepNotifyingCharacteristicWrapper.GattServerCharacteristic);
            GattServerService = builder.Build();
        }
 public BleDeviceSelectorDialog(IBluetoothManager bluetoothManager, ConnectionProfile connectionProfile)
 {
     ScanResultItemSource = new ObservableCollection <BleDeviceViewModel>();
     BluetoothManager     = bluetoothManager;
     ConnectionProfile    = connectionProfile;
     this.InitializeComponent();
     ScanResultListView.ItemsSource = ScanResultItemSource;
     ConnectButton.Click           += ConnectButton_Click;
     Opened += BleDeviceSelectorDialog_Opened;
     Closed += BleDeviceSelectorDialog_Closed;
 }
Beispiel #28
0
        public TranspondCharacteristicWrapper(IBluetoothManager bluetoothManager)
        {
            ClientCharacteristicConfigurationDescriptorWrapper = new ClientCharacteristicConfigurationDescriptorWrapper(bluetoothManager);
            var builder = bluetoothManager.NewGattCharacteristicBuilder();

            GattServerCharacteristic = builder.SetUuid(UUID)
                                       .AddDescriptors(ClientCharacteristicConfigurationDescriptorWrapper.GattServerDescriptor)
                                       .SetPermissions(PERMISSIONS)
                                       .SetProperties(PROPERTIES)
                                       .Build();
        }
Beispiel #29
0
 public KeyboardServiceWrapper(IBluetoothManager bluetoothManager)
 {
     BluetoothManager = bluetoothManager;
     KeyActionCharacteristicWrapper   = new KeyActionCharacteristicWrapper(this);
     MouseActionCharacteristicWrapper = new MouseActionCharacteristicWrapper(this);
     GattServerService = BluetoothManager.NewGattServiceBuilder()
                         .SetUuid(Guid)
                         .AddCharacteristics(KeyActionCharacteristicWrapper.GattServerCharacteristic)
                         .AddCharacteristics(MouseActionCharacteristicWrapper.GattServerCharacteristic)
                         .Build();
 }
Beispiel #30
0
        public DeviceInfomationServiceBuilder(IBluetoothManager bluetoothManager)
        {
            BluetoothManager = bluetoothManager;
            var manufacturerNameStringCharacteristic = new ManufacturerNameStringCharacteristicBuilder(BluetoothManager).Build();

            manufacturerNameStringCharacteristic.OnRead  += OnManufacturerNameStringCharacteristicRead;
            manufacturerNameStringCharacteristic.OnWrite += OnManufacturerNameStringCharacteristicWrite;
            _ServiceBuilder = BluetoothManager.NewGattServiceBuilder().SetUuid(SERVICE_DEVICE_INFORMATION)
                              .SetServiceType(GattServiceType.Primary)
                              .AddCharacteristics(manufacturerNameStringCharacteristic);
        }
Beispiel #31
0
        public MainPageViewModel()
        {
            lbl1 = "Bluetoothデバイス一覧";
            Initialize();
            IBluetoothManager btMan = DependencyService.Get <IBluetoothManager>();

            btMan.DataReceived += (sender, e) =>
            {
                Console.WriteLine("#debug {0}", e.Data);
            };

            btMan.Start();
        }
        public SmartSwitchViewModel()
        {
            // instantiate/retrieve Bluetooth manager
            _btManager = DependencyService.Get<IBluetoothManager>();

            _devices = new List<DeviceInfo>();

            _devices.Add(SelectedDevice);

            // refresh command
            Refresh = new Command( async () =>
            {
                try
                {
                    // disconnect the Bluetooth mnager from any existing connections
                    _btManager.Disconnect();
                    ErrorMessage = string.Empty;
                    // get the paired devices and select the first one
                    Devices = await _btManager.GetPairedDevices();
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }

                if (Devices.Count > 0)
                {
                    // This was changed for Xamarin.Forms
                    // SelectedDevice = Devices[0];
                    // SelectedDeviceIndex = -1; ;
                    SelectedDeviceIndex = 0;
                }

                // Notify the listeners of the affected properties
                RaisePropertyChanged("CanConnect");
                RaisePropertyChanged("IsConnected");
            });

            // Connect command
            Connect = new Command(async () => await ConnectToBT(), () => CanConnect);

            // there is no command for OnOff as WindowsPhone does not support it for toggleSwitch
            // instead IsOn property is used.

            // if you wish to use plug-in and a command to launch web browser, this may be helpful
            // http://stackoverflow.com/questions/16616774/mvvmcross-how-to-navigate-to-something-besides-a-viewmodel
        }