コード例 #1
0
        public LinearAccelerationPageViewModel()
        {
            // Command to start the subscription
            ToggleSubscribeSwitchCommand = new Xamarin.Forms.Command(
                async() =>
            {
                if (IsSubscribeSwitchOn)
                {
                    ConnectionStatusText = "Connecting...";
                    await MovesenseDeviceVM.Connect();
                    ConnectionStatusText = "Subscribing...";

                    subscription = await MovesenseDeviceVM.MovesenseDevice.SubscribeAccelerometerAsync(
                        (d) =>
                    {
                        PlotData(d.Data.Timestamp, d.Data.AccData[0].X, d.Data.AccData[0].Y, d.Data.AccData[0].Z);
                    },
                        26);
                    ConnectionStatusText = "Subscribed";
                }
                else
                {
                    // Unsubscribe
                    subscription.Unsubscribe();
                    ConnectionStatusText = "Unsubscribed";
                    await MovesenseDeviceVM.Disconnect();
                    ConnectionStatusText = "Disconnected";
                }
            }
                , () => (MovesenseDeviceVM != null) // Enable command only if we've got a device
                );

            InitPlotModel();
        }
コード例 #2
0
 public void OnExit()
 {
     subscription?.Unsubscribe();
 }