uPyLibs/flash.ps1

58 lines
1.4 KiB
PowerShell

param(
[String]$COMPort,
[switch]$Extras,
[switch]$ResetAfterFlash,
[String[]]$Libs
)
Function Write-AmpyFile {
[cmdletbinding()]
param(
[String]$Filename,
[String]$COMPort
)
If ((Get-Command -Name ampy -ErrorAction SilentlyContinue) -eq $false) {
Write-Error -Message "Couldn't locate ``ampy`` in environment paths - please run ``pip install adafruit-ampy``." -ErrorAction Stop
}
ampy -p $COMPort put $Filename
}
Function Reset-AmpyDevice {
[cmdletbinding()]
param(
[String]$COMPort
)
If ((Get-Command -Name ampy -ErrorAction SilentlyContinue) -eq $false) {
Write-Error -Message "Couldn't locate ``ampy`` in environment paths - please run ``pip install adafruit-ampy``." -ErrorAction Stop
}
ampy -p $COMPort reset
}
$BaseFiles=(
'boot',
'main',
'uPyConfig'
)
$ExtraFiles=(
'init_sample'
)
$CfgFiles=(
'wifi_cfg',
'webrepl_cfg'
)
$BaseFiles | % {
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort
}
$CfgFiles | % {
If (Get-ChildItem "$_.py" -ErrorAction SilentlyContinue) {
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort
}
}
If ($Extras) { $ExtraFiles | % {
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort
}}
If ($Libs.Count -gt 0) { $Libs | %{
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort
}}
If ($ResetAfterFlash) { Reset-AmpyDevice -COMPort $COMPort }