Ejemplo n.º 1
0
        public ModulesVM(ConnectionVM connection, SettingsVM settings, ModuleVM menu, params ModuleVM[] modules)
        {
            //set fields
            _connection              = connection;
            _settings                = settings;
            _menu                    = menu;
            Modules                  = new ObservableCollection <ModuleVM>(modules);
            ModuleColumns            = new ObservableCollection <ObservableCollection <ModuleVM> >();
            ModuleSizeChangedCommand = new RelayCommand <SizeChangedEventArgs>(ModuleSizeChanged);

            //connect to events
            _connectionEvents = new PropertyObserver <ConnectionVM>(_connection)
                                .RegisterHandler(i => i.CurrentArm, CurrentRobotChanged)
                                .RegisterHandler(i => i.Ports, PortsChanged)
                                .RegisterHandler(i => i.IsScanning, ScanningChanged);
            _settingsEvents = new PropertyObserver <SettingsVM>(_settings)
                              .RegisterHandler(i => i.FirstTimeUse, FirstTimeUseChanged);
            settings.HasReset += Settings_HasReset;
            foreach (var module in modules)
            {
                module.Selected += Module_Selected;
            }
            App.Current.Exit += Current_Exit;

            UpdateRobotChanged();
            GotoMenu();
        }
Ejemplo n.º 2
0
        public FirmwareVM()
        {
            //set fields
            Log               = new ObservableStringWriter();
            _uploader         = new Uploader();
            _uploader.Out     = Log;
            _uploader.Status += Uploader_Status;
            var connection = App.Instance.Connection;

            FlashCommand           = new RelayCommandAsync(Flash);
            SelectFileImageCommand = new RelayCommandAsync(SelectFileImage);
            Ports = connection.Ports;
            var storage = App.Instance.Storage;

            FirmwareModels = (from f in storage.Firmware
                              group f by f.Model into g
                              orderby g.Key descending
                              select new FirmwareModelVM()
            {
                Model = g.Key,
                Images = g.Select(i => new FirmwareImageVM(i)
                {
                    Description = $"{i.Model}  v{i.Version}  released {i.ReleaseDate.ToShortDateString()}"
                }).OrderByDescending(i => i.Firmware.Version).ToArray()
            }
                              ).ToArray();
            //select the most recent
            SelectedFirmwareModel = FirmwareModels.First();
            SelectedFirmwareImage = SelectedFirmwareModel.Images.First();

            //connect to events
            _connectionEvents = new PropertyObserver <ConnectionVM>(connection)
                                .RegisterHandler(i => i.CurrentArm, CurrentRobotChanged)
                                .RegisterHandler(i => i.Ports, CurrentRobotChanged);

            CurrentRobotChanged(connection);
        }