示例#1
0
        private Grid DefineSliderGrid(RegisterBankDefinition bankDef)
        {
            Grid grid = new Grid
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                RowSpacing        = 35,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(40, GridUnitType.Absolute)
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = new GridLength(100, GridUnitType.Star)
                    }
                }
            };

            RowDefinitionCollection rdc = new RowDefinitionCollection();

            foreach (var item in bankDef.Registers)
            {
                rdc.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            for (int i = 0; i < bankDef.Registers.Length; i++)
            {
                grid.Children.Add(new Label
                {
                    Text              = i.ToString("000"),
                    FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Center
                }, 0, i);

                grid.Children.Add(new Label
                {
                    Text              = bankDef.Registers[i],
                    FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Center
                }, 1, i);

                Slider slider = new Slider(0, 255, 0);
                slider.HorizontalOptions = LayoutOptions.FillAndExpand;
                slider.VerticalOptions   = LayoutOptions.Center;
                slider.ValueChanged     += OnRegisterValueChanged;
                sliders.Add(slider);
                grid.Children.Add(slider, 2, i);
            }

            return(grid);
        }
示例#2
0
        public static List <RegisterBankDefinition> ReadYaml(string filePath)
        {
            //check if file exists, if not: make default file
            if (!File.Exists(filePath))
            {
                RegisterBankDefinition rd = new RegisterBankDefinition();
                rd.Name       = "userBank";
                rd.I2CAddress = 22;
                rd.Registers  = new string[] { "reg0", "reg1" };

                List <RegisterBankDefinition> allRegisters = new List <RegisterBankDefinition>();
                allRegisters.Add(rd);
                WriteYaml(allRegisters, filePath);
            }

            //file is sure to exist: read and parse
            StreamReader reader       = File.OpenText(filePath);
            var          deserializer = new YamlDotNet.Serialization.Deserializer();
            List <RegisterBankDefinition> registerBanks = deserializer.Deserialize <List <RegisterBankDefinition> >(reader);

            return(registerBanks);
        }
示例#3
0
        public App(RegisterBankDefinition[] allBanks)
        {
            this.bankDef = allBanks[0];

            //image
            Image embeddedImage = new Image {
                Aspect            = Aspect.AspectFit,
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.Fill,
                Source            = ImageSource.FromResource("MakerKit.Resources.labnation-logo.png")
            };

            //title
            var label = new Label {
                Text = "SmartScope Maker Kit", FontSize = 24
            };
            var labelStacker = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                Orientation       = StackOrientation.Horizontal,
                Padding           = new Thickness(0, 0, 0, 30),
                Children          = { label }
            };

            //bottom status bar
            statusLabel = new Label {
                Text = "Status", FontSize = 12
            };
            var statusLabelStacker = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End,
                Orientation       = StackOrientation.Horizontal,
                Padding           = new Thickness(0, 0, 0, 30),
                Children          = { statusLabel }
            };

            ContentPage textboxPage = new ContentPage {
                Content = new ScrollView {
                    Content = new StackLayout
                    {
                        Spacing           = 10,
                        Padding           = 10,
                        VerticalOptions   = LayoutOptions.Start,
                        Orientation       = StackOrientation.Vertical,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          = { embeddedImage, labelStacker, DefineEntryGrid(allBanks[0]), statusLabelStacker }
                    }
                }
            };

            textboxPage.Title = "Values";

            ContentPage sliderPage = new ContentPage {
                Content = new ScrollView {
                    Content = new StackLayout
                    {
                        Spacing           = 10,
                        Padding           = 10,
                        VerticalOptions   = LayoutOptions.Start,
                        Orientation       = StackOrientation.Vertical,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          = { embeddedImage, labelStacker, DefineSliderGrid(allBanks[0]), statusLabelStacker }
                    }
                }
            };

            sliderPage.Title = "Sliders";

            MainPage = new TabbedPage {
                Children = { textboxPage, sliderPage }
            };
        }
示例#4
0
        private Grid DefineEntryGrid(RegisterBankDefinition bankDef)
        {
            Grid grid = new Grid
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                RowSpacing        = 35,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(40, GridUnitType.Absolute)
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = new GridLength(100, GridUnitType.Star)
                    }
                }
            };

            RowDefinitionCollection rdc = new RowDefinitionCollection();

            foreach (var item in bankDef.Registers)
            {
                rdc.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            for (int i = 0; i < bankDef.Registers.Length; i++)
            {
                grid.Children.Add(new Label
                {
                    Text              = i.ToString("000"),
                    FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Center
                }, 0, i);

                grid.Children.Add(new Label
                {
                    Text              = bankDef.Registers[i],
                    FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Center
                }, 1, i);

                Entry entry = new Entry {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Center,
                    Text     = "0",
                    Keyboard = Keyboard.Numeric
                };
                entry.Completed += OnRegisterValueChanged;
                entries.Add(entry);
                grid.Children.Add(entry, 2, i);
            }

            return(grid);
        }