added led.sh and gitlab-ci shellcheck

This commit is contained in:
Simon Wörner
2017-03-30 16:40:56 +02:00
parent 422cd435c6
commit 69fc6e0797
2 changed files with 60 additions and 0 deletions

16
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,16 @@
# image: scorpil/rust:stable
stages:
- test
shellcheck:
stage: test
image: ubuntu:yakkety
before_script:
- apt-get update && apt-get install -y shellcheck
- locale-gen en_US.UTF-8
- export LANG=en_US.UTF-8
- export LANGUAGE=en_US:en
- export LC_ALL=en_US.UTF-8
script:
- find . -type f -name '*.sh' -print0 | xargs -n 1 -0 shellcheck --color

44
V1/led.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# usage: led.sh <port>
set -o xtrace
# config default
GPIO_PORT="${1:-18}"
function export_port() {
port="${1}"
echo "${port}" > /sys/class/gpio/export
}
function unexport_port() {
port="${1}"
echo "${port}" > /sys/class/gpio/unexport
}
function set_value() {
port="${1}"
value="${2}"
echo "${value}" > "/sys/class/gpio/gpio${port}/value"
}
function on() {
port="${1}"
set_value "${port}" "0"
}
function off() {
port="${1}"
set_value "${port}" "1"
}
# set exit trap
trap 'unexport_port "${GPIO_PORT}"' EXIT
# init GPIO port
export_port "${GPIO_PORT}"
# loop led on/off
while true; do
on "${GPIO_PORT}"
sleep 1
off "${GPIO_PORT}"
sleep 1
done