153 lines
6.5 KiB
C
153 lines
6.5 KiB
C
#include "domain.h"
|
|
#include "printer_protocol_internal.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
static esp_err_t unsupported_operation(char *err, size_t err_len, const char *op) {
|
|
if (err != NULL && err_len > 0) {
|
|
snprintf(err, err_len, "%s is not supported on direct backend", op);
|
|
}
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
}
|
|
|
|
esp_err_t printer_protocol_gap_move(uint32_t timeout_ms, char *err, size_t err_len) {
|
|
if (!runtime_policy_direct_printer_enabled()) {
|
|
write_err(err, err_len, "direct backend disabled");
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
}
|
|
return platform_direct_printer_gap_move(timeout_ms, err, err_len);
|
|
}
|
|
|
|
esp_err_t printer_protocol_get_label_offset(uint8_t *out_offset, uint32_t timeout_ms, char *err, size_t err_len) {
|
|
(void)out_offset;
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "label offset");
|
|
}
|
|
|
|
esp_err_t printer_protocol_set_label_offset(uint8_t offset, uint32_t timeout_ms, char *err, size_t err_len) {
|
|
(void)offset;
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "label offset");
|
|
}
|
|
|
|
esp_err_t printer_protocol_ota_jump_boot(uint32_t timeout_ms, char *err, size_t err_len) {
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "ota jump boot");
|
|
}
|
|
|
|
esp_err_t printer_protocol_ota_jump_app(uint32_t timeout_ms, char *err, size_t err_len) {
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "ota jump app");
|
|
}
|
|
|
|
esp_err_t printer_protocol_ota_erase_page(uint16_t page_num, uint32_t timeout_ms, char *err, size_t err_len) {
|
|
(void)page_num;
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "ota erase");
|
|
}
|
|
|
|
esp_err_t printer_protocol_ota_write_frame(uint16_t packet_num,
|
|
bool is_last_frame,
|
|
const uint8_t *data,
|
|
size_t data_len,
|
|
uint32_t timeout_ms,
|
|
char *err,
|
|
size_t err_len) {
|
|
(void)packet_num;
|
|
(void)is_last_frame;
|
|
(void)data;
|
|
(void)data_len;
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "ota write");
|
|
}
|
|
|
|
esp_err_t printer_protocol_ota_get_version(printer_ota_version_t *out_version,
|
|
uint32_t timeout_ms,
|
|
char *err,
|
|
size_t err_len) {
|
|
(void)out_version;
|
|
(void)timeout_ms;
|
|
return unsupported_operation(err, err_len, "ota version");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
esp_err_t rc = platform_direct_printer_get_debug_config(&out_config->shift_clock_high_us,
|
|
&out_config->shift_clock_low_us,
|
|
&out_config->latch_pulse_us,
|
|
&out_config->strobe_active_high,
|
|
&out_config->boost_active_high,
|
|
&out_config->override_strobe_on_us,
|
|
&out_config->override_strobe_interval_us,
|
|
&out_config->override_motor_step_us,
|
|
&out_config->override_steps_per_line);
|
|
if (rc != ESP_OK) {
|
|
write_err(err, err_len, "get direct debug config failed");
|
|
return rc;
|
|
}
|
|
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;
|
|
}
|
|
|
|
return platform_direct_printer_set_debug_config(config != NULL,
|
|
config != NULL ? config->shift_clock_high_us : 0,
|
|
config != NULL ? config->shift_clock_low_us : 0,
|
|
config != NULL ? config->latch_pulse_us : 0,
|
|
config != NULL ? config->strobe_active_high : false,
|
|
config != NULL ? config->boost_active_high : false,
|
|
config != NULL ? config->override_strobe_on_us : 0,
|
|
config != NULL ? config->override_strobe_interval_us : 0,
|
|
config != NULL ? config->override_motor_step_us : 0,
|
|
config != NULL ? config->override_steps_per_line : 0,
|
|
reset_defaults,
|
|
err,
|
|
err_len);
|
|
}
|
|
|
|
const char *printer_protocol_job_state_str(print_job_state_t state) {
|
|
switch (state) {
|
|
case PRINT_JOB_STATE_NONE:
|
|
return "none";
|
|
case PRINT_JOB_STATE_QUEUED:
|
|
return "queued";
|
|
case PRINT_JOB_STATE_RUNNING:
|
|
return "running";
|
|
case PRINT_JOB_STATE_SUCCESS:
|
|
return "success";
|
|
case PRINT_JOB_STATE_FAILED:
|
|
return "failed";
|
|
case PRINT_JOB_STATE_CANCELED:
|
|
return "canceled";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|