Exemplo n.º 1
0
        private void ListAvailableHexArchives()
        {
            AvailableHexArchives = Directory.GetFiles(App.HexArchiveDirectory, "*.arduboy")
                                   .ToList()
                                   .Select(f => HexArchive.FromFile(f))
                                   .Where(f => f.HasValue)
                                   .Select(f => f.Value)
                                   .OrderBy(h => h.Filename)
                                   .ToObservableCollection();

            SelectedHexArchive = AvailableHexArchives.Count > 0 ? AvailableHexArchives[0] : null;
        }
Exemplo n.º 2
0
        private async Task UploadHexOrArchive(string filename)
        {
            BusyTextLabel.StringValue              = "";
            UploadArchiveButton.Enabled            = false;
            UploadSelectedHexArchiveButton.Enabled = false;

            if (!String.IsNullOrWhiteSpace(filename))
            {
                if (filename.EndsWith(("arduboy"), StringComparison.Ordinal))
                {
                    var hexArchive = HexArchive.FromFile((filename));
                    if (hexArchive.HasValue)
                    {
                        var hexData = hexArchive.Value.ExtactHexData();
                        filename = Path.GetTempFileName();
                        File.WriteAllBytes(filename, hexData);
                    }
                }


                BusyIndicator.StartAnimation(this);
                BusyTextLabel.StringValue = "Uploading...";


                await Task.Run(() =>
                {
                    var arduboy = new Arduboy();

                    if (arduboy.TryGetBootloader(out var bootloader))
                    {
                        Debug.WriteLine($"Bootloader found: {bootloader.ComName}");
                        var avrdude  = new AvrDudeInvoker(filename, bootloader.ComName);
                        var progress = new Progress <string>(i => Debug.WriteLine((i)));
                        avrdude.Invoke(progress);
                        InvokeOnMainThread(() => BusyTextLabel.StringValue = "Upload complete.");
                    }
                    else
                    {
                        InvokeOnMainThread(() => BusyTextLabel.StringValue = "Upload failed, Arduboy bootloader not found");
                    }
                });

                BusyIndicator.StopAnimation(this);
                UploadArchiveButton.Enabled            = true;
                UploadSelectedHexArchiveButton.Enabled = true;
            }
        }
Exemplo n.º 3
0
        private void PopulateWithData()
        {
            var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Arduboy");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            DataSource = new HexArchiveCollectionViewDataSource(HexArchiveCollection);

            DataSource.Data.AddRange(Directory.EnumerateFiles(path, "*.arduboy")
                                     .Select(a => HexArchive.FromFile(a))
                                     .Where(o => o.HasValue)
                                     .Select(o => o.Value)
                                     .ToList());
        }
Exemplo n.º 4
0
        private void ImportHexArchiveCommand_Execute()
        {
            var message = new OpenFileDialogMessage("Import Ardobuy Files", true, ".arduboy", "Ardobuy Files|*.arduboy", async(filenames) =>
            {
                LogItems = new ObservableCollection <LogEntry>();
                await Task.Run(async() =>
                {
                    IsBusy = true;
                    foreach (var filePath in filenames)
                    {
                        var filename = Path.GetFileName(filePath);
                        AddLogEntry($"Checking {filename}");
                        var targetFilename = Path.Combine(App.HexArchiveDirectory, filename);

                        if (File.Exists(targetFilename))
                        {
                            AddLogEntry($"{filename} already exists, trying to replace");
                            if (!TryToDeleteFile(targetFilename))
                            {
                                AddLogEntry($"{filename} already exists, unable to delete");
                                continue;
                            }
                        }

                        var archive = HexArchive.FromFile(filePath);
                        if (archive.HasValue)
                        {
                            AddLogEntry($"Found {archive.Value.Info.Title}. Importing...");
                            File.Copy(filePath, targetFilename);
                        }
                        else
                        {
                            AddLogEntry($"{filename} is not a valid Arduboy File");
                        }
                    }

                    AddLogEntry($"Reloading files");
                    ListAvailableHexArchives();
                    AddLogEntry($"Import complete");
                    await Task.Delay(5000);
                    IsBusy = false;
                });
            });

            MessengerInstance.Send(message);
        }