|
1 | | -#!/usr/bin/python3 |
2 | | -# pylint: disable=E1101,W0614 |
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Python3 script to print the current date and time, using |
| 4 | +# the Adafruit_Thermal library, in ISO 8601 format. |
| 5 | +# https://www.iso.org/iso-8601-date-and-time-format.html |
3 | 6 |
|
4 | 7 | import time |
5 | 8 | from Adafruit_Thermal import * |
6 | 9 |
|
| 10 | +# Lines of margin (integer) |
7 | 11 | i_feed = 3 |
| 12 | +# Seconds to pause (float) |
8 | 13 | f_pause = 1.0 |
9 | 14 |
|
10 | | -printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) |
| 15 | +# Define the printer port, speed, and timeout |
| 16 | +printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=5) |
11 | 17 |
|
| 18 | +# Build the date stamp in the format YYYY-MM-DD ex: "2021-12-25" |
12 | 19 | datestamp = time.strftime("%Y-%m-%d", time.gmtime()) |
13 | 20 | print ("Date in preferred format:", datestamp) |
| 21 | + |
| 22 | +# Build the time stamp in the format Thh:mm:ssZ ex: "T23:59:59Z" |
14 | 23 | timestamp = 'T' + time.strftime("%H:%M:%S", time.gmtime()) + 'Z' |
15 | 24 | print ("Time in preferred format:", timestamp) |
16 | 25 |
|
| 26 | +# Tell printer to sleep |
| 27 | +printer.sleep() |
| 28 | +# Sleep for the defined time in case we're called many times in a row |
| 29 | +time.sleep(f_pause) |
| 30 | +# Call wake() before printing again, even if reset |
| 31 | +printer.wake() |
| 32 | +# Restore printer to defaults |
| 33 | +printer.setDefault() |
| 34 | + |
17 | 35 | # Give a little room at the top |
18 | 36 | printer.feed(i_feed) |
19 | 37 | # Center justify |
|
26 | 44 | printer.println(timestamp) |
27 | 45 | # Give a little room at the bottom |
28 | 46 | printer.feed(i_feed) |
29 | | - |
30 | | -# Tell printer to sleep |
31 | | -printer.sleep() |
32 | | -# Call wake() before printing again, even if reset |
33 | | -printer.wake() |
34 | | -# Restore printer to defaults |
35 | | -printer.setDefault() |
36 | | - |
37 | | -# Sleep for one second in case we're called many times |
38 | | -time.sleep(f_pause) |
|
0 commit comments