Compare commits

...

3 Commits

Author SHA1 Message Date
45d945a9d4 Merge branch 'main' of https://git.leuschner.dev/Tobias/Fichero
Some checks failed
Deploy to GitHub Pages / build (push) Has been cancelled
Deploy to GitHub Pages / deploy (push) Has been cancelled
2026-03-07 14:30:06 +01:00
7317a60818 Bump version to 0.1.9 in API and package.json 2026-03-07 14:30:03 +01:00
4dd04d1d34 Add printer scanning functionality and enhance UI for address input 2026-03-07 14:29:32 +01:00
3 changed files with 47 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ async def lifespan(app: FastAPI): # noqa: ARG001
app = FastAPI( app = FastAPI(
title="Fichero Printer API", title="Fichero Printer API",
description="REST API for the Fichero D11s (AiYin) thermal label printer.", description="REST API for the Fichero D11s (AiYin) thermal label printer.",
version="0.1.0", version="0.1.9",
lifespan=lifespan, lifespan=lifespan,
docs_url=None, docs_url=None,
redoc_url=None, redoc_url=None,

View File

@@ -35,6 +35,7 @@ from fichero.printer import (
PrinterNotFound, PrinterNotFound,
PrinterTimeout, PrinterTimeout,
connect, connect,
find_printer,
) )
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -72,7 +73,7 @@ async def lifespan(app: FastAPI): # noqa: ARG001
app = FastAPI( app = FastAPI(
title="Fichero Printer API", title="Fichero Printer API",
description="REST API for the Fichero D11s (AiYin) thermal label printer.", description="REST API for the Fichero D11s (AiYin) thermal label printer.",
version="0.1.0", version="0.1.9",
lifespan=lifespan, lifespan=lifespan,
docs_url=None, docs_url=None,
redoc_url=None, redoc_url=None,
@@ -217,7 +218,10 @@ def _ui_html() -> str:
<div class="card"> <div class="card">
<h2>Connection</h2> <h2>Connection</h2>
<label for="address">Printer address</label> <label for="address">Printer address</label>
<input id="address" value="{default_address}" placeholder="C9:48:8A:69:D5:C0"> <div style="display:flex;gap:8px;align-items:center">
<input id="address" value="{default_address}" placeholder="C9:48:8A:69:D5:C0" style="flex:1;width:auto">
<button type="button" id="scan-btn" class="alt" style="width:auto;white-space:nowrap" onclick="scanAddress()">&#128268; Scan</button>
</div>
<div class="row"> <div class="row">
<div> <div>
@@ -352,6 +356,29 @@ def _ui_html() -> str:
await showResponse(response); await showResponse(response);
}} }}
async function scanAddress() {{
const btn = document.getElementById("scan-btn");
const output = document.getElementById("output");
btn.disabled = true;
btn.textContent = "Scanning…";
output.textContent = "Scanning for printer (up to 8 s)…";
try {{
const response = await fetch("scan");
const data = await response.json();
if (response.ok && data.address) {{
document.getElementById("address").value = data.address;
output.textContent = JSON.stringify({{ status: response.status, ok: true, data }}, null, 2);
}} else {{
output.textContent = JSON.stringify({{ status: response.status, ok: false, data }}, null, 2);
}}
}} catch (e) {{
output.textContent = "Scan failed: " + e;
}} finally {{
btn.disabled = false;
btn.innerHTML = "&#128268; Scan";
}}
}}
async function printText() {{ async function printText() {{
const form = new FormData(); const form = new FormData();
form.set("text", document.getElementById("text").value); form.set("text", document.getElementById("text").value);
@@ -410,6 +437,22 @@ async def docs():
) )
@app.get(
"/scan",
summary="Scan for printer",
response_description="BLE address of the discovered printer",
)
async def scan_printer():
"""Scan for a Fichero/D11s printer via BLE and return its address."""
try:
address = await find_printer()
except PrinterNotFound as exc:
raise HTTPException(status_code=404, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=502, detail=str(exc)) from exc
return {"address": address}
@app.get( @app.get(
"/status", "/status",
summary="Get printer status", summary="Get printer status",

View File

@@ -2,7 +2,7 @@
"name": "fichero-web", "name": "fichero-web",
"private": true, "private": true,
"type": "module", "type": "module",
"version": "0.0.1", "version": "0.1.9",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",