diff --git a/README.md b/README.md
index 6ff897e..fd4f071 100644
--- a/README.md
+++ b/README.md
@@ -69,3 +69,20 @@ In the project root run:
nix-shell --option sandbox false
make firmware -j$(nproc)
```
+
+
+
+>>> import htmlmin
+>>> input_html = '''
+
+ htmlmin rocks
+
+ and rolls
+
+ '''
+>>> htmlmin.minify(input_html)
+u' htmlmin rocks
\n and rolls\n
'
+>>> print htmlmin.minify(input_html)
+ htmlmin rocks
+ and rolls
+
diff --git a/firmware/Makefile b/firmware/Makefile
index bc8dc8b..67abfc0 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -14,7 +14,7 @@ html: fsdata/fsdata.c
fsdata/fsdata.c: fsdata/fs/index.html fsdata/fs/404.html fsdata/fs/css/picnic.min.css fsdata/fs/css/style.css fsdata/fs/js/smoothie_min.js
@echo "Generating fsdata.."
- cd fsdata && ./makefsdata
+ ./mkwebfs.py
test: unittest systest
@@ -24,4 +24,4 @@ unittest:
systest:
true
-.NOTPARALLEL: html all
\ No newline at end of file
+.NOTPARALLEL: html all
diff --git a/firmware/fsdata/makefsdata b/firmware/fsdata/makefsdata
index 5361370..f3c440d 100755
--- a/firmware/fsdata/makefsdata
+++ b/firmware/fsdata/makefsdata
@@ -41,10 +41,6 @@ while($file = ) {
print(HEADER "Content-type: image/jpeg\r\n");
} elsif($file =~ /\.bmp$/) {
print(HEADER "Content-type: image/bmp\r\n\r\n");
- } elsif($file =~ /\.class$/) {
- print(HEADER "Content-type: application/octet-stream\r\n");
- } elsif($file =~ /\.ram$/) {
- print(HEADER "Content-type: audio/x-pn-realaudio\r\n");
} else {
print(HEADER "Content-type: text/plain\r\n");
}
diff --git a/firmware/mkwebfs.py b/firmware/mkwebfs.py
new file mode 100755
index 0000000..39d5c14
--- /dev/null
+++ b/firmware/mkwebfs.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python3
+import os
+import gzip
+
+incHttpHeader = True
+useCompression = True
+fileDir = "fsdata/fs/"
+
+def dumpBin2CHex(f, b):
+ oStr = "\t"
+ n = 0
+ for val in b:
+ oStr += hex(val) + ", "
+ n += 1
+ if n % 8 == 0:
+ oStr += "\n\t"
+ oStr += "\n"
+ f.write(oStr)
+
+
+f_fsdata_c = open('fsdata/fsdata.c', 'w')
+f_fsdata_c.write('#include "httpd/fsdata.h"\n\n')
+
+httpFiles = []
+for root, dirs, files in os.walk(fileDir):
+ for file in files:
+ httpFiles.append("{}/{}".format(root, file).replace("//", "/"))
+
+lastFileStruct = "NULL"
+
+for file in httpFiles:
+ response = b''
+ if incHttpHeader:
+ print(file)
+ if("404" in file):
+ response = b'HTTP/1.0 404 File not found\r\n'
+ else:
+ response = b'HTTP/1.0 200 OK\r\n'
+ response += b"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n"
+ fext = file.split('.')[-1]
+ ctype = b'Content-type: text/plain\r\n'
+ if(fext.endswith("html") or fext.endswith("htm") or fext.endswith("shtml") or fext.endswith("shtm") or fext.endswith("ssi")):
+ ctype = b'Content-type: text/html\r\n'
+ if(fext.endswith("js")):
+ ctype = b'Content-type: application/x-javascript\r\n'
+ if(fext.endswith("css")):
+ ctype = b'Content-type: text/css\r\n'
+ if(fext.endswith("ico")):
+ ctype = b'Content-type: image/x-icon\r\n'
+ if(fext.endswith("gif")):
+ ctype = b'Content-type: image/gif\r\n'
+ if(fext.endswith("png")):
+ ctype = b'Content-type: image/png\r\n'
+ if(fext.endswith("jpg")):
+ ctype = b'Content-type: image/jpeg\r\n'
+ if(fext.endswith("bmp")):
+ ctype = b'Content-type: image/bmp\r\n'
+ if(fext.endswith("class")):
+ ctype = b'Content-type: application/octet-stream\r\n'
+ if(fext.endswith("ram")):
+ ctype = b'Content-type: audio/x-pn-realaudio\r\n'
+ response += ctype
+
+ binFile = open(file, 'rb')
+ binData = binFile.read()
+ compEff = False
+ if useCompression:
+ compData = gzip.compress(binData, 9)
+ if len(compData) < len(binData):
+ compEff = True
+ print("- Compressed from {} to {}".format(len(binData), len(compData)))
+ binData = compData
+ else:
+ print("- Compression skipped Orig: {} Comp: {}".format(len(binData), len(compData)))
+ binFile.close()
+
+ if compEff:
+ response += b'Content-Encoding: gzip\r\n'
+ response += b"\r\n"
+ response += binData
+ binFile.close()
+ escFile = file.replace("/", "_").replace(".", "_")
+ escFileData = "data_" + escFile
+ escFileFile = "file_" + escFile
+ webPath = ("/" + file.replace(fileDir, "")).replace("//", "/")
+
+ f_fsdata_c.write('static const unsigned char {}[] = {{\n'.format(escFileData))
+ f_fsdata_c.write('\t/* LOCAL:{} */\n'.format(file))
+ f_fsdata_c.write('\t/* WEB: {} */\n'.format(webPath))
+ fnameBin = webPath.encode("ascii") + b'\0'
+ dumpBin2CHex(f_fsdata_c, fnameBin)
+ dumpBin2CHex(f_fsdata_c, response)
+ f_fsdata_c.write("};\n\n")
+
+ f_fsdata_c.write("const struct fsdata_file {}[] = {{{{\n {},\n {}, {} + {}, sizeof({}) - {}, 1 }}}};\n\n"
+ .format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData, len(fnameBin)))
+ #TODO: The last value is 1 if incHttpHeader == True
+ lastFileStruct = escFileFile
+
+f_fsdata_c.write("\n")
+f_fsdata_c.write("#define FS_ROOT {}\n\n".format(lastFileStruct))
+f_fsdata_c.write("#define FS_NUMFILES {}\n\n".format(len(httpFiles)))
diff --git a/firmware/web.cpp b/firmware/web.cpp
index 6176a43..8e2e0a7 100644
--- a/firmware/web.cpp
+++ b/firmware/web.cpp
@@ -239,7 +239,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
cmd = 'G';
break;
case 'F':
- togl = ~togl;
+ togl = !togl;
signal_led(togl);
{
auto *f = (fw_frame *) data;