From 7bb6daa4bf09947142e38ff468b7f62baae110fd Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 28 Nov 2022 05:45:20 +0300 Subject: esp8266 relay controller wip --- platformio/relayctl/make_static.sh | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 platformio/relayctl/make_static.sh (limited to 'platformio/relayctl/make_static.sh') diff --git a/platformio/relayctl/make_static.sh b/platformio/relayctl/make_static.sh new file mode 100755 index 0000000..079d26b --- /dev/null +++ b/platformio/relayctl/make_static.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +#set -x +#set -e + +DIR="$(dirname "$(realpath "$0")")" + +fw_version="$(cat "$DIR/src/config.def.h" | grep "^#define FW_VERSION" | awk '{print $3}')" +header="$DIR/src/static.h" +source="$DIR/src/static.cpp" + +[ -f "$header" ] && rm "$header" +[ -f "$source" ] && rm "$source" + +is_minifyable() { + local ext="$1" + [ "$ext" = "html" ] || [ "$ext" = "css" ] || [ "$ext" = "js" ] +} + +minify() { + local ext="$1" + local bin="$(realpath "$DIR"/../../tools/minify.js)" + "$bin" --type "$ext" +} + +# .h header +cat <> "$header" +/** + * This file is autogenerated with make_static.sh script + */ + +#pragma once + +#include + +namespace homekit::files { + +typedef struct { + size_t size; + const uint8_t* content; +} StaticFile; + +EOF + +cat <> "$source" +/** + * This file is autogenerated with make_static.sh script + */ + +#include "static.h" + +namespace homekit::files { + +EOF + +# loop over files +for ext in html js css ico; do + for f in "$DIR"/static/*.$ext; do + filename="$(basename "$f")" + echo "processing ${filename}..." + filename="${filename/./_}" + + # write .h + echo "extern const StaticFile $filename;" >> "$header" + + # write .c + { + echo "static const uint8_t ${filename}_content[] PROGMEM = {" + + cat "$f" | + ( [ "$ext" = "html" ] && sed "s/{version}/$fw_version/" || cat ) | + ( is_minifyable "$ext" && minify "$ext" || cat ) | + gzip | + xxd -ps -c 16 | + sed 's/.\{2\}/0x&, /g' | + sed 's/^/ /' + + echo "};" + echo "const StaticFile $filename PROGMEM = {(sizeof(${filename}_content)/sizeof(${filename}_content[0])), ${filename}_content};" + echo "" + } >> "$source" + done +done + +# end of homekit::files +( echo ""; echo "}" ) >> "$header" +echo "}" >> "$source" -- cgit v1.2.3