添加热敏打印机调试功能
This commit is contained in:
@@ -146,6 +146,18 @@ typedef struct {
|
||||
bool direct_ignore_precheck;
|
||||
} printer_print_options_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t shift_clock_high_us;
|
||||
uint16_t shift_clock_low_us;
|
||||
uint16_t latch_pulse_us;
|
||||
bool strobe_active_high;
|
||||
bool boost_active_high;
|
||||
uint16_t override_strobe_on_us;
|
||||
uint16_t override_strobe_interval_us;
|
||||
uint16_t override_motor_step_us;
|
||||
uint8_t override_steps_per_line;
|
||||
} printer_direct_debug_config_t;
|
||||
|
||||
typedef struct {
|
||||
bool supports_connect;
|
||||
bool supports_gap_move;
|
||||
@@ -184,6 +196,13 @@ esp_err_t printer_protocol_connect(const char *target_name, uint32_t timeout_ms)
|
||||
esp_err_t printer_protocol_connect_ex(const printer_connect_options_t *opt, char *err, size_t err_len);
|
||||
void printer_protocol_disconnect(void);
|
||||
void printer_protocol_get_capabilities(printer_capabilities_t *out_capabilities);
|
||||
esp_err_t printer_protocol_get_direct_debug_config(printer_direct_debug_config_t *out_config,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
esp_err_t printer_protocol_set_direct_debug_config(const printer_direct_debug_config_t *config,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
|
||||
void printer_protocol_get_runtime_status(printer_runtime_status_t *out_status);
|
||||
printer_status_poll_pause_token_t printer_protocol_status_poll_pause_acquire(void);
|
||||
|
||||
@@ -51,6 +51,14 @@ static const char *TAG = "printer_protocol";
|
||||
|
||||
static void on_rx_frame(const uint8_t *data, size_t len);
|
||||
|
||||
static printer_backend_t default_backend_on_startup(void) {
|
||||
// This hardware has a first-class direct path; BLE remains opt-in via API.
|
||||
if (runtime_policy_direct_printer_enabled()) {
|
||||
return PRINTER_BACKEND_DIRECT;
|
||||
}
|
||||
return PRINTER_BACKEND_BLE;
|
||||
}
|
||||
|
||||
static void backend_capabilities_for(printer_backend_t backend, printer_capabilities_t *out_caps) {
|
||||
if (out_caps == NULL) {
|
||||
return;
|
||||
@@ -643,9 +651,7 @@ esp_err_t printer_protocol_init(void) {
|
||||
s_protocol_initialized = true;
|
||||
s_protocol_stopping = false;
|
||||
s_ble_client_initialized = false;
|
||||
s_backend = (runtime_policy_printer_default_backend() == 1 && runtime_policy_direct_printer_enabled())
|
||||
? PRINTER_BACKEND_DIRECT
|
||||
: PRINTER_BACKEND_BLE;
|
||||
s_backend = default_backend_on_startup();
|
||||
|
||||
esp_err_t err = ensure_backend_ready(s_backend);
|
||||
if (err != ESP_OK) {
|
||||
@@ -757,7 +763,7 @@ esp_err_t printer_protocol_stop(uint32_t timeout_ms) {
|
||||
s_protocol_initialized = false;
|
||||
s_protocol_stopping = false;
|
||||
s_ble_client_initialized = false;
|
||||
s_backend = PRINTER_BACKEND_BLE;
|
||||
s_backend = default_backend_on_startup();
|
||||
|
||||
runtime_diag_set_gauge(RUNTIME_DIAG_GAUGE_STATUS_POLL_PAUSE_DEPTH, 0);
|
||||
runtime_diag_set_gauge(RUNTIME_DIAG_GAUGE_PRINTER_QUEUE_DEPTH, 0);
|
||||
|
||||
@@ -15,6 +15,12 @@ static esp_err_t unsupported_for_direct(char *err, size_t err_len, const char *o
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static void write_err(char *err, size_t err_len, const char *msg) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "%s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_gap_move(uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return platform_direct_printer_gap_move(timeout_ms, err, err_len);
|
||||
@@ -343,6 +349,68 @@ esp_err_t printer_protocol_ota_get_version(printer_ota_version_t *out_version,
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_get_direct_debug_config(printer_direct_debug_config_t *out_config,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
if (out_config == NULL) {
|
||||
write_err(err, err_len, "invalid args");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!runtime_policy_direct_printer_enabled()) {
|
||||
write_err(err, err_len, "direct backend disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
platform_direct_debug_config_t cfg = {0};
|
||||
esp_err_t rc = platform_direct_printer_get_debug_config(&cfg);
|
||||
if (rc != ESP_OK) {
|
||||
write_err(err, err_len, "get direct debug config failed");
|
||||
return rc;
|
||||
}
|
||||
|
||||
out_config->shift_clock_high_us = cfg.shift_clock_high_us;
|
||||
out_config->shift_clock_low_us = cfg.shift_clock_low_us;
|
||||
out_config->latch_pulse_us = cfg.latch_pulse_us;
|
||||
out_config->strobe_active_high = cfg.strobe_active_high;
|
||||
out_config->boost_active_high = cfg.boost_active_high;
|
||||
out_config->override_strobe_on_us = cfg.override_strobe_on_us;
|
||||
out_config->override_strobe_interval_us = cfg.override_strobe_interval_us;
|
||||
out_config->override_motor_step_us = cfg.override_motor_step_us;
|
||||
out_config->override_steps_per_line = cfg.override_steps_per_line;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_set_direct_debug_config(const printer_direct_debug_config_t *config,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
if (config == NULL && !reset_defaults) {
|
||||
write_err(err, err_len, "invalid args");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!runtime_policy_direct_printer_enabled()) {
|
||||
write_err(err, err_len, "direct backend disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
platform_direct_debug_config_t cfg = {0};
|
||||
platform_direct_debug_config_t *pcfg = NULL;
|
||||
if (config != NULL) {
|
||||
cfg.shift_clock_high_us = config->shift_clock_high_us;
|
||||
cfg.shift_clock_low_us = config->shift_clock_low_us;
|
||||
cfg.latch_pulse_us = config->latch_pulse_us;
|
||||
cfg.strobe_active_high = config->strobe_active_high;
|
||||
cfg.boost_active_high = config->boost_active_high;
|
||||
cfg.override_strobe_on_us = config->override_strobe_on_us;
|
||||
cfg.override_strobe_interval_us = config->override_strobe_interval_us;
|
||||
cfg.override_motor_step_us = config->override_motor_step_us;
|
||||
cfg.override_steps_per_line = config->override_steps_per_line;
|
||||
pcfg = &cfg;
|
||||
}
|
||||
|
||||
return platform_direct_printer_set_debug_config(pcfg, reset_defaults, err, err_len);
|
||||
}
|
||||
|
||||
const char *printer_protocol_job_state_str(print_job_state_t state) {
|
||||
switch (state) {
|
||||
case PRINT_JOB_STATE_NONE:
|
||||
|
||||
Reference in New Issue
Block a user