mirror of
https://codeberg.org/icewind/ptouch-api.git
synced 2026-06-03 10:54:07 +02:00
change status output
This commit is contained in:
parent
ac046df6c0
commit
9613b2c3ef
5 changed files with 142 additions and 31 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod config;
|
||||
mod status;
|
||||
|
||||
use crate::config::{Config, ListenConfig};
|
||||
use axum::body::Bytes;
|
||||
|
|
@ -12,7 +13,7 @@ use image::imageops::FilterType;
|
|||
use image::{EncodableLayout, ImageError, ImageReader};
|
||||
use listenfd::ListenFd;
|
||||
use main_error::MainResult;
|
||||
use ptouch_rs::{Printer, Status};
|
||||
use ptouch_rs::Printer;
|
||||
use std::fs::{create_dir_all, remove_file, set_permissions};
|
||||
use std::io::Cursor;
|
||||
use std::net::SocketAddr;
|
||||
|
|
@ -24,6 +25,7 @@ use tokio::net::UnixListener;
|
|||
use tokio::signal::ctrl_c;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{debug, info};
|
||||
use crate::status::PStatus;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {
|
||||
|
|
@ -171,11 +173,11 @@ impl IntoResponse for ApiError {
|
|||
}
|
||||
}
|
||||
|
||||
async fn status(State(state): State<App>) -> Result<Json<Status>, ApiError> {
|
||||
async fn status(State(state): State<App>) -> Result<Json<PStatus>, ApiError> {
|
||||
let mut printer = state.printer.lock().await;
|
||||
debug!("reloading printer status");
|
||||
printer.reload_status().await?;
|
||||
Ok(Json(printer.status()))
|
||||
Ok(Json(PStatus::new(printer.status(), printer.ty())))
|
||||
}
|
||||
|
||||
async fn print(State(state): State<App>, bytes: Bytes) -> Result<(), ApiError> {
|
||||
|
|
|
|||
103
src/status.rs
Normal file
103
src/status.rs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
use ptouch_rs::{MediaType, PrinterType, Status, TapeColor, TapeSize, TextColor};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PStatus {
|
||||
/// width in mm
|
||||
media_width: f32,
|
||||
pixel_width: u32,
|
||||
media_type: &'static str,
|
||||
text_color: &'static str,
|
||||
tape_color: &'static str,
|
||||
}
|
||||
|
||||
impl PStatus {
|
||||
pub fn new(status: Status, printer_type: PrinterType) -> Self {
|
||||
PStatus {
|
||||
media_width: tape_size(&status.media_width),
|
||||
pixel_width: printer_type.info().max_px,
|
||||
media_type: media_type(&status.media_type),
|
||||
text_color: text_color(&status.text_color),
|
||||
tape_color: tape_color(&status.tape_color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tape_color(color: &TapeColor) -> &'static str {
|
||||
match color {
|
||||
TapeColor::None => "none",
|
||||
TapeColor::BerryPink_TZe_MQP35 => "berry-pink",
|
||||
TapeColor::Black => "black",
|
||||
TapeColor::Blue_TZe_5_345_5 => "blue",
|
||||
TapeColor::Blue => "blue",
|
||||
TapeColor::Cleaning => "cleaning",
|
||||
TapeColor::Clear => "clear",
|
||||
TapeColor::ClearMatte => "clear-matte",
|
||||
TapeColor::GoldSatin => "gold-satin",
|
||||
TapeColor::Green => "green",
|
||||
TapeColor::HeatShrinkTube => "heat-shrink-tube",
|
||||
TapeColor::Incompatible => "incompatible",
|
||||
TapeColor::LightGray_TZe_MQL35 => "light-gray",
|
||||
TapeColor::LimeGreen_TZe_MQG35 => "lime-green",
|
||||
TapeColor::OrangeFluorescent => "orange-fluorescent",
|
||||
TapeColor::Pink => "pink",
|
||||
TapeColor::Red_TZe_435 => "red",
|
||||
TapeColor::Red => "red",
|
||||
TapeColor::SilverMatte => "silver-matte",
|
||||
TapeColor::SilverSatin => "silver-satin",
|
||||
TapeColor::Stencil => "stencil",
|
||||
TapeColor::White => "white",
|
||||
TapeColor::WhiteFlexId => "white-flex-id",
|
||||
TapeColor::WhiteMatte => "white-matte",
|
||||
TapeColor::Yellow => "yellow",
|
||||
TapeColor::YellowFlexId => "yellow-flex-id",
|
||||
TapeColor::YellowFluorescent => "yellow-fluorescent",
|
||||
TapeColor::Other => "other",
|
||||
TapeColor::Unknown(_) => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn text_color(color: &TextColor) -> &'static str {
|
||||
match color {
|
||||
TextColor::None => "none",
|
||||
TextColor::Black => "black",
|
||||
TextColor::Blue => "blue",
|
||||
TextColor::BlueF => "blue",
|
||||
TextColor::Cleaning => "cleaning",
|
||||
TextColor::Gold => "gold",
|
||||
TextColor::Incompatible => "incompatible",
|
||||
TextColor::Red => "red",
|
||||
TextColor::Stencil => "stencil",
|
||||
TextColor::White => "white",
|
||||
TextColor::Other => "other",
|
||||
TextColor::Unknown(_) => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn media_type(ty: &MediaType) -> &'static str {
|
||||
match ty {
|
||||
MediaType::None => "none",
|
||||
MediaType::Laminated => "laminated",
|
||||
MediaType::NonLaminated => "non-laminated",
|
||||
MediaType::Fabric => "fabric",
|
||||
MediaType::HeatShrink => "heat-shrink",
|
||||
MediaType::Fle => "flex",
|
||||
MediaType::FlexibleId => "flexible-id",
|
||||
MediaType::Satin => "satin",
|
||||
MediaType::Incompatible => "incompatible",
|
||||
MediaType::Unknown(_) => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn tape_size(size: &TapeSize) -> f32 {
|
||||
match size {
|
||||
TapeSize::None => 0.0,
|
||||
TapeSize::ThreePointFive => 3.5,
|
||||
TapeSize::Six => 6.0,
|
||||
TapeSize::Nine => 9.0,
|
||||
TapeSize::Twelve => 12.0,
|
||||
TapeSize::Eighteen => 18.0,
|
||||
TapeSize::TwentyFour => 24.0,
|
||||
TapeSize::ThirtySix => 36.0,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue