Beispiel #1
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);
        }
Beispiel #2
0
        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";
                }
            }
        }