1 # Licence: GPLv3+ <http://www.gnu.org/licenses/gpl.txt>
 
   2 # Copyright 2015: Julien Moutinho <julm+air@autogeree.net>
 
  12         uniq,$(wordlist 2,$(words $1),$1),$2 $(if \
 
  13                 $(filter $(firstword $1),$2),,$(firstword $1))) \
 
  23 SENSOR_LABEL_temperature=Température (°C)
 
  24 SENSOR_LABEL_humidity=Humidité (%)
 
  25 SENSOR_LABEL_particles=Particules
 
  26 SENSOR_LABEL_quality=Qualité de l’air
 
  34 ## Round Robin Database (RRD)
 
  38 .rrd = $(wildcard rrd/*/*.rrd)
 
  45 ARDUINO_DIR   := /usr/share/arduino/
 
  46 ARDMK_DIR     := /usr/share/arduino/
 
  55  Humidity_Temperature_Sensor \
 
  59 USER_LIB_PATH := $(abspath ./libraries)
 
  62 include $(ARDMK_DIR)/Arduino.mk
 
  65 ino: $(TARGET_EEP) $(TARGET_HEX)
 
  71 define view/sensor/png
 
  74 define view/sensor/year/png
 
  75 view/$(sensor)/$(year)/png:
 
  78 define view/sensor/year/month/png
 
  79 view/$(sensor)/$(year)/$(month)/png: \
 
  80 view/$(sensor)/$(year)/$(month).png
 
  82 view/$(sensor)/$(year)/$(month).png: \
 
  83 rrd/$(year)/$(month).rrd
 
  86          -w 785 -h 120 -a PNG \
 
  88          --start $(month_begin) --end $(month_end) \
 
  89          --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
 
  90          --x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
 
  91          DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
 
  92          LINE1:$(sensor)'#ff0000':"$(sensor)"
 
  95 define view/sensor/year/month/day/png
 
  96 view/$(sensor)/$(year)/$(month)/$(day)/png: \
 
  97 view/$(sensor)/$(year)/$(month)/$(day).png
 
  99 view/$(sensor)/$(year)/$(month)/$(day).png: \
 
 100 rrd/$(year)/$(month).rrd
 
 103          -w 785 -h 120 -a PNG \
 
 105          --start $(day_begin) --end $(day_end) \
 
 106          --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
 
 107          --x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
 
 108          DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
 
 109          LINE1:$(sensor)'#ff0000':"$(sensor)";
 
 112 define view/year/month/png
 
 113 view/$(year)/$(month)/png: \
 
 114 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/png)
 
 116 define view/year/month/day/png
 
 117 view/$(year)/$(month)/$(day)/png: \
 
 118 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/$(day)/png)
 
 125 define view/sensor/html5
 
 128 define view/sensor/year/html5
 
 129 view/$(sensor)/$(year)/html5:
 
 132 define view/sensor/year/month/html5
 
 133 view/$(sensor)/$(year)/$(month)/html5: \
 
 134 view/$(sensor)/$(year)/$(month).html5
 
 136 view/$(sensor)/$(year)/$(month).html5: \
 
 137 view/$(sensor)/$(year)/$(month)/png
 
 139         <report sensor="$(sensor)" year="$(year)" month="$(month)"> \
 
 140                 $(foreach day,$(days), \
 
 143                  day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"/>) \
 
 145         xsltproc --output $$@ \
 
 146          xsl/sensor/year/month.html5.xsl -
 
 148 define view/year/month/html5
 
 149 view/$(year)/$(month)/html5: \
 
 150 view/$(year)/$(month).html5
 
 152 view/$(year)/$(month).html5: \
 
 153 view/$(year)/$(month)/png
 
 156         <report year="$(year)" month="$(month)"> \
 
 157                 $(foreach day,$(days), \
 
 160                  day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"> \
 
 161                         $(foreach sensor,$(sensors), \
 
 162                                 <sensor name="$(sensor)"/> \
 
 166         xsltproc --output $$@ \
 
 167          xsl/year/month.html5.xsl -
 
 173 years=$(call uniq,$(foreach rrd,$(.rrd),$(word 2,$(subst /, ,$(rrd)))))
 
 174 months=$(foreach rrd,$(filter rrd/$(year)/%,$(.rrd)),$(basename $(word 3,$(subst /, ,$(rrd)))))
 
 175 days=$(shell seq -w $$(date +'%d' -d '$(year)/$(month)/01 + 1 month - 1 second'))
 
 177 month_begin=$(shell date +'%s' -d '$(year)/$(month)/01')
 
 178 month_end=$(shell date +'%s' -d '$(year)/$(month)/01 + 1 month - 1 second')
 
 180 day_begin=$(shell date +'%s' -d '$(year)/$(month)/$(day)')
 
 181 day_end=$(shell date +'%s' -d '$(year)/$(month)/$(day) + 1 day - 1 second')
 
 183 define foreach/sensor
 
 184 .PHONY:     view/$(sensor)/$(view)
 
 185 view/$(view): view/$(sensor)/$(view)
 
 186 $(call view/sensor/$(view))
 
 189 define foreach/year/sensor/view
 
 190 .PHONY:               view/$(sensor)/$(year)/$(view)
 
 191 view/$(sensor)/$(view): view/$(sensor)/$(year)/$(view)
 
 192 $(call view/sensor/year/$(view))
 
 195 define foreach/year/month/sensor/view
 
 196 .PHONY:                         view/$(sensor)/$(year)/$(month)/$(view)
 
 197 view/$(sensor)/$(year)/$(view): view/$(sensor)/$(year)/$(month)/$(view)
 
 198 $(call view/sensor/year/month/$(view))
 
 200 define foreach/year/month/view
 
 201 .PHONY:             view/$(year)/$(month)/$(view)
 
 202 view/$(year)/$(view): view/$(year)/$(month)/$(view)
 
 203 $(call view/year/month/$(view))
 
 206 define foreach/year/month/day/sensor/view
 
 207 .PHONY:                                  view/$(sensor)/$(year)/$(month)/$(day)/$(view)
 
 208 view/$(sensor)/$(year)/$(month)/$(view): view/$(sensor)/$(year)/$(month)/$(day)/$(view)
 
 209 $(call view/sensor/year/month/day/$(view))
 
 211 define foreach/year/month/day/view
 
 212 .PHONY:                        view/$(year)/$(month)/$(day)/$(view)
 
 213 view/$(year)/$(month)/$(view): view/$(year)/$(month)/$(day)/$(view)
 
 214 $(call view/year/month/day/$(view))
 
 217 $(foreach sensor,$(sensors), \
 
 218         $(foreach view,$(views), \
 
 219                 $(eval $(call foreach/sensor)) \
 
 222 $(foreach year,$(years), \
 
 223         $(foreach view,$(views), \
 
 224                 $(eval $(call foreach/year/view)) \
 
 226         $(foreach sensor,$(sensors), \
 
 227                 $(foreach view,$(views), \
 
 228                         $(eval $(call foreach/year/sensor/view)) \
 
 231         $(foreach month,$(months), \
 
 232                 $(foreach view,$(views), \
 
 233                         $(eval $(call foreach/year/month/view)) \
 
 235                 $(foreach sensor,$(sensors), \
 
 236                         $(foreach view,$(views), \
 
 237                                 $(eval $(call foreach/year/month/sensor/view)) \
 
 240                 $(foreach day,$(days), \
 
 241                         $(foreach view,$(views), \
 
 242                                 $(eval $(call foreach/year/month/day/view)) \
 
 244                         $(foreach sensor,$(sensors), \
 
 245                                 $(foreach view,$(views), \
 
 246                                         $(eval $(call foreach/year/month/day/sensor/view)) \