Updated flasher script to work with submodules for libraries

This commit is contained in:
Maff 2018-06-19 20:25:47 +01:00
parent 03ae4768e7
commit 1d46664233
1 changed files with 57 additions and 41 deletions

View File

@ -1,58 +1,74 @@
param( param(
[String]$COMPort, [String]$COMPort,
[switch]$Extras, [switch]$Extras,
[switch]$ResetAfterFlash, [switch]$ResetAfterFlash,
[String[]]$Libs [String[]]$Libs
) )
Function Find-LibraryFile {
[cmdletbinding()]
param(
[String]$Library,
[String]$SearchPath = $(Get-Location)
)
return (Get-ChildItem -Path $SearchPath -Recurse -Name "$Library.py").FullName
}
Function Write-AmpyFile { Function Write-AmpyFile {
[cmdletbinding()] [cmdletbinding()]
param( param(
[String]$Filename, [String]$Filename,
[String]$COMPort [String]$COMPort
) )
If ((Get-Command -Name ampy -ErrorAction SilentlyContinue) -eq $false) { 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 Write-Error -Message "Couldn't locate ``ampy`` in environment paths - please run ``pip install adafruit-ampy``." -ErrorAction Stop
} }
ampy -p $COMPort put $Filename ampy -p $COMPort put $Filename
} }
Function Reset-AmpyDevice { Function Reset-AmpyDevice {
[cmdletbinding()] [cmdletbinding()]
param( param(
[String]$COMPort [String]$COMPort
) )
If ((Get-Command -Name ampy -ErrorAction SilentlyContinue) -eq $false) { 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 Write-Error -Message "Couldn't locate ``ampy`` in environment paths - please run ``pip install adafruit-ampy``." -ErrorAction Stop
} }
ampy -p $COMPort reset ampy -p $COMPort reset
} }
$BaseFiles=( $BaseFiles = (
'boot', 'boot',
'main', 'main',
'uPyConfig' 'uPyConfig'
) )
$ExtraFiles=( $ExtraFiles = (
'init_sample' 'init_sample'
) )
$CfgFiles=( $CfgFiles = (
'wifi_cfg', 'wifi_cfg',
'webrepl_cfg' 'webrepl_cfg'
) )
$BaseFiles | % { $BaseFiles | % {
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort $Lib = Find-LibraryFile -Library $_
Write-AmpyFile -Filename "$Lib" -COMPort $COMPort
} }
$CfgFiles | % { $CfgFiles | % {
If (Get-ChildItem "$_.py" -ErrorAction SilentlyContinue) { If (Get-ChildItem "$_.py" -ErrorAction SilentlyContinue) {
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort Write-AmpyFile -Filename "$_.py" -COMPort $COMPort
} }
}
If ($Extras) {
$ExtraFiles | % {
$Lib = Find-LibraryFile -Library $_
Write-AmpyFile -Filename "$Lib" -COMPort $COMPort
}
}
If ($Libs.Count -gt 0) {
$Libs | % {
$Lib = Find-LibraryFile -Library $_
Write-AmpyFile -Filename "$Lib" -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 } If ($ResetAfterFlash) { Reset-AmpyDevice -COMPort $COMPort }