Skip to content

Commit

Permalink
refactor: Update repo to use make instead of grunt. (#167)
Browse files Browse the repository at this point in the history
* feat(utils): Added makefile with stubs
* fix(perms): Not sure why firmata file had x perms so removed them
* refactor(utils): Moved from gruntfile to makefile
* refactor(utils): Removed gruntfile and grunt related packages
* refactor(utils): removed grunt tests
* refactor(packages): Move of some files out of dependency list
* docs(dev): Updated dev documentation around make
  • Loading branch information
ajfisher committed Oct 4, 2020
1 parent be57708 commit c27958e
Show file tree
Hide file tree
Showing 6 changed files with 680 additions and 3,129 deletions.
149 changes: 0 additions & 149 deletions Gruntfile.js

This file was deleted.

134 changes: 134 additions & 0 deletions Makefile
@@ -0,0 +1,134 @@
.PHONY: clean test

# use this so we can call make again robustly if needed
THIS_FILE := $(lastword $(MAKEFILE_LIST))

FIRMWARE_DIR = ./firmware
BUILD_DIR = $(FIRMWARE_DIR)/build
BIN_DIR = $(FIRMWARE_DIR)/bin
SRC_DIR = $(FIRMWARE_DIR)/src
LIBS_DIR = $(SRC_DIR)/libs

help:
@echo "Development actions:"
@echo "--------------------"
@echo "clean: Cleans up everything"
@echo "clean-node: Cleans all of the node modules up"
@echo "clean-build: Cleans up all of the build folders"
@echo "clean-compiled: Cleans up all of the compiled files"
@echo "install: Installs all of the packages"
@echo "lint: Runs the linter"
@echo "test: Runs all of the tests"
@echo ""
@echo "Build actions:"
@echo "--------------"
@echo "build: Builds all of the codebase"
@echo "compile: Compiles all of the binaries"
@echo ""
@echo "Release actions:"
@echo "----------------"
@echo "release: Tags and releases code to NPM"
@echo ""

clean: clean-node clean-build clean-compiled
@echo "Run npm install to get started"

clean-node:
# remove node files
rm -rf node_modules/

clean-build-backpack:
@# remove the firmware build items
rm -rf $(BUILD_DIR)/backpack

clean-build-firmata:
@# remove the firmware build items
rm -rf $(BUILD_DIR)/node_pixel_firmata

clean-build: clean-build-backpack clean-build-firmata
@# grunt clean
@# remove the compiled bins
rm -rf $(BIN_DIR)/firmata/*
rm -rf $(BIN_DIR)/backpack/*

clean-compiled:
# removes all of the compilation intermediate files
for f in $(BIN_DIR)/*/*/*; \
do \
if [[ $${f} != *.ino.hex ]]; \
then \
rm -rf $${f}; \
fi; \
done

install: clean
@echo "Installing all of the packages needed"
npm install

lint:
@echo "Not implemented"

test:
npm run test


# make the Firmata build process to copy the files to the right place
FIRMATA_DEST_DIR = $(BUILD_DIR)/node_pixel_firmata
FIRMATA_FILES = $(LIBS_DIR)/firmata/arduino/*.{h,cpp}

build-firmata: clean-build-firmata
@echo "Creating firmata build files"
mkdir $(FIRMATA_DEST_DIR)
cp $(FIRMATA_FILES) $(FIRMATA_DEST_DIR)/
cp $(LIBS_DIR)/ws2812/* $(FIRMATA_DEST_DIR)/
cp $(LIBS_DIR)/lightws2812/* $(FIRMATA_DEST_DIR)/
cp $(SRC_DIR)/controller_src/firmata/* $(FIRMATA_DEST_DIR)/
@echo "Firmata build files ready"


# Make the backpack build process to copy the files to the right place
BACKPACK_DEST_DIR = $(BUILD_DIR)/backpack

build-backpack: clean-build-backpack
@echo "Creating backpack build files"
mkdir $(BACKPACK_DEST_DIR)
cp $(LIBS_DIR)/ws2812/* $(BACKPACK_DEST_DIR)/
cp $(LIBS_DIR)/lightws2812/* $(BACKPACK_DEST_DIR)/
cp $(SRC_DIR)/controller_src/backpack/* $(BACKPACK_DEST_DIR)/
@echo "Backpack build files ready"

build: build-backpack build-firmata
@echo "run make compile to compile"


# Set out all of the targets and info to build the bins from
BOARD_TGTS = uno nano pro-mini mega diecimila leonardo micro
PKG_uno = "arduino:avr:uno"
PKG_nano = "arduino:avr:nano:cpu=atmega328"
PKG_pro-mini = "arduino:avr:pro:cpu=16MHzatmega328"
PKG_mega = "arduino:avr:mega:cpu=atmega2560"
PKG_diecimila = "arduino:avr:diecimila:cpu=atmega328"
PKG_leonardo = "arduino:avr:leonardo"
PKG_micro = "arduino:avr:micro"

FIRMATA_INO = $(FIRMATA_DEST_DIR)/node_pixel_firmata.ino
BACKPACK_INO = $(BACKPACK_DEST_DIR)/backpack.ino

compile: build-backpack build-firmata $(BOARD_TGTS)
@# clean up all of the garbage files
@$(MAKE) -f $(THIS_FILE) clean-compiled

$(BOARD_TGTS):
@echo "This is $@ and package is $(PKG_$@) firmata $(FIRMATA_INO) BP $(BACKPACK_INO)"
@# make the firmata bin for this target board
$$ARDUINO_PATH --verify --verbose-build --board $(PKG_$@) \
--pref build.path=$(BIN_DIR)/firmata/$@ $(FIRMATA_INO)

@# make the firmata bin for this target board
$$ARDUINO_PATH --verify --verbose-build --board $(PKG_$@) \
--pref build.path=$(BIN_DIR)/backpack/$@ $(BACKPACK_INO)

release:
@echo "Not implemented"


33 changes: 20 additions & 13 deletions firmware/src/README.md
Expand Up @@ -25,34 +25,41 @@ relevant locations during the build process.
## Dev environment set up

Due to the way this is all managed, the best way to work with this set up is
to use something like arduino CLI tools so you can edit, have the
grunt watch task run to put the files in the appropriate place and then build.
INO is no longer supported as of v0.4.0 as the project has stagnated and the
arduino CLI is preferred.
to use something like arduino CLI tools so you can edit and then use make to
build and compile the files.

If you don't have that sort of setup then the next easiest way is to switch your
arduino IDE in preferences to "use an external editor". Then open up the target
you want to build and edit the source file in a separate editor (eg Sublime Text,
Vim or whatever). Then when you compile, the file and any supporting files will
be loaded.

## Grunt
Export the path to your ARDUINO application:

A `Gruntfile` is included that comprises a watcher on the `src` directory. When
files here change then the targets are rebuilt appropriately with copy commands
to put the files in the appropriate locations.
`export ARDUINO_PATH=~/Downloads/Arduino.app/Contents/MacOS/Arduino`

To ease your development process use:
To make sure it's available to make.

## Make

A `Makefile` is included that has pretty much everything you need in it.

`make build` will get all the files to the right location and then you can use
the arduino cli tools or the arduino IDE to compile and flash to the board.

`make compile` is used to build and compile all targets and will use the arduino
command like invocation.

A useful trick is if you just want to build one target use `make uno` or `make nano`
and this will build just the backpack and firmata for that target.

```
grunt watch
```

## Building for deployment

If there are any mods to the src files then run `grunt build` to make sure
If there are any mods to the src files then run `make build` to make sure
everything is updated properly.


## TODO

* Get issue fixed with arduino cli in order to build hex files automatically for
Expand Down
Empty file modified firmware/src/controller_src/firmata/node_pixel_firmata.ino 100755 → 100644
Empty file.

0 comments on commit c27958e

Please sign in to comment.