3 Commits

Author SHA1 Message Date
n07070
09e588c3ff Change Error to warning when not on a Raspberry 2026-06-12 17:20:53 +02:00
n07070
0699775d35 Add welcome message 2026-06-12 17:20:44 +02:00
n07070
7d19098b61 Change management of state : we assume the printer is online. Otherwise,
because this is a real-time command, we might not get the good answer
and fail to print fast enough. See https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/realtime_commands.html
2026-06-12 17:19:53 +02:00
3 changed files with 18 additions and 9 deletions

View File

@@ -123,6 +123,8 @@ limiter = Limiter(
)
app.logger.info("🖶 Welcome to LittlePrynter !")
# General routes
@app.route("/")
@limiter.limit("1/second", override_defaults=False)

View File

@@ -322,22 +322,29 @@ class EscPosPrinter(Printer):
self.app.logger.info("Did a cut")
self.ready = True
def _state(self):
self.app.logger.debug("Online : %s " , self.printer.is_online())
self.app.logger.debug("Has paper : %s " , self._has_paper())
self.app.logger.debug("Ready : %s " , self.ready)
return self.printer.is_online() and self.ready and self._has_paper()
def _state(self) -> bool:
has_paper = self._has_paper()
is_ready = self.ready
self.app.logger.debug("Has paper : %s " , has_paper )
self.app.logger.debug("Ready : %s " , is_ready )
return is_ready and has_paper # and is_online
def print_task(self, task_type, data):
"""Execute actual print based on task type"""
with self._lock:
self.app.logger.debug("Acquired lock to start print")
while not self._state():
self.app.logger.debug("Waiting for the printer to become ready..")
i_m_ready = self._state()
while not i_m_ready:
self.app.logger.debug("Waiting for the printer to become ready, current state %s ", str(i_m_ready))
i_m_ready = self._state()
time.sleep(0.3)
self.app.logger.debug("Checked state to start printing %s", self._state())
self.app.logger.debug("Checked state to start printing : %s", self._state())
self.ready = False
try:
self.app.logger.debug("Checking task type")

View File

@@ -68,7 +68,7 @@ class Raspberry:
self.app.logger.warning(
"Couldn't get sufficient hardware information from /proc/cpuinfo"
)
self.app.logger.error("Unable to determine if we are on a Raspberry Pi.")
self.app.logger.warning("Unable to determine if we are on a Raspberry Pi.")
return False
except IOError:
self.app.logger.error("Unable to open `/proc/cpuinfo`.")