# The weather station firmware: compile, upload, and the logic tests.
#   make             compile weather_station/ for an ESP32 DevKit and print its size
#   make flash PORT=/dev/ttyUSB0
#   make test        run the logic tests (rain debounce and rate, wind and gusts, the vane, the day's
#                    minimum, maximum and rain, dew point, sea-level pressure) with g++, AddressSanitizer
#                    and UndefinedBehaviorSanitizer
# Needs the esp32 core (3.x or 4.x) and the libraries PubSubClient, ArduinoJson 7 and Adafruit BME280.

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

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

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

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

clean:
	rm -f test/test_weather_logic

.PHONY: all flash test clean
