private async Task DiscoverDevices() { var devices = await CargoClient.GetConnectedDevicesAsync(); if (devices.Count() > 0) { // must create on the UI thread for various Binding reasons _deviceInfo = devices[0]; Application.Current.Dispatcher.BeginInvoke(new Action(async() => { // TODO: support more than one device? InitializeCargoLogging(); CargoClient = await CargoClient.CreateAsync(_deviceInfo); IsConnected = true; //TODO: call an "OnConnected" function Properties = new BandProperties(CargoClient); Theme = new BandTheme(CargoClient); Sensors = new BandSensors(CargoClient); Tiles = new BandTiles(CargoClient); })); } }
public static async Task<CargoClient> CreateAsync(IBandInfo deviceInfo) { if (deviceInfo.ConnectionType != BandConnectionType.Bluetooth) { throw new ArgumentException("Only use BlutoothClient to instantiate Bluetooth devices"); } // since constructors can't be async (and we can't use the builtin CreateAsync since it will // choke on Bluetooth) wrap the creation in a Task return await Task.Run<CargoClient>(() => { var client = new CargoClient(new BluetoothDeviceTransport((BluetoothDeviceInfo)deviceInfo), null, null, null, null); // if we don't set this most actions will fail. I assume this causes weirdness if the Band is not in // App mode (perhaps during initial setup?), but in reality we always seem to be in App mode // REMOVED FROM LATEST DLL: client.deviceTransportApp = RunningAppType.App; return client; }); }
public static async Task <CargoClient> CreateAsync(IBandInfo deviceInfo) { if (deviceInfo.ConnectionType != BandConnectionType.Bluetooth) { throw new ArgumentException("Only use BlutoothClient to instantiate Bluetooth devices"); } // since constructors can't be async (and we can't use the builtin CreateAsync since it will // choke on Bluetooth) wrap the creation in a Task return(await Task.Run <CargoClient>(() => { var client = new CargoClient(new BluetoothDeviceTransport((BluetoothDeviceInfo)deviceInfo), null, null, null, null); // if we don't set this most actions will fail. I assume this causes weirdness if the Band is not in // App mode (perhaps during initial setup?), but in reality we always seem to be in App mode // REMOVED FROM LATEST DLL: client.deviceTransportApp = RunningAppType.App; return client; })); }
public static void Start() { if (Instance == null) { Create(); } // While I don't love the whole Timer(1) thing, it simply means that we trigger the first run immediately // TODO: Since this could potentially cause race conditions if someone really wanted to garauntee order // of execution we could split out object creation from Start(). Timer timer = new Timer(1); timer.Elapsed += async(sender, e) => { if (!Instance.IsConnected) { await Instance.DiscoverDevices(); } else { // make sure we still have devices var devices = await CargoClient.GetConnectedDevicesAsync(); if (!(devices.Count() > 0 && devices[0].Id == Instance._deviceInfo.Id)) { Instance.IsConnected = false; } } // only reset once we finished processing timer.Interval = 1000; timer.Start(); }; timer.AutoReset = false; timer.Start(); }
public BandSensors(CargoClient client) { _client = client; Init(); }
public BandTiles(CargoClient client) { _client = client; }
public BandSensors(CargoClient client) { _client = client; }
public BandPedometer(CargoClient client) { _client = client; Init(); }
public BandTheme(CargoClient client) { _client = client; }
public BandPedometer(CargoClient client) { _client = client; }
internal BandProperties(CargoClient client) { _client = client; }
internal BandProperties(CargoClient client) { _client = client; Init(); }