feat(infrared): expand open source remote library
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$InputFile
|
||||
)
|
||||
|
||||
$lines = Get-Content -LiteralPath $InputFile
|
||||
$signals = @()
|
||||
|
||||
function Convert-Signal([string]$Protocol, [string]$Address, [string]$Command) {
|
||||
$addressBytes = $Address -split '\s+' | Where-Object { $_ }
|
||||
$commandBytes = $Command -split '\s+' | Where-Object { $_ }
|
||||
|
||||
if ($Protocol -eq 'NEC') {
|
||||
if ($addressBytes.Count -lt 1 -or $commandBytes.Count -lt 1) { return $null }
|
||||
$addressValue = [Convert]::ToInt32($addressBytes[0], 16)
|
||||
$commandValue = [Convert]::ToInt32($commandBytes[0], 16)
|
||||
return '0x{0:X2}{1:X2}{2:X2}{3:X2}' -f $addressValue, (255 - $addressValue), $commandValue, (255 - $commandValue)
|
||||
}
|
||||
|
||||
if ($Protocol -eq 'NECext') {
|
||||
if ($addressBytes.Count -lt 2 -or $commandBytes.Count -lt 2) { return $null }
|
||||
return '0x{0}{1}{2}{3}' -f $addressBytes[0].ToUpper(), $addressBytes[1].ToUpper(), $commandBytes[0].ToUpper(), $commandBytes[1].ToUpper()
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
for ($index = 0; $index -lt $lines.Count; $index++) {
|
||||
if ($lines[$index] -notmatch '^name:\s*(.+)$') { continue }
|
||||
|
||||
$name = $matches[1].Trim()
|
||||
$type = ''
|
||||
$protocol = ''
|
||||
$address = ''
|
||||
$command = ''
|
||||
|
||||
for ($lookahead = $index + 1; $lookahead -lt [Math]::Min($index + 8, $lines.Count); $lookahead++) {
|
||||
if ($lines[$lookahead] -match '^name:' -or $lines[$lookahead] -eq '#') {
|
||||
if ($lookahead -gt $index + 1) { break }
|
||||
}
|
||||
if ($lines[$lookahead] -match '^type:\s*(.+)$') { $type = $matches[1].Trim() }
|
||||
if ($lines[$lookahead] -match '^protocol:\s*(.+)$') { $protocol = $matches[1].Trim() }
|
||||
if ($lines[$lookahead] -match '^address:\s*(.+)$') { $address = $matches[1].Trim() }
|
||||
if ($lines[$lookahead] -match '^command:\s*(.+)$') { $command = $matches[1].Trim() }
|
||||
}
|
||||
|
||||
if ($type -ne 'parsed' -or $protocol -notin @('NEC', 'NECext')) { continue }
|
||||
$hexCode = Convert-Signal $protocol $address $command
|
||||
if ($null -ne $hexCode) {
|
||||
$signals += [pscustomobject]@{
|
||||
name = $name
|
||||
protocol = $protocol
|
||||
code = $hexCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$signals | ConvertTo-Json -Depth 3
|
||||
Reference in New Issue
Block a user