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(); }
private void ScanningChanged(ConnectionVM sender) { //TODO: work in progress ////close if module not showing //if (!_isModuleShowing && _scanningDialog != null) //{ // _scanningDialog.Close(); // _scanningDialog = null; // return; //} //if (_isModuleShowing) //{ // //show if scanning // if (_connection.IsScanning && _scanningDialog == null) // { // _scanningDialog = new MessageDialog() { Title = "new connection detected", Message = "scanning. please wait..." }; // App.Instance.ShowDialog(_scanningDialog).ContinueWith(i => { }); // } // //close if not scanning // else if (!_connection.IsScanning && _scanningDialog != null) // { // _scanningDialog.Close(); // _scanningDialog = null; // } //} }
private void CurrentRobotChanged(ConnectionVM sender) { UpdateRobotChanged(); }
private void PortsChanged(ConnectionVM sender) { UpdateAlerts(); }
void CurrentRobotChanged(ConnectionVM sender) { FlashRequired = false; if (sender.CurrentArm != null) { CurrentFirmware = $"v{sender.CurrentArm.Settings.Version}"; //select current robots port var selectedPort = Ports.FirstOrDefault(i => i.Port == sender.CurrentArm.Communication.ConnectedPort); if (selectedPort != null) { SelectedPort = selectedPort; } if (sender.CurrentArm.Settings.Version < RequiredFirmware) { FlashInstructions = $"An upgrade to you robots firmware is required in order to use this software. Your robot must be updated to a firmware version of v{RequiredFirmware} or beyond"; FlashCommand.Enabled = true; FlashActionText = "Upgrade Firmware"; FlashRequired = true; } else { //select current robots model var model = sender.CurrentArm.Settings.ModelNumber; var robotModel = FirmwareModels.FirstOrDefault(i => i.Model == model); if (robotModel != null) { SelectedFirmwareModel = robotModel; } var newerFirmwareAvailible = sender.CurrentArm.Settings.Version < SelectedFirmwareImage.Firmware.Version; if (newerFirmwareAvailible) { FlashInstructions = "A new firmware version for your robot is availible"; FlashCommand.Enabled = true; FlashActionText = "Upgrade Firmware"; } else { FlashInstructions = "Your robot is up to date"; FlashCommand.Enabled = false; FlashActionText = "Upgrade Firmware"; } } } else { CurrentFirmware = null; //select best guess port var selectedPort = Ports.FirstOrDefault(i => i.PossibleArm); if (selectedPort != null) { SelectedPort = selectedPort; } if (Ports.Count == 0) { FlashInstructions = "Please connect your robot to your PC by a USB cable"; FlashCommand.Enabled = false; FlashActionText = "Install Firmware"; } else { FlashInstructions = "No robot recognized. Install firmware onto your robot."; FlashCommand.Enabled = true; FlashActionText = "Install Firmware"; } } }