Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-user config implementation #9

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# same exact way, here's a script to do the same thing

if [ 0 = "$#" ]; then
echo "Usage: build.sh TARGET USER"
echo "Example: build.sh hw/hank/emisar-d4/anduril.h users/myuser"
echo "(but USER isn't implemented yet)"
echo "Usage: build.sh TARGET"
echo "Example: build.sh hw/hank/emisar-d4/anduril.h"
exit
fi

Expand All @@ -21,6 +20,8 @@ ARGS="$*"
UI=$(basename "$TARGET" .h)
MODEL=$(dirname "$TARGET")
PROGRAM="ui/$UI/$UI"
USER_MODEL_CFG=$(dirname ${TARGET//hw/users\/$USER} )/config.h
USER_DEFAULT_CFG=users/$USER/config.h

# figure out the model number
MODEL_NUMBER=$(head -1 "$MODEL/model")
Expand Down Expand Up @@ -48,7 +49,6 @@ export CC=avr-gcc
export CPP=avr-cpp
export OBJCOPY=avr-objcopy
export DFPFLAGS="-B $DFPPATH/gcc/dev/$MCUNAME/ -I $DFPPATH/include/"
# TODO: include $user/ first so it can override other stuff
INCLUDES="-I ui -I hw -I. -I.. -I../.. -I../../.."
export CFLAGS=" -Wall -g -Os -mmcu=$MCUNAME -c -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS"
export CPPFLAGS="-Wall -g -Os -mmcu=$MCUNAME -C -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS"
Expand All @@ -59,6 +59,16 @@ export OBJS=$PROGRAM.o

OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\" $ARGS"

if [ -f $USER_DEFAULT_CFG ]; then
echo " Using custom configuration from $USER_DEFAULT_CFG"
OTHERFLAGS="$OTHERFLAGS -DUSER_DEFAULT_H=$USER_DEFAULT_CFG"
fi

if [ -f $USER_MODEL_CFG ]; then
echo " Using custom configuration from $USER_MODEL_CFG"
OTHERFLAGS="$OTHERFLAGS -DUSER_MODEL_H=$USER_MODEL_CFG"
fi

function run () {
#echo "$1" ; shift
#echo "$*"
Expand Down
24 changes: 23 additions & 1 deletion docs/per-user-config.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
# Per-User Configuration

(write me)
To customize the configuration for all models, create a
`users/<username>/config.h` file.

To customize the configuration for a specific model, create a
`users/<username>/<manufacturer>/<model>/config.h` file (same directory
structure as that under `hw`, just replace `hw` with `users/<username>`).

Both customization methods can be used together, ie. you can have a global
`config.h` with all your favorite settings and a model-specific `config.h`
to override some of them on a specific light.

In the global or model-specific `config.h` you can override default settings
like this:

#undef RAMP_SMOOTH_FLOOR
#define RAMP_SMOOTH_FLOOR 30

To use these customizations, set the USER variable when running `make`:

USER=username ./make [target]

If you place customizations in a directory under `users/` that matches your
Unix username (ie. `users/<your username>`), they will be used automatically
and you don't need to specify the username in the `make` command.
9 changes: 9 additions & 0 deletions ui/anduril/anduril.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
#include "fsm/tk.h"
#include incfile(CFG_H)

// Per-user global overrides
#ifdef USER_DEFAULT_H
#include incfile(USER_DEFAULT_H)
#endif

// Per-user model-specific overrides
#ifdef USER_MODEL_H
#include incfile(USER_MODEL_H)
#endif

/********* Include headers which need to be before FSM *********/

Expand Down
4 changes: 4 additions & 0 deletions users/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!README.md

3 changes: 3 additions & 0 deletions users/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Per-User Configuration

See [Per-User Configuration](../docs/per-user-config.md)