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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| Private Sub MainPage_Loaded() Handles Me.Loaded
OneLed_Load()
End Sub
Private Sub MainPage_Unloaded() Handles Me.Unloaded
UnloadGPIO()
End Sub
Private stateGpioPin5 As Integer = -1 '-1 : no value / 0 : OFF / 1 : ON
Private Const idGpioPin5 As Integer = 5 'GPIO Pin(5) = Physical Pin(29)
Private esGpioPin5 As GpioPin
Private esGpioPinValue5 As GpioPinValue
Private Sub OneLed_Load()
btnOneLedInit.Content = "Click Me for Init"
End Sub
Private Sub btnOneLedInit_Click(sender As Object, e As RoutedEventArgs) Handles btnOneLedInit.Click
Try
If stateGpioPin5 < 0 Then
If InitGPIO() Then
btnOneLedInit.Content = "Disable"
tbxOneLedStatement.Text = "GPIO ENABLE !"
End If
ElseIf stateGpioPin5 >= 0 Then
If UnloadGPIO() Then
btnOneLedInit.Content = "Enable"
tbxOneLedStatement.Text = "GPIO DISABLE !"
End If
End If
Catch ex As Exception
tbxOneLedStatement.Text = "btnOneLedInit_Click FAILED : " & ex.ToString
End Try
End Sub
Private Sub btnOneLedPushON_Click(sender As Object, e As RoutedEventArgs) Handles btnOneLedPushON.Click
If PushGPIO(True) Then
tbxOneLedStatement.Text = "LED ON !"
Else
UnloadGPIO()
End If
End Sub
Private Sub btnOneLedPushOFF_Click(sender As Object, e As RoutedEventArgs) Handles btnOneLedPushOFF.Click
If PushGPIO(False) Then
tbxOneLedStatement.Text = "LED OFF !"
Else
UnloadGPIO()
End If
End Sub
Private Function PushGPIO(pStatement As Boolean) As Boolean
Dim output As Boolean = False
Try
If pStatement Then
esGpioPinValue5 = (GpioPinValue.High)
Else
esGpioPinValue5 = (GpioPinValue.Low)
End If
esGpioPin5.Write(esGpioPinValue5)
output = True
Catch ex As Exception
tbxOneLedStatement.Text = "PushGPIO FAILED : " & ex.ToString
End Try
Return output
End Function
Private Function InitGPIO() As Boolean
Dim output As Boolean = False
Try
Dim gpio = GpioController.GetDefault()
If Not gpio Is Nothing Then
esGpioPin5 = gpio.OpenPin(idGpioPin5)
esGpioPin5.Write(GpioPinValue.Low)
esGpioPin5.SetDriveMode(GpioPinDriveMode.Output)
stateGpioPin5 = 0
output = True
End If
Catch ex As Exception
tbxOneLedStatement.Text = "InitGPIO FAILED : " & ex.ToString
End Try
Return output
End Function
Private Function UnloadGPIO() As Boolean
Dim output As Boolean = False
Try
esGpioPin5.Dispose()
stateGpioPin5 = -1
output = True
Catch ex As Exception
tbxOneLedStatement.Text = "UnloadGPIO FAILED : " & ex.ToString
End Try
Return output
End Function |
Partager