Esempio n. 1
0
        public void RefreshDeviceList()
        {
            MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

            Devices.Items.Clear();
            Devices.Items.Add(new SerialDevice {
                Caption = "Select Target Device Port"
            });
            Devices.SelectedIndex = 0;

            var index    = 1;
            var captions = MeadowDeviceManager.GetSerialDeviceCaptions();

            foreach (var c in captions.Distinct())
            {
                var port = Regex.Match(c, @"(?<=\().+?(?=\))").Value;
                Devices.Items.Add(new SerialDevice()
                {
                    Caption = c,
                    Port    = port
                });

                if (port == settings.DeviceTarget)
                {
                    Devices.SelectedIndex = index;
                }
                index++;
            }
        }
Esempio n. 2
0
        private void Devices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (Devices.SelectedIndex <= 0)
            {
                return;
            }

            MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath, false);

            settings.DeviceTarget = Devices.SelectedValue.ToString();
            settings.Save();
        }
Esempio n. 3
0
        private async void Check_Version(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsDfuMode())
                {
                    await OutputMessageAsync($"Device is in bootloader mode. Connect device in normal mode to check version.", true);

                    return;
                }

                EnableControls(false);

                MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

                await OutputMessageAsync($"Initialize device (~30s)", true);

                if (string.IsNullOrEmpty(settings.DeviceTarget))
                {
                    await OutputMessageAsync($"Select Target Device Port and click '{Flash_Device_Text}' to resume.");

                    _skipFlashToSelectDevice = true;
                    EnableControls(true);
                    return;
                }

                MeadowSerialDevice meadow = null;
                // initialize connection. need to jump through hoops after exiting dfu mode =(
                meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                await MeadowDeviceManager.ResetMeadow(meadow).ConfigureAwait(false);

                await Task.Delay(1000);

                meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                await MeadowDeviceManager.GetDeviceInfo(meadow);
                await OutputMessageAsync($"Device {meadow.DeviceInfo.MeadowOSVersion}", true);
            }
            catch (Exception ex)
            {
                await OutputMessageAsync($"Could not read device version.");
            }
            finally
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                EnableControls(true);
            }
        }
        public void RefreshDeviceList()
        {
            MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

            Devices.Items.Clear();
            Devices.Items.Add("Select Target Device Port");

            var devices       = MeadowDeviceManager.FindSerialDevices();
            var selectedIndex = 0;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i] == settings.DeviceTarget)
                {
                    selectedIndex = i + 1;
                }
                Devices.Items.Add(devices[i]);
            }

            Devices.SelectedIndex = selectedIndex;
        }
Esempio n. 5
0
        public async Task DeployAsync(CancellationToken cts, TextWriter outputPaneWriter)
        {
            var generalProperties = await this.Properties.GetConfigurationGeneralPropertiesAsync();

            var projectDir = await generalProperties.Rule.GetPropertyValueAsync("ProjectDir");

            var outputPath = Path.Combine(projectDir, await generalProperties.Rule.GetPropertyValueAsync("OutputPath"));

            MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

            if (string.IsNullOrEmpty(settings.DeviceTarget))
            {
                throw new Exception("Device has not been selected. Hit Ctrl+Shift+M to access the Device list.");
            }

            var attachedDevices = MeadowDeviceManager.FindSerialDevices();

            if (!attachedDevices.Contains(settings.DeviceTarget))
            {
                throw new Exception($"Device on '{settings.DeviceTarget}' is not connected or busy.");
            }

            await DeployAppAsync(settings.DeviceTarget, Path.Combine(projectDir, outputPath), outputPaneWriter, cts);
        }
Esempio n. 6
0
        private async void Flash_ESP_Click(object sender, RoutedEventArgs e)
        {
            _verbose = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

            MeadowSerialDevice meadow = null;

            try
            {
                MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

                await OutputMessageAsync($"Begin '{Flash_Coprocessor_Text}'", true);

                EnableControls(false);

                await OutputMessageAsync($"Initialize device (~30s)");

                if (string.IsNullOrEmpty(settings.DeviceTarget))
                {
                    await OutputMessageAsync($"Select Target Device Port and click '{Flash_Device_Text}' to resume.");

                    _skipFlashToSelectDevice = true;
                    EnableControls(true);
                    return;
                }

                // initialize connection. need to jump through hoops after exiting dfu mode =(
                meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                await MeadowDeviceManager.ResetMeadow(meadow).ConfigureAwait(false);

                await Task.Delay(1000);

                meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                if (_verbose)
                {
                    await MeadowDeviceManager.TraceEnable(meadow).ConfigureAwait(false);
                }
                else
                {
                    await MeadowDeviceManager.TraceDisable(meadow).ConfigureAwait(false);
                }
                meadow.OnMeadowMessage += MeadowMesageHandler;
                await Task.Delay(1000);

                await MeadowDeviceManager.MonoDisable(meadow).ConfigureAwait(false);

                await Task.Delay(10000); // wait for reconnect, need an event for this

                await MeadowFileManager.WriteFileToEspFlash(meadow, Path.Combine(Globals.FirmwareDownloadsFilePath, networkMeadowCommsFilename), mcuDestAddr : "0x10000").ConfigureAwait(false);

                await Task.Delay(1000);

                await MeadowFileManager.WriteFileToEspFlash(meadow, Path.Combine(Globals.FirmwareDownloadsFilePath, networkBootloaderFilename), mcuDestAddr : "0x1000").ConfigureAwait(false);

                await Task.Delay(1000);

                await MeadowFileManager.WriteFileToEspFlash(meadow, Path.Combine(Globals.FirmwareDownloadsFilePath, networkPartitionTableFilename), mcuDestAddr : "0x8000").ConfigureAwait(false);

                await Task.Delay(1000);

                await OutputMessageAsync($"{Flash_Coprocessor_Text} completed.");

                await MeadowDeviceManager.MonoEnable(meadow).ConfigureAwait(false);

                await Task.Delay(10000); // wait for reconnect, need an event for this
            }
            catch (Exception ex)
            {
                await OutputMessageAsync($"An unexpected error occurred. Please try again.");
            }
            finally
            {
                if (meadow != null)
                {
                    meadow.OnMeadowMessage -= MeadowMesageHandler;
                }
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                EnableControls(true);
            }
        }
Esempio n. 7
0
        private async void Flash_Device(object sender, RoutedEventArgs e)
        {
            _verbose = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

            MeadowSerialDevice meadow = null;

            try
            {
                MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

                var(osFilePath, runtimeFilePath) = await GetWorkingFiles();

                if (string.IsNullOrEmpty(osFilePath) && string.IsNullOrEmpty(runtimeFilePath))
                {
                    await OutputMessageAsync($"Meadow OS files not found. 'Download Meadow OS' first.");

                    return;
                }

                EnableControls(false);

                await OutputMessageAsync($"Begin '{Flash_Device_Text}'", true);

                if (_verbose)
                {
                    await OutputMessageAsync($"Trace output enabled.");
                }

                if (!string.IsNullOrEmpty(osFilePath))
                {
                    if (!await DfuFlash(osFilePath, osAddress).ConfigureAwait(false))
                    {
                        EnableControls(true);
                        return;
                    }
                }
                else
                {
                    await OutputMessageAsync($"{osFilename} not selected. Skipping OS flash.");
                }

                //reset skip flash flag
                _skipFlashToSelectDevice = false;

                if (!string.IsNullOrEmpty(runtimeFilePath))
                {
                    await OutputMessageAsync($"Initialize device (~30s)");

                    if (string.IsNullOrEmpty(settings.DeviceTarget))
                    {
                        await OutputMessageAsync($"Select Target Device Port and click '{Flash_Device_Text}' to resume.");

                        _skipFlashToSelectDevice = true;
                        EnableControls(true);
                        return;
                    }

                    // initialize connection. need to jump through hoops after exiting dfu mode =(
                    meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                    await MeadowDeviceManager.ResetMeadow(meadow).ConfigureAwait(false);

                    await Task.Delay(1000);

                    meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false);

                    if (_verbose)
                    {
                        await MeadowDeviceManager.TraceEnable(meadow).ConfigureAwait(false);
                    }
                    else
                    {
                        await MeadowDeviceManager.TraceDisable(meadow).ConfigureAwait(false);
                    }
                    meadow.OnMeadowMessage += MeadowMesageHandler;
                    await Task.Delay(1000);

                    await MeadowDeviceManager.MonoDisable(meadow).ConfigureAwait(false);

                    await Task.Delay(10000); // wait for reconnect, need an event for this

                    await MeadowFileManager.WriteFileToFlash(meadow, runtimeFilePath).ConfigureAwait(false);

                    await MeadowDeviceManager.MonoFlash(meadow).ConfigureAwait(false);

                    await meadow.DeleteFile(runtimeFilename).ConfigureAwait(false);

                    await MeadowDeviceManager.MonoEnable(meadow).ConfigureAwait(false);

                    await Task.Delay(10000); // wait for reconnect, need an event for this
                }
                else
                {
                    await OutputMessageAsync($"{runtimeFilename} not selected. Skipping Runtime flash.");
                }

                await OutputMessageAsync($"'{Flash_Device_Text}' completed");
            }
            catch (Exception ex)
            {
                await OutputMessageAsync($"An unexpected error occurred. Please try again.");
            }
            finally
            {
                if (meadow != null)
                {
                    meadow.OnMeadowMessage -= MeadowMesageHandler;
                }
                _verbose = false;
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                EnableControls(true);
            }
        }
Esempio n. 8
0
        private async void Flash_Device(object sender, RoutedEventArgs e)
        {
            try
            {
                MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath);

                var(osFilePath, runtimeFilePath) = await GetWorkingFiles();

                if (string.IsNullOrEmpty(osFilePath) && string.IsNullOrEmpty(runtimeFilePath))
                {
                    await OutputMessageAsync($"Meadow OS files not found. 'Download Meadow OS' first.");

                    return;
                }

                EnableControls(false);

                await OutputMessageAsync($"Begin '{Flash_Device_Text}'", true);

                if (!string.IsNullOrEmpty(osFilePath))
                {
                    if (!await DfuFlash(osFilePath, osAddress))
                    {
                        EnableControls(true);
                        return;
                    }
                }
                else
                {
                    await OutputMessageAsync($"{osFilename} not selected. Skipping OS flash.");
                }

                //reset skip flash flag
                _skipFlashToSelectDevice = false;

                if (!string.IsNullOrEmpty(runtimeFilePath))
                {
                    await OutputMessageAsync($"Initialize device");

                    MeadowDeviceManager.CurrentDevice = null;

                    if (string.IsNullOrEmpty(settings.DeviceTarget))
                    {
                        await OutputMessageAsync($"Select Target Device Port and click '{Flash_Device_Text}' to resume.");

                        _skipFlashToSelectDevice = true;
                        EnableControls(true);
                        return;
                    }
                    else
                    {
                        await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget);
                    }

                    if (MeadowDeviceManager.CurrentDevice == null)
                    {
                        await OutputMessageAsync($"Initialization failed. Try again.");

                        return;
                    }

                    if (!await Process(() => MeadowDeviceManager.ResetMeadow(MeadowDeviceManager.CurrentDevice, 0)))
                    {
                        return;
                    }

                    if (!await Process(() => MeadowDeviceManager.MonoDisable(MeadowDeviceManager.CurrentDevice)))
                    {
                        return;
                    }

                    await OutputMessageAsync($"Erase flash (~3 mins)");

                    if (!await Process(() => MeadowFileManager.EraseFlash(MeadowDeviceManager.CurrentDevice)))
                    {
                        return;
                    }

                    await OutputMessageAsync($"Restart device");

                    if (!await Process(() => MeadowDeviceManager.ResetMeadow(MeadowDeviceManager.CurrentDevice, 0)))
                    {
                        return;
                    }

                    await OutputMessageAsync($"Upload {runtimeFilename} (~1 min)");

                    if (!await Process(() => MeadowFileManager.WriteFileToFlash(MeadowDeviceManager.CurrentDevice, runtimeFilePath)))
                    {
                        return;
                    }

                    await OutputMessageAsync($"Process {runtimeFilename} (~30 secs)");

                    if (!await Process(() => MeadowDeviceManager.MonoFlash(MeadowDeviceManager.CurrentDevice)))
                    {
                        return;
                    }

                    await MeadowDeviceManager.CurrentDevice.DeleteFile(runtimeFilename);

                    if (!await Process(() => MeadowDeviceManager.MonoEnable(MeadowDeviceManager.CurrentDevice)))
                    {
                        return;
                    }

                    await OutputMessageAsync($"Restart device");

                    if (!await Process(() => MeadowDeviceManager.ResetMeadow(MeadowDeviceManager.CurrentDevice, 0)))
                    {
                        return;
                    }
                }
                else
                {
                    await OutputMessageAsync($"{runtimeFilename} not selected. Skipping Runtime flash.");
                }

                EnableControls(true);

                await OutputMessageAsync($"'{Flash_Device_Text}' completed");
            }
            catch (Exception ex)
            {
                await OutputMessageAsync($"An unexpected error occurred. Please try again.");

                EnableControls(true);
            }
        }