Add module template and new_module.sh

This commit is contained in:
Midgard 2020-08-25 21:07:42 +02:00
parent fc2a36cb9b
commit 181dd87752
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 90 additions and 0 deletions

57
src/new_module.sh Executable file
View file

@ -0,0 +1,57 @@
#/bin/bash
# "Bash strict mode", see http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
# Go to the current working directory so things work if people are in a different one and e.g. use ../src/new_module.sh
cd "$(dirname "$0")"
# Make sure the template dir exists so we don't let people enter details unnecessarily
if [ ! -d ./module_template ]; then
echo "module_template doesn't exist" >&2
exit 1
fi
# Ask for module name
read -p "Name of module (e.g. Oil gauge): " module_name
if [[ $module_name == *%* ]]; then
echo "Module name must not contain %" >&2
exit 1
fi
# Determine a "clean" module name: lowercase, no spaces
module="${module_name,,}"
module="${module// /_}"
module="${module//\'/}"
# Make sure `modules` directory exists and target directory doesn't
mkdir -p modules
module_dir="modules/$module"
if [[ -e "$module_dir" ]]; then
echo "$module_dir already exists" >&2
exit 1
fi
# Ask for author name
read -p "How would you like to be credited? Your name: " author
if [[ $author == *%* ]]; then
echo "Author name must not contain %" >&2
exit 1
fi
# Copy the template directory
cp -r -T template_module "$module_dir"
cd "$module_dir"
# Fill in the blanks in the template
sed -i "
s/{YEAR}/$(date +%Y)/
s%{AUTHOR}%$author%
s%{MODULE_NAME}%$module_name%
s%{MODULE}%$module%
" $(find -type f)
# Arduino IDE requires .ino sketches to have the same name as their directory
mv main.ino "$module.ino"
echo "The basic structure for your module is now ready in $module_dir"

View file

@ -0,0 +1,19 @@
## {MODULE_NAME}
Write the defusing guide for your module here. For inspiration, look at the documentation of
existing modules.
Use drawings! Put them in the same directory as this file and include them like this:
![](filename.pdf)
Use tables! Write them like this:
| Symbol | Action to take |
|------------------|----------------|
| ![](symbol1.pdf) | Do nothing |
| ![](symbol2.pdf) | Press the red button |
| ![](symbol3.pdf) | Press the yellow button |
### Credits
Module developed by {AUTHOR}.

View file

@ -0,0 +1,14 @@
// (c) {YEAR}, {AUTHOR}
// See the LICENSE file for conditions for copying
#include <obus_module.h>
void setup() {
Serial.begin(9600);
obus_module_init();
}
void loop() {
obus_module_loop();
}