feat(printer): add direct thermal backend and debug controls
This commit is contained in:
@@ -16,6 +16,7 @@ typedef struct {
|
||||
bool invert;
|
||||
uint16_t max_height;
|
||||
const char *density;
|
||||
bool direct_ignore_precheck;
|
||||
} image_print_options_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -68,7 +69,8 @@ static void parse_image_upload_options(httpd_req_t *req,
|
||||
uint8_t *out_threshold,
|
||||
bool *out_invert,
|
||||
uint16_t *out_max_height,
|
||||
const char **out_density) {
|
||||
const char **out_density,
|
||||
bool *out_direct_ignore_precheck) {
|
||||
if (out_scale_to_width != NULL) {
|
||||
*out_scale_to_width = true;
|
||||
}
|
||||
@@ -84,6 +86,9 @@ static void parse_image_upload_options(httpd_req_t *req,
|
||||
if (out_density != NULL) {
|
||||
*out_density = "中等";
|
||||
}
|
||||
if (out_direct_ignore_precheck != NULL) {
|
||||
*out_direct_ignore_precheck = false;
|
||||
}
|
||||
|
||||
if (req == NULL) {
|
||||
return;
|
||||
@@ -138,6 +143,14 @@ static void parse_image_upload_options(httpd_req_t *req,
|
||||
*out_density = map_density_text(value);
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(query, "ignore_precheck", value, sizeof(value)) == ESP_OK &&
|
||||
out_direct_ignore_precheck != NULL) {
|
||||
bool parsed = *out_direct_ignore_precheck;
|
||||
if (parse_bool_text(value, &parsed)) {
|
||||
*out_direct_ignore_precheck = parsed;
|
||||
}
|
||||
}
|
||||
|
||||
free(query);
|
||||
}
|
||||
|
||||
@@ -150,6 +163,7 @@ static void image_print_options_set_defaults(image_print_options_t *out) {
|
||||
out->invert = false;
|
||||
out->max_height = 2200;
|
||||
out->density = "中等";
|
||||
out->direct_ignore_precheck = false;
|
||||
}
|
||||
|
||||
static void parse_image_print_options_from_json(cJSON *json, image_print_options_t *out) {
|
||||
@@ -162,6 +176,7 @@ static void parse_image_print_options_from_json(cJSON *json, image_print_options
|
||||
cJSON *jinvert = cJSON_GetObjectItemCaseSensitive(json, "invert");
|
||||
cJSON *jmaxh = cJSON_GetObjectItemCaseSensitive(json, "max_height");
|
||||
cJSON *jdensity = cJSON_GetObjectItemCaseSensitive(json, "density");
|
||||
cJSON *jignore = cJSON_GetObjectItemCaseSensitive(json, "ignore_precheck");
|
||||
|
||||
out->scale_to_width = rest_server_json_bool_with_default(jscale, out->scale_to_width);
|
||||
out->invert = rest_server_json_bool_with_default(jinvert, out->invert);
|
||||
@@ -174,6 +189,7 @@ static void parse_image_print_options_from_json(cJSON *json, image_print_options
|
||||
if (cJSON_IsString(jdensity) && jdensity->valuestring != NULL) {
|
||||
out->density = map_density_text(jdensity->valuestring);
|
||||
}
|
||||
out->direct_ignore_precheck = rest_server_json_bool_with_default(jignore, out->direct_ignore_precheck);
|
||||
}
|
||||
|
||||
static bool parse_image_size_text(const char *text, uint32_t *out_w, uint32_t *out_h) {
|
||||
@@ -345,21 +361,24 @@ static esp_err_t rest_server_print_image_binary(httpd_req_t *req) {
|
||||
bool invert = false;
|
||||
uint16_t max_height = 2200;
|
||||
const char *density = "中等";
|
||||
bool direct_ignore_precheck = false;
|
||||
parse_image_upload_options(req,
|
||||
&scale_to_width,
|
||||
&threshold,
|
||||
&invert,
|
||||
&max_height,
|
||||
&density);
|
||||
&density,
|
||||
&direct_ignore_precheck);
|
||||
|
||||
ESP_LOGI(TAG,
|
||||
"image process start (upload), png_bytes=%u, scale_to_width=%d, threshold=%u, invert=%d, max_height=%u, density=%s",
|
||||
"image process start (upload), png_bytes=%u, scale_to_width=%d, threshold=%u, invert=%d, max_height=%u, density=%s, ignore_precheck=%d",
|
||||
(unsigned)req->content_len,
|
||||
scale_to_width,
|
||||
(unsigned)threshold,
|
||||
invert,
|
||||
(unsigned)max_height,
|
||||
density != NULL ? density : "中等");
|
||||
density != NULL ? density : "中等",
|
||||
direct_ignore_precheck);
|
||||
|
||||
char *body = NULL;
|
||||
esp_err_t body_err = rest_server_read_body(req, &body);
|
||||
@@ -407,6 +426,7 @@ static esp_err_t rest_server_print_image_binary(httpd_req_t *req) {
|
||||
width,
|
||||
height,
|
||||
density,
|
||||
direct_ignore_precheck,
|
||||
NULL,
|
||||
NULL);
|
||||
free(raster);
|
||||
@@ -458,12 +478,13 @@ static esp_err_t rest_server_print_image_generate(httpd_req_t *req) {
|
||||
(unsigned)gen_opt.timeout_ms,
|
||||
(unsigned)gen_opt.fetch_timeout_ms);
|
||||
ESP_LOGI(TAG,
|
||||
"image process config, scale_to_width=%d, threshold=%u, invert=%d, max_height=%u, density=%s",
|
||||
"image process config, scale_to_width=%d, threshold=%u, invert=%d, max_height=%u, density=%s, ignore_precheck=%d",
|
||||
print_opt.scale_to_width,
|
||||
(unsigned)print_opt.threshold,
|
||||
print_opt.invert,
|
||||
(unsigned)print_opt.max_height,
|
||||
print_opt.density != NULL ? print_opt.density : "中等");
|
||||
print_opt.density != NULL ? print_opt.density : "中等",
|
||||
print_opt.direct_ignore_precheck);
|
||||
|
||||
image_generation_request_t gen_req = {
|
||||
.prompt = gen_opt.prompt,
|
||||
@@ -553,6 +574,7 @@ static esp_err_t rest_server_print_image_generate(httpd_req_t *req) {
|
||||
width,
|
||||
height,
|
||||
print_opt.density,
|
||||
print_opt.direct_ignore_precheck,
|
||||
warning,
|
||||
request_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user