Skip to content

Commit f6aced3

Browse files
committed
Made good progress implementing more generic functions to write content and know when a space should be left after each letter. Need to finish the content to be displayed on the display
1 parent 1a7afed commit f6aced3

File tree

3 files changed

+127
-11
lines changed

3 files changed

+127
-11
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ If you don't have PowerShell installed on your Raspberry, follow [this guide](ht
88

99
After that, you need to install [PowerShell-IoT Module](https://github.com/PowerShell/PowerShell-IoT#installation)
1010

11+
# What's available so far?
12+
This is still in a really early phase. So far I've been "designing" (if you can call it that way) the alphabet so that later we can send a whole text.
13+
14+
* So far you can only play with setting the brightness `Set-Brightness` (Low, Medium or High)
15+
16+
* Turn the leds off with `Set-LedsOff`
17+
18+
* Write some letters (a string) with `Write-String`. The number of letters actually depend, but it's usually 3 because each letter is using 3 rows. "M" for example uses 5.
19+
20+
After setting the whole alphabet and things to be displayed on the ScrollpHat, will work on a way to scroll the text.
21+
22+
1123
Any suggestion/contribution is really welcome!

ScrollpHat.psm1

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# Implement your module commands in this script.
2+
$registerObjectArray = @();
3+
for([int] $i = 1; $i -le 11<#numberOfRegisters#>; ++$i){
4+
$registerObjectArray += [PSCustomObject]@{
5+
Address = $i
6+
InUse = $false
7+
}
8+
}
9+
New-Variable -Name "MatrixRegisters" -Value $registerObjectArray -Scope Script
10+
11+
New-Variable -Name "InitialEmptyColumns" -Value 0x04, 0x08 -Option Constant -Scope Script
12+
213
function Select-ScrollpHat {
314
[int]$DeviceAddress = 0x60
415
######### Configuration Register and Value #########
@@ -12,6 +23,7 @@ function Select-ScrollpHat {
1223
function Set-Brightness{
1324
[CmdletBinding()]
1425
param (
26+
[Parameter(Mandatory=$true)]
1527
[ValidateSet('Low', 'Medium', 'High')]
1628
[string]$Intensity
1729
)
@@ -22,23 +34,60 @@ function Set-Brightness{
2234
High = [convert]::toint32('0000111',2)
2335
}
2436
Set-I2CRegister -Device $Script:Device -Register $LightningEffectRegisterAddress -Data $IntensityMap[$Intensity]
37+
Update-Registers
38+
}
39+
40+
function Write-String {
41+
param(
42+
[string]$text
43+
)
44+
for($i =0; $i -lt $text.Length ; ++$i)
45+
{
46+
Write-Char $text[$i]
47+
#After Writing the char, make sure to leave a space.
48+
$blankSpaceRegister = Get-NextAvailableRegisters 1
49+
if($blankSpaceRegister -eq $null){ #we have reached the end of the registers....
50+
return
51+
}
52+
Set-I2CRegister -Device $Script:Device -Register $blankSpaceRegister.Address -Data 0
53+
$blankSpaceRegister.InUse = $true
54+
}
55+
Update-Registers
2556
}
2657

2758
function Write-Char {
28-
[CmdletBinding()]
29-
param (
30-
[char]$character
59+
param(
60+
[ValidateLength(1,1)]
61+
[string]$char
3162
)
32-
#Until the dictionary is complete, this method will write the letter A on the 1st position, just for debug
33-
#Get-NextAvailableRegister
34-
[int[]]$Matrix1DataRegisterAddress = 0x01 ..0x03
35-
[int[]]$values = 0x3E, 0x05, 0x3E
63+
##############TEMP#################
64+
$alphabet = @{
65+
A = 0x3E, 0x05, 0x3E
66+
B = 0x1F, 0x15, 0x0A
67+
C = 0x0E, 0x11, 0x11
68+
D = 0x1F, 0x11, 0x0E
69+
E = 0x1F, 0x15, 0x11
70+
F = 0x1F, 0x05, 0x01
71+
G = 0x0E, 0x11, 0x1D
72+
H = 0x1F, 0x04, 0x1F
73+
I = 0x11, 0x1F, 0x11
74+
J = 0x09, 0x11, 0x0F
75+
K = 0x1F, 0x04, 0x1B
76+
L = 0x1F, 0x10, 0x10
77+
M = 0x1F, 0x02, 0x04, 0x02, 0x1F
78+
"!" = 0x17
79+
}
80+
###################################
81+
#get respective bits from hashtable
82+
$bitsArray = $alphabet[$char] # this is an array with required data
83+
$registers = Get-NextAvailableRegisters $bitsArray.Count
3684
$i = 0
37-
foreach ($register in $Matrix1DataRegisterAddress) {
38-
Set-RegisterValue -Device $Script:Device -Register $register -Value $values[$i]
39-
$i++
85+
foreach($register in $registers)
86+
{
87+
Set-I2CRegister -Device $Script:Device -Register $register.Address -Data $bitsArray[$i]
88+
$register.InUse = $true
89+
++$i
4090
}
41-
Update-Registers
4291
}
4392

4493
function Update-Registers{
@@ -47,6 +96,31 @@ function Update-Registers{
4796
Set-I2CRegister -Device $Script:Device -Register $UpdateRegisterAddress -Data $UpdateValue
4897
}
4998

99+
function Set-LedsOff {
100+
foreach ($register in @($Script:MatrixRegisters | % {$_})) { # this weird sintax flattens the list.
101+
Set-I2CRegister -Device $Script:Device -Register $register.Address -Data 0x0
102+
$register.InUse = $false
103+
}
104+
105+
Update-Registers
106+
}
107+
108+
function Reset-Registers {
109+
$resetRegisterAddress = 0xFF
110+
$resetRegisterValue = 0xF #can be any value
111+
Set-I2CRegister -Device $Script:Device -Register $resetRegisterAddress -Data $resetRegisterValue
112+
}
113+
114+
function Get-NextAvailableRegisters {
115+
param(
116+
[int]$numberOfRequiredRegisters
117+
)
118+
$Script:MatrixRegisters | Where-Object {$_.InUse -eq $false} | Select-Object -First $numberOfRequiredRegisters
119+
120+
}
121+
122+
Select-ScrollpHat
123+
50124
# Export only the functions using PowerShell standard verb-noun naming.
51125
# Be sure to list each exported functions in the FunctionsToExport field of the module manifest file.
52126
# This improves performance of command discovery in PowerShell.

alphabet.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$alphabet = @{
2+
A = 0x3E, 0x05, 0x3E
3+
B = 0x1F, 0x15, 0x0A
4+
C = 0x0E, 0x11, 0x11
5+
D = 0x1F, 0x11, 0x0E
6+
E = 0x1F, 0x15, 0x11
7+
F = 0x1F, 0x05, 0x01
8+
G = 0x0E, 0x11, 0x1D
9+
H = 0x1F, 0x04, 0x1F
10+
I = 0x11, 0x1F, 0x11
11+
J = 0x09, 0x11, 0x0F
12+
K = 0x1F, 0x04, 0x1B
13+
L = 0x1F, 0x10, 0x10
14+
M = 0x1F, 0x02, 0x04, 0x02, 0x1F
15+
}
16+
N =
17+
O =
18+
P =
19+
Q =
20+
R =
21+
S =
22+
T =
23+
U =
24+
V =
25+
W =
26+
X =
27+
Y =
28+
Z =
29+
30+
}

0 commit comments

Comments
 (0)