refactor(printer): remove controller residue and coex hooks
- rename printer protocol helpers to driver-centric names\n- remove image download coex preference code and config\n- drop esp_coex dependency from domain\n- remove unused set_black helper to keep build warning-free
This commit is contained in:
@@ -29,7 +29,6 @@ idf_component_register(
|
|||||||
espressif__libpng
|
espressif__libpng
|
||||||
json
|
json
|
||||||
mbedtls
|
mbedtls
|
||||||
esp_coex
|
|
||||||
EMBED_FILES
|
EMBED_FILES
|
||||||
"assets/fonts/cn16_index.bin"
|
"assets/fonts/cn16_index.bin"
|
||||||
"assets/fonts/cn16_glyphs.bin"
|
"assets/fonts/cn16_glyphs.bin"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "esp_coexist.h"
|
|
||||||
#include "esp_crt_bundle.h"
|
#include "esp_crt_bundle.h"
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
@@ -80,36 +79,6 @@ static SemaphoreHandle_t s_prewarm_lock;
|
|||||||
static bool s_prewarm_running;
|
static bool s_prewarm_running;
|
||||||
static char s_last_oss_origin[160] = "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/";
|
static char s_last_oss_origin[160] = "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/";
|
||||||
|
|
||||||
static bool image_generation_boost_coex_for_download(void) {
|
|
||||||
#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_TQ_Z_IMAGE_COEX_PREFER_WIFI_DURING_DOWNLOAD
|
|
||||||
esp_err_t rc = esp_coex_preference_set(ESP_COEX_PREFER_WIFI);
|
|
||||||
if (rc != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "failed to prefer Wi-Fi coexist mode, rc=0x%x", (unsigned)rc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "coexist prefer Wi-Fi enabled for image download");
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void image_generation_restore_coex_after_download(bool boosted) {
|
|
||||||
#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_TQ_Z_IMAGE_COEX_PREFER_WIFI_DURING_DOWNLOAD
|
|
||||||
if (!boosted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
esp_err_t rc = esp_coex_preference_set(ESP_COEX_PREFER_BALANCE);
|
|
||||||
if (rc != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "failed to restore coexist balance mode, rc=0x%x", (unsigned)rc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "coexist preference restored to balance");
|
|
||||||
#else
|
|
||||||
(void)boosted;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void image_generation_fill_err(char *err, size_t err_len, const char *msg) {
|
static void image_generation_fill_err(char *err, size_t err_len, const char *msg) {
|
||||||
if (err != NULL && err_len > 0) {
|
if (err != NULL && err_len > 0) {
|
||||||
snprintf(err, err_len, "%s", msg != NULL ? msg : "unknown error");
|
snprintf(err, err_len, "%s", msg != NULL ? msg : "unknown error");
|
||||||
@@ -791,7 +760,6 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
|
|||||||
char *err,
|
char *err,
|
||||||
size_t err_len) {
|
size_t err_len) {
|
||||||
ESP_LOGI(TAG, "generated image download start, timeout_ms=%u", (unsigned)timeout_ms);
|
ESP_LOGI(TAG, "generated image download start, timeout_ms=%u", (unsigned)timeout_ms);
|
||||||
bool coex_boosted = image_generation_boost_coex_for_download();
|
|
||||||
|
|
||||||
esp_http_client_config_t config = {
|
esp_http_client_config_t config = {
|
||||||
.url = out_result->image_url,
|
.url = out_result->image_url,
|
||||||
@@ -822,7 +790,6 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
|
|||||||
(unsigned)rc,
|
(unsigned)rc,
|
||||||
(err != NULL && err[0] != '\0') ? err : "download failed");
|
(err != NULL && err[0] != '\0') ? err : "download failed");
|
||||||
bytes_buffer_free(&resp);
|
bytes_buffer_free(&resp);
|
||||||
image_generation_restore_coex_after_download(coex_boosted);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -831,7 +798,6 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
|
|||||||
if (rc != ESP_OK) {
|
if (rc != ESP_OK) {
|
||||||
bytes_buffer_free(&resp);
|
bytes_buffer_free(&resp);
|
||||||
image_generation_fill_err(err, err_len, "image download failed");
|
image_generation_fill_err(err, err_len, "image download failed");
|
||||||
image_generation_restore_coex_after_download(coex_boosted);
|
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
extract_remote_error_message((const char *)resp.data, http_status, err, err_len);
|
extract_remote_error_message((const char *)resp.data, http_status, err, err_len);
|
||||||
@@ -840,7 +806,6 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
|
|||||||
http_status,
|
http_status,
|
||||||
(err != NULL && err[0] != '\0') ? err : "image download failed");
|
(err != NULL && err[0] != '\0') ? err : "image download failed");
|
||||||
bytes_buffer_free(&resp);
|
bytes_buffer_free(&resp);
|
||||||
image_generation_restore_coex_after_download(coex_boosted);
|
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -851,14 +816,12 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
|
|||||||
bytes_buffer_free(&resp);
|
bytes_buffer_free(&resp);
|
||||||
image_generation_fill_err(err, err_len, "downloaded image is not png");
|
image_generation_fill_err(err, err_len, "downloaded image is not png");
|
||||||
ESP_LOGW(TAG, "generated image download invalid png signature");
|
ESP_LOGW(TAG, "generated image download invalid png signature");
|
||||||
image_generation_restore_coex_after_download(coex_boosted);
|
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_result->png = resp.data;
|
out_result->png = resp.data;
|
||||||
out_result->png_len = resp.len;
|
out_result->png_len = resp.len;
|
||||||
ESP_LOGI(TAG, "generated image download done, png_bytes=%u", (unsigned)out_result->png_len);
|
ESP_LOGI(TAG, "generated image download done, png_bytes=%u", (unsigned)out_result->png_len);
|
||||||
image_generation_restore_coex_after_download(coex_boosted);
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ static const char *TAG = "printer_protocol";
|
|||||||
#define PRINT_WORKER_CORE_ID 1
|
#define PRINT_WORKER_CORE_ID 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static esp_err_t ensure_direct_backend_ready(void) {
|
static esp_err_t ensure_printer_driver_ready(void) {
|
||||||
return platform_printer_init();
|
return platform_printer_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void refresh_direct_status_locked(void) {
|
static void refresh_printer_status_locked(void) {
|
||||||
platform_printer_sensors_t sensors = {0};
|
platform_printer_sensors_t sensors = {0};
|
||||||
if (platform_printer_get_sensors(&sensors) == ESP_OK) {
|
if (platform_printer_get_sensors(&sensors) == ESP_OK) {
|
||||||
s_status.has_paper = sensors.has_paper;
|
s_status.has_paper = sensors.has_paper;
|
||||||
@@ -224,7 +224,7 @@ static void status_poll_task(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (can_poll && xSemaphoreTake(s_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
if (can_poll && xSemaphoreTake(s_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||||
refresh_direct_status_locked();
|
refresh_printer_status_locked();
|
||||||
xSemaphoreGive(s_mutex);
|
xSemaphoreGive(s_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ esp_err_t printer_protocol_init(void) {
|
|||||||
s_protocol_initialized = true;
|
s_protocol_initialized = true;
|
||||||
s_protocol_stopping = false;
|
s_protocol_stopping = false;
|
||||||
|
|
||||||
esp_err_t err = ensure_direct_backend_ready();
|
esp_err_t err = ensure_printer_driver_ready();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
s_protocol_initialized = false;
|
s_protocol_initialized = false;
|
||||||
destroy_runtime_objects();
|
destroy_runtime_objects();
|
||||||
@@ -295,7 +295,7 @@ esp_err_t printer_protocol_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (xSemaphoreTake(s_mutex, pdMS_TO_TICKS(200)) == pdTRUE) {
|
if (xSemaphoreTake(s_mutex, pdMS_TO_TICKS(200)) == pdTRUE) {
|
||||||
refresh_direct_status_locked();
|
refresh_printer_status_locked();
|
||||||
xSemaphoreGive(s_mutex);
|
xSemaphoreGive(s_mutex);
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "printer driver ready at startup");
|
ESP_LOGI(TAG, "printer driver ready at startup");
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ static bool precheck_printer_ready(bool ignore_precheck, char *err, size_t err_l
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool run_print_job_direct(job_slot_t *job) {
|
static bool run_print_job_printer_driver(job_slot_t *job) {
|
||||||
char check_err[96];
|
char check_err[96];
|
||||||
if (!precheck_printer_ready(job->ignore_precheck, check_err, sizeof(check_err))) {
|
if (!precheck_printer_ready(job->ignore_precheck, check_err, sizeof(check_err))) {
|
||||||
snprintf(job->error, sizeof(job->error), "%s", check_err);
|
snprintf(job->error, sizeof(job->error), "%s", check_err);
|
||||||
@@ -89,11 +89,11 @@ static bool run_print_job_direct(job_slot_t *job) {
|
|||||||
xSemaphoreGive(s_mutex);
|
xSemaphoreGive(s_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
char direct_err[96] = {0};
|
char print_err[96] = {0};
|
||||||
esp_err_t rc = platform_printer_print(&req, direct_err, sizeof(direct_err));
|
esp_err_t rc = platform_printer_print(&req, print_err, sizeof(print_err));
|
||||||
if (rc != ESP_OK) {
|
if (rc != ESP_OK) {
|
||||||
if (direct_err[0] != 0) {
|
if (print_err[0] != 0) {
|
||||||
snprintf(job->error, sizeof(job->error), "%s", direct_err);
|
snprintf(job->error, sizeof(job->error), "%s", print_err);
|
||||||
} else if (rc == ESP_ERR_TIMEOUT) {
|
} else if (rc == ESP_ERR_TIMEOUT) {
|
||||||
snprintf(job->error, sizeof(job->error), "print timeout");
|
snprintf(job->error, sizeof(job->error), "print timeout");
|
||||||
} else if (rc == ESP_ERR_INVALID_STATE && job->cancel_requested) {
|
} else if (rc == ESP_ERR_INVALID_STATE && job->cancel_requested) {
|
||||||
@@ -113,7 +113,7 @@ static bool run_print_job_direct(job_slot_t *job) {
|
|||||||
|
|
||||||
static bool run_print_job(job_slot_t *job) {
|
static bool run_print_job(job_slot_t *job) {
|
||||||
ESP_LOGI(TAG,
|
ESP_LOGI(TAG,
|
||||||
"job %u print start, mode=printer, raster_bytes=%u, size=%ux%u, density=%s, ignore_precheck=%d",
|
"job %u print start, raster_bytes=%u, size=%ux%u, density=%s, ignore_precheck=%d",
|
||||||
(unsigned)job->id,
|
(unsigned)job->id,
|
||||||
(unsigned)job->data_len,
|
(unsigned)job->data_len,
|
||||||
(unsigned)job->width,
|
(unsigned)job->width,
|
||||||
@@ -126,7 +126,7 @@ static bool run_print_job(job_slot_t *job) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_print_job_direct(job);
|
return run_print_job_printer_driver(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer_protocol_worker_task(void *arg) {
|
void printer_protocol_worker_task(void *arg) {
|
||||||
|
|||||||
@@ -15,16 +15,6 @@
|
|||||||
|
|
||||||
static const uint8_t s_bit_mask[8] = {0x80u, 0x40u, 0x20u, 0x10u, 0x08u, 0x04u, 0x02u, 0x01u};
|
static const uint8_t s_bit_mask[8] = {0x80u, 0x40u, 0x20u, 0x10u, 0x08u, 0x04u, 0x02u, 0x01u};
|
||||||
|
|
||||||
static void set_black(uint8_t *buf, uint16_t width, uint16_t x, uint16_t y) {
|
|
||||||
if (x >= width) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint16_t bpr = width / 8;
|
|
||||||
size_t idx = (size_t)y * bpr + (x / 8);
|
|
||||||
uint8_t bit = (uint8_t)(7 - (x % 8));
|
|
||||||
buf[idx] |= (uint8_t)(1u << bit);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *alloc_prefer_psram(size_t size) {
|
static void *alloc_prefer_psram(size_t size) {
|
||||||
void *ptr = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
void *ptr = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
|
|||||||
@@ -192,10 +192,6 @@ config TQ_Z_IMAGE_HTTP_READ_CHUNK_BYTES
|
|||||||
range 4096 32768
|
range 4096 32768
|
||||||
default 16384
|
default 16384
|
||||||
|
|
||||||
config TQ_Z_IMAGE_COEX_PREFER_WIFI_DURING_DOWNLOAD
|
|
||||||
bool "Prefer Wi-Fi RF during image download"
|
|
||||||
default y
|
|
||||||
|
|
||||||
config TQ_VOICE_API_KEY
|
config TQ_VOICE_API_KEY
|
||||||
string "Voice API Key for DashScope WebSocket (optional)"
|
string "Voice API Key for DashScope WebSocket (optional)"
|
||||||
default "sk-7a50eca6856d4afb968ac3bf512f6d1b"
|
default "sk-7a50eca6856d4afb968ac3bf512f6d1b"
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ CONFIG_TQ_WIFI_PROV_SOFTAP_MAX_CONN=4
|
|||||||
CONFIG_TQ_Z_IMAGE_DEFAULT_SIZE="512*768"
|
CONFIG_TQ_Z_IMAGE_DEFAULT_SIZE="512*768"
|
||||||
CONFIG_TQ_Z_IMAGE_HTTP_BUFFER_BYTES=16384
|
CONFIG_TQ_Z_IMAGE_HTTP_BUFFER_BYTES=16384
|
||||||
CONFIG_TQ_Z_IMAGE_HTTP_READ_CHUNK_BYTES=16384
|
CONFIG_TQ_Z_IMAGE_HTTP_READ_CHUNK_BYTES=16384
|
||||||
CONFIG_TQ_Z_IMAGE_COEX_PREFER_WIFI_DURING_DOWNLOAD=y
|
|
||||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||||
|
|||||||
Reference in New Issue
Block a user