Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ checksum.sha256
mqjs_build
docker-logs
lib/mquickjs_headers/mqjs_stdlib_generator
lib/mquickjs_headers/mqjs_stdlib_generator.exe
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def q(p): return f"\"{p}\""
env.Exit(1)

cmd = " ".join([
"pio pkg exec -p \"tool-esptoolpy\" -- esptool.py",
q(python_exe), "-m", "platformio", "pkg", "exec", "-p", q("tool-esptoolpy"), "--", "esptool.py",
"--chip", chip_arg,
"merge-bin",
"--output", q(out_bin),
Expand Down
67 changes: 65 additions & 2 deletions gen_mqjs_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import hashlib
import shutil

PIOENV = env.subst("$PIOENV")
MQJS_PATH = os.path.join(".pio/libdeps", PIOENV, "mquickjs")
Expand All @@ -21,6 +22,7 @@
CFLAGS = [
"-Wall",
"-O2",
"-m32",
"-I" + MQJS_PATH,
]

Expand Down Expand Up @@ -55,7 +57,8 @@ def sha256_file(path):
chunk = f.read(8192)
if not chunk:
break
h.update(chunk)
# Normalize CRLF to LF so signatures are stable across OSes.
h.update(chunk.replace(b"\r\n", b"\n"))
return h.hexdigest()

def _project_option(name: str):
Expand All @@ -64,6 +67,32 @@ def _project_option(name: str):
except Exception:
return ""

def _resolve_host_cc():
override = os.environ.get("MQJS_HOST_CC") or _project_option("mqjs_host_cc")
return override if override else HOST_CC

def _has_define(name: str) -> bool:
try:
flags = env.ParseFlags(env['BUILD_FLAGS'])
except Exception:
return False
for define in flags.get('CPPDEFINES', []):
if define == name:
return True
if isinstance(define, list) and define and define[0] == name:
return True
return False

def _gen_enabled() -> bool:
# Default to enabled for backward compatibility.
if _has_define("DISABLE_MQJS_HEADERS_GEN"):
return False
if _has_define("GEN_MQJS_HEADERS"):
value = get_build_flag_value("GEN_MQJS_HEADERS")
if value is not None and str(value).strip().lower() in ("0", "false", "no", "off"):
return False
return True

def _normalize_option_value(value) -> str:
if value is None:
return ""
Expand Down Expand Up @@ -116,15 +145,49 @@ def generate_headers():
if get_build_flag_value("LITE_VERSION") is not None or get_build_flag_value("DISABLE_INTERPRETER") is not None:
return

if not _gen_enabled():
print("Skipped MQJS headers build.")
return

os.makedirs(BUILD_DIR, exist_ok=True)

if not needs_rebuild():
return

try:
host_cc = _resolve_host_cc()
if not shutil.which(host_cc):
if os.path.exists(os.path.join(BJS_INTERPRETER_PATH, "mqjs_stdlib.h")):
print("Host compiler not found; skipping mqjs_stdlib header generation.")
print("Set MQJS_HOST_CC or mqjs_host_cc to a GCC-compatible compiler, or use Docker.")
print("\nOn Windows:\n- install MSYS2 https://www.msys2.org/ at default path")
print("- open C:\\msys64\\ucrt64.exe")
print("- run on UCRT64 terminal: pacman -S --needed mingw-w64-i686-toolchain")
print("- add C:\\msys64\\mingw32\\bin to PATH, cmd: setx PATH \"%PATH%;C:\\msys64\\mingw32\\bin\\\"")
print("- close and open VSCode again")
print("\nOn Mac:\n- run on terminal: xcode-select --install")
print("\nOn Linux:\n- run on terminal: sudo apt-get install -y --no-install-recommends gcc-multilib libc6-dev-i386\n\n")
return
raise RuntimeError("Host compiler not found and mqjs_stdlib.h is missing.")

# Build the generator as a native host executable. The output headers are
# still forced to 32-bit target format via the generator's `-m32` flag.
subprocess.check_call([HOST_CC, *CFLAGS, "-o", GEN, *SRC])
gcc_result = subprocess.run(
[host_cc, *CFLAGS, "-o", GEN, *SRC],
capture_output=True,
text=True,
)
if gcc_result.returncode != 0:
if gcc_result.stdout:
print("gcc stdout:\n" + gcc_result.stdout)
if gcc_result.stderr:
print("gcc stderr:\n" + gcc_result.stderr)
raise subprocess.CalledProcessError(
gcc_result.returncode,
gcc_result.args,
output=gcc_result.stdout,
stderr=gcc_result.stderr,
)

print("gen_mqjs_headers.py Generating QuickJS headers for 32-bit targets")

Expand Down
5 changes: 5 additions & 0 deletions include/VectorDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ class VectorDisplayClass : public Print {
uint32_t textcolor = TFT_WHITE;
uint32_t textbgcolor = TFT_BLACK;

uint32_t getTextColor() { return textcolor; };
uint32_t getTextBgColor() { return textbgcolor; };
uint8_t getTextSize() { return textsize; };
uint8_t getRotation() { return rotation; };

void setWaitForAck(bool wait) { waitForAck = wait; }

void setDelay(uint32_t delayMillis) {
Expand Down
5 changes: 3 additions & 2 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ extern RTC_DateTypeDef _date;

// Declaração dos objetos TFT
#if defined(HAS_SCREEN)
#include <display/tft.h>
#include <tftLogger.h>
extern tft_logger tft;
extern TFT_eSprite sprite;
extern TFT_eSprite draw;
extern tft_sprite sprite;
extern tft_sprite draw;
#else
#include <tftLogger.h>
extern tft_logger tft;
Expand Down
25 changes: 23 additions & 2 deletions include/tftLogger.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef __DISPLAY_LOGER
#define __DISPLAY_LOGER
#ifdef HAS_SCREEN
#include <TFT_eSPI.h>
#define BRUCE_TFT_DRIVER TFT_eSPI
#include <display/tft.h>
#define BRUCE_TFT_DRIVER tft_display
#else
#include <VectorDisplay.h>
#define BRUCE_TFT_DRIVER SerialDisplayClass
Expand Down Expand Up @@ -64,6 +64,27 @@ class tft_logger : public BRUCE_TFT_DRIVER {
TaskHandle_t asyncSerialTask = NULL;
QueueHandle_t asyncSerialQueue = NULL;
static void asyncSerialTaskFunc(void *pv);
inline uint8_t currentTextSize() const {
#if defined(HAS_SCREEN)
return getTextSize();
#else
return textsize;
#endif
}
inline uint16_t currentTextColor() const {
#if defined(HAS_SCREEN)
return getTextColor();
#else
return textcolor;
#endif
}
inline uint16_t currentTextBgColor() const {
#if defined(HAS_SCREEN)
return getTextBgColor();
#else
return textbgcolor;
#endif
}

public:
tft_logger(int16_t w = TFT_WIDTH, int16_t h = TFT_HEIGHT);
Expand Down
Loading