This post is part 1 of 6 of the GPIO Test Application. The following parts together compose the full article:
- GPIO Test Application Part 1 – Overview (this post)
- GPIO Test Application Part 2 – Hardware
- GPIO Test Application Part 3 – Model
- GPIO Test Application Part 4 – View Model
- GPIO Test Application Part 5 – View
- GPIO Test Application Part 6 – Result
As a first application that involves hardware, I decided to keep things simple. The idea is just to hook up a couple Inputs and Outputs and have a program that will work with the GPIO to read/write the values.
Source Code
To follow along, you might want to download the full solution right here:
You can run the application on your computer, but it will run in simulation mode (no GPOI). See the First Windows 10 IoT Core Windows Application post for information on how to run it on your Raspberry Pi.
The source code for the project has the same requirements as stated in my post: Setting up Visual Studio 2015 for Windows 10 IoT Core development
Requirements
The requirements that I chose for this application will allow us to explore the GPIO and programming model associated with creating User Interface on the Raspberry Pi 2 under the Windows 10 IoT Core operating system. The application should incorporate:
- Hardware components accessed through the GPIO
- A responsive UI that will display the status of the hardware components as it changes.
- And some control by the user to set how the output are calculated.
For simplicity, this application assumes the Raspberry Pi is configured for user interactivity and that it is connected to a full size screen and has an input pointing device. I will explore different form factors as well as headless device development at another time.
Solution
To achieve these requirements I will create a programmable LogicGate application that will take input from 2 push buttons, will calculate a result based on a logic operation applied to the 2 inputs, and will light up a green LED for true and a red LED for false.
In addition, we will include UI to control the calculation by selecting which logic operation is used. We will also include UI to visually display the status of the Inputs and Outputs.
Whenever any of the inputs or logic operation parameter changes, the application should update the displayed status, recalculate the output and light up the appropriate LED.
Application Components Overview
The application will be based on the MVVM pattern that we have shown earlier. This pattern is well adapted to the creation of reactive WPF applications. It this case, the application is composed of 4 main components that are:
- Hardware
- Model
- View Model
- View
The components are organized as follow:
Hardware
The hardware is composed of:
- 2 switches (right / left)
- 1 red LED
- 1 green LED
More details about the electronic circuit will be available in the following post GPIO Test Application Part 2 – Hardware.
Model
On this application , we will used the model to encapsulate the access to the hardware through the GPIOs.
The model will provide a comprehensive Model API that allows seamless access to read the Inputs and write to the Outputs. The interface will contain the following Properties:
- SwitchRight
- SwitchLeft
- RedLED
- GreenLED
More details about the Model will be available in the post GPIO Test Application Part 3 – Model.
ViewModel
The ViewModel contains an instance of the Model and makes it available to the View. It also provides the functionality to calculate the Output based on the Logic Operation selected by the user on the View.
The available Logic Operations are:
- AND
- OR
- NAND
- NOR
- XOR
More details about the ViewModel will be available in the post GPIO Test Application Part 4 – ViewModel.
View
The View provides the User Interface that the user to view the hardware status and to select the Logic Operation that determines the output. The user interface will look something like this:
Where:
- Logic Operation: Section that allows the user to select which logic operation is used to calculate the output.
- Device Interface: Displays the symboles that represents the different hardware components. The symbol is only displayed when the switch is pressed or the LED is lit. The symbols are:
- Blue Square: for the switches
- Red Circle: for the red LED
- Green Circle: for the green LED
More details about the View will be available in the post GPIO Test Application Part 5 – View.
Results
In the last section, GPIO Test Application Part 6 – Result, I will provide access to the full source code of this application and we’ll see the resulting application in action.