Updated draft to add how to code works

This commit is contained in:
N07070 2022-10-27 20:11:30 +02:00
parent c49d9e9026
commit 76354960a4
1 changed files with 29 additions and 2 deletions

View File

@ -40,7 +40,7 @@ Thankfully, Adafruit has tutorial on how to build a polaroïd camera with a ther
Even with theses issues, I knew that thermal printing was a cool tech, and I could use it for a lot of my other printing and propaganda projects. So I started looking for another thermal printer.
### Making it searious
### Making it serious
I eventually settled on an EPSON TM20-III, which is around 250€. Nearly the same prince as a LittlePrinter, but it has Ethernet, a standard-ish protocol, USB, two sizes of paper, a cutting blade, 300 dpi resolution, and prints so fast that when you fuck up the orientation of the print, before you can stop it, it already printed 3 meters of paper. In a word, it's perfect. I then bought 4 _kilometers_ of paper for around 50€. Also keep in mind that these printers are used around the world in industrial settings, and if you know how I'm sure you could find one for very cheap or second-hand.
@ -50,6 +50,33 @@ After a few days of hacking, I finally had a complete photomaton that could be a
There was Little Prynter.
### How to code works
The program starts thanks to a bash script, `run.sh`, that starts a Python virtual environnement, install the dependencies and runs the server with the good environnement variable.
It will in turn, call the flask command, that will launch a developpement server with the `main.py` file as it's starting point.
This fille will define the routes that will be accessible on the server.
The `main.py` file will start by loading the configuration file, and then start trying to connect to the printer via the `Printer` class.
```python
configuration_file = toml.load("configuration/config.toml")
```
The tricky thing about connecting via USB is that you need the USB vendor and device ID loaded, but they are encoded in hexadecimal. So we pass thoses options to the Printer class, that will initiate a new global connection to the Printer. It's faster this way, but we could open a new connection each time instead. The continus connexion sometimes hangs up, making it necessary to restart the software.
```python
# Printer connection
# Uses the class defined in the printer.py file
printer = Printer(app,0x04b8, 0x0e28)
printer.init_printer()
```
This class will mainly load the `escpos` library that does all the heavy lifting will connecting to the printer. To note, the library, at time of writing, did not have the exact printer I has in it's database, but instead a close relative of it, which works _well enough_. It also defines to methods to print texte and an image.
The web interface part is handle just after, in a `Web` class that makes heavy use of Flask. I'm using a Python framework called Flask. It makes it easy to run a web server. I've learned how to write it thanks to [Miguel Grinberg's Flask Mega Tutorial](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world).
A few pictures to show it off ;
![A picture of rubber duck on a thermal printer](result.jpg)
@ -62,6 +89,6 @@ A few pictures to show it off ;
I also paid attention to the git repository I was writing this code to, and I provide instructions on how to set it up if you want to. You can find it all here : [Little Prynter @ git.n07070.xyz](https://git.n07070.xyz/n07070/littleprynter).
### In the futur
### In the future
I would very much like to make it portable, and maybe add some flash device to it, so it can be used in dark settings. Maybe keeping the image in cache, dithering it and offering a downloaded version would be nice too. Maybe offering a reprint so every one can have one, printing them by bunch of 4 like a real photomaton might do the trick.