summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-11-01 09:46:52 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-11-01 09:46:52 +0800
commit9f938ab8ba5af561bd44dbc7142f338ce317a01a (patch)
tree7104ce2ac9456c5895f752eff26bad31f8436978 /scripts
downloadetlas-9f938ab8ba5af561bd44dbc7142f338ce317a01a.tar.gz
Etlas project.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/fonttool.py91
-rw-r--r--scripts/httpd.conf21
-rw-r--r--scripts/imgtool.py84
3 files changed, 196 insertions, 0 deletions
diff --git a/scripts/fonttool.py b/scripts/fonttool.py
new file mode 100644
index 0000000..a2f1a1e
--- /dev/null
+++ b/scripts/fonttool.py
@@ -0,0 +1,91 @@
+"""
+Converts glyphs in the current directory to a C header.
+
+Usage: python -m fonttool font_24.h 24
+"""
+
+import os
+import re
+import sys
+import subprocess
+
+dst = sys.argv[1]
+font_size = sys.argv[2]
+header = "FONT_{}_H".format(font_size)
+files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith(".jpg")]
+files.sort()
+
+with open(dst, "w") as o:
+ o.write("#ifndef {}\n".format(header))
+ o.write("#define {}\n\n".format(header))
+
+ for i, src in enumerate(files):
+ id = src.split('.')[0]
+
+ rv = subprocess.run(
+ ["identify", "-ping", "-format", "%w %h", src],
+ capture_output=True,
+ text=True
+ )
+
+ dim = rv.stdout.split(' ')
+ width = int(dim[0])
+ height = int(dim[1])
+
+ print("Image={}, size={}x{}".format(src, width, height))
+
+ if i == 0:
+ o.write("int font_{0}_height = {1};\n\n".format(font_size, height))
+
+ subprocess.run(["convert", src, "-threshold", "80%", "mon.jpg"])
+ subprocess.run(["convert", "mon.jpg", "-depth", "1", "-format", "'txt'", "mon.txt"])
+
+ n = 7
+ x = 0
+ column_len = 0
+ byte_count = 0
+
+ res = width * height
+ image_size = (res // 8) + (res % 8 > 0)
+
+ o.write("int {0}_width = {1};\n\n".format(id, width))
+ o.write("unsigned char {0}_bmp[{1}] = {{\n\t".format(id, image_size))
+
+ with open("mon.txt", "r") as fd:
+ fd.readline()
+ for line in fd:
+ px = re.search("\([^\)]+\)", line).group()
+ if px == "(0)":
+ x |= (1 << n)
+
+ n -= 1
+
+ if n < 0:
+ o.write("0x{:02X}, ".format(x))
+
+ column_len += 1
+ byte_count += 1
+
+ if column_len >= 12:
+ o.write("\n\t")
+ column_len = 0
+
+ x = 0
+ n = 7
+
+ if res % 8 != 0:
+ o.write("0x{:02X}, ".format(x))
+ byte_count += 1
+
+ o.write("\n};\n\n")
+
+ if (image_size != byte_count):
+ raise Exception("Detected image size {} and bytes written {} not equal".format(image_size, byte_count))
+
+
+ o.write("#endif")
+
+os.remove("mon.jpg")
+os.remove("mon.txt")
+
+print("Wrote {} bytes of image data to {}".format(byte_count, dst))
diff --git a/scripts/httpd.conf b/scripts/httpd.conf
new file mode 100644
index 0000000..c70e3a5
--- /dev/null
+++ b/scripts/httpd.conf
@@ -0,0 +1,21 @@
+server "<server-name>" {
+ listen on * tls port 443
+
+ # rest of the tls config - see man pages
+
+ location "/prices" {
+ authenticate with "/htdocs/atlas/.htpasswd"
+ fastcgi {
+ socket "/run/atlas.sock"
+ }
+ }
+}
+
+server "<server-name>" {
+ # redirect http to https
+ listen on * port 80
+
+ locaion "/prices" {
+ block return 301 "https://$HTTP_HOST$REQUEST_URI"
+ }
+}
diff --git a/scripts/imgtool.py b/scripts/imgtool.py
new file mode 100644
index 0000000..04429c9
--- /dev/null
+++ b/scripts/imgtool.py
@@ -0,0 +1,84 @@
+"""
+Converts input image to a c header with image data for
+Waveshare 7.5-inch e-paper display (V2) using ImageMagick.
+
+Usage: python -m imgtool image.jpg offset_x offset_y
+"""
+
+import os
+import re
+import sys
+import subprocess
+
+src = sys.argv[1]
+offset_x = int(sys.argv[2])
+offset_y = int(sys.argv[3])
+
+file_name = src.replace("." + src.split('.')[-1], "")
+dst = file_name + ".h"
+header = file_name.upper() + "_IMG_H"
+
+rv = subprocess.run(
+ ["identify", "-ping", "-format", "%w %h", src],
+ capture_output=True,
+ text=True
+)
+
+dim = rv.stdout.split(' ')
+width = int(dim[0])
+height = int(dim[1])
+print("Detected image size: {}x{}".format(width, height))
+
+subprocess.run(["convert", src, "-threshold", "80%", "mon.jpg"])
+subprocess.run(["convert", "mon.jpg", "-depth", "1", "-format", "'txt'", "mon.txt"])
+
+n = 7
+x = 0
+column_len = 0
+byte_count = 0
+
+res = width * height
+image_size = (res // 8) + (res % 8 > 0)
+
+with open(dst, "w") as o:
+ o.write("#ifndef {}\n".format(header))
+ o.write("#define {}\n\n".format(header))
+
+ o.write("const int {0}_width = {1};\n".format(file_name, width))
+ o.write("const int {0}_height = {1};\n\n".format(file_name, height))
+
+ o.write("const int {0}_offset_x = {1};\n".format(file_name, offset_x))
+ o.write("const int {0}_offset_y = {1};\n\n".format(file_name, offset_y))
+
+ o.write("const unsigned char {0}_bmp[{1}] = {{\n\t".format(file_name, image_size))
+
+ with open("mon.txt", "r") as i:
+ i.readline()
+ for line in i:
+ px = re.search("\([^\)]+\)", line).group()
+ if px == "(0)":
+ x |= (1 << n)
+ n -= 1
+ if n < 0:
+ o.write("0x{:02X}, ".format(x))
+ column_len += 1
+ byte_count += 1
+ if column_len >= 12:
+ o.write("\n\t")
+ column_len = 0
+ x = 0
+ n = 7
+ if res % 8 != 0:
+ o.write("0x{:02X}, ".format(x))
+ byte_count += 1
+
+ o.write("\n};\n\n")
+ o.write("#endif")
+
+os.remove("mon.jpg")
+os.remove("mon.txt")
+
+if (image_size != byte_count):
+ raise Exception("Detected image size {} and bytes written {} not equal".format(image_size, byte_count))
+
+print("Wrote {} bytes of image data to {}".format(byte_count, dst))