From 95c1b1da312082c571d6d23799f6603e413a3c66 Mon Sep 17 00:00:00 2001 From: peteGSX <97784652+peteGSX@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:48:11 +1000 Subject: [PATCH 1/7] Figuring out commands --- installer.ps1 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 installer.ps1 diff --git a/installer.ps1 b/installer.ps1 new file mode 100644 index 0000000..e740d80 --- /dev/null +++ b/installer.ps1 @@ -0,0 +1,53 @@ +# +# © 2023 Peter Cole +# +# This file is part of EX-CommandStation +# +# This is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# It is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with CommandStation. If not, see . +# + +# 32/64 bit Win installer +# https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip +# https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip + +param( + [Parameter()] + [String]$BUILD_DIR +) + +if (!$PSBoundParameters.ContainsKey('BUILD_DIR')) { +# Use the current date/time stamp to create a unique directory if one is not specified. + $BUILD_DATE = Get-Date -Format 'yyyyMMdd-HHmmss' + $BUILD_DIR = $env:TEMP + "\" + $BUILD_DATE +} + +if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -eq "64-bit") { + $URL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip" + $OUTFILE = $env:TEMP + "\" + "arduino-cli_latest_Windows_64bit.zip" +} else { + $URL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip" + $OUTFILE = $env:TEMP + "\" + "arduino-cli_latest_Windows_32bit.zip" +} + +Write-Output "Downloading installer to $OUTFILE" + +$ProgressPreference = "SilentlyContinue" +Invoke-WebRequest -Uri $URL -OutFile $OUTFILE + +$CLI_INSTALL = $env:TEMP + "\" + "arduino-cli_installer" + +Expand-Archive -Path $OUTFILE -DestinationPath $CLI_INSTALL -Force +$ProgressPreference = "Continue" + +Write-Output "Installing using directory $BUILD_DIR" \ No newline at end of file From 305e0902f47bafb24d012ae6c2dd738c3cef4b45 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 4 Apr 2023 19:30:59 +1000 Subject: [PATCH 2/7] Got tag list --- installer.ps1 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/installer.ps1 b/installer.ps1 index e740d80..defccd6 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -21,33 +21,39 @@ # https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip # https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip +$gitHubAPITags = "https://api.github.com/repos/DCC-EX/CommandStation-EX/git/refs/tags" + param( [Parameter()] - [String]$BUILD_DIR + [String]$buildDirectory ) -if (!$PSBoundParameters.ContainsKey('BUILD_DIR')) { +if (!$PSBoundParameters.ContainsKey('buildDirectory')) { # Use the current date/time stamp to create a unique directory if one is not specified. - $BUILD_DATE = Get-Date -Format 'yyyyMMdd-HHmmss' - $BUILD_DIR = $env:TEMP + "\" + $BUILD_DATE + $buildDate = Get-Date -Format 'yyyyMMdd-HHmmss' + $buildDirectory = $env:TEMP + "\" + $buildDate } if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -eq "64-bit") { - $URL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip" - $OUTFILE = $env:TEMP + "\" + "arduino-cli_latest_Windows_64bit.zip" + $arduinoCLIURL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip" + $arduinoCLIZip = $env:TEMP + "\" + "arduino-cli_latest_Windows_64bit.zip" } else { - $URL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip" - $OUTFILE = $env:TEMP + "\" + "arduino-cli_latest_Windows_32bit.zip" + $arduinoCLIURL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip" + $arduinoCLIZip = $env:TEMP + "\" + "arduino-cli_latest_Windows_32bit.zip" } -Write-Output "Downloading installer to $OUTFILE" +Write-Output "Downloading installer to $arduinoCLIZip" $ProgressPreference = "SilentlyContinue" -Invoke-WebRequest -Uri $URL -OutFile $OUTFILE +Invoke-WebRequest -Uri $arduinoCLIURL -OutFile $arduinoCLIZip -$CLI_INSTALL = $env:TEMP + "\" + "arduino-cli_installer" +$arduinoCLIDirectory = $env:TEMP + "\" + "arduino-cli_installer" -Expand-Archive -Path $OUTFILE -DestinationPath $CLI_INSTALL -Force +Expand-Archive -Path $arduinoCLIZip -DestinationPath $arduinoCLIDirectory -Force $ProgressPreference = "Continue" -Write-Output "Installing using directory $BUILD_DIR" \ No newline at end of file +Write-Output "Installing using directory $buildDirectory" + +foreach ($tag in Invoke-RestMethod -Uri $gitHubAPITags | Format-List -Property ref) { + $tag.getType() +} From b18df1405cc0317cf419977a7f57a3626ed84258 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Wed, 5 Apr 2023 05:30:00 +1000 Subject: [PATCH 3/7] Got tag version and URL --- installer.ps1 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/installer.ps1 b/installer.ps1 index defccd6..3b95535 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -20,10 +20,11 @@ # 32/64 bit Win installer # https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip # https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip +# +# For script errors set ExecutionPolicy: +# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -$gitHubAPITags = "https://api.github.com/repos/DCC-EX/CommandStation-EX/git/refs/tags" - -param( +Param( [Parameter()] [String]$buildDirectory ) @@ -34,6 +35,8 @@ if (!$PSBoundParameters.ContainsKey('buildDirectory')) { $buildDirectory = $env:TEMP + "\" + $buildDate } +$gitHubAPITags = "https://api.github.com/repos/DCC-EX/CommandStation-EX/git/refs/tags" + if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -eq "64-bit") { $arduinoCLIURL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip" $arduinoCLIZip = $env:TEMP + "\" + "arduino-cli_latest_Windows_64bit.zip" @@ -54,6 +57,12 @@ $ProgressPreference = "Continue" Write-Output "Installing using directory $buildDirectory" -foreach ($tag in Invoke-RestMethod -Uri $gitHubAPITags | Format-List -Property ref) { - $tag.getType() +$tagList = Invoke-RestMethod -Uri $gitHubAPITags + +# Example zip: https://github.com/DCC-EX/CommandStation-EX/archive/refs/tags/v4.2.36-Devel.zip + +foreach ($tag in $tagList) { + $version = $tag.ref.split("/")[2] + $versionURL = "https://github.com/DCC-EX/CommandStation-EX/archive/" + $tag.ref + Write-Output "$version : $versionURL" } From de6e91a7782576c460d4d2011ffea9ad5cf49994 Mon Sep 17 00:00:00 2001 From: peteGSX <97784652+peteGSX@users.noreply.github.com> Date: Wed, 5 Apr 2023 15:54:48 +1000 Subject: [PATCH 4/7] Working on logic --- installer.ps1 | 119 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/installer.ps1 b/installer.ps1 index 3b95535..d232187 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -1,4 +1,4 @@ -# +<# # © 2023 Peter Cole # # This file is part of EX-CommandStation @@ -15,28 +15,31 @@ # # You should have received a copy of the GNU General Public License # along with CommandStation. If not, see . -# +#> -# 32/64 bit Win installer -# https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip -# https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip -# -# For script errors set ExecutionPolicy: -# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass +<############################################ +For script errors set ExecutionPolicy: +Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass +############################################> +<############################################ +Optional command line parameters: + $buildDirectory - specify an existing directory rather than generating a new unique one + $version - specify an exact version to download +############################################> Param( [Parameter()] - [String]$buildDirectory + [String]$buildDirectory, + [Parameter()] + [String]$version ) -if (!$PSBoundParameters.ContainsKey('buildDirectory')) { -# Use the current date/time stamp to create a unique directory if one is not specified. - $buildDate = Get-Date -Format 'yyyyMMdd-HHmmss' - $buildDirectory = $env:TEMP + "\" + $buildDate -} - +<############################################ +Define global parameters here such as known URLs etc. +############################################> +$installerVersion = "v0.0.1" $gitHubAPITags = "https://api.github.com/repos/DCC-EX/CommandStation-EX/git/refs/tags" - +$gitHubURLPrefix = "https://github.com/DCC-EX/CommandStation-EX/archive/" if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -eq "64-bit") { $arduinoCLIURL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip" $arduinoCLIZip = $env:TEMP + "\" + "arduino-cli_latest_Windows_64bit.zip" @@ -44,25 +47,87 @@ if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchi $arduinoCLIURL = "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip" $arduinoCLIZip = $env:TEMP + "\" + "arduino-cli_latest_Windows_32bit.zip" } - -Write-Output "Downloading installer to $arduinoCLIZip" - -$ProgressPreference = "SilentlyContinue" -Invoke-WebRequest -Uri $arduinoCLIURL -OutFile $arduinoCLIZip - $arduinoCLIDirectory = $env:TEMP + "\" + "arduino-cli_installer" +$arduinoCLI = $arduinoCLIDirectory + "\arduino-cli.exe" -Expand-Archive -Path $arduinoCLIZip -DestinationPath $arduinoCLIDirectory -Force -$ProgressPreference = "Continue" +<############################################ +Set default action for progress indicators, warnings, and errors +############################################> +$global:ProgressPreference = "SilentlyContinue" +$global:WarningPreference = "SilentlyContinue" +$global:ErrorActionPreference = "SilentlyContinue" +<############################################ +If $buildDirectory not provided, generate a new time/date stamp based directory to use +############################################> +if (!$PSBoundParameters.ContainsKey('buildDirectory')) { + $buildDate = Get-Date -Format 'yyyyMMdd-HHmmss' + $buildDirectory = $env:TEMP + "\" + $buildDate +} +$commandStationDirectory = $buildDirectory + "\CommandStation-EX" + +<############################################ +Write out intro message and prompt to continue +############################################> +@" +Welcome to the DCC-EX PowerShell installer for EX-CommandStation ($installerVersion) + +Current installer options: +- EX-CommandStation will be built in $commandStationDirectory +- Arduino CLI will be in $arduinoCLIDirectory +"@ + + +<############################################ +Create build directory if it doesn't exist, or fail +############################################> +if (!(Test-Path -PathType Container -Path $buildDirectory)) { + try { + New-Item -ItemType Directory -Path $buildDirectory | Out-Null + } + catch { + Write-Output "Could not create build directory $buildDirectory" + Exit + } +} + +<############################################ +See if we have the Arduino CLI already, otherwise download and extract it +############################################> +if (!(Test-Path -PathType Leaf -Path $arduinoCLI)) { + if (!(Test-Path -PathType Container -Path $arduinoCLIDirectory)) { + try { + New-Item -ItemType Directory -Path $arduinoCLIDirectory | Out-Null + } + catch { + Write-Output "Arduino CLI does not exist and cannot create directory $arduinoCLIDirectory" + Exit + } + } + Write-Output "Downloading and extracting Arduino CLI" + try { + Invoke-WebRequest -Uri $arduinoCLIURL -OutFile $arduinoCLIZip + } + catch { + Write-Output "Failed to download Arduino CLI" + Exit + } + try { + Expand-Archive -Path $arduinoCLIZip -DestinationPath $arduinoCLIDirectory -Force + } + catch { + Write-Output "Failed to extract Arduino CLI" + } +} + +<# Write-Output "Installing using directory $buildDirectory" $tagList = Invoke-RestMethod -Uri $gitHubAPITags -# Example zip: https://github.com/DCC-EX/CommandStation-EX/archive/refs/tags/v4.2.36-Devel.zip - foreach ($tag in $tagList) { $version = $tag.ref.split("/")[2] - $versionURL = "https://github.com/DCC-EX/CommandStation-EX/archive/" + $tag.ref + $versionURL = $gitHubURLPrefix + $tag.ref Write-Output "$version : $versionURL" } +#> \ No newline at end of file From 18a992bf0867a64d335fce149bfffd053d4afb0e Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 6 Apr 2023 05:31:11 +1000 Subject: [PATCH 5/7] Start getting tag list --- installer.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/installer.ps1 b/installer.ps1 index d232187..296fb6d 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -120,6 +120,31 @@ if (!(Test-Path -PathType Leaf -Path $arduinoCLI)) { } } +<# +Get the list of tags +#> +try { + $tagList = Invoke-RestMethod -Uri $gitHubAPITags +} +catch { + Write-Output "Failed to obtain list of available EX-CommandStation versions" + Exit +} + +<# +Get latest two Prod and Devel releases, add to hash table for selection by user +#> +foreach ($tag in $tagList | Sort-Object -Property ref -Descending) { + if ($tag.ref -Like "*Prod") { + Write-Output $tag.ref + } +} +foreach ($tag in $tagList | Sort-Object -Property ref -Descending) { + if ($tag.ref -Like "*Devel") { + Write-Output $tag.ref + } +} + <# Write-Output "Installing using directory $buildDirectory" From de06c0ae3eb9422f8e4d85e7d0d5de432507658e Mon Sep 17 00:00:00 2001 From: peteGSX <97784652+peteGSX@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:06:22 +1000 Subject: [PATCH 6/7] Working on CLI commands --- installer.ps1 | 129 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 14 deletions(-) diff --git a/installer.ps1 b/installer.ps1 index 296fb6d..b803e50 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -31,7 +31,7 @@ Param( [Parameter()] [String]$buildDirectory, [Parameter()] - [String]$version + [String]$configDirectory ) <############################################ @@ -120,30 +120,131 @@ if (!(Test-Path -PathType Leaf -Path $arduinoCLI)) { } } -<# +<############################################ Get the list of tags -#> +############################################> try { - $tagList = Invoke-RestMethod -Uri $gitHubAPITags + $gitHubTags = Invoke-RestMethod -Uri $gitHubAPITags } catch { Write-Output "Failed to obtain list of available EX-CommandStation versions" Exit } -<# -Get latest two Prod and Devel releases, add to hash table for selection by user -#> -foreach ($tag in $tagList | Sort-Object -Property ref -Descending) { - if ($tag.ref -Like "*Prod") { - Write-Output $tag.ref +<############################################ +Get our GitHub tag list in a hash so we can sort by version numbers and extract just the ones we want +############################################> +$versionMatch = ".*?v(\d+)\.(\d+).(\d+)-(.*)" +$tagList = @{} +foreach ($tag in $gitHubTags) { + $tagHash = @{} + $tagHash["Ref"] = $tag.ref + $version = $tag.ref.split("/")[2] + $null = $version -match $versionMatch + $tagHash["Major"] = [int]$Matches[1] + $tagHash["Minor"] = [int]$Matches[2] + $tagHash["Patch"] = [int]$Matches[3] + $tagHash["Type"] = $Matches[4] + $tagList.Add($version, $tagHash) +} + +<############################################ +Get latest two Prod and Devel for user to select +############################################> +$userList = @{} +$prodCount = 1 +$devCount = 1 +$select = 1 +foreach ($tag in $tagList.Keys | Sort-Object {$tagList[$_]["Major"]},{$tagList[$_]["Minor"]},{$tagList[$_]["Patch"]} -Descending) { + if (($tagList[$tag]["Type"] -eq "Prod") -and $prodCount -le 2) { + $userList[$select] = $tag + $select++ + $prodCount++ + } elseif (($tagList[$tag]["Type"] -eq "Devel") -and $devCount -le 2) { + $userList[$select] = $tag + $select++ + $devCount++ } } -foreach ($tag in $tagList | Sort-Object -Property ref -Descending) { - if ($tag.ref -Like "*Devel") { - Write-Output $tag.ref - } + +<############################################ +Display options for user to select and get the selection +############################################> +foreach ($selection in $userList.Keys | Sort-Object $selection) { + Write-Output "$selection - $($userList[$selection])" } +Write-Output "5 - Exit" +$userSelection = 0 +do { + [int]$userSelection = Read-Host "Select the version to install from the list above (1 - 5)" +} until ( + (($userSelection -ge 1) -and ($userSelection -le 5)) +) +if ($userSelection -eq 5) { + Write-Output "Exiting installer" + Exit +} else { + $downloadURL = $gitHubURLPrefix + $tagList[$userList[$userSelection]]["Ref"] + ".zip" +} + +<############################################ +Download the chosen version to the build directory +############################################> +$downladFile = $buildDirectory + "\CommandStation-EX.zip" +Write-Output "Downloading and extracting $($userList[$userSelection])" +try { + Invoke-WebRequest -Uri $downloadURL -OutFile $downladFile +} +catch { + Write-Output "Error downloading EX-CommandStation zip file" + Exit +} + +<############################################ +Extract and rename to CommandStation-EX to allow building +############################################> +try { + Expand-Archive -Path $downladFile -DestinationPath $buildDirectory -Force +} +catch { + Write-Output "Failed to extract EX-CommandStation zip file" + Exit +} + +$folderName = $buildDirectory + "\CommandStation-EX-" + ($userList[$userSelection] -replace "^v", "") +Write-Output $folderName +try { + Rename-Item -Path $folderName -NewName $commandStationDirectory +} +catch { + Write-Output "Could not rename folder" + Exit +} + +<############################################ +If config directory provided, copy files here +############################################> + + +<############################################ +Once files all together, identify available board(s) +############################################> +# Need to do an initial board list to download everything first +& $arduinoCLI board list | Out-Null +# Run again to generate the list of discovered boards +& $arduinoCLI board list --format json + +<############################################ +Get user to select board +############################################> + + + + +<############################################ +Upload the sketch to the selected board +############################################> +#$arduinoCLI upload -b fqbn -p port $commandStationDirectory <# Write-Output "Installing using directory $buildDirectory" From 9f212c27bf3ec38576fd7a4525db6bde85ee7e24 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Fri, 7 Apr 2023 08:06:32 +1000 Subject: [PATCH 7/7] Initial test working! --- installer.ps1 | 142 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 16 deletions(-) diff --git a/installer.ps1 b/installer.ps1 index b803e50..1c47fc3 100644 --- a/installer.ps1 +++ b/installer.ps1 @@ -34,6 +34,24 @@ Param( [String]$configDirectory ) +<############################################ +List of supported devices with FQBN in case clones used that aren't detected +############################################> +$supportedDevices = @( + @{ + name = "Arduino Mega or Mega 2560" + fqbn = "arduino:avr:mega" + }, + @{ + name = "Arduino Nano" + fqbn = "arduino:avr:nano" + }, + @{ + name = "Arduino Uno" + fqbn = "arduino:avr:uno" + } +) + <############################################ Define global parameters here such as known URLs etc. ############################################> @@ -75,6 +93,9 @@ Welcome to the DCC-EX PowerShell installer for EX-CommandStation ($installerVers Current installer options: - EX-CommandStation will be built in $commandStationDirectory - Arduino CLI will be in $arduinoCLIDirectory + +Available EX-CommandStation versions: +------------------------------------- "@ @@ -176,7 +197,7 @@ foreach ($selection in $userList.Keys | Sort-Object $selection) { Write-Output "5 - Exit" $userSelection = 0 do { - [int]$userSelection = Read-Host "Select the version to install from the list above (1 - 5)" + [int]$userSelection = Read-Host "`r`nSelect the version to install from the list above (1 - 5)" } until ( (($userSelection -ge 1) -and ($userSelection -le 5)) ) @@ -200,6 +221,14 @@ catch { Exit } +<############################################ +If folder exists, bail out and tell user +############################################> +if (Test-Path -PathType Container -Path "$buildDirectory\CommandStation-EX") { + Write-Output "EX-CommandStation directory already exists, please ensure you have copied any user files then delete manually: $buildDirectory\CommandStation-EX" + Exit +} + <############################################ Extract and rename to CommandStation-EX to allow building ############################################> @@ -224,36 +253,117 @@ catch { <############################################ If config directory provided, copy files here ############################################> - +# To be done +# If exists copy config.h, myAutomation.h, myHal.cpp, mySetup.h <############################################ Once files all together, identify available board(s) ############################################> # Need to do an initial board list to download everything first -& $arduinoCLI board list | Out-Null -# Run again to generate the list of discovered boards -& $arduinoCLI board list --format json +try { + & $arduinoCLI board list | Out-Null +} +catch { + Write-Output "Failed to update Arduino CLI board list" + Exit +} +# Run again to generate the list of discovered boards into a custom object +try { + $boardList = & $arduinoCLI board list --format jsonmini | ConvertFrom-Json +} +catch { + Write-Output "Failed to obtain list of boards" + Exit +} <############################################ Get user to select board ############################################> +if ($boardList.count -eq 0) { + Write-Output "Could not find any attached devices, please ensure your device is plugged in to a USB port and Windows recognises it" + Exit +} else { +@" +Devices attached to COM ports: +------------------------------ +"@ + $boardSelect = 1 + foreach ($board in $boardList) { + if ($board.matching_boards.name) { + $boardName = $board.matching_boards.name + } else { + $boardName = "Unknown device" + } + $port = $board.port.address + Write-Output "$boardSelect - $boardName on port $port" + $boardSelect++ + } + Write-Output "$boardSelect - Exit" + $userSelection = 0 + do { + [int]$userSelection = Read-Host "`r`nSelect the device to use from the list above" + } until ( + (($userSelection -ge 1) -and ($userSelection -le ($boardList.count + 1))) + ) + if ($userSelection -eq ($boardList.count + 1)) { + Write-Output "Exiting installer" + Exit + } else { + $selectedBoard = $userSelection - 1 + } +} +<############################################ +If the board is unknown, need to choose which one +############################################> +if ($null -eq $boardList[$selectedBoard].matching_boards.name) { + Write-Output "The device selected is unknown, these boards are supported:`r`n" + $deviceSelect = 1 + foreach ($device in $supportedDevices) { + Write-Output "$deviceSelect - $($supportedDevices[$deviceSelect - 1].name)" + $deviceSelect++ + } + Write-Output "$deviceSelect - Exit" + $userSelection = 0 + do { + [int]$userSelection = Read-Host "Select the board type from the list above" + } until ( + (($userSelection -ge 1) -and ($userSelection -le ($supportedDevices.count + 1))) + ) + if ($userSelection -eq ($supportedDevices.count + 1)) { + Write-Output "Exiting installer" + Exit + } else { + $deviceName = $supportedDevices[$userSelection - 1].name + $deviceFQBN = $supportedDevices[$userSelection - 1].fqbn + } +} else { + $deviceName = $boardList[$selectedBoard].matching_boards.name + $deviceFQBN = $boardList[$selectedBoard].matching_boards.fqbn + $devicePort = $boardList[$selectedBoard].port.address +} <############################################ Upload the sketch to the selected board ############################################> #$arduinoCLI upload -b fqbn -p port $commandStationDirectory - -<# -Write-Output "Installing using directory $buildDirectory" - -$tagList = Invoke-RestMethod -Uri $gitHubAPITags - -foreach ($tag in $tagList) { - $version = $tag.ref.split("/")[2] - $versionURL = $gitHubURLPrefix + $tag.ref - Write-Output "$version : $versionURL" +Write-Output "Compiling for $deviceName" +try { + $output = & $arduinoCLI compile -b $deviceFQBN $commandStationDirectory --format jsonmini | ConvertFrom-Json } -#> \ No newline at end of file +catch { + Write-Output "Failed to compile" + Exit +} +Write-Output "$output" +Write-Output "Now uploading to $deviceName on port $devicePort" +try { + $output = & $arduinoCLI upload -t -b $deviceFQBN -p $devicePort $commandStationDirectory --format jsonmini | ConvertFrom-Json +} +catch { + Write-Output "Failed to upload" + Exit +} +Write-Output "$output"