Add module template and new_module.sh
This commit is contained in:
parent
fc2a36cb9b
commit
181dd87752
3 changed files with 90 additions and 0 deletions
57
src/new_module.sh
Executable file
57
src/new_module.sh
Executable 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"
|
19
src/template_module/doc/index.md
Normal file
19
src/template_module/doc/index.md
Normal 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}.
|
14
src/template_module/main.ino
Normal file
14
src/template_module/main.ino
Normal 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();
|
||||
}
|
Loading…
Reference in a new issue