-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
131 lines (111 loc) · 3.14 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
param (
[Parameter(Mandatory=$true)]
[string]$Command,
[string]$Argument
)
$SRC_DIR = "src"
function copy-settings {
Write-Output "Copying device.json to remote device"
mpremote fs cp device.json :device.json
}
function copy-dependencies {
Write-Output "Copying dependencies to remote device"
# Mqtt lib
$jsonContent = Get-Content -Path "lib/micropython-mqtt/package.json" -Raw
$jsonObject = $jsonContent | ConvertFrom-Json
$files = $jsonObject.urls
$files | ForEach-Object {
$_[1] = $_[1] -replace "github:peterhinch/", ""
$src = "lib/" + $_[1]
$dst = ":" + $_[0]
mpremote fs cp $src $dst
}
# rotary encoder lib
$jsonContent = Get-Content -Path "lib/micropython-rotary/package.json" -Raw
$jsonObject = $jsonContent | ConvertFrom-Json
$files = $jsonObject.urls
$files | ForEach-Object {
$_[1] = $_[1] -replace "github:miketeachman/", ""
if ($_[1] -eq "micropython-rotary/rotary_irq_esp.py" -or $_[1] -eq "micropython-rotary/rotary_irq_esp32.py") {
return
}
$src = "lib/" + $_[1]
$dst = ":" + $_[0]
mpremote fs cp $src $dst
}
Copy-Item lib/micropython-async/v3/primitives/queue.py src/aio_queue.py
mpremote fs cp lib/micropython-async/v3/primitives/queue.py :aio_queue.py
}
function copy-src {
Write-Output "Copying ./src/* to remote device"
Get-ChildItem -Path $SRC_DIR -Recurse | ForEach-Object {
if ($_.Name -eq "queue.py") {
return
}
$file = "src/" + $_.Name
$dst = ":" + $_.Name
mpremote fs cp $file $dst
}
}
function reset {
Write-Output "Resetting device"
mpremote soft-reset
}
function clean {
$counter = 0
Write-Output "Removing files from remote device"
mpremote fs ls | ForEach-Object {
$counter++
if ($counter -eq 1) {
return
}
$file = ":" + $_.Trim() -split '\s+' | Select-Object -Last 1
if ($file -eq ":") {
return
}
mpremote.exe fs rm $file
}
reset
}
function run {
reset
Start-Sleep -Seconds 2
copy-src
mpremote run src/main.py
}
function list {
mpremote fs ls
}
function build {
copy-settings
copy-dependencies
copy-src
reset
}
function get {
param (
[Parameter(Mandatory=$true)]
[string]$Filename
)
$src = ":" + $Filename
mpremote fs cp $src $Filename
}
function send {
param (
[Parameter(Mandatory=$true)]
[string]$Filename
)
$dst = ":" + $Filename
mpremote fs cp $Filename $dst
}
switch ($Command) {
"copy-src" { copy-src } # upload only src files to pico
"reset" { reset } # reset pico
"clean" { clean } # delete all files on pico
"run" { run } # upload only src files and reset pico
"list" { list } # list all files on pico
"build" { build } # upload everything and reset pico
"get" { get $Argument } # retrieve file from pico
"send" { send $Argument } # retrieve file from pico
default { Write-Host "Check build.ps1 for available commands" }
}