public DeviceLandingPageViewModel(ParticleDevice device) { Device = device; if (!device.Connected) { SetLock(); IsBusy = false; } }
public async Task<bool> GetDevice(string id) { IsBusy = true; Device = await ParticleCloud.SharedInstance.GetDeviceAsync(id); if (Device == null) { //device not owned var success = await ParticleCloud.SharedInstance.ClaimDeviceAsync(id); if (success) { Device = await ParticleCloud.SharedInstance.GetDeviceAsync(id); IsBusy = false; return true; } else { IsBusy = false; var device = InternetButtonHelper.GetDeviceName(id); Application.Current.MainPage.DisplayAlert("Uh Oh", $"Can you get a Xamarin to help reset {device}?", "Will do"); return false; } } else if (Device.Connected) { //Device is owned and connected IsBusy = false; return true; } else if (!Device.Connected) { //Device is owned but disconnected IsBusy = false; return true; } return false; //var success = await ParticleCloud.SharedInstance.ClaimDeviceAsync(id); //if (success) //{ // Device = await ParticleCloud.SharedInstance.GetDeviceAsync(id); // IsBusy = false; // return true; //} //else //{ // IsBusy = false; // var device = InternetButtonHelper.GetDeviceName(id); // Application.Current.MainPage.DisplayAlert("Uh Oh", $"Someone already has this device claimed, can you please ask a Xamarin to reset {device}", "Will do"); // return false; //} }
public ChangeLEDColorViewModel(ParticleDevice device, Dictionary<string, string> variables) { ColorBoxColor = Color.FromRgb(0, 0, 0); Makeup.R = ToInt32(variables["red"]); Makeup.G = ToInt32(variables["grn"]); Makeup.B = ToInt32(variables["blu"]); ColorBoxColor = Color.FromHsla(Makeup.R, Makeup.G, Makeup.B); Device = device; }
public ChangeLEDColorPage(ParticleDevice device, Dictionary<string, string> variables) { Title = "RBG LED"; BackgroundColor = AppColors.BackgroundColor; ViewModel = new ChangeLEDColorViewModel(device, variables); BindingContext = ViewModel; var indicator = new ActivityIndicator { HeightRequest = Device.OnPlatform(50, 30, 50) }; var colorPreview = new BoxView { HeightRequest = 100 }; var redSlider = new Slider { StyleId = "redSlider", Minimum = 0, Maximum = 255, Value = 0 }; var greenSlider = new Slider { StyleId = "greenSlider", Minimum = 0, Maximum = 255, Value = 0 }; var blueSlider = new Slider { StyleId = "blueSlider", Minimum = 0, Maximum = 255, Value = 0 }; var push = new StyledButton { StyleId = "pushRGBvalueButton", Text = "PUSH TO PHOTON", BackgroundColor = AppColors.Blue, CssStyle = "button", BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight, VerticalOptions = LayoutOptions.Fill }; var lightShow = new StyledButton { StyleId = "startLightShowButton", Text = "START A LIGHT SHOW", BackgroundColor = AppColors.Green, CssStyle = "button", BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight, VerticalOptions = LayoutOptions.End }; var previewLabel = new StyledLabel { CssStyle = "body", Text = "Color Preview:", HorizontalOptions = LayoutOptions.Start }; var rLabel = new StyledLabel { CssStyle = "body", Text = "R Value", HorizontalOptions = LayoutOptions.Start }; var gLabel = new StyledLabel { CssStyle = "body", Text = "G Value", HorizontalOptions = LayoutOptions.Start }; var bLabel = new StyledLabel { CssStyle = "body", Text = "B Value", HorizontalOptions = LayoutOptions.Start }; Func<RelativeLayout, View, double> layoutAfterPrevious = (p, v) => Device.OnPlatform( v.Y + v.Height + 5, v.Y + v.Height + 5, v.Y + v.Height + 2); RelativeLayout relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(previewLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.Constant(10) ); relativeLayout.Children.Add(colorPreview, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(previewLabel, layoutAfterPrevious), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(AppSettings.ButtonHeight * 2) ); relativeLayout.Children.Add(rLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(colorPreview, layoutAfterPrevious) ); relativeLayout.Children.Add(redSlider, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(rLabel, layoutAfterPrevious), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); relativeLayout.Children.Add(gLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(redSlider, layoutAfterPrevious) ); relativeLayout.Children.Add(greenSlider, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(gLabel, layoutAfterPrevious), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); relativeLayout.Children.Add(bLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(greenSlider, layoutAfterPrevious) ); relativeLayout.Children.Add(blueSlider, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(bLabel, layoutAfterPrevious), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); relativeLayout.Children.Add(indicator, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(blueSlider, layoutAfterPrevious), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(Device.OnPlatform(50,50,25)) ); relativeLayout.Children.Add(lightShow, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(AppSettings.ButtonHeight) ); relativeLayout.Children.Add(push, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(lightShow, (p, v) => v.Y - AppSettings.ButtonHeight - 10), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(AppSettings.ButtonHeight) ); // StackLayout layout = new StackLayout //{ // VerticalOptions = LayoutOptions.CenterAndExpand, // Padding = new Thickness(AppSettings.Margin, 10, AppSettings.Margin, AppSettings.Margin), // Spacing = 10, // Children = { // new StyledLabel { CssStyle = "body", Text = "Color Preview:", HorizontalOptions = LayoutOptions.Start }, // colorPreview, // new StyledLabel { CssStyle = "body", Text = "R Value", HorizontalOptions = LayoutOptions.Start }, // redSlider, // new StyledLabel { CssStyle = "body", Text = "G Value", HorizontalOptions = LayoutOptions.Start }, // greenSlider, // new StyledLabel { CssStyle = "body", Text = "B Value", HorizontalOptions = LayoutOptions.Start }, // blueSlider, // indicator, // push, // lightShow // } //}; if (Device.OS == TargetPlatform.iOS) { push.FontFamily = "SegoeUI-Light"; push.FontSize = 16; push.TextColor = Color.FromHex("#ffffff"); lightShow.FontFamily = "SegoeUI-Light"; lightShow.FontSize = 16; lightShow.TextColor = Color.FromHex("#ffffff"); } var off = new ToolbarItem { Text = "LEDs Off" }; Content = relativeLayout; indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android) indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); redSlider.SetBinding(Slider.ValueProperty, "R", BindingMode.TwoWay); greenSlider.SetBinding(Slider.ValueProperty, "G", BindingMode.TwoWay); blueSlider.SetBinding(Slider.ValueProperty, "B", BindingMode.TwoWay); colorPreview.SetBinding(BoxView.BackgroundColorProperty, "ColorBoxColor"); push.SetBinding(Button.CommandProperty, "PushColorCommand"); lightShow.SetBinding(Button.CommandProperty, "LightShowCommand"); off.SetBinding(ToolbarItem.CommandProperty, "LedsOffCommand"); ToolbarItems.Add(off); }
/// <summary> /// Initializes a new instance of the <see cref="Variable"/> class. /// </summary> /// <param name="device">The device.</param> public Variable(ParticleDevice device) { this.device = device; }
public SimonSaysViewModel(ParticleDevice device) { InternetButton = device; }
public DeviceLandingPage(ParticleDevice device) { Title = "Mission Control"; BackgroundColor = AppColors.BackgroundColor; ViewModel = new DeviceLandingPageViewModel(device); BindingContext = ViewModel; var refreshDevice = new ToolbarItem { Icon = "ic_cached_white_24dp.png" }; var back = new ToolbarItem { Icon = "ic_clear_white.png" }; var layout = new RelativeLayout(); var indicator = new ActivityIndicator(); var deviceName = new StyledLabel { CssStyle = "h1" }; var deviceConnected = new Image { Source = "notconnected.png" }; var currentAppLabel = new StyledLabel { CssStyle = "h2" }; var variableWidget = new DashboardWidget(); var functionWidget = new DashboardWidget(); var appDescription = new StyledLabel { CssStyle = "body" }; var interactButton = new StyledButton { StyleId = "startInteractionButton", Text = "START INTERACTION", BackgroundColor = AppColors.Green, CssStyle = "button", BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight, IsEnabled = false }; var flashButton = new StyledButton { StyleId = "flashBinaryButton", Text = "FLASH NEW APP", BackgroundColor = AppColors.Purple, CssStyle = "button", BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight, IsEnabled = false }; var boxConstraint = Constraint.RelativeToParent(p => p.Width / 2 - AppSettings.Margin - AppSettings.ItemPadding / 2); layout.Children.Add(deviceName, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.Constant(Device.OnPlatform(AppSettings.Margin, 10, 10)), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); layout.Children.Add(currentAppLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Y + v.Height + 5), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Height) ); layout.Children.Add(variableWidget, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(currentAppLabel, (p, v) => Device.OnPlatform( v.Y + v.Height + 5, v.Y + v.Height, v.Y + v.Height) ), widthConstraint: boxConstraint, heightConstraint: boxConstraint ); layout.Children.Add(functionWidget, xConstraint: Constraint.RelativeToParent(p => p.Width / 2 + AppSettings.ItemPadding / 2), yConstraint: Constraint.RelativeToView(variableWidget, (p, v) => v.Y), widthConstraint: boxConstraint, heightConstraint: boxConstraint ); layout.Children.Add(new ScrollView { Content = appDescription }, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20) ); layout.Children.Add(flashButton, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(AppSettings.ButtonHeight) ); layout.Children.Add(interactButton, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(flashButton, (p, v) => v.Y - AppSettings.ButtonHeight - 10), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(AppSettings.ButtonHeight) ); layout.Children.Add(indicator, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20) ); variableWidget.WidgetTitle.Text = "Variables"; functionWidget.WidgetTitle.Text = "Functions"; if (Device.OS == TargetPlatform.iOS) { interactButton.TextColor = Color.FromHex("#ffffff"); flashButton.TextColor = Color.FromHex("#ffffff"); } Content = layout; ToolbarItems.Add(refreshDevice); ToolbarItems.Add(back); indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android) indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); deviceName.SetBinding(Label.TextProperty, "Device.Name"); currentAppLabel.SetBinding(Label.TextProperty, "CurrentApp"); deviceConnected.SetBinding(Image.IsVisibleProperty, "DeviceConnected"); variableWidget.WidgetCount.SetBinding(Label.TextProperty, "VariableCount"); functionWidget.WidgetCount.SetBinding(Label.TextProperty, "FunctionCount"); interactButton.SetBinding(Button.IsEnabledProperty, "InteractButtonLock"); flashButton.SetBinding(Button.IsEnabledProperty, "FlashButtonLock"); refreshDevice.SetBinding(ToolbarItem.CommandProperty, "RefreshDeviceCommand"); appDescription.SetBinding(Label.TextProperty, "AppDescription"); interactButton.Clicked += async (object sender, EventArgs e) => { if (ViewModel.CurrentApp.ToLower().Contains("rgb led picker")) await Navigation.PushAsync(new ChangeLEDColorPage(ViewModel.Device, ViewModel.variables)); else if (ViewModel.CurrentApp.ToLower().Contains("simonsays")) await Navigation.PushAsync(new SimonSaysPage(ViewModel.Device)); else DisplayAlert("Sorry...", "There isn't a mobile interaction with this IoT app. Try flashing either the 'Simon Says' or ' RBG LED' app.", "Ok"); }; flashButton.Clicked += async (object sender, EventArgs e) => { var result = await DisplayActionSheet("Pick File to Flash", "Cancel", null, "RGB LED", "Shake LED", "Simon Says", "Follow me LED"); if (result != "Cancel") { var success = await ViewModel.TryFlashFileAsync(result); if (!success) { await DisplayAlert("Error", "The Device connection timed out. Please try again once the device breaths a solid cyan light", "Ok"); } } }; back.Clicked += async (object sender, EventArgs e) => { var success = await ViewModel.Device.UnclaimAsync(); //if (success) Navigation.PopModalAsync(true); }; }
public SimonSaysPage(ParticleDevice device) { ViewModel = new SimonSaysViewModel(device); BindingContext = ViewModel; BackgroundColor = AppColors.BackgroundColor; Title = $"{device.Name} Says"; red = new Button { StyleId = "red", BackgroundColor = SimonSaysColors.Red, BorderRadius = 0 }; blue = new Button { StyleId = "blue", BackgroundColor = SimonSaysColors.Blue, BorderRadius = 0 }; green = new Button { StyleId = "green", BackgroundColor = SimonSaysColors.Green, BorderRadius = 0 }; yellow = new Button { StyleId = "yellow", BackgroundColor = SimonSaysColors.Yellow, BorderRadius = 0 }; l1 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l2 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l3 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l4 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l5 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l6 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l7 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l8 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l9 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; l10 = new ContentView { HorizontalOptions = LayoutOptions.FillAndExpand }; var stackPadding = 2d; StackLayout lightStack = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { l1, l2, l3, l4, l5, l6, l7, l8, l9, l10 }, Padding = new Thickness(stackPadding, 0, stackPadding, 0), BackgroundColor = Color.Transparent }; var clearSubmission = new Button { StyleId = "clearMoveButton", Text = "X", FontSize = Device.OnPlatform(10, 8, 10), TextColor = Color.Black, FontAttributes = FontAttributes.Bold, BorderRadius = 10, BackgroundColor = Color.White, BorderColor = Color.Black, BorderWidth = 1 }; StyledButton actionButton = new StyledButton { StyleId = "actionButton", BorderRadius = 0, TextColor = Color.White, CssStyle = "button", BorderColor = AppColors.Blue }; var layout = new RelativeLayout(); var buttonConstraint = Constraint.RelativeToParent((p) => (p.Width / 2) - AppSettings.Margin - AppSettings.ItemPadding / 2); layout.Children.Add(red, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.Constant(AppSettings.Margin), widthConstraint: buttonConstraint, heightConstraint: buttonConstraint ); layout.Children.Add(yellow, xConstraint: Constraint.RelativeToParent((p) => (p.Width / 2) + AppSettings.ItemPadding / 2), yConstraint: Constraint.Constant(AppSettings.Margin), widthConstraint: buttonConstraint, heightConstraint: buttonConstraint ); layout.Children.Add(blue, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(red, (p, v) => v.Height + v.Y + AppSettings.ItemPadding), widthConstraint: buttonConstraint, heightConstraint: buttonConstraint ); layout.Children.Add(green, xConstraint: Constraint.RelativeToParent((p) => (p.Width / 2) + AppSettings.ItemPadding / 2), yConstraint: Constraint.RelativeToView(yellow, (p, v) => v.Height + v.Y + AppSettings.ItemPadding), widthConstraint: buttonConstraint, heightConstraint: buttonConstraint ); layout.Children.Add(lightStack, xConstraint: Constraint.Constant(AppSettings.Margin - stackPadding), yConstraint: Constraint.RelativeToView(blue, (p, v) => v.Height + v.Y + AppSettings.ItemPadding * 2), widthConstraint: Constraint.RelativeToParent((p) => p.Width - AppSettings.Margin * 2 + stackPadding * 2), heightConstraint: Constraint.Constant(25) // TODO calculate the square size based on the width of the view ); layout.Children.Add(clearSubmission, xConstraint: Constraint.RelativeToParent((p) => p.Width - AppSettings.Margin - Device.OnPlatform(10, 15, 15)), yConstraint: Constraint.RelativeToView(lightStack, (p, v) => Device.OnPlatform( v.Y - 10, v.Y - 15, v.Y - 15 ) ), widthConstraint: Constraint.Constant(Device.OnPlatform(25, 30, 30)), heightConstraint: Constraint.Constant(Device.OnPlatform(25, 30, 30)) ); layout.Children.Add(actionButton, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(50) ); Content = layout; red.Clicked += async (object sender, EventArgs e) => { await ViewModel.PlayerPressButtonAsync("r"); }; blue.Clicked += async (object sender, EventArgs e) => { await ViewModel.PlayerPressButtonAsync("b"); }; green.Clicked += async (object sender, EventArgs e) => { await ViewModel.PlayerPressButtonAsync("g"); }; yellow.Clicked += async (object sender, EventArgs e) => { await ViewModel.PlayerPressButtonAsync("y"); }; clearSubmission.Clicked += (object sender, EventArgs e) => { ViewModel.ClearPlayerEntry(); }; red.SetBinding(Button.OpacityProperty, "RedOpacity"); green.SetBinding(Button.OpacityProperty, "GreenOpacity"); blue.SetBinding(Button.OpacityProperty, "BlueOpacity"); yellow.SetBinding(Button.OpacityProperty, "YellowOpacity"); l1.SetBinding(ContentView.BackgroundColorProperty, "L1"); l2.SetBinding(ContentView.BackgroundColorProperty, "L2"); l3.SetBinding(ContentView.BackgroundColorProperty, "L3"); l4.SetBinding(ContentView.BackgroundColorProperty, "L4"); l5.SetBinding(ContentView.BackgroundColorProperty, "L5"); l6.SetBinding(ContentView.BackgroundColorProperty, "L6"); l7.SetBinding(ContentView.BackgroundColorProperty, "L7"); l8.SetBinding(ContentView.BackgroundColorProperty, "L8"); l9.SetBinding(ContentView.BackgroundColorProperty, "L9"); l10.SetBinding(ContentView.BackgroundColorProperty, "L10"); clearSubmission.SetBinding(Button.IsVisibleProperty, "ShowClearButton"); actionButton.SetBinding(Button.BackgroundColorProperty, "ActionColor"); actionButton.SetBinding(Button.TextProperty, "ActionText"); actionButton.SetBinding(Button.CommandProperty, "ActionCommand"); }