-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.ps1
70 lines (55 loc) · 2.36 KB
/
run.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
using namespace System
class ValidPortsGenerator : System.Management.Automation.IValidateSetValuesGenerator {
[String[]] GetValidValues() {
$Values = [System.IO.Ports.SerialPort]::getportnames()
return $Values
}
}
# I remembered that the code is written in assemply which makes it hardware dependant
# but my heart couldn't bear 😭😭 to delete the code responsible for generating board list after
# spending so much time on this bit 2>&1
# class ValidBoardsGenerator : System.Management.Automation.IValidateSetValuesGenerator {
# [String[]] GetValidValues() {
# $arduinoConf = "${env:ProgramFiles(x86)}\Arduino\hardware\tools\avr\etc\avrdude.conf"
# $parts = ((( avrdude.exe -C $arduinoConf -p ?) 2>&1) -split [System.Environment]::NewLine)
# $Values = $parts[2..($parts.Length - 3)] | ForEach-Object -Process { $_.Substring($_.IndexOf("= ") + 1).Trim() }
# return $Values
# }
# }
function Install-XRobot {
[CmdletBinding()]
param (
[Parameter()]
[ValidateSet([ValidPortsGenerator])]
[string]
$Port = "COM5",
[Parameter()]
[switch]
$Upload
)
$Board = 'ATmega328P'
$arduinoTooling = "${env:ProgramFiles(x86)}\Arduino\hardware\tools\avr\bin"
$arduinoConf = "${env:ProgramFiles(x86)}\Arduino\hardware\tools\avr\etc\avrdude.conf"
if (Test-Path $arduinoTooling) {
if (-not ($env:Path -split ';' -contains $arduinoTooling)) {
$env:Path += ";${arduinoTooling}"
}
.\tools\gavrasm.exe -lq .\src\Microcontroller\XRobot\Assembly\main.asm
Write-Host "Done Compiling To ${Board}." -ForegroundColor green
if ($Upload) {
if (Test-Path -Path ".\src\main.hex" -PathType Leaf) {
avrdude.exe -C $arduinoConf -v -p $Board.ToLowerInvariant() -c arduino -P $Port -U flash:w:.\src\Microcontroller\XRobot\Assembly\main.hex:i
Write-Host "Done Uploading To ${Board}." -ForegroundColor green
}
else {
Write-Host "Errors Found." -ForegroundColor red
}
}
if (Test-Path -Path ".\src\main.hex" -PathType Leaf) {
Remove-Item .\src\Microcontroller\XRobot\Assembly\main.hex
}
}
else {
Write-Host "Arduino is not installed." -ForegroundColor red
}
}