refactor(printer): replace direct_printer with printer naming
This commit is contained in:
@@ -2,7 +2,7 @@ idf_component_register(
|
||||
SRCS
|
||||
"src/platform_bootstrap.c"
|
||||
"src/wifi_manager.c"
|
||||
"src/direct_thermal_printer.c"
|
||||
"src/thermal_printer.c"
|
||||
"src/display_st7789.c"
|
||||
"src/display_lcd_module.c"
|
||||
"src/display_lcd_decode_image.c"
|
||||
|
||||
@@ -20,7 +20,7 @@ esp_err_t wifi_manager_stop(void);
|
||||
bool wifi_manager_is_ready(void);
|
||||
void wifi_manager_get_ip(char *buf, size_t buf_len);
|
||||
|
||||
// ---------- direct_thermal_printer ----------
|
||||
// ---------- thermal_printer ----------
|
||||
typedef struct {
|
||||
bool has_paper;
|
||||
int8_t paper_gpio_level;
|
||||
@@ -42,40 +42,37 @@ typedef struct {
|
||||
uint32_t timeout_ms;
|
||||
bool ignore_precheck;
|
||||
const volatile bool *cancel_flag;
|
||||
} platform_direct_print_request_t;
|
||||
} platform_printer_print_request_t;
|
||||
|
||||
esp_err_t platform_direct_printer_init(void);
|
||||
void platform_direct_printer_deinit(void);
|
||||
esp_err_t platform_direct_printer_connect(uint32_t timeout_ms);
|
||||
void platform_direct_printer_disconnect(void);
|
||||
bool platform_direct_printer_is_connected(void);
|
||||
esp_err_t platform_direct_printer_get_sensors(platform_printer_sensors_t *out_sensors);
|
||||
esp_err_t platform_direct_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
|
||||
uint16_t *out_shift_clock_low_us,
|
||||
uint16_t *out_latch_pulse_us,
|
||||
bool *out_strobe_active_high,
|
||||
bool *out_boost_active_high,
|
||||
uint16_t *out_override_strobe_on_us,
|
||||
uint16_t *out_override_strobe_interval_us,
|
||||
uint16_t *out_override_motor_step_us,
|
||||
uint8_t *out_override_steps_per_line);
|
||||
esp_err_t platform_direct_printer_set_debug_config(bool has_config,
|
||||
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,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *request,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
esp_err_t platform_direct_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_len);
|
||||
esp_err_t platform_printer_init(void);
|
||||
void platform_printer_deinit(void);
|
||||
esp_err_t platform_printer_get_sensors(platform_printer_sensors_t *out_sensors);
|
||||
esp_err_t platform_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
|
||||
uint16_t *out_shift_clock_low_us,
|
||||
uint16_t *out_latch_pulse_us,
|
||||
bool *out_strobe_active_high,
|
||||
bool *out_boost_active_high,
|
||||
uint16_t *out_override_strobe_on_us,
|
||||
uint16_t *out_override_strobe_interval_us,
|
||||
uint16_t *out_override_motor_step_us,
|
||||
uint8_t *out_override_steps_per_line);
|
||||
esp_err_t platform_printer_set_debug_config(bool has_config,
|
||||
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,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
esp_err_t platform_printer_print(const platform_printer_print_request_t *request,
|
||||
char *err,
|
||||
size_t err_len);
|
||||
esp_err_t platform_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_len);
|
||||
|
||||
// ---------- display_st7789 ----------
|
||||
esp_err_t platform_display_init(void);
|
||||
@@ -149,25 +146,23 @@ uint32_t runtime_policy_printer_queue_retry_delay_ms(void);
|
||||
uint32_t runtime_policy_printer_status_poll_interval_ms(void);
|
||||
uint32_t runtime_policy_printer_stop_timeout_ms(void);
|
||||
|
||||
bool runtime_policy_direct_printer_enabled(void);
|
||||
uint32_t runtime_policy_direct_printer_operation_timeout_ms(void);
|
||||
uint16_t runtime_policy_direct_printer_strobe_on_us(void);
|
||||
uint16_t runtime_policy_direct_printer_strobe_interval_us(void);
|
||||
uint16_t runtime_policy_direct_printer_motor_step_us(void);
|
||||
bool runtime_policy_direct_printer_motor_reverse(void);
|
||||
uint8_t runtime_policy_direct_printer_steps_per_line(void);
|
||||
uint16_t runtime_policy_direct_printer_gap_steps(void);
|
||||
float runtime_policy_direct_printer_temp_min_c(void);
|
||||
float runtime_policy_direct_printer_temp_max_c(void);
|
||||
uint8_t runtime_policy_direct_printer_battery_min_percent(void);
|
||||
uint8_t runtime_policy_direct_printer_paper_present_level(void);
|
||||
uint16_t runtime_policy_direct_printer_battery_empty_mv(void);
|
||||
uint16_t runtime_policy_direct_printer_battery_full_mv(void);
|
||||
uint16_t runtime_policy_direct_printer_battery_divider_ratio_x1000(void);
|
||||
uint32_t runtime_policy_direct_printer_ntc_pullup_ohms(void);
|
||||
uint32_t runtime_policy_direct_printer_ntc_r25_ohms(void);
|
||||
uint32_t runtime_policy_direct_printer_ntc_beta(void);
|
||||
uint32_t runtime_policy_printer_connect_timeout_ms(void);
|
||||
uint32_t runtime_policy_printer_operation_timeout_ms(void);
|
||||
uint16_t runtime_policy_printer_strobe_on_us(void);
|
||||
uint16_t runtime_policy_printer_strobe_interval_us(void);
|
||||
uint16_t runtime_policy_printer_motor_step_us(void);
|
||||
bool runtime_policy_printer_motor_reverse(void);
|
||||
uint8_t runtime_policy_printer_steps_per_line(void);
|
||||
uint16_t runtime_policy_printer_gap_steps(void);
|
||||
float runtime_policy_printer_temp_min_c(void);
|
||||
float runtime_policy_printer_temp_max_c(void);
|
||||
uint8_t runtime_policy_printer_battery_min_percent(void);
|
||||
uint8_t runtime_policy_printer_paper_present_level(void);
|
||||
uint16_t runtime_policy_printer_battery_empty_mv(void);
|
||||
uint16_t runtime_policy_printer_battery_full_mv(void);
|
||||
uint16_t runtime_policy_printer_battery_divider_ratio_x1000(void);
|
||||
uint32_t runtime_policy_printer_ntc_pullup_ohms(void);
|
||||
uint32_t runtime_policy_printer_ntc_r25_ohms(void);
|
||||
uint32_t runtime_policy_printer_ntc_beta(void);
|
||||
|
||||
uint32_t runtime_policy_image_generation_timeout_default_ms(void);
|
||||
uint32_t runtime_policy_image_generation_timeout_min_ms(void);
|
||||
|
||||
@@ -179,7 +179,7 @@ static esp_err_t lcd_recover_panel_for_shared_spi(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Direct-printer path temporarily takes over shared MOSI/CLK as GPIO.
|
||||
* Printer path temporarily takes over shared MOSI/CLK as GPIO.
|
||||
* Recover LCD SPI routing only when printer touched shared pins.
|
||||
*/
|
||||
esp_err_t recover_rc = st7789p3_recover_spi_bus(s_lcd.panel);
|
||||
|
||||
@@ -34,80 +34,72 @@
|
||||
#define CONFIG_TQ_PRINTER_STOP_TIMEOUT_MS 8000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_ENABLE 1
|
||||
#ifndef CONFIG_TQ_PRINTER_OPERATION_TIMEOUT_MS
|
||||
#define CONFIG_TQ_PRINTER_OPERATION_TIMEOUT_MS 90000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_OPERATION_TIMEOUT_MS
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_OPERATION_TIMEOUT_MS 90000
|
||||
#ifndef CONFIG_TQ_PRINTER_STROBE_ON_US
|
||||
#define CONFIG_TQ_PRINTER_STROBE_ON_US 1000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_STROBE_ON_US
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_STROBE_ON_US 1000
|
||||
#ifndef CONFIG_TQ_PRINTER_STROBE_INTERVAL_US
|
||||
#define CONFIG_TQ_PRINTER_STROBE_INTERVAL_US 200
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_STROBE_INTERVAL_US
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_STROBE_INTERVAL_US 200
|
||||
#ifndef CONFIG_TQ_PRINTER_MOTOR_STEP_US
|
||||
#define CONFIG_TQ_PRINTER_MOTOR_STEP_US 2000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_MOTOR_STEP_US
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_MOTOR_STEP_US 2000
|
||||
#ifndef CONFIG_TQ_PRINTER_MOTOR_REVERSE
|
||||
#define CONFIG_TQ_PRINTER_MOTOR_REVERSE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_MOTOR_REVERSE
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_MOTOR_REVERSE 0
|
||||
#ifndef CONFIG_TQ_PRINTER_STEPS_PER_LINE
|
||||
#define CONFIG_TQ_PRINTER_STEPS_PER_LINE 2
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_STEPS_PER_LINE
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_STEPS_PER_LINE 2
|
||||
#ifndef CONFIG_TQ_PRINTER_GAP_STEPS
|
||||
#define CONFIG_TQ_PRINTER_GAP_STEPS 96
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_GAP_STEPS
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_GAP_STEPS 96
|
||||
#ifndef CONFIG_TQ_PRINTER_TEMP_MIN_C
|
||||
#define CONFIG_TQ_PRINTER_TEMP_MIN_C 15
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_TEMP_MIN_C
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_TEMP_MIN_C 15
|
||||
#ifndef CONFIG_TQ_PRINTER_TEMP_MAX_C
|
||||
#define CONFIG_TQ_PRINTER_TEMP_MAX_C 55
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_TEMP_MAX_C
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_TEMP_MAX_C 55
|
||||
#ifndef CONFIG_TQ_PRINTER_BATTERY_MIN_PERCENT
|
||||
#define CONFIG_TQ_PRINTER_BATTERY_MIN_PERCENT 5
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_BATTERY_MIN_PERCENT
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_BATTERY_MIN_PERCENT 5
|
||||
#ifndef CONFIG_TQ_PRINTER_PAPER_PRESENT_LEVEL
|
||||
#define CONFIG_TQ_PRINTER_PAPER_PRESENT_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_PAPER_PRESENT_LEVEL
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_PAPER_PRESENT_LEVEL 0
|
||||
#ifndef CONFIG_TQ_PRINTER_BATTERY_EMPTY_MV
|
||||
#define CONFIG_TQ_PRINTER_BATTERY_EMPTY_MV 3300
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_BATTERY_EMPTY_MV
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_BATTERY_EMPTY_MV 3300
|
||||
#ifndef CONFIG_TQ_PRINTER_BATTERY_FULL_MV
|
||||
#define CONFIG_TQ_PRINTER_BATTERY_FULL_MV 4200
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_BATTERY_FULL_MV
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_BATTERY_FULL_MV 4200
|
||||
#ifndef CONFIG_TQ_PRINTER_BATTERY_DIVIDER_RATIO_X1000
|
||||
#define CONFIG_TQ_PRINTER_BATTERY_DIVIDER_RATIO_X1000 2000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_BATTERY_DIVIDER_RATIO_X1000
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_BATTERY_DIVIDER_RATIO_X1000 2000
|
||||
#ifndef CONFIG_TQ_PRINTER_NTC_PULLUP_OHMS
|
||||
#define CONFIG_TQ_PRINTER_NTC_PULLUP_OHMS 10000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_NTC_PULLUP_OHMS
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_NTC_PULLUP_OHMS 10000
|
||||
#ifndef CONFIG_TQ_PRINTER_NTC_R25_OHMS
|
||||
#define CONFIG_TQ_PRINTER_NTC_R25_OHMS 10000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_NTC_R25_OHMS
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_NTC_R25_OHMS 10000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_NTC_BETA
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_NTC_BETA 3950
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_PRINTER_CONNECT_TIMEOUT_MS
|
||||
#define CONFIG_TQ_PRINTER_CONNECT_TIMEOUT_MS 15000
|
||||
#ifndef CONFIG_TQ_PRINTER_NTC_BETA
|
||||
#define CONFIG_TQ_PRINTER_NTC_BETA 3950
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_Z_IMAGE_TIMEOUT_MS
|
||||
@@ -189,85 +181,77 @@ uint32_t runtime_policy_printer_stop_timeout_ms(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_STOP_TIMEOUT_MS, 1000, 30000);
|
||||
}
|
||||
|
||||
bool runtime_policy_direct_printer_enabled(void) {
|
||||
return CONFIG_TQ_DIRECT_PRINTER_ENABLE != 0;
|
||||
uint32_t runtime_policy_printer_operation_timeout_ms(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_OPERATION_TIMEOUT_MS, 1000, 300000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_direct_printer_operation_timeout_ms(void) {
|
||||
return clamp_u32(CONFIG_TQ_DIRECT_PRINTER_OPERATION_TIMEOUT_MS, 1000, 300000);
|
||||
uint16_t runtime_policy_printer_strobe_on_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_STROBE_ON_US, 100, 10000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_strobe_on_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_STROBE_ON_US, 100, 10000);
|
||||
uint16_t runtime_policy_printer_strobe_interval_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_STROBE_INTERVAL_US, 0, 10000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_strobe_interval_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_STROBE_INTERVAL_US, 0, 10000);
|
||||
uint16_t runtime_policy_printer_motor_step_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_MOTOR_STEP_US, 100, 20000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_motor_step_us(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_MOTOR_STEP_US, 100, 20000);
|
||||
bool runtime_policy_printer_motor_reverse(void) {
|
||||
return CONFIG_TQ_PRINTER_MOTOR_REVERSE != 0;
|
||||
}
|
||||
|
||||
bool runtime_policy_direct_printer_motor_reverse(void) {
|
||||
return CONFIG_TQ_DIRECT_PRINTER_MOTOR_REVERSE != 0;
|
||||
uint8_t runtime_policy_printer_steps_per_line(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_PRINTER_STEPS_PER_LINE, 1, 8);
|
||||
}
|
||||
|
||||
uint8_t runtime_policy_direct_printer_steps_per_line(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_DIRECT_PRINTER_STEPS_PER_LINE, 1, 8);
|
||||
uint16_t runtime_policy_printer_gap_steps(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_GAP_STEPS, 1, 2000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_gap_steps(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_GAP_STEPS, 1, 2000);
|
||||
float runtime_policy_printer_temp_min_c(void) {
|
||||
return (float)clamp_u32((uint32_t)CONFIG_TQ_PRINTER_TEMP_MIN_C, 0, 120);
|
||||
}
|
||||
|
||||
float runtime_policy_direct_printer_temp_min_c(void) {
|
||||
return (float)clamp_u32((uint32_t)CONFIG_TQ_DIRECT_PRINTER_TEMP_MIN_C, 0, 120);
|
||||
float runtime_policy_printer_temp_max_c(void) {
|
||||
return (float)clamp_u32((uint32_t)CONFIG_TQ_PRINTER_TEMP_MAX_C, 1, 150);
|
||||
}
|
||||
|
||||
float runtime_policy_direct_printer_temp_max_c(void) {
|
||||
return (float)clamp_u32((uint32_t)CONFIG_TQ_DIRECT_PRINTER_TEMP_MAX_C, 1, 150);
|
||||
uint8_t runtime_policy_printer_battery_min_percent(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_PRINTER_BATTERY_MIN_PERCENT, 0, 100);
|
||||
}
|
||||
|
||||
uint8_t runtime_policy_direct_printer_battery_min_percent(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_DIRECT_PRINTER_BATTERY_MIN_PERCENT, 0, 100);
|
||||
uint8_t runtime_policy_printer_paper_present_level(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_PRINTER_PAPER_PRESENT_LEVEL, 0, 1);
|
||||
}
|
||||
|
||||
uint8_t runtime_policy_direct_printer_paper_present_level(void) {
|
||||
return clamp_u8((uint8_t)CONFIG_TQ_DIRECT_PRINTER_PAPER_PRESENT_LEVEL, 0, 1);
|
||||
uint16_t runtime_policy_printer_battery_empty_mv(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_BATTERY_EMPTY_MV, 2500, 5000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_battery_empty_mv(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_BATTERY_EMPTY_MV, 2500, 5000);
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_battery_full_mv(void) {
|
||||
uint16_t empty_mv = runtime_policy_direct_printer_battery_empty_mv();
|
||||
uint16_t full_mv = clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_BATTERY_FULL_MV, 2600, 6000);
|
||||
uint16_t runtime_policy_printer_battery_full_mv(void) {
|
||||
uint16_t empty_mv = runtime_policy_printer_battery_empty_mv();
|
||||
uint16_t full_mv = clamp_u16((uint16_t)CONFIG_TQ_PRINTER_BATTERY_FULL_MV, 2600, 6000);
|
||||
if (full_mv <= empty_mv) {
|
||||
full_mv = (uint16_t)(empty_mv + 100);
|
||||
}
|
||||
return full_mv;
|
||||
}
|
||||
|
||||
uint16_t runtime_policy_direct_printer_battery_divider_ratio_x1000(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_DIRECT_PRINTER_BATTERY_DIVIDER_RATIO_X1000, 1000, 10000);
|
||||
uint16_t runtime_policy_printer_battery_divider_ratio_x1000(void) {
|
||||
return clamp_u16((uint16_t)CONFIG_TQ_PRINTER_BATTERY_DIVIDER_RATIO_X1000, 1000, 10000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_direct_printer_ntc_pullup_ohms(void) {
|
||||
return clamp_u32(CONFIG_TQ_DIRECT_PRINTER_NTC_PULLUP_OHMS, 1000, 200000);
|
||||
uint32_t runtime_policy_printer_ntc_pullup_ohms(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_NTC_PULLUP_OHMS, 1000, 200000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_direct_printer_ntc_r25_ohms(void) {
|
||||
return clamp_u32(CONFIG_TQ_DIRECT_PRINTER_NTC_R25_OHMS, 1000, 200000);
|
||||
uint32_t runtime_policy_printer_ntc_r25_ohms(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_NTC_R25_OHMS, 1000, 200000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_direct_printer_ntc_beta(void) {
|
||||
return clamp_u32(CONFIG_TQ_DIRECT_PRINTER_NTC_BETA, 1000, 10000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_printer_connect_timeout_ms(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_CONNECT_TIMEOUT_MS, 1000, 60000);
|
||||
uint32_t runtime_policy_printer_ntc_beta(void) {
|
||||
return clamp_u32(CONFIG_TQ_PRINTER_NTC_BETA, 1000, 10000);
|
||||
}
|
||||
|
||||
uint32_t runtime_policy_image_generation_timeout_default_ms(void) {
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
#include "freertos/task.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifndef CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
#define CONFIG_TQ_DIRECT_PRINTER_ENABLE 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_KEY_PRINT_BOOST_ACTIVE_HIGH
|
||||
#define CONFIG_TQ_KEY_PRINT_BOOST_ACTIVE_HIGH 1
|
||||
#endif
|
||||
@@ -63,7 +59,6 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
bool connected;
|
||||
uint8_t motor_phase;
|
||||
direct_debug_config_t debug;
|
||||
SemaphoreHandle_t lock;
|
||||
@@ -71,9 +66,9 @@ typedef struct {
|
||||
adc_oneshot_unit_handle_t adc2_handle;
|
||||
adc_pin_t battery_adc;
|
||||
adc_pin_t ntc_adc;
|
||||
} direct_printer_state_t;
|
||||
} printer_state_t;
|
||||
|
||||
static direct_printer_state_t s_state;
|
||||
static printer_state_t s_state;
|
||||
|
||||
static const uint8_t k_motor_step_table[4] = {0x05, 0x09, 0x0A, 0x06};
|
||||
|
||||
@@ -228,7 +223,7 @@ static void motor_step_once_locked(uint16_t step_delay_us) {
|
||||
if (step_delay_us > 0) {
|
||||
esp_rom_delay_us(step_delay_us);
|
||||
}
|
||||
if (runtime_policy_direct_printer_motor_reverse()) {
|
||||
if (runtime_policy_printer_motor_reverse()) {
|
||||
s_state.motor_phase = (uint8_t)((s_state.motor_phase + 3) & 0x03);
|
||||
} else {
|
||||
s_state.motor_phase = (uint8_t)((s_state.motor_phase + 1) & 0x03);
|
||||
@@ -362,7 +357,7 @@ static bool read_paper_present_locked(int *out_level) {
|
||||
if (out_level != NULL) {
|
||||
*out_level = level;
|
||||
}
|
||||
return level == (int)runtime_policy_direct_printer_paper_present_level();
|
||||
return level == (int)runtime_policy_printer_paper_present_level();
|
||||
}
|
||||
|
||||
static uint16_t battery_raw_to_mv(int raw) {
|
||||
@@ -373,7 +368,7 @@ static uint16_t battery_raw_to_mv(int raw) {
|
||||
raw = ADC_RAW_MAX;
|
||||
}
|
||||
float adc_mv = ((float)raw * 3300.0f) / (float)ADC_RAW_MAX;
|
||||
float ratio = (float)runtime_policy_direct_printer_battery_divider_ratio_x1000() / 1000.0f;
|
||||
float ratio = (float)runtime_policy_printer_battery_divider_ratio_x1000() / 1000.0f;
|
||||
float batt_mv = adc_mv * ratio;
|
||||
if (batt_mv < 0.0f) {
|
||||
batt_mv = 0.0f;
|
||||
@@ -385,8 +380,8 @@ static uint16_t battery_raw_to_mv(int raw) {
|
||||
}
|
||||
|
||||
static uint8_t battery_mv_to_percent(uint16_t batt_mv) {
|
||||
uint16_t empty_mv = runtime_policy_direct_printer_battery_empty_mv();
|
||||
uint16_t full_mv = runtime_policy_direct_printer_battery_full_mv();
|
||||
uint16_t empty_mv = runtime_policy_printer_battery_empty_mv();
|
||||
uint16_t full_mv = runtime_policy_printer_battery_full_mv();
|
||||
if (full_mv <= empty_mv) {
|
||||
return 100;
|
||||
}
|
||||
@@ -404,9 +399,9 @@ static float ntc_raw_to_temp_c(int raw) {
|
||||
return 25.0f;
|
||||
}
|
||||
|
||||
float pullup = (float)runtime_policy_direct_printer_ntc_pullup_ohms();
|
||||
float r25 = (float)runtime_policy_direct_printer_ntc_r25_ohms();
|
||||
float beta = (float)runtime_policy_direct_printer_ntc_beta();
|
||||
float pullup = (float)runtime_policy_printer_ntc_pullup_ohms();
|
||||
float r25 = (float)runtime_policy_printer_ntc_r25_ohms();
|
||||
float beta = (float)runtime_policy_printer_ntc_beta();
|
||||
if (pullup <= 0.0f || r25 <= 0.0f || beta <= 0.0f) {
|
||||
return 25.0f;
|
||||
}
|
||||
@@ -433,7 +428,7 @@ static void sample_sensors_locked(platform_printer_sensors_t *out_sensors) {
|
||||
int paper_level = -1;
|
||||
out_sensors->has_paper = read_paper_present_locked(&paper_level);
|
||||
out_sensors->paper_gpio_level = (int8_t)paper_level;
|
||||
out_sensors->paper_present_level = runtime_policy_direct_printer_paper_present_level();
|
||||
out_sensors->paper_present_level = runtime_policy_printer_paper_present_level();
|
||||
out_sensors->battery_percent = 100;
|
||||
out_sensors->temperature_c = 25.0f;
|
||||
out_sensors->updated_ms = esp_timer_get_time() / 1000;
|
||||
@@ -459,8 +454,8 @@ static esp_err_t precheck_before_print_locked(char *err, size_t err_len) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
float temp_min = runtime_policy_direct_printer_temp_min_c();
|
||||
float temp_max = runtime_policy_direct_printer_temp_max_c();
|
||||
float temp_min = runtime_policy_printer_temp_min_c();
|
||||
float temp_max = runtime_policy_printer_temp_max_c();
|
||||
if (temp_max <= temp_min) {
|
||||
temp_max = temp_min + 1.0f;
|
||||
}
|
||||
@@ -469,7 +464,7 @@ static esp_err_t precheck_before_print_locked(char *err, size_t err_len) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
uint8_t battery_min = runtime_policy_direct_printer_battery_min_percent();
|
||||
uint8_t battery_min = runtime_policy_printer_battery_min_percent();
|
||||
if (sensors.battery_percent < battery_min) {
|
||||
write_err(err, err_len, "battery too low");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -485,10 +480,7 @@ static bool has_timed_out(int64_t deadline_ms) {
|
||||
return (esp_timer_get_time() / 1000) > deadline_ms;
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_init(void) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t platform_printer_init(void) {
|
||||
if (s_state.initialized) {
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -552,21 +544,21 @@ esp_err_t platform_direct_printer_init(void) {
|
||||
init_adc_pin_if_possible(CONFIG_TQ_NTC_ADC_PIN, "ntc_adc", &s_state.ntc_adc);
|
||||
|
||||
s_state.motor_phase = 0;
|
||||
s_state.connected = false;
|
||||
set_gpio_level_if_valid(CONFIG_TQ_KEY_PRINT_PIN, boost_on_level_locked());
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
safe_drive_off_locked(true);
|
||||
s_state.initialized = true;
|
||||
ESP_LOGI(TAG, "printer initialized");
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
void platform_direct_printer_deinit(void) {
|
||||
void platform_printer_deinit(void) {
|
||||
if (!s_state.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_state.lock != NULL && xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||
safe_drive_off_locked(false);
|
||||
s_state.connected = false;
|
||||
xSemaphoreGive(s_state.lock);
|
||||
}
|
||||
|
||||
@@ -584,67 +576,7 @@ void platform_direct_printer_deinit(void) {
|
||||
memset(&s_state, 0, sizeof(s_state));
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_connect(uint32_t timeout_ms) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)timeout_ms;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t err = platform_direct_printer_init();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
uint32_t lock_timeout_ms = timeout_ms == 0 ? 500 : timeout_ms;
|
||||
if (lock_timeout_ms > 5000) {
|
||||
lock_timeout_ms = 5000;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(lock_timeout_ms)) != pdTRUE) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
if (!s_state.connected) {
|
||||
err = ensure_shared_shift_pins_gpio_locked();
|
||||
if (err != ESP_OK) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return err;
|
||||
}
|
||||
set_gpio_level_if_valid(CONFIG_TQ_KEY_PRINT_PIN, boost_on_level_locked());
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
safe_drive_off_locked(true);
|
||||
s_state.connected = true;
|
||||
}
|
||||
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
void platform_direct_printer_disconnect(void) {
|
||||
if (!s_state.initialized || s_state.lock == NULL) {
|
||||
return;
|
||||
}
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
safe_drive_off_locked(false);
|
||||
s_state.connected = false;
|
||||
xSemaphoreGive(s_state.lock);
|
||||
}
|
||||
|
||||
bool platform_direct_printer_is_connected(void) {
|
||||
if (!s_state.initialized || s_state.lock == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(100)) != pdTRUE) {
|
||||
return false;
|
||||
}
|
||||
bool connected = s_state.connected;
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return connected;
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_get_sensors(platform_printer_sensors_t *out_sensors) {
|
||||
esp_err_t platform_printer_get_sensors(platform_printer_sensors_t *out_sensors) {
|
||||
if (out_sensors == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -659,7 +591,7 @@ esp_err_t platform_direct_printer_get_sensors(platform_printer_sensors_t *out_se
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
|
||||
esp_err_t platform_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
|
||||
uint16_t *out_shift_clock_low_us,
|
||||
uint16_t *out_latch_pulse_us,
|
||||
bool *out_strobe_active_high,
|
||||
@@ -668,25 +600,13 @@ esp_err_t platform_direct_printer_get_debug_config(uint16_t *out_shift_clock_hig
|
||||
uint16_t *out_override_strobe_interval_us,
|
||||
uint16_t *out_override_motor_step_us,
|
||||
uint8_t *out_override_steps_per_line) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)out_shift_clock_high_us;
|
||||
(void)out_shift_clock_low_us;
|
||||
(void)out_latch_pulse_us;
|
||||
(void)out_strobe_active_high;
|
||||
(void)out_boost_active_high;
|
||||
(void)out_override_strobe_on_us;
|
||||
(void)out_override_strobe_interval_us;
|
||||
(void)out_override_motor_step_us;
|
||||
(void)out_override_steps_per_line;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
if (out_shift_clock_high_us == NULL || out_shift_clock_low_us == NULL || out_latch_pulse_us == NULL ||
|
||||
out_strobe_active_high == NULL || out_boost_active_high == NULL || out_override_strobe_on_us == NULL ||
|
||||
out_override_strobe_interval_us == NULL || out_override_motor_step_us == NULL ||
|
||||
out_override_steps_per_line == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_err_t init_rc = platform_direct_printer_init();
|
||||
esp_err_t init_rc = platform_printer_init();
|
||||
if (init_rc != ESP_OK) {
|
||||
return init_rc;
|
||||
}
|
||||
@@ -704,10 +624,9 @@ esp_err_t platform_direct_printer_get_debug_config(uint16_t *out_shift_clock_hig
|
||||
*out_override_steps_per_line = s_state.debug.override_steps_per_line;
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_set_debug_config(bool has_config,
|
||||
esp_err_t platform_printer_set_debug_config(bool has_config,
|
||||
uint16_t shift_clock_high_us,
|
||||
uint16_t shift_clock_low_us,
|
||||
uint16_t latch_pulse_us,
|
||||
@@ -720,27 +639,12 @@ esp_err_t platform_direct_printer_set_debug_config(bool has_config,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)has_config;
|
||||
(void)shift_clock_high_us;
|
||||
(void)shift_clock_low_us;
|
||||
(void)latch_pulse_us;
|
||||
(void)strobe_active_high;
|
||||
(void)boost_active_high;
|
||||
(void)override_strobe_on_us;
|
||||
(void)override_strobe_interval_us;
|
||||
(void)override_motor_step_us;
|
||||
(void)override_steps_per_line;
|
||||
(void)reset_defaults;
|
||||
write_err(err, err_len, "printer driver disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
if (!has_config && !reset_defaults) {
|
||||
write_err(err, err_len, "invalid args");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
esp_err_t init_rc = platform_direct_printer_init();
|
||||
esp_err_t init_rc = platform_printer_init();
|
||||
if (init_rc != ESP_OK) {
|
||||
write_err(err, err_len, "printer driver not initialized");
|
||||
return init_rc;
|
||||
@@ -798,19 +702,14 @@ esp_err_t platform_direct_printer_set_debug_config(bool has_config,
|
||||
s_state.debug.override_steps_per_line = override_steps_per_line;
|
||||
}
|
||||
|
||||
safe_drive_off_locked(s_state.connected);
|
||||
safe_drive_off_locked(true);
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *request,
|
||||
esp_err_t platform_printer_print(const platform_printer_print_request_t *request,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
write_err(err, err_len, "printer driver disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
if (request == NULL || request->raster == NULL || request->width == 0 || request->height == 0) {
|
||||
write_err(err, err_len, "invalid args");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@@ -834,7 +733,7 @@ esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *r
|
||||
|
||||
uint32_t timeout_ms = request->timeout_ms;
|
||||
if (timeout_ms == 0) {
|
||||
timeout_ms = runtime_policy_direct_printer_operation_timeout_ms();
|
||||
timeout_ms = runtime_policy_printer_operation_timeout_ms();
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(1000)) != pdTRUE) {
|
||||
@@ -842,12 +741,6 @@ esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *r
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
if (!s_state.connected) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "printer not connected");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
esp_err_t rc = ensure_shared_shift_pins_gpio_locked();
|
||||
if (rc != ESP_OK) {
|
||||
safe_drive_off_locked(true);
|
||||
@@ -858,16 +751,16 @@ esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *r
|
||||
|
||||
uint16_t strobe_on_us = (request->strobe_on_time_us > 0)
|
||||
? request->strobe_on_time_us
|
||||
: runtime_policy_direct_printer_strobe_on_us();
|
||||
: runtime_policy_printer_strobe_on_us();
|
||||
uint16_t strobe_interval_us = (request->strobe_interval_us > 0)
|
||||
? request->strobe_interval_us
|
||||
: runtime_policy_direct_printer_strobe_interval_us();
|
||||
: runtime_policy_printer_strobe_interval_us();
|
||||
uint16_t motor_step_us = (request->motor_step_delay_us > 0)
|
||||
? request->motor_step_delay_us
|
||||
: runtime_policy_direct_printer_motor_step_us();
|
||||
: runtime_policy_printer_motor_step_us();
|
||||
uint8_t steps_per_line = (request->motor_steps_per_line > 0)
|
||||
? request->motor_steps_per_line
|
||||
: runtime_policy_direct_printer_steps_per_line();
|
||||
: runtime_policy_printer_steps_per_line();
|
||||
|
||||
if (s_state.debug.override_strobe_on_us > 0) {
|
||||
strobe_on_us = s_state.debug.override_strobe_on_us;
|
||||
@@ -944,42 +837,31 @@ esp_err_t platform_direct_printer_print(const platform_direct_print_request_t *r
|
||||
safe_drive_off_locked(true);
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
write_err(err, err_len, "printer driver disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t platform_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_len) {
|
||||
if (!s_state.initialized || s_state.lock == NULL) {
|
||||
write_err(err, err_len, "printer driver not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (timeout_ms == 0) {
|
||||
timeout_ms = runtime_policy_direct_printer_operation_timeout_ms();
|
||||
timeout_ms = runtime_policy_printer_operation_timeout_ms();
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(1000)) != pdTRUE) {
|
||||
write_err(err, err_len, "printer lock timeout");
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
if (!s_state.connected) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "printer not connected");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
esp_err_t rc = ESP_OK;
|
||||
uint16_t steps = runtime_policy_direct_printer_gap_steps();
|
||||
uint16_t step_delay_us = runtime_policy_direct_printer_motor_step_us();
|
||||
uint16_t steps = runtime_policy_printer_gap_steps();
|
||||
uint16_t step_delay_us = runtime_policy_printer_motor_step_us();
|
||||
if (s_state.debug.override_motor_step_us > 0) {
|
||||
step_delay_us = s_state.debug.override_motor_step_us;
|
||||
}
|
||||
platform_printer_sensors_t sensors = {0};
|
||||
sample_sensors_locked(&sensors);
|
||||
|
||||
uint8_t battery_min = runtime_policy_direct_printer_battery_min_percent();
|
||||
uint8_t battery_min = runtime_policy_printer_battery_min_percent();
|
||||
if (sensors.battery_percent < battery_min) {
|
||||
write_err(err, err_len, "battery too low");
|
||||
safe_drive_off_locked(true);
|
||||
@@ -1016,5 +898,4 @@ esp_err_t platform_direct_printer_gap_move(uint32_t timeout_ms, char *err, size_
|
||||
safe_drive_off_locked(true);
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user