From a897b54de6348116dc65deed1872d0b08774719a Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Fri, 13 Mar 2026 22:40:13 -0700 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20`GapSize`=20param?= =?UTF-8?q?eter=20to=20`Show-AwtrixScreen`=20for=20pixel=20spacing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated the `PixelSize` default to 1 for better visibility. * Introduced `GapSize` to simulate the dark border between LEDs. * Enhanced documentation to reflect new parameter and its usage. --- awtrix/Public/Show-AwtrixScreen.ps1 | 43 +++++++++++++++++++---------- awtrix/awtrix.psm1 | 10 +++++-- docs/en-US/Show-AwtrixScreen.md | 18 +++++++++++- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/awtrix/Public/Show-AwtrixScreen.ps1 b/awtrix/Public/Show-AwtrixScreen.ps1 index 619efa0..c876fb6 100644 --- a/awtrix/Public/Show-AwtrixScreen.ps1 +++ b/awtrix/Public/Show-AwtrixScreen.ps1 @@ -15,8 +15,11 @@ function Show-AwtrixScreen { .PARAMETER BaseUri The base URI of the AWTRIX device. If not specified, uses the connection from Connect-Awtrix. .PARAMETER PixelSize - Scale factor for each pixel. Default is 2, meaning each LED pixel maps to - a 2x2 block on the canvas for better visibility. + Scale factor for each pixel. Default is 1, meaning each LED pixel maps to + a 1x1 block on the canvas for better visibility. + .PARAMETER GapSize + Number of black pixels to insert between each LED pixel, simulating the + dark border between LEDs on a real matrix display. Default is 0. .EXAMPLE PS> Show-AwtrixScreen @@ -40,15 +43,19 @@ function Show-AwtrixScreen { [Parameter()] [ValidateRange(1, 5)] - [int]$PixelSize = 2 + [int]$PixelSize = 1, + + [Parameter()] + [ValidateRange(0, 3)] + [int]$GapSize = 0 ) begin { - if (-not (Get-Module -Name PwshSpectreConsole -ListAvailable)) { + if (-not (Get-Module -Name PwshSpectreConsole)) { throw 'PwshSpectreConsole module is required. Install it with: Install-Module PwshSpectreConsole' } - Import-Module PwshSpectreConsole -ErrorAction Stop + # Import-Module PwshSpectreConsole -ErrorAction Stop $collectedData = [System.Collections.Generic.List[int]]::new() } @@ -65,9 +72,14 @@ function Show-AwtrixScreen { if ($collectedData.Count -eq 0) { $fetchParams = @{} if ($BaseUri) { $fetchParams['BaseUri'] = $BaseUri } - $collectedData = [System.Collections.Generic.List[int]]::new( - [int[]](Get-AwtrixScreen @fetchParams) - ) + try { + $collectedData = [System.Collections.Generic.List[int]]::new( + [int[]](Get-AwtrixScreen @fetchParams -ErrorAction Stop) + ) + } + catch { + $PSCmdlet.ThrowTerminatingError($_) + } } $matrixWidth = 32 @@ -78,8 +90,9 @@ function Show-AwtrixScreen { throw "Expected $expectedPixels pixel values (32x8) but received $($collectedData.Count)." } - $canvasWidth = $matrixWidth * $PixelSize - $canvasHeight = $matrixHeight * $PixelSize + $stride = $PixelSize + $GapSize + $canvasWidth = $matrixWidth * $stride - $GapSize + $canvasHeight = $matrixHeight * $stride - $GapSize $canvas = [Spectre.Console.Canvas]::new($canvasWidth, $canvasHeight) for ($y = 0; $y -lt $matrixHeight; $y++) { @@ -91,12 +104,12 @@ function Show-AwtrixScreen { $b = [byte]($colorInt -band 0xFF) $color = [Spectre.Console.Color]::new($r, $g, $b) - # Fill the scaled pixel block + # Fill the scaled pixel block, leaving gap rows/columns black for ($py = 0; $py -lt $PixelSize; $py++) { for ($px = 0; $px -lt $PixelSize; $px++) { - $canvas.SetPixel( - ($x * $PixelSize) + $px, - ($y * $PixelSize) + $py, + $canvas = $canvas.SetPixel( + ($x * $stride) + $px, + ($y * $stride) + $py, $color ) } @@ -104,6 +117,6 @@ function Show-AwtrixScreen { } } - [Spectre.Console.AnsiConsole]::Write($canvas) + $canvas | Out-SpectreHost } } diff --git a/awtrix/awtrix.psm1 b/awtrix/awtrix.psm1 index 793ff61..8b905f3 100644 --- a/awtrix/awtrix.psm1 +++ b/awtrix/awtrix.psm1 @@ -13,6 +13,10 @@ foreach ($import in @($classes + $public + $private)) { } } +if ( Get-Module -Name PwshSpectreConsole -ListAvailable) { + Import-Module PwshSpectreConsole -ErrorAction Stop +} + Export-ModuleMember -Function $public.Basename # Define the types to export with type accelerators. @@ -29,10 +33,12 @@ $TypeAcceleratorsClass = [psobject].Assembly.GetType( # If a type accelerator with the same name exists, throw an exception. $ExistingTypeAccelerators = $TypeAcceleratorsClass::Get foreach ($Type in $ExportableTypes) { - if ($Type.FullName -in $ExistingTypeAccelerators.Keys) { + if ($Type.FullName -in $ExistingTypeAccelerators.Keys -and + # Check if it's from our assembly, if it exists. This allows re-importing the module without error. + $ExistingTypeAccelerators[$Type.FullName].Assembly.GetName().Name -ne 'awtrix') { $Message = @( "Unable to register type accelerator '$($Type.FullName)'" - 'Accelerator already exists.' + "Accelerator already exists from assembly '$($ExistingTypeAccelerators[$Type.FullName].Assembly.GetName().Name)'." ) -join ' - ' throw [System.Management.Automation.ErrorRecord]::new( diff --git a/docs/en-US/Show-AwtrixScreen.md b/docs/en-US/Show-AwtrixScreen.md index ea0bcb1..18a9951 100644 --- a/docs/en-US/Show-AwtrixScreen.md +++ b/docs/en-US/Show-AwtrixScreen.md @@ -13,7 +13,7 @@ Renders the current AWTRIX screen as colored pixels in the terminal. ## SYNTAX ``` -Show-AwtrixScreen [[-ScreenData] ] [[-BaseUri] ] [[-PixelSize] ] +Show-AwtrixScreen [[-ScreenData] ] [[-BaseUri] ] [[-PixelSize] ] [[-GapSize] ] [-ProgressAction ] [] ``` @@ -99,6 +99,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -GapSize +Number of black pixels to insert between each LED pixel, simulating the +dark border between LEDs on a real matrix display. Default is 1. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: 1 +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ProgressAction {{ Fill ProgressAction Description }} From bba04f7bc9bd043094ef15d6ff6dbde913571cd5 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Fri, 13 Mar 2026 22:41:18 -0700 Subject: [PATCH 2/2] chore(release): 0.3.0 - Add GapSize parameter to Show-AwtrixScreen --- CHANGELOG.md | 7 +++++++ awtrix/awtrix.psd1 | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e46f8f3..da0c283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.0] 2026-03-13 + +### Added + +- `GapSize` parameter on `Show-AwtrixScreen` — Control black pixel spacing + between LEDs to simulate the dark borders on a real matrix display + ## [0.2.0] 2026-03-13 ### Added diff --git a/awtrix/awtrix.psd1 b/awtrix/awtrix.psd1 index 5feb214..6939e00 100644 --- a/awtrix/awtrix.psd1 +++ b/awtrix/awtrix.psd1 @@ -12,7 +12,7 @@ RootModule = 'awtrix.psm1' # Version number of this module. - ModuleVersion = '0.2.0' + ModuleVersion = '0.3.0' # Supported PSEditions # CompatiblePSEditions = @()