Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add powershell version of install script #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions install-on-device-fs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Write-Host -NoNewline "Checking for mpremote..."
try {
$command = Get-Command mpremote -ErrorAction Stop
Write-Output "mpremote is available."
} catch {
Write-Output "mpremote is not found."
Write-Host "Please install mpremote by running 'pip install mpremote'"
exit 1
}

$DEVICES = mpremote connect list
if ($DEVICES -eq $null) {
Write-Host "No MicroPython devices found"
exit 1
} elseif ( {$DEVICES | Select-String -Pattern "MicroPython" } -ne $null) {
Write-Host -NoNewline "Devices found, incorrectly named, trying first one "
$DEVICES = $DEVICES | ForEach-Object { $_ -split " " | Select-Object -First 1 }
Write-Host "($DEVICES)"
} else {
Write-Host -NoNewline "MicroPython Devices found, using first one "
$DEVICES = $DEVICES | Select-String -Pattern "MicroPython" | ForEach-Object { $_ -split " " | Select-Object -First 1 }
Write-Host "($DEVICES)"
}

if ($DEVICES -eq $null) {
Write-Host "No MicroPython devices found in FS mode"
exit 1
}

$DEVICE = ($DEVICES.Count -ne 1) ? $DEVICES[0] : $DEVICES

Write-Host "Copying Enviro firmware files to $DEVICE"

function create_directory {
param($dir)
Write-Host -NoNewline "> creating directory $dir"

$RESULT = mpremote connect $DEVICE mkdir $dir
$ERROR = $LASTEXITCODE

if ($ERROR -eq 0) {
Write-Host " .. done!"
}
else {
if ($RESULT -match "EEXIST") {
Write-Host " .. already exists, skipping."
}
else {
Write-Host " .. failed!"
Write-Host "! it looks like this device is already in use - is Thonny running?"
exit 1
}
}
}

function mp_copy {
param($source, $destination)
foreach ($file in (Get-ChildItem -Path $source)) {
Write-Host -NoNewline "> copying file $($file.FullName) to $destination"
mpremote connect $DEVICE cp $file.FullName $destination > $null
if ($LASTEXITCODE -eq 0) {
Write-Host " .. done!"
}
else {
Write-Host " .. failed!"
}
}
}

create_directory "enviro"
create_directory "enviro/boards"
create_directory "enviro/destinations"
create_directory "enviro/html"
create_directory "enviro/html/images"
create_directory "phew"
create_directory "phew/phew"

mp_copy "main.py" ":"

mp_copy "enviro/*.py" ":enviro/"

mp_copy "enviro/boards/*.py" ":enviro/boards/"
mp_copy "enviro/destinations/*.py" ":enviro/destinations/"

mp_copy "enviro/html/*.html" ":enviro/html/"

mp_copy "enviro/html/images/*" ":enviro/html/images/"

mp_copy "phew/__init__.py" ":phew/"
mp_copy "phew/phew/*.py" ":phew/phew/"