Update gpio.md

pull/60/head
Maxim Devaev 4 years ago committed by GitHub
parent 3d00729024
commit f00878428d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,99 +9,102 @@ that can also be used transparently by emulating abstract GPIO API.
# Configuration # Configuration
Setting up GPIO is quite complex. The interface is divided into several layers for flexibility. All configuration is performed using a file `/etc/kvmd/override.yaml` which has the [YAML syntax](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html). We will look at each part of the configuration separately in a small test example. Setting up GPIO is quite complex. The interface is divided into several layers for flexibility. All configuration is performed using a file `/etc/kvmd/override.yaml` which has the [YAML syntax](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html). We will look at each part of the configuration separately in a small test example.
* **Drivers** is the first layer that reflects the hardware that represents the IO ports (standard GPIO of Raspberry Pi, USB relay, and so on). Each driver has a type (a plugin that implements the hardware support) and an unique name. Multiple drivers of the same type can be defined at the same time. ### Drivers
The first layer that reflects the hardware that represents the IO ports (standard GPIO of Raspberry Pi, USB relay, and so on). Each driver has a type (a plugin that implements the hardware support) and an unique name. Multiple drivers of the same type can be defined at the same time.
For example, you can connect multiple relays and give each one its own name. By default, one driver is configured with the name `__gpio__`, representing the physical GPIO interface of the Raspberry Pi.
For example, you can connect multiple relays and give each one its own name. By default, one driver is configured with the name `__gpio__`, representing the physical GPIO interface of the Raspberry Pi.
```yaml
kvmd: ```yaml
gpio: kvmd:
drivers: gpio:
# This example shows how the __gpio__ driver is defined. You don't need to write it in your configuration. drivers:
__gpio__: # Names that start and end with two underscores are reserved. You don't have to define similar names yourself. # This example shows how the __gpio__ driver is defined. You don't need to write it in your configuration.
type: gpio __gpio__: # Names that start and end with two underscores are reserved. You don't have to define similar names yourself.
state_poll: 0.1 type: gpio
state_poll: 0.1
# You can define another gpio driver with a different polling interval
my_gpio: # You can define another gpio driver with a different polling interval
type: gpio my_gpio:
state_poll: 1.5 type: gpio
state_poll: 1.5
# We have HID relay connected to Pi-KVM
relay: # We have HID relay connected to Pi-KVM
type: hidrelay relay:
device: /dev/hidraw0 type: hidrelay
``` device: /dev/hidraw0
```
* **Scheme** is the second layer that reflects how the various driver ports are configured. Each port has a unique name, mode (`input` or `output`), a pin number, and refers to the driver that provides it.
### Scheme
Two interaction modes are available for outputs: `pulse` and `switch`. In pulse mode, the output quickly switches its state to logical 1 and back (just like a button). In switch mode, it saves the state that the user set. When KVMD starts and finishes, all output ports are reset to 0. This can be avoided using the `initial` parameter. The second layer that reflects how the various driver ports are configured. Each port has a unique name, mode (`input` or `output`), a pin number, and refers to the driver that provides it.
If no driver is specified for the port in the scheme, `__gpio__` will be used as default. Two interaction modes are available for outputs: `pulse` and `switch`. In pulse mode, the output quickly switches its state to logical 1 and back (just like a button). In switch mode, it saves the state that the user set. When KVMD starts and finishes, all output ports are reset to 0. This can be avoided using the `initial` parameter.
```yaml If no driver is specified for the port in the scheme, `__gpio__` will be used as default.
kvmd:
gpio: ```yaml
scheme: kvmd:
# A certain device sends signals to the RPi and we want the Pi-KVM to display this as an led gpio:
led1: scheme:
pin: 19 # A certain device sends signals to the RPi and we want the Pi-KVM to display this as an led
mode: input led1:
led2: pin: 19
pin: 16 mode: input
mode: input led2:
pin: 16
# Two outputs of RPi's GPIO mode: input
button1:
pin: 26 # Two outputs of RPi's GPIO
mode: output button1:
switch: false # Disable switching, only pulse available pin: 26
button2: mode: output
pin: 20 switch: false # Disable switching, only pulse available
mode: output button2:
switch: false pin: 20
mode: output
relay1: # Channel 1 of the relay /dev/hidraw0 switch: false
pin: 0 # Numerating starts from 0
mode: output # Relays can't be inputs relay1: # Channel 1 of the relay /dev/hidraw0
initial: null # Don't reset the state to 0 when initializing and terminating KVMD pin: 0 # Numerating starts from 0
relay2: # Channel 2 mode: output # Relays can't be inputs
pin: 1 initial: null # Don't reset the state to 0 when initializing and terminating KVMD
mode: output relay2: # Channel 2
initial: null pin: 1
pulse: mode: output
delay: 2 # Default pulse value initial: null
max_delay: 2 # The pulse interval can be between min_pulse (0.1 by default) and max_pulse=5 pulse:
``` delay: 2 # Default pulse value
max_delay: 2 # The pulse interval can be between min_pulse (0.1 by default) and max_pulse=5
* **View** is the visualization layer of the scheme. It describes what the menu with GPIO functions will look like. It is easier to show by example. ```
```yaml ### View
kvmd: This is the last layer of the scheme. It describes what the menu with GPIO functions will look like. It is easier to show by example.
gpio:
view: ```yaml
header: kvmd:
title: Switches # Menu title gpio:
table: # The menu items are rendered in the form of a table of text labels and controls view:
- ["#Generic GPIO leds"] # Text starting with the sharp symbol will be a label header:
- [] # Horizontal separator and start of a new table title: Switches # Menu title
- ["#Test 1:", led1, button1] # Text label, one input, one button with text "Click" table: # The menu items are rendered in the form of a table of text labels and controls
- ["#Test 2:", led2, button2] - ["#Generic GPIO leds"] # Text starting with the sharp symbol will be a label
- [] - [] # Horizontal separator and start of a new table
- ["#HID Relays /dev/hidraw0"] - ["#Test 1:", led1, button1] # Text label, one input, one button with text "Click"
- [] - ["#Test 2:", led2, button2]
- ["#Relay #1:", "relay1,Boop 0.1"] # Text label and button with alternative text - []
- ["#Relay #2:", "relay2,Boop 2.0"] - ["#HID Relays /dev/hidraw0"]
``` - []
- ["#Relay #1:", "relay1,Boop 0.1"] # Text label and button with alternative text
This will be rendered as: - ["#Relay #2:", "relay2,Boop 2.0"]
```
<img src="../img/gpio_menu.png" alt="drawing" />
This will be rendered as:
Here the rules:
- Text starting with the `#` symbol will be a label. <img src="../img/gpio_menu.png" alt="drawing" />
- To place a port in a cell, just put its name from the scheme.
- The inputs are displayed as round LEDs. Here the rules:
- The outputs are displayed as a switch AND a button. - Text starting with the `#` symbol will be a label.
- If the switch mode is disabled, only a button will be displayed. If pulse is disabled, only a switch will be shown. - To place a port in a cell, just put its name from the scheme.
- To rename the output button, write some its identifier using comma like `"relay1,My cool relay"`. - The inputs are displayed as round LEDs.
- The outputs are displayed as a switch AND a button.
- If the switch mode is disabled, only a button will be displayed. If pulse is disabled, only a switch will be shown.
- To rename the output button, write some its identifier using comma like `"relay1,My cool relay"`.

Loading…
Cancel
Save