11# Copyright (c) Microsoft Corporation. All rights reserved.
22# Licensed under the MIT License.
33
4- Describe " Empty Test" {
5- Context " Empty Test" {
6- It " Empty Test" {
7- $true | Should Be $true
4+ Describe " PowerShell IoT tests" {
5+ BeforeAll {
6+ # This creates the session to the test Pi. The hostname maps to a random IP
7+ $Global :SESSION = New-PSSession - HostName raspberry - UserName pi
8+ }
9+ Context " I2C tests" {
10+ BeforeAll {
11+ Invoke-Command - Session $Global :SESSION - ScriptBlock {
12+ # Import the example BME280 which wraps PowerShell IoT cmdlets
13+ Import-Module Microsoft.PowerShell.IoT.BME280
14+ }
15+
16+ }
17+ It " Can get the the BME280 I2C device" {
18+ $device = Invoke-Command - Session $Global :SESSION - ScriptBlock {
19+ return Get-BME280Device - Id 0x76
20+ }
21+ $device | Should -Not - BeNullOrEmpty
22+ $device.Id | Should - Be 118
23+ $device.FriendlyName | Should - Be " BME280"
24+ }
25+ It " Can get the BME280 data" {
26+ $data = Invoke-Command - Session $Global :SESSION - ScriptBlock {
27+ return Get-BME280Data
28+ }
29+ $data.Temperature | Should -Not - BeNullOrEmpty
30+ $data.Pressure | Should -Not - BeNullOrEmpty
31+ $data.Humidity | Should -Not - BeNullOrEmpty
32+ }
33+ }
34+ Context " GPIO tests" {
35+ # GPIO pins can either act as an input or output pin. In other words,
36+ # you can either set a pin's value or read a pin's value. For example,
37+ # if you set pin 20 to "High" (aka 1) and attempt to read the value of
38+ # pin 20, you will not get the result of your previous set operation.
39+
40+ # To get around this limitation, on the test Raspberry Pi we have two pins
41+ # (22 and 26) connected. By doing this, we can set the value on pin 22 and
42+ # read that value on pin 26. This next test demonstrates that.
43+ It " Can get and set a GPIO's pin value" {
44+ $highValueResult = Invoke-Command - Session $Global :SESSION - ScriptBlock {
45+ Set-GpioPin - Id 26 - Value High
46+ return Get-GpioPin - Id 22
47+ }
48+ $highValueResult.Id | Should - Be 22
49+ $highValueResult.Value | Should - Be " High"
50+
51+ $lowValueResult = Invoke-Command - Session $Global :SESSION - ScriptBlock {
52+ Set-GpioPin - Id 26 - Value Low
53+ return Get-GpioPin - Id 22
54+ }
55+ $lowValueResult.Id | Should - Be 22
56+ $lowValueResult.Value | Should - Be " Low"
57+ }
58+ It " Can use the -Raw flag to get the raw value" {
59+ $rawValue = Invoke-Command - Session $Global :SESSION - ScriptBlock {
60+ Set-GpioPin - Id 26 - Value High
61+ return Get-GpioPin - Id 22 - Raw
62+ }
63+ $rawValue | Should - Be 1
64+ }
65+ It " Read non-connected pin with PullDown and return Low" {
66+ $result = Invoke-Command - Session $Global :SESSION - ScriptBlock {
67+ return Get-GpioPin - Id 23 - PullMode PullDown - Raw
68+ }
69+ $result | Should - Be 0
70+ }
71+ It " Read non-connected pin with PullUp and return High" {
72+ $result = Invoke-Command - Session $Global :SESSION - ScriptBlock {
73+ return Get-GpioPin - Id 23 - PullMode PullUp - Raw
74+ }
75+ $result | Should - Be 1
76+ }
77+ }
78+ Context " SPI tests" {
79+ # SPI test: LIS3DH motion sensor; datasheet: www.st.com/resource/en/datasheet/lis3dh.pdf
80+ # Read "WHO_AM_I (0Fh)" register; value should be 0x33
81+ It " Can read data from the LIS3DH motion sensor" {
82+ $result = Invoke-Command - Session $Global :SESSION - ScriptBlock {
83+ $d = @ (0x8F , 0x0 )
84+ return Send-SPIData - Channel 0 - Data $d
85+ }
86+ $result.Channel | Should - Be 0
87+ $result.Data [0 ] | Should - Be 0x8F
88+ $result.Responce [1 ] | Should - Be 0x33
89+ $result.Frequency | Should - Be 500000
90+ }
91+ It " Can use the -Raw flag to get the raw value" {
92+ $result = Invoke-Command - Session $Global :SESSION - ScriptBlock {
93+ $d = @ (0x8F , 0x0 )
94+ return Send-SPIData - Channel 0 - Data $d - Raw
95+ }
96+ $result [1 ] | Should - Be 0x33
897 }
998 }
10- }
99+ }
0 commit comments