# The greenhouse node firmware: compile, upload, and the logic tests.
#   make             compile greenhouse_node/ for an ESP32 DevKit and print its size
#   make flash PORT=/dev/ttyUSB0
#   make test        run the logic tests (the SHT check bytes and units, the BH1750 lux and light per day,
#                    the soil calibration, the vapour pressure deficit, the fan and watering rules, the day)
#                    with g++, AddressSanitizer and UndefinedBehaviorSanitizer
# Needs the esp32 core (3.x or 4.x) and the libraries PubSubClient and ArduinoJson 7. The sensors need no library.

FQBN ?= esp32:esp32:esp32
PORT ?= /dev/ttyUSB0
CLI  ?= arduino-cli

all:
	$(CLI) compile --fqbn $(FQBN) --warnings all greenhouse_node

flash:
	$(CLI) compile --fqbn $(FQBN) --upload -p $(PORT) greenhouse_node

test:
	g++ -std=c++17 -O1 -g -Wall -Wextra -Werror -fsanitize=address,undefined -fno-sanitize-recover=all -Igreenhouse_node test/test_greenhouse_logic.cpp -o test/test_greenhouse_logic
	./test/test_greenhouse_logic

clean:
	rm -f test/test_greenhouse_logic

.PHONY: all flash test clean
