fix(printer): limit thermal print power draw
This commit is contained in:
@@ -261,6 +261,21 @@ static bool json_get_bool(cJSON *obj, const char *key, bool fallback) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static const char *json_get_print_density(cJSON *obj, const char *key, const char *fallback) {
|
||||
const char *density = json_get_str(obj, key, fallback);
|
||||
if (density == NULL || density[0] == '\0') {
|
||||
return fallback;
|
||||
}
|
||||
if (strcmp(density, "test") == 0 ||
|
||||
strcmp(density, "较淡") == 0 ||
|
||||
strcmp(density, "中等") == 0 ||
|
||||
strcmp(density, "较浓") == 0 ||
|
||||
strcmp(density, "最深") == 0) {
|
||||
return density;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static void add_printer_status_fields(cJSON *obj, const printer_runtime_status_t *printer) {
|
||||
if (obj == NULL || printer == NULL) {
|
||||
return;
|
||||
@@ -526,6 +541,7 @@ static void handle_print_pattern(uint32_t seq, const char *name, cJSON *payload)
|
||||
uint16_t height = (uint16_t)clamp_u32(height_arg, 16, 512);
|
||||
bool wait_done = json_get_bool(payload, "wait_done", true);
|
||||
bool ignore_precheck = json_get_bool(payload, "ignore_precheck", false);
|
||||
const char *density = json_get_print_density(payload, "density", "test");
|
||||
|
||||
int64_t start = now_ms();
|
||||
emit_progress(seq, name, "build_pattern", NULL);
|
||||
@@ -548,7 +564,7 @@ static void handle_print_pattern(uint32_t seq, const char *name, cJSON *payload)
|
||||
raster_len,
|
||||
384,
|
||||
height,
|
||||
"test",
|
||||
density,
|
||||
&options,
|
||||
&job_id,
|
||||
err,
|
||||
@@ -599,6 +615,7 @@ static void handle_image_generate(uint32_t seq, const char *name, cJSON *payload
|
||||
bool prompt_extend = json_get_bool(payload, "prompt_extend", true);
|
||||
bool ignore_precheck = json_get_bool(payload, "ignore_precheck", false);
|
||||
bool wait_done = json_get_bool(payload, "wait_done", true);
|
||||
const char *density = json_get_print_density(payload, "density", "test");
|
||||
|
||||
int64_t start = now_ms();
|
||||
emit_progress(seq, name, "image_generate", NULL);
|
||||
@@ -693,7 +710,7 @@ static void handle_image_generate(uint32_t seq, const char *name, cJSON *payload
|
||||
raster_len,
|
||||
raster_width,
|
||||
raster_height,
|
||||
"test",
|
||||
density,
|
||||
&options,
|
||||
&job_id,
|
||||
err,
|
||||
|
||||
@@ -21,6 +21,7 @@ static const char *TAG = "voice_interaction";
|
||||
#define VOICE_IMAGE_MARKER_TEMPLATE \
|
||||
"%s,线稿风格,白色背景,边缘清晰,细节简洁,高对比,避免大面积阴影和灰度渐变,适配热敏打印机打印。"
|
||||
#define VOICE_IMAGE_MARKER_TEMPLATE_FALLBACK_SUBJECT "简洁卡通图案"
|
||||
#define VOICE_IMAGE_PRINT_DENSITY "较淡"
|
||||
|
||||
typedef struct {
|
||||
char prompt[VOICE_IMAGE_MARKER_PROMPT_MAX_LEN + 1];
|
||||
@@ -285,13 +286,13 @@ static esp_err_t voice_submit_marker_generated_image(const voice_image_generatio
|
||||
uint32_t job_id = 0;
|
||||
char submit_err[128] = {0};
|
||||
printer_print_options_t print_opt = {
|
||||
.ignore_precheck = true,
|
||||
.ignore_precheck = false,
|
||||
};
|
||||
esp_err_t submit_rc = printer_protocol_submit_raster_job_ex(raster,
|
||||
raster_len,
|
||||
raster_width,
|
||||
raster_height,
|
||||
NULL,
|
||||
VOICE_IMAGE_PRINT_DENSITY,
|
||||
&print_opt,
|
||||
&job_id,
|
||||
submit_err,
|
||||
|
||||
Reference in New Issue
Block a user