feat(printer): add direct thermal backend and debug controls
This commit is contained in:
@@ -4,8 +4,22 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static bool is_direct_backend(void) {
|
||||
return printer_protocol_get_backend() == PRINTER_BACKEND_DIRECT;
|
||||
}
|
||||
|
||||
static esp_err_t unsupported_for_direct(char *err, size_t err_len, const char *op) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "%s 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 (is_direct_backend()) {
|
||||
return platform_direct_printer_gap_move(timeout_ms, err, err_len);
|
||||
}
|
||||
|
||||
if (!ble_printer_client_is_connected()) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "printer not connected");
|
||||
@@ -34,6 +48,10 @@ esp_err_t printer_protocol_gap_move(uint32_t timeout_ms, char *err, size_t err_l
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_get_label_offset(uint8_t *out_offset, uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "label offset");
|
||||
}
|
||||
|
||||
if (out_offset == NULL) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "invalid args");
|
||||
@@ -88,6 +106,10 @@ esp_err_t printer_protocol_get_label_offset(uint8_t *out_offset, uint32_t timeou
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_set_label_offset(uint8_t offset, uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "label offset");
|
||||
}
|
||||
|
||||
if (!ble_printer_client_is_connected()) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "printer not connected");
|
||||
@@ -115,6 +137,10 @@ esp_err_t printer_protocol_set_label_offset(uint8_t offset, uint32_t timeout_ms,
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_ota_jump_boot(uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "ota jump boot");
|
||||
}
|
||||
|
||||
if (!ble_printer_client_is_connected()) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "printer not connected");
|
||||
@@ -142,6 +168,10 @@ esp_err_t printer_protocol_ota_jump_boot(uint32_t timeout_ms, char *err, size_t
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_ota_jump_app(uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "ota jump app");
|
||||
}
|
||||
|
||||
if (!ble_printer_client_is_connected()) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "printer not connected");
|
||||
@@ -169,6 +199,10 @@ esp_err_t printer_protocol_ota_jump_app(uint32_t timeout_ms, char *err, size_t e
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_ota_erase_page(uint16_t page_num, uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "ota erase");
|
||||
}
|
||||
|
||||
if (!ble_printer_client_is_connected()) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "printer not connected");
|
||||
@@ -207,6 +241,10 @@ esp_err_t printer_protocol_ota_write_frame(uint16_t packet_num,
|
||||
uint32_t timeout_ms,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "ota write");
|
||||
}
|
||||
|
||||
if ((data_len > 0 && data == NULL) || data_len > OTA_MAX_DATA_PER_FRAME) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "invalid frame length");
|
||||
@@ -252,6 +290,10 @@ esp_err_t printer_protocol_ota_get_version(printer_ota_version_t *out_version,
|
||||
uint32_t timeout_ms,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
if (is_direct_backend()) {
|
||||
return unsupported_for_direct(err, err_len, "ota version");
|
||||
}
|
||||
|
||||
if (out_version == NULL) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "invalid args");
|
||||
|
||||
Reference in New Issue
Block a user