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:
admin
2026-03-01 15:07:13 +08:00
parent 742cff63bb
commit 4f574fb65c
7 changed files with 12 additions and 65 deletions

View File

@@ -6,7 +6,6 @@
#include <string.h>
#include "cJSON.h"
#include "esp_coexist.h"
#include "esp_crt_bundle.h"
#include "esp_heap_caps.h"
#include "esp_http_client.h"
@@ -80,36 +79,6 @@ static SemaphoreHandle_t s_prewarm_lock;
static bool s_prewarm_running;
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) {
if (err != NULL && err_len > 0) {
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,
size_t err_len) {
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 = {
.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,
(err != NULL && err[0] != '\0') ? err : "download failed");
bytes_buffer_free(&resp);
image_generation_restore_coex_after_download(coex_boosted);
return rc;
}
@@ -831,7 +798,6 @@ static esp_err_t image_generation_download_png(image_generation_result_t *out_re
if (rc != ESP_OK) {
bytes_buffer_free(&resp);
image_generation_fill_err(err, err_len, "image download failed");
image_generation_restore_coex_after_download(coex_boosted);
return ESP_FAIL;
}
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,
(err != NULL && err[0] != '\0') ? err : "image download failed");
bytes_buffer_free(&resp);
image_generation_restore_coex_after_download(coex_boosted);
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);
image_generation_fill_err(err, err_len, "downloaded image is not png");
ESP_LOGW(TAG, "generated image download invalid png signature");
image_generation_restore_coex_after_download(coex_boosted);
return ESP_FAIL;
}
out_result->png = resp.data;
out_result->png_len = resp.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;
}