This commit is contained in:
Miguel Fuertes committed 2025-10-16 21:42:49 +02:00
1 parent dfc3b42a24
commit 06462fffbe
6 files changed
+69 -69

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ show_logo() {
if [ -d "$BACKLIGHT" ]; then
echo 0 > $BACKLIGHT/bl_power 2>/dev/null
echo 128 > $BACKLIGHT/brightness 2>/dev/null
echo 1 > $BACKLIGHT/brightness 2>/dev/null
fi
) &
}
+3 -5
View File
@@ -42,7 +42,8 @@ define Build/Prepare
endef
define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) \
$(TARGET_CC) $(TARGET_CFLAGS) -O3 -ffast-math \
$(TARGET_CPPFLAGS) \
-I$(STAGING_DIR)/usr/include/freetype2 \
$(TARGET_LDFLAGS) \
-o $(PKG_BUILD_DIR)/router-display \
@@ -58,12 +59,9 @@ define Package/router-display/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) ./files/update-display.sh $(1)/usr/sbin/update-display
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) ./files/openwrt_logo.fb $(1)/etc/openwrt_logo.fb
$(INSTALL_DIR) $(1)/etc/hotplug.d/button
$(INSTALL_BIN) ./files/hotplugs/20_power_dimm $(1)/etc/hotplug.d/button/20_power_dimm
$(INSTALL_BIN) ./files/hotplugs/30_power_update $(1)/etc/hotplug.d/button/20_power_update
$(INSTALL_BIN) ./files/hotplugs/30_power_update $(1)/etc/hotplug.d/button/30_power_update
endef
$(eval $(call BuildPackage,router-display))
@@ -22,6 +22,9 @@ TIMER_PID_FILE="/tmp/screen_timer.pid"
# Set brightness level
set_brightness() {
echo $1 > $BACKLIGHT_PATH/brightness
[ "$1" = "$BRIGHTNESS_OFF" ] && [ -f /etc/boot_logo.fb ] && \
cat /etc/boot_logo.fb > /dev/fb0 2>/dev/null
}
# Function to start a timer
Binary file not shown.
+33 -17
View File
@@ -1,6 +1,8 @@
#!/bin/sh
# /usr/sbin/update-display
# Optimized display update script - caches operator name (requires reboot to change SIM)
# === BATERÍA ===
# === BATTERY ===
BMS_PATH="/sys/class/power_supply/pm8916-bms-vm"
VOLTAGE=$(cat "$BMS_PATH/voltage_now" 2>/dev/null)
@@ -19,26 +21,40 @@ if ip link show phy0-ap0 2>/dev/null | grep -q "state UP"; then
SHOW_QR=1
fi
# === MODEM ===
# === MODEM (OPTIMIZED - single mmcli call + operator cache) ===
OPERATOR_CACHE="/tmp/modem_operator.cache"
MODEM_IDX=$(mmcli -L 2>/dev/null | grep -oE 'Modem/[0-9]+' | head -1 | cut -d'/' -f2)
if [ -n "$MODEM_IDX" ]; then
# Operador siempre viene de la SIM (disponible aunque no haya señal)
SIM_IDX=$(mmcli -m "$MODEM_IDX" -K 2>/dev/null | grep 'modem.generic.sim' | awk -F': ' '{print $2}' | grep -oE '[0-9]+$')
# Single mmcli call - cache all modem data
MODEM_DATA=$(mmcli -m "$MODEM_IDX" -K 2>/dev/null)
if [ -n "$SIM_IDX" ]; then
OPERATOR=$(mmcli -i "$SIM_IDX" -K 2>/dev/null | grep 'sim.properties.operator-name' | awk -F': ' '{print $2}')
# Try to get operator from cache first (SIM doesn't change without reboot)
if [ -f "$OPERATOR_CACHE" ]; then
OPERATOR=$(cat "$OPERATOR_CACHE")
else
# Cache miss - fetch operator from SIM
SIM_IDX=$(echo "$MODEM_DATA" | grep 'modem.generic.sim' | awk -F': ' '{print $2}' | grep -oE '[0-9]+$')
if [ -n "$SIM_IDX" ]; then
OPERATOR=$(mmcli -i "$SIM_IDX" -K 2>/dev/null | grep 'sim.properties.operator-name' | awk -F': ' '{print $2}')
fi
# Fallback: operator from network (use cached modem data)
if [ -z "$OPERATOR" ]; then
OPERATOR=$(echo "$MODEM_DATA" | grep 'modem.3gpp.operator-name' | awk -F': ' '{print $2}')
fi
# Cache operator for future calls
if [ -n "$OPERATOR" ]; then
echo "$OPERATOR" > "$OPERATOR_CACHE"
fi
fi
# Fallback al operador de red si la SIM no tiene nombre
if [ -z "$OPERATOR" ]; then
OPERATOR=$(mmcli -m "$MODEM_IDX" -K 2>/dev/null | grep 'modem.3gpp.operator-name' | awk -F': ' '{print $2}')
fi
# Access technology (use cached modem data)
ACCESS_TECH=$(echo "$MODEM_DATA" | grep 'modem.generic.access-technologies' | awk -F': ' '{print $2}')
# Tecnología de acceso (solo disponible si hay conexión activa)
ACCESS_TECH=$(mmcli -m "$MODEM_IDX" -K 2>/dev/null | grep 'modem.generic.access-technologies' | awk -F': ' '{print $2}')
# Si no hay access-technologies, no hay conexión -> red vacía
# Determine network type only if connected
if [ -n "$ACCESS_TECH" ] && [ "$ACCESS_TECH" != "unknown" ]; then
case "$ACCESS_TECH" in
*lte*) NETWORK="4G" ;;
@@ -47,11 +63,11 @@ if [ -n "$MODEM_IDX" ]; then
*) NETWORK="$ACCESS_TECH" ;;
esac
else
# Sin conexión: mostrar operador pero sin tipo de red
# No connection: show operator but no network type
NETWORK=""
fi
else
# Sin módem
# No modem
OPERATOR=""
NETWORK=""
fi
@@ -61,7 +77,7 @@ SSID=$(uci get wireless.@wifi-iface[0].ssid 2>/dev/null || echo "WiFi")
PASSWORD=$(uci get wireless.@wifi-iface[0].key 2>/dev/null || echo "")
HOSTNAME=$(uci get system.@system[0].hostname 2>/dev/null || echo "Router")
# === Actualizar Display ===
# === Update Display ===
if [ "$SHOW_QR" -eq 1 ]; then
/usr/bin/router-display -q -b "$BATTERY" -n "$OPERATOR" -t "$NETWORK" -s "$SSID" -p "$PASSWORD" -h "$HOSTNAME" > /dev/fb0
else
+29 -46
View File
@@ -16,8 +16,9 @@
#define COLOR_WHITE RGB565(255, 255, 255)
#define COLOR_BLACK RGB565(0, 0, 0)
#define LOGO_SIZE 80
#define LOGO_PATH "/etc/openwrt_logo.fb"
#define QR_SIZE 108
#define QR_TOP_MARGIN 6
#define TEXT_HEIGHT 13
typedef struct {
uint16_t data[WIDTH * HEIGHT];
@@ -70,31 +71,6 @@ void fb_draw_rect(Framebuffer *fb, int x, int y, int w, int h, uint16_t color) {
}
}
void fb_draw_logo(Framebuffer *fb, const char *logo_file, int x, int y) {
FILE *f = fopen(logo_file, "rb");
if (!f) {
fprintf(stderr, "Logo file not found: %s\n", logo_file);
return;
}
uint16_t logo_data[LOGO_SIZE * LOGO_SIZE];
size_t read = fread(logo_data, sizeof(uint16_t), LOGO_SIZE * LOGO_SIZE, f);
fclose(f);
if (read != LOGO_SIZE * LOGO_SIZE) {
fprintf(stderr, "Logo file size mismatch\n");
return;
}
for (int row = 0; row < LOGO_SIZE; row++) {
for (int col = 0; col < LOGO_SIZE; col++) {
uint16_t pixel = logo_data[row * LOGO_SIZE + col];
// Copiar todos los pixels (incluso el negro de fondo)
fb_put_pixel(fb, x + col, y + row, pixel);
}
}
}
void fb_draw_text(Framebuffer *fb, FT_Face face, const char *text, int x, int y, int size) {
int pen_x = x;
@@ -154,15 +130,20 @@ void fb_draw_qr(Framebuffer *fb, const char *text, int x, int y, int size) {
return;
}
int qr_size = qrcodegen_getSize(qr_data);
int module_size = size / qr_size;
int qr_modules = qrcodegen_getSize(qr_data);
int module_size = size / qr_modules;
for (int row = 0; row < qr_size; row++) {
for (int col = 0; col < qr_size; col++) {
// Calculate actual QR size and center horizontally, align top vertically
int actual_qr_size = qr_modules * module_size;
int offset_x = (size - actual_qr_size) / 2; // Center horizontally
int offset_y = 0; // Top aligned (no vertical centering)
for (int row = 0; row < qr_modules; row++) {
for (int col = 0; col < qr_modules; col++) {
if (qrcodegen_getModule(qr_data, col, row)) {
fb_draw_rect(fb,
x + col * module_size,
y + row * module_size,
x + offset_x + col * module_size,
y + offset_y + row * module_size,
module_size, module_size,
COLOR_WHITE);
}
@@ -190,35 +171,37 @@ void generate_display(Framebuffer *fb, DisplayConfig *cfg, FT_Face face) {
str_to_upper(hostname_text);
}
int logo_x = (WIDTH - LOGO_SIZE) / 2 + 2;
int logo_y = 12;
// Calculate space to center QR perfectly vertically
int qr_available_height = HEIGHT - TEXT_HEIGHT - QR_TOP_MARGIN;
int qr_size = (QR_SIZE < qr_available_height) ? QR_SIZE : qr_available_height;
int qr_x = (WIDTH - qr_size) / 2;
int qr_y = QR_TOP_MARGIN + (qr_available_height - qr_size) / 2;
if (cfg->show_qr) {
char wifi_qr[256];
snprintf(wifi_qr, sizeof(wifi_qr),
"WIFI:T:WPA;S:%s;P:%s;;", cfg->ssid, cfg->password);
fb_draw_qr(fb, wifi_qr, logo_x, logo_y, LOGO_SIZE);
} else {
// Mostrar logo de OpenWrt cuando no hay QR
fb_draw_logo(fb, LOGO_PATH, logo_x, logo_y);
fb_draw_qr(fb, wifi_qr, qr_x, qr_y, qr_size);
}
// If no QR: stay black (fb_init already cleared to black)
// No logo drawn
int fontsz = 15;
int line1_y = HEIGHT - fontsz - 6;
int line2_y = HEIGHT - 5;
int fontsz = 12;
int line1_y = HEIGHT - fontsz - 3;
int line2_y = HEIGHT - 3;
fb_draw_text(fb, face, operator_text, 3, line1_y, fontsz);
fb_draw_text(fb, face, operator_text, 2, line1_y, fontsz);
int net_width = fb_get_text_width(face, network_text, fontsz);
fb_draw_text(fb, face, network_text, WIDTH - net_width - 3, line1_y, fontsz);
fb_draw_text(fb, face, network_text, WIDTH - net_width - 2, line1_y, fontsz);
fb_draw_text(fb, face, hostname_text, 3, line2_y, fontsz);
fb_draw_text(fb, face, hostname_text, 2, line2_y, fontsz);
char battery_text[8];
snprintf(battery_text, sizeof(battery_text), "%d%%", cfg->battery);
int battery_width = fb_get_text_width(face, battery_text, fontsz);
fb_draw_text(fb, face, battery_text, WIDTH - battery_width - 3, line2_y, fontsz);
fb_draw_text(fb, face, battery_text, WIDTH - battery_width - 2, line2_y, fontsz);
}
void print_usage(const char *prog) {