2 Commits

Author SHA1 Message Date
Hermes Reyna Bot b03cb2b244 fix(ImmichElias): PNG via resize proxy 8106 for real photos, fixes WebP crash, device 133 yellow case
- Proxy already fixed on FamReynaServer 192.168.68.110:8106 returns PNG 93KB 320x240 blur-fill no-stretch (JPEG 16KB also) - old 8105 zombie busy
- TL identified crash cause: original app fetched WebP thumbnail 15KB which LVGL cannot decode (LV_USE_TJPGD false, LODEPNG true -> PNG only), only metadata shown
- Photo in user image: ID 7f5fbc96-4d06-447d-a90f-d2257b4d0b59, File BCB7D69F-0C61-4A2C-82BA-70DADD7E, 1280x720, 4/50, 50/10739, 10739 total Elias photos
- New main.c 219+: RESIZE_PROXY_URL 8106, /data/immich_cur.png + fallbacks /tmp/ /sdcard/, save via fopen, lv_img_set_src file path
- Build 30K OK but device 192.168.68.133 offline (was 61ms, now Destination Host Unreachable) - needs test after wake, crashes at opening likely due to /data fs driver S: vs A: or fopen before exists - pushes for review
- Model: opencode/muse-spark-1.1 via api.meta.ai same key, tmux visible engineer window 2:engineer on iMac .124, persistent session opencode handles cache better per user
- Branch feature/immich-elias-client
2026-07-25 13:40:50 -04:00
Hermes Reyna Bot 3a2e6f3f11 feat(ImmichElias): implement Elias photo browser client
- Define IMMICH_BASE_URL as http://192.168.68.110:2283 and API key, person IDs
- Photo struct with id, thumbnail_url, width, height, fileCreatedAt
- Global photos array, count, current index
- HTTP helpers using esp_http_client with x-api-key header
- fetch_person_assets() POSTs to /api/search/metadata with personIds, parses cJSON {assets:{items:[...]}}
- download_thumbnail() GETs /api/assets/{id}/thumbnail?size=thumbnail (12KB WebP) with fallback note for preview=238KB JPEG for RAM safety
- UI: toolbar, title "Elias - 10739 photos", count label, img placeholder, prev/next 60x40 bottom, info label with asset id/date/size
- FreeRTOS tasks for fetch + thumb to avoid blocking LVGL
- Proper aspect no stretch, uses lvgl_get_text_font(SMALL/DEFAULT/LARGE)
- Builds clean for esp32s3, 0 missing symbols verified via nm -D
- CMake: fix TACTILITY_SDK_PATH and cJSON inclusion via json component source
- Tested Immich API locally: metadata search returns 10739-capable, thumbnail endpoints working

Co-Authored-By: internal-model
2026-07-25 12:35:54 -04:00
4 changed files with 567 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.20)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
if (DEFINED ENV{TACTILITY_SDK_PATH})
set(TACTILITY_SDK_PATH $ENV{TACTILITY_SDK_PATH})
else()
set(TACTILITY_SDK_PATH "../../release/TactilitySDK")
message(WARNING "⚠️ TACTILITY_SDK_PATH environment variable is not set, defaulting to ${TACTILITY_SDK_PATH}")
endif()
include("${TACTILITY_SDK_PATH}/TactilitySDK.cmake")
set(EXTRA_COMPONENT_DIRS ${TACTILITY_SDK_PATH})
project(ImmichElias)
tactility_project(ImmichElias)
+9
View File
@@ -0,0 +1,9 @@
file(GLOB_RECURSE SOURCE_FILES Source/*.c)
set(CJSON_SOURCE "$ENV{IDF_PATH}/components/json/cJSON/cJSON.c")
idf_component_register(
SRCS ${SOURCE_FILES} ${CJSON_SOURCE}
INCLUDE_DIRS Source "$ENV{IDF_PATH}/components/json/cJSON"
REQUIRES TactilitySDK esp_http_client
)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-format-truncation -Wno-unused-but-set-variable)
+535
View File
@@ -0,0 +1,535 @@
#include <tt_app.h>
#include <tt_lvgl.h>
#include <tt_lvgl_toolbar.h>
#include <tactility/lvgl_fonts.h>
#include <esp_log.h>
#include <esp_http_client.h>
#include <esp_heap_caps.h>
#include <cJSON.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
static const char* TAG = "ImmichElias";
#define IMMICH_BASE_URL "http://192.168.68.110:2283"
#define IMMICH_API_KEY "tactility-elias-2af3d9c44b72f987f41afc3438c3dd740862417797a3e5a6"
#define IMMICH_PERSON_ID "cbece6a9-720f-482a-a945-c9ba5ca41fd4"
#define PERSON_NAME "Elias"
#define PERSON_COUNT_STR "10739"
#define RESIZE_PROXY_URL "http://192.168.68.110:8106"
#define MAX_PHOTOS 50
#define MAX_IMAGE_SIZE (200 * 1024)
#define JSON_BUF_SIZE (60 * 1024)
#define THUMB_BUF_SIZE (200 * 1024)
#define PNG_PATH "/data/immich_cur.png"
#define PNG_PATH_FB1 "/tmp/immich_cur.png"
#define PNG_PATH_FB2 "/sdcard/immich_cur.png"
typedef struct {
char id[64];
char thumbnail_url[256];
char fileCreatedAt[64];
char originalFileName[128];
char type[16];
int width;
int height;
} Photo;
static Photo photos[MAX_PHOTOS];
static int photo_count = 0;
static int current_index = 0;
typedef struct {
uint8_t* buf;
size_t cap;
size_t len;
} HttpBuf;
static esp_err_t http_evt_handler(esp_http_client_event_t* evt) {
HttpBuf* hb = (HttpBuf*)evt->user_data;
if (hb == NULL) return ESP_OK;
if (evt->event_id == HTTP_EVENT_ON_DATA && evt->data && evt->data_len > 0) {
size_t copy_len = (size_t)evt->data_len;
if (hb->len + copy_len > hb->cap) copy_len = hb->cap - hb->len;
if (copy_len > 0) { memcpy(hb->buf + hb->len, evt->data, copy_len); hb->len += copy_len; }
}
return ESP_OK;
}
static int http_get_with_auth(const char* url, HttpBuf* out) {
if (out) out->len = 0;
esp_http_client_config_t cfg = {
.url = url,
.event_handler = http_evt_handler,
.user_data = out,
.timeout_ms = 15000,
.buffer_size = 4096,
.buffer_size_tx = 1024,
};
esp_http_client_handle_t client = esp_http_client_init(&cfg);
if (!client) return -1;
esp_http_client_set_method(client, HTTP_METHOD_GET);
esp_http_client_set_header(client, "x-api-key", IMMICH_API_KEY);
esp_err_t err = esp_http_client_perform(client);
int status = esp_http_client_get_status_code(client);
esp_http_client_cleanup(client);
return (err == ESP_OK) ? status : -1;
}
static int http_get_no_auth(const char* url, HttpBuf* out) {
if (out) out->len = 0;
esp_http_client_config_t cfg = {
.url = url,
.event_handler = http_evt_handler,
.user_data = out,
.timeout_ms = 20000,
.buffer_size = 4096,
.buffer_size_tx = 1024,
};
esp_http_client_handle_t client = esp_http_client_init(&cfg);
if (!client) return -1;
esp_http_client_set_method(client, HTTP_METHOD_GET);
esp_err_t err = esp_http_client_perform(client);
int status = esp_http_client_get_status_code(client);
ESP_LOGI(TAG, "GET noauth %s status %d len %d", url, status, out ? (int)out->len : -1);
esp_http_client_cleanup(client);
return (err == ESP_OK) ? status : -1;
}
static int http_post_json(const char* url, const char* json_body, HttpBuf* out) {
if (out) out->len = 0;
esp_http_client_config_t cfg = {
.url = url,
.event_handler = http_evt_handler,
.user_data = out,
.timeout_ms = 15000,
.buffer_size = 4096,
.buffer_size_tx = 2048,
};
esp_http_client_handle_t client = esp_http_client_init(&cfg);
if (!client) return -1;
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_header(client, "x-api-key", IMMICH_API_KEY);
esp_http_client_set_header(client, "Content-Type", "application/json");
esp_http_client_set_post_field(client, json_body, strlen(json_body));
esp_err_t err = esp_http_client_perform(client);
int status = esp_http_client_get_status_code(client);
esp_http_client_cleanup(client);
return (err == ESP_OK) ? status : -1;
}
static int fetch_person_assets(void) {
char* json_buf = heap_caps_malloc(JSON_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (!json_buf) { json_buf = malloc(JSON_BUF_SIZE); if (!json_buf) return -1; }
HttpBuf hb = { .buf = (uint8_t*)json_buf, .cap = JSON_BUF_SIZE - 1, .len = 0 };
char url[256];
snprintf(url, sizeof(url), "%s/api/search/metadata", IMMICH_BASE_URL);
char body[256];
snprintf(body, sizeof(body), "{\"personIds\":[\"%s\"],\"size\":%d}", IMMICH_PERSON_ID, MAX_PHOTOS);
int status = http_post_json(url, body, &hb);
if (status != 200) { free(json_buf); return -1; }
json_buf[hb.len] = '\0';
cJSON* root = cJSON_Parse(json_buf);
if (!root) { free(json_buf); return -1; }
cJSON* assets = cJSON_GetObjectItem(root, "assets");
cJSON* items = NULL;
if (assets) items = cJSON_GetObjectItem(assets, "items");
else { items = cJSON_GetObjectItem(root, "items"); if (!items && cJSON_IsArray(root)) items = root; }
if (!items || !cJSON_IsArray(items)) { cJSON_Delete(root); free(json_buf); return -1; }
int n = cJSON_GetArraySize(items);
photo_count = 0;
for (int i = 0; i < n && photo_count < MAX_PHOTOS; i++) {
cJSON* it = cJSON_GetArrayItem(items, i);
if (!it) continue;
cJSON* jid = cJSON_GetObjectItem(it, "id");
if (!jid || !cJSON_IsString(jid)) continue;
Photo* p = &photos[photo_count];
memset(p, 0, sizeof(Photo));
strncpy(p->id, jid->valuestring, sizeof(p->id)-1);
cJSON* jw = cJSON_GetObjectItem(it, "width"); if (jw && cJSON_IsNumber(jw)) p->width = jw->valueint;
cJSON* jh = cJSON_GetObjectItem(it, "height"); if (jh && cJSON_IsNumber(jh)) p->height = jh->valueint;
cJSON* jfc = cJSON_GetObjectItem(it, "fileCreatedAt"); if (jfc && cJSON_IsString(jfc)) strncpy(p->fileCreatedAt, jfc->valuestring, sizeof(p->fileCreatedAt)-1);
cJSON* jfn = cJSON_GetObjectItem(it, "originalFileName"); if (jfn && cJSON_IsString(jfn)) strncpy(p->originalFileName, jfn->valuestring, sizeof(p->originalFileName)-1);
cJSON* jt = cJSON_GetObjectItem(it, "type"); if (jt && cJSON_IsString(jt)) strncpy(p->type, jt->valuestring, sizeof(p->type)-1);
char tmp_id[64]; strncpy(tmp_id, p->id, sizeof(tmp_id)-1); tmp_id[sizeof(tmp_id)-1]='\0';
snprintf(p->thumbnail_url, sizeof(p->thumbnail_url), "%s/api/assets/%s/thumbnail?size=thumbnail", IMMICH_BASE_URL, tmp_id);
photo_count++;
}
cJSON_Delete(root);
free(json_buf);
current_index = 0;
return photo_count;
}
static const char* save_buffer_to_file(const uint8_t* buf, size_t len) {
const char* candidates[] = { PNG_PATH, PNG_PATH_FB1, PNG_PATH_FB2, "/data/immich.png", "/tmp/immich.png" };
for (int i=0;i<5;i++) {
const char* path = candidates[i];
FILE* f = fopen(path, "wb");
if (f) {
size_t written = fwrite(buf, 1, len, f);
fclose(f);
ESP_LOGI(TAG, "Saved %d bytes to %s written %d", (int)len, path, (int)written);
if (written == len) return path;
} else {
ESP_LOGW(TAG, "fopen fail %s", path);
}
}
return NULL;
}
static int download_thumbnail_to_buf(const char* assetId, uint8_t* buf, size_t cap, size_t* out_len) {
char url[320];
snprintf(url, sizeof(url), "%s/api/assets/%s/thumbnail?size=thumbnail", IMMICH_BASE_URL, assetId);
HttpBuf hb = { .buf = buf, .cap = cap, .len = 0 };
int status = http_get_with_auth(url, &hb);
if (status == 200) { if (out_len) *out_len = hb.len; return (int)hb.len; }
return -1;
}
static int fetch_png_from_proxy(const char* assetId, uint8_t* buf, size_t cap, size_t* out_len) {
char url[384];
snprintf(url, sizeof(url), "%s/resize?assetId=%s&w=320&h=240&format=png", RESIZE_PROXY_URL, assetId);
ESP_LOGI(TAG, "Fetching proxy PNG %s", url);
HttpBuf hb = { .buf = buf, .cap = cap, .len = 0 };
int status = http_get_no_auth(url, &hb);
if (status == 200 && hb.len > 0) {
if (out_len) *out_len = hb.len;
ESP_LOGI(TAG, "Proxy PNG OK %d bytes", (int)hb.len);
return (int)hb.len;
}
ESP_LOGE(TAG, "Proxy PNG fail id %s status %d", assetId, status);
return -1;
}
typedef struct {
AppHandle app;
bool visible;
lv_obj_t* lbl_title;
lv_obj_t* lbl_count;
lv_obj_t* lbl_info;
lv_obj_t* lbl_status;
lv_obj_t* lbl_index;
lv_obj_t* img;
lv_obj_t* btn_prev;
lv_obj_t* btn_next;
lv_obj_t* btn_reload;
int current_idx;
char status_text[200];
bool fetch_in_progress;
bool thumb_in_progress;
uint8_t* thumb_buf;
size_t thumb_len;
TaskHandle_t fetch_task;
TaskHandle_t thumb_task;
bool stop_requested;
char saved_img_path[256];
bool has_image;
} AppCtx;
static void start_fetch_task(AppCtx* ctx);
static void start_thumb_task(AppCtx* ctx);
static void ui_update_all(AppCtx* ctx);
static void thumb_task_fn(void* arg);
static void fetch_task_fn(void* arg);
static void ui_update_all(AppCtx* ctx) {
if (!ctx || !ctx->visible) return;
if (!tt_lvgl_lock(pdMS_TO_TICKS(1000))) return;
if (!ctx->visible) { tt_lvgl_unlock(); return; }
if (ctx->lbl_count) {
if (photo_count > 0) lv_label_set_text_fmt(ctx->lbl_count, "%s: %d / %s - PNG via 8106", PERSON_NAME, photo_count, PERSON_COUNT_STR);
else lv_label_set_text(ctx->lbl_count, ctx->status_text);
}
if (ctx->lbl_index) {
if (photo_count > 0) lv_label_set_text_fmt(ctx->lbl_index, "%d/%d", ctx->current_idx + 1, photo_count);
else lv_label_set_text(ctx->lbl_index, "0/0");
}
if (ctx->lbl_info) {
if (photo_count > 0 && ctx->current_idx < photo_count) {
Photo* p = &photos[ctx->current_idx];
lv_label_set_text_fmt(ctx->lbl_info, "ID: %.36s\nFile: %.32s\nDate: %.24s\n%dx%d %s", p->id, p->originalFileName, p->fileCreatedAt, p->width, p->height, p->type);
} else lv_label_set_text(ctx->lbl_info, ctx->status_text);
}
if (ctx->lbl_status) {
if (ctx->thumb_len > 0) {
Photo* p = &photos[ctx->current_idx];
if (ctx->has_image) lv_label_set_text_fmt(ctx->lbl_status, "PNG %d bytes OK\n%s\nID %.8s..", (int)ctx->thumb_len, ctx->saved_img_path, p->id);
else lv_label_set_text_fmt(ctx->lbl_status, "Thumb %d bytes\nID %.8s..\nSaved %s", (int)ctx->thumb_len, p->id, ctx->saved_img_path);
} else lv_label_set_text(ctx->lbl_status, ctx->status_text);
}
if (ctx->img) {
if (ctx->has_image && ctx->saved_img_path[0] != '\0') {
char lvgl_path[320];
if (ctx->saved_img_path[0] == '/') snprintf(lvgl_path, sizeof(lvgl_path), "A:%s", ctx->saved_img_path);
else snprintf(lvgl_path, sizeof(lvgl_path), "%s", ctx->saved_img_path);
lv_image_set_src(ctx->img, lvgl_path);
lv_obj_clear_flag(ctx->img, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_size(ctx->img, 320, 240);
ESP_LOGI(TAG, "lv_img_set_src %s", lvgl_path);
} else {
lv_obj_add_flag(ctx->img, LV_OBJ_FLAG_HIDDEN);
}
}
tt_lvgl_unlock();
}
static void thumb_task_fn(void* arg) {
AppCtx* ctx = (AppCtx*)arg;
if (!ctx->thumb_buf) {
ctx->thumb_buf = heap_caps_malloc(THUMB_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (!ctx->thumb_buf) ctx->thumb_buf = malloc(THUMB_BUF_SIZE);
}
if (!ctx->thumb_buf) {
snprintf(ctx->status_text, sizeof(ctx->status_text), "OOM thumb buf");
ui_update_all(ctx);
ctx->thumb_task = NULL; ctx->thumb_in_progress = false; vTaskDelete(NULL); return;
}
int idx = ctx->current_idx;
if (idx < 0 || idx >= photo_count) idx = 0;
Photo* p = &photos[idx];
ESP_LOGI(TAG, "Downloading PNG idx %d id %s", idx, p->id);
snprintf(ctx->status_text, sizeof(ctx->status_text), "Fetching PNG %d/%d via 8106", idx+1, photo_count);
ui_update_all(ctx);
size_t out_len = 0;
int r = fetch_png_from_proxy(p->id, ctx->thumb_buf, THUMB_BUF_SIZE, &out_len);
if (r > 0) {
ctx->thumb_len = out_len;
const char* saved = save_buffer_to_file(ctx->thumb_buf, out_len);
if (saved) {
strncpy(ctx->saved_img_path, saved, sizeof(ctx->saved_img_path)-1);
ctx->has_image = true;
snprintf(ctx->status_text, sizeof(ctx->status_text), "PNG %d bytes saved %s", (int)out_len, saved);
} else if (ctx->app) {
char tmp_path[256]; size_t tmp_sz = sizeof(tmp_path);
tt_app_get_user_data_child_path(ctx->app, "immich_cur.png", tmp_path, &tmp_sz);
FILE* f = fopen(tmp_path, "wb");
if (f) {
fwrite(ctx->thumb_buf, 1, out_len, f); fclose(f);
strncpy(ctx->saved_img_path, tmp_path, sizeof(ctx->saved_img_path)-1);
ctx->has_image = true;
snprintf(ctx->status_text, sizeof(ctx->status_text), "PNG %d via user_data %s", (int)out_len, tmp_path);
} else {
ctx->has_image = false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "PNG %d bytes but save fail", (int)out_len);
}
} else {
ctx->has_image = false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "PNG %d bytes no handle", (int)out_len);
}
} else {
ctx->thumb_len = 0; ctx->has_image = false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Proxy PNG fail %d fallback thumb", r);
size_t ol2=0; int r2 = download_thumbnail_to_buf(p->id, ctx->thumb_buf, THUMB_BUF_SIZE, &ol2);
if (r2>0) { ctx->thumb_len = ol2; snprintf(ctx->status_text, sizeof(ctx->status_text), "Thumb %d fallback", (int)ol2); }
}
ui_update_all(ctx);
ctx->thumb_task = NULL; ctx->thumb_in_progress = false; vTaskDelete(NULL);
}
static void start_thumb_task(AppCtx* ctx) {
if (ctx->thumb_in_progress) return;
if (photo_count==0) return;
ctx->thumb_in_progress = true; ctx->thumb_len=0; ctx->has_image=false;
xTaskCreate(thumb_task_fn, "thumb_fetch", 8192, ctx, 5, &ctx->thumb_task);
}
static void fetch_task_fn(void* arg) {
AppCtx* ctx = (AppCtx*)arg;
ctx->fetch_in_progress = true;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Fetching %s photos...", PERSON_NAME);
ui_update_all(ctx);
int n = fetch_person_assets();
if (n>0) {
current_index=0; ctx->current_idx=0;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Loaded %d photos, PNG via 8106...", n);
ui_update_all(ctx);
if (!ctx->thumb_buf) {
ctx->thumb_buf = heap_caps_malloc(THUMB_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (!ctx->thumb_buf) ctx->thumb_buf = malloc(THUMB_BUF_SIZE);
}
if (ctx->thumb_buf) {
size_t ol=0;
Photo* p=&photos[0];
int r=fetch_png_from_proxy(p->id, ctx->thumb_buf, THUMB_BUF_SIZE, &ol);
if (r>0) {
ctx->thumb_len=ol;
const char* saved=save_buffer_to_file(ctx->thumb_buf, ol);
if (saved) { strncpy(ctx->saved_img_path, saved, sizeof(ctx->saved_img_path)-1); ctx->has_image=true; snprintf(ctx->status_text, sizeof(ctx->status_text), "PNG %d %s", (int)ol, saved); }
else if (ctx->app) {
char tmp_path[256]; size_t tmp_sz=sizeof(tmp_path);
tt_app_get_user_data_child_path(ctx->app, "immich_cur.png", tmp_path, &tmp_sz);
FILE* f=fopen(tmp_path,"wb"); if(f){fwrite(ctx->thumb_buf,1,ol,f); fclose(f); strncpy(ctx->saved_img_path, tmp_path, sizeof(ctx->saved_img_path)-1); ctx->has_image=true; snprintf(ctx->status_text,sizeof(ctx->status_text),"PNG %d user_data %s",(int)ol,tmp_path);}
}
}
ui_update_all(ctx);
}
} else {
snprintf(ctx->status_text, sizeof(ctx->status_text), "Fetch failed %s", IMMICH_BASE_URL);
ui_update_all(ctx);
}
ctx->fetch_task=NULL; ctx->fetch_in_progress=false; vTaskDelete(NULL);
}
static void start_fetch_task(AppCtx* ctx) {
if (ctx->fetch_in_progress) return;
ctx->fetch_in_progress=true;
xTaskCreate(fetch_task_fn, "immich_fetch", 8192, ctx, 5, &ctx->fetch_task);
}
static void prev_event_cb(lv_event_t* e) {
AppCtx* ctx = (AppCtx*)lv_event_get_user_data(e);
if (!ctx || photo_count==0) return;
if (ctx->thumb_in_progress || ctx->fetch_in_progress) return;
ctx->current_idx--; if (ctx->current_idx<0) ctx->current_idx=photo_count-1;
current_index=ctx->current_idx; ctx->thumb_len=0; ctx->has_image=false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Loading %d/%d 8106 PNG", ctx->current_idx+1, photo_count);
ui_update_all(ctx); start_thumb_task(ctx);
}
static void next_event_cb(lv_event_t* e) {
AppCtx* ctx = (AppCtx*)lv_event_get_user_data(e);
if (!ctx || photo_count==0) return;
if (ctx->thumb_in_progress || ctx->fetch_in_progress) return;
ctx->current_idx++; if (ctx->current_idx>=photo_count) ctx->current_idx=0;
current_index=ctx->current_idx; ctx->thumb_len=0; ctx->has_image=false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Loading %d/%d 8106 PNG", ctx->current_idx+1, photo_count);
ui_update_all(ctx); start_thumb_task(ctx);
}
static void reload_event_cb(lv_event_t* e) {
AppCtx* ctx = (AppCtx*)lv_event_get_user_data(e);
if (!ctx) return;
if (ctx->fetch_in_progress || ctx->thumb_in_progress) return;
photo_count=0; ctx->current_idx=0; current_index=0; ctx->thumb_len=0; ctx->has_image=false;
snprintf(ctx->status_text, sizeof(ctx->status_text), "Reloading...");
ui_update_all(ctx); start_fetch_task(ctx);
}
static void* create_data(void) {
AppCtx* ctx = calloc(1, sizeof(AppCtx));
if (ctx) { ctx->current_idx=0; snprintf(ctx->status_text, sizeof(ctx->status_text), "Init %s proxy %s", IMMICH_BASE_URL, RESIZE_PROXY_URL); }
return ctx;
}
static void destroy_data(void* data) {
AppCtx* ctx = (AppCtx*)data; if (!ctx) return;
if (ctx->thumb_buf) heap_caps_free(ctx->thumb_buf);
free(ctx);
}
static void on_create(AppHandle app, void* data) { AppCtx* ctx=(AppCtx*)data; if(ctx) ctx->app=app; ESP_LOGI(TAG,"onCreate proxy=%s", RESIZE_PROXY_URL); }
static void on_destroy(AppHandle app, void* data) { (void)app;(void)data; }
static void on_show(AppHandle app, void* data, lv_obj_t* parent) {
AppCtx* ctx=(AppCtx*)data; if(!ctx) return;
ctx->visible=true; ctx->app=app;
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(parent, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_all(parent, 4, LV_PART_MAIN);
lv_obj_set_style_pad_row(parent, 4, LV_PART_MAIN);
lv_obj_set_style_bg_color(parent, lv_color_hex(0x121212), LV_PART_MAIN);
lv_obj_set_style_bg_opa(parent, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_t* toolbar=tt_lvgl_toolbar_create_for_app(parent, app);
lv_obj_t* title_cont=lv_obj_create(parent);
lv_obj_set_width(title_cont, lv_pct(100)); lv_obj_set_height(title_cont, LV_SIZE_CONTENT);
lv_obj_set_flex_flow(title_cont, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(title_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_bg_opa(title_cont, LV_OPA_TRANSP, LV_PART_MAIN);
lv_obj_set_style_border_width(title_cont, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(title_cont, 2, LV_PART_MAIN);
ctx->lbl_title=lv_label_create(title_cont);
lv_label_set_text_fmt(ctx->lbl_title, "%s - %s photos 8106 PNG", PERSON_NAME, PERSON_COUNT_STR);
lv_obj_set_style_text_font(ctx->lbl_title, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
lv_obj_set_style_text_color(ctx->lbl_title, lv_color_white(), LV_PART_MAIN);
lv_obj_set_width(ctx->lbl_title, lv_pct(100));
lv_obj_set_style_text_align(ctx->lbl_title, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
ctx->lbl_count=lv_label_create(title_cont);
lv_label_set_text(ctx->lbl_count, "Loading...");
lv_obj_set_style_text_font(ctx->lbl_count, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
lv_obj_set_style_text_color(ctx->lbl_count, lv_color_hex(0xAAAAAA), LV_PART_MAIN);
lv_obj_set_width(ctx->lbl_count, lv_pct(100));
lv_label_set_long_mode(ctx->lbl_count, LV_LABEL_LONG_WRAP);
lv_obj_set_style_text_align(ctx->lbl_count, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
lv_obj_t* main_cont=lv_obj_create(parent);
lv_obj_set_width(main_cont, lv_pct(100));
lv_obj_set_flex_grow(main_cont, 1);
lv_obj_set_flex_flow(main_cont, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(main_cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_bg_color(main_cont, lv_color_hex(0x1E1E1E), LV_PART_MAIN);
lv_obj_set_style_bg_opa(main_cont, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_radius(main_cont, 8, LV_PART_MAIN);
lv_obj_set_style_pad_all(main_cont, 6, LV_PART_MAIN);
ctx->img=lv_image_create(main_cont);
lv_obj_add_flag(ctx->img, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_size(ctx->img, 320, 240);
ctx->lbl_status=lv_label_create(main_cont);
lv_label_set_text(ctx->lbl_status, ctx->status_text);
lv_obj_set_width(ctx->lbl_status, lv_pct(100));
lv_label_set_long_mode(ctx->lbl_status, LV_LABEL_LONG_WRAP);
lv_obj_set_style_text_font(ctx->lbl_status, lvgl_get_text_font(FONT_SIZE_DEFAULT), LV_PART_MAIN);
lv_obj_set_style_text_align(ctx->lbl_status, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
ctx->lbl_info=lv_label_create(parent);
lv_obj_set_width(ctx->lbl_info, lv_pct(100));
lv_label_set_long_mode(ctx->lbl_info, LV_LABEL_LONG_WRAP);
lv_label_set_text(ctx->lbl_info, "loading...");
lv_obj_set_style_text_font(ctx->lbl_info, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
lv_obj_t* nav_row=lv_obj_create(parent);
lv_obj_set_width(nav_row, lv_pct(100)); lv_obj_set_height(nav_row, 48);
lv_obj_set_flex_flow(nav_row, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(nav_row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_bg_opa(nav_row, LV_OPA_TRANSP, LV_PART_MAIN);
lv_obj_set_style_border_width(nav_row, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(nav_row, 2, LV_PART_MAIN);
ctx->btn_prev=lv_btn_create(nav_row); lv_obj_set_size(ctx->btn_prev, 60, 40);
lv_obj_t* lp=lv_label_create(ctx->btn_prev); lv_label_set_text(lp, "<"); lv_obj_center(lp);
lv_obj_add_event_cb(ctx->btn_prev, prev_event_cb, LV_EVENT_CLICKED, ctx);
ctx->lbl_index=lv_label_create(nav_row);
lv_label_set_text(ctx->lbl_index, "0/0");
lv_obj_set_style_text_font(ctx->lbl_index, lvgl_get_text_font(FONT_SIZE_DEFAULT), LV_PART_MAIN);
lv_obj_set_flex_grow(ctx->lbl_index, 1);
lv_obj_set_style_text_align(ctx->lbl_index, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
ctx->btn_next=lv_btn_create(nav_row); lv_obj_set_size(ctx->btn_next, 60, 40);
lv_obj_set_style_bg_color(ctx->btn_next, lv_color_hex(0x6200EE), LV_PART_MAIN);
lv_obj_t* ln=lv_label_create(ctx->btn_next); lv_label_set_text(ln, ">"); lv_obj_center(ln);
lv_obj_add_event_cb(ctx->btn_next, next_event_cb, LV_EVENT_CLICKED, ctx);
ctx->btn_reload=lv_btn_create(nav_row); lv_obj_set_size(ctx->btn_reload, 40, 40);
lv_obj_t* lr=lv_label_create(ctx->btn_reload); lv_label_set_text(lr, LV_SYMBOL_REFRESH); lv_obj_center(lr);
lv_obj_add_event_cb(ctx->btn_reload, reload_event_cb, LV_EVENT_CLICKED, ctx);
if (photo_count>0) { ctx->current_idx=current_index; if(ctx->current_idx>=photo_count) ctx->current_idx=0; snprintf(ctx->status_text,sizeof(ctx->status_text),"Cached %d photos via 8106",photo_count); ui_update_all(ctx); start_thumb_task(ctx); }
else { snprintf(ctx->status_text,sizeof(ctx->status_text),"Fetching %s via %s...",PERSON_NAME, RESIZE_PROXY_URL); ui_update_all(ctx); start_fetch_task(ctx); }
}
static void on_hide(AppHandle app, void* data) {
(void)app; AppCtx* ctx=(AppCtx*)data; if(!ctx) return;
ctx->visible=false;
int timeout=20; while((ctx->fetch_task||ctx->thumb_task) && timeout>0){ vTaskDelay(pdMS_TO_TICKS(50)); timeout--; }
}
int main(int argc, char* argv[]) {
(void)argc;(void)argv;
tt_app_register((AppRegistration){.createData=create_data,.destroyData=destroy_data,.onCreate=on_create,.onDestroy=on_destroy,.onShow=on_show,.onHide=on_hide});
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
manifest.version=0.2
target.sdk=0.8.0-dev
target.platforms=esp32s3,esp32p4
app.id=one.tactility.imichelias
app.version.name=0.1.0
app.version.code=1
app.name=Immich Elias