78 lines
2.1 KiB
PowerShell
78 lines
2.1 KiB
PowerShell
param(
|
|
[String]$COMPort,
|
|
[switch]$Extras,
|
|
[switch]$ResetAfterFlash,
|
|
[switch]$Verbose,
|
|
[String[]]$Libs
|
|
)
|
|
|
|
Function Find-LibraryFile {
|
|
[cmdletbinding()]
|
|
param(
|
|
[String]$Library,
|
|
[String]$SearchPath = $(Get-Location)
|
|
)
|
|
return (Get-ChildItem -Path $SearchPath -Recurse -Verbose:$Verbose -Name "$Library.py"|Convert-Path -Verbose:$Verbose)
|
|
}
|
|
|
|
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
|
|
}
|
|
Write-Verbose "Writing $Filename to port $COMPort" -Verbose:$Verbose
|
|
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
|
|
}
|
|
Write-Verbose "Resetting port $COMPort" -Verbose:$Verbose
|
|
ampy -p $COMPort reset
|
|
}
|
|
|
|
$BaseFiles = (
|
|
'boot',
|
|
'main',
|
|
'uPyConfig'
|
|
)
|
|
$ExtraFiles = (
|
|
'init_sample'
|
|
)
|
|
$CfgFiles = (
|
|
'wifi_cfg',
|
|
'webrepl_cfg'
|
|
)
|
|
|
|
$BaseFiles | % {
|
|
$Lib = Find-LibraryFile -Library $_ -Verbose:$Verbose
|
|
Write-AmpyFile -Filename "$Lib" -COMPort $COMPort -Verbose:$Verbose
|
|
}
|
|
$CfgFiles | % {
|
|
If (Get-ChildItem "$_.py" -ErrorAction SilentlyContinue) {
|
|
Write-AmpyFile -Filename "$_.py" -COMPort $COMPort -Verbose:$Verbose
|
|
}
|
|
}
|
|
If ($Extras) {
|
|
$ExtraFiles | % {
|
|
$Lib = Find-LibraryFile -Library $_ -Verbose:$Verbose
|
|
Write-AmpyFile -Filename "$Lib" -COMPort $COMPort -Verbose:$Verbose
|
|
}
|
|
}
|
|
If ($Libs.Count -gt 0) {
|
|
$Libs | % {
|
|
$Lib = Find-LibraryFile -Library $_ -Verbose:$Verbose
|
|
Write-AmpyFile -Filename "$Lib" -COMPort $COMPort -Verbose:$Verbose
|
|
}
|
|
}
|
|
If ($ResetAfterFlash) { Reset-AmpyDevice -COMPort $COMPort -Verbose:$Verbose }
|