From 69fc6e0797dde92d8d69979a97242e6a2ac0c6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=B6rner?= Date: Thu, 30 Mar 2017 16:40:56 +0200 Subject: [PATCH 1/2] added led.sh and gitlab-ci shellcheck --- .gitlab-ci.yml | 16 ++++++++++++++++ V1/led.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100755 V1/led.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..fae1209 --- /dev/null +++ b/.gitlab-ci.yml @@ -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 diff --git a/V1/led.sh b/V1/led.sh new file mode 100755 index 0000000..45fade7 --- /dev/null +++ b/V1/led.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# usage: led.sh +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 From d7c15c5c7798ed4705e5c15b9e1fc83209b8519a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=B6rner?= Date: Thu, 30 Mar 2017 17:09:04 +0200 Subject: [PATCH 2/2] set gpio direction --- V1/led.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/V1/led.sh b/V1/led.sh index 45fade7..a0033e7 100755 --- a/V1/led.sh +++ b/V1/led.sh @@ -14,6 +14,12 @@ function unexport_port() { echo "${port}" > /sys/class/gpio/unexport } +function set_direction() { + port="${1}" + value="${2}" + echo "${value}" > "/sys/class/gpio/gpio${port}/direction" +} + function set_value() { port="${1}" value="${2}" @@ -34,6 +40,7 @@ trap 'unexport_port "${GPIO_PORT}"' EXIT # init GPIO port export_port "${GPIO_PORT}" +set_direction "${GPIO_PORT}" "out" # loop led on/off while true; do