Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2examplespage_bufferA2PrinterA2Printer.ino

167 lines · 4.5 KB

1/*
2
3 A2Printer.ino
4
5 This is a special example for the A2 Thermo Printer
6 This example can NOT be used with LCDs and OLEDs
7
8 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
9
10 Copyright (c) 2016, olikraus@gmail.com
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification,
14 are permitted provided that the following conditions are met:
15
16 * Redistributions of source code must retain the above copyright notice, this list
17 of conditions and the following disclaimer.
18
19 * Redistributions in binary form must reproduce the above copyright notice, this
20 list of conditions and the following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37*/
38
39// use this serial interface
40#define PRINTER_SERIAL Serial
41// #define PRINTER_SERIAL Serial1
42
43
44#include <Arduino.h>
45#include <U8g2lib.h>
46
47#ifdef U8X8_HAVE_HW_SPI
48#include <SPI.h>
49#endif
50#ifdef U8X8_HAVE_HW_I2C
51#include <Wire.h>
52#endif
53
54
55
56/* define our own serial function, this will be assigned later */
57
58extern "C" uint8_t u8x8_byte_arduino_serial(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
59{
60 uint8_t *data;
61
62 switch(msg)
63 {
64 case U8X8_MSG_BYTE_SEND:
65 data = (uint8_t *)arg_ptr;
66 while( arg_int > 0 )
67 {
68 while(PRINTER_SERIAL.available() > 0)
69 PRINTER_SERIAL.read();
70 PRINTER_SERIAL.write((uint8_t)*data);
71 data++;
72 arg_int--;
73 }
74 break;
75
76 case U8X8_MSG_BYTE_INIT:
77 delay(1000);
78 PRINTER_SERIAL.begin(19200);
79 /* send something.... */
80 //PRINTER_SERIAL.begin(9600);
81 PRINTER_SERIAL.write(27); /* ESC */
82 PRINTER_SERIAL.write(64); /* @ --> reset printer */
83 delay(1000);
84
85 break;
86
87 case U8X8_MSG_BYTE_SET_DC:
88 break;
89
90 case U8X8_MSG_BYTE_START_TRANSFER:
91 break;
92
93 case U8X8_MSG_BYTE_END_TRANSFER:
94 break;
95
96 default:
97 return 0;
98 }
99 return 1;
100}
101
102/* define a u8g2 object just with the base class */
103/* the baseclass will be configured for the A2 printer in the setup() procedure */
104class U8G2 u8g2;
105
106void setup(void) {
107
108 u8g2_Setup_a2printer_384x240_1( /* several different a2 printer procs exist... */
109 u8g2.getU8g2(), /* this is a c call, so use the u8g2 struct instead of the class */
110 U8G2_R0, /* this defines the usual rotation of the bitmap */
111 u8x8_byte_arduino_serial, /* this is the new procedure from above */
112 u8x8_gpio_and_delay_arduino); /* standard arduino low level proc, used only for delay */
113
114 u8g2.beginSimple(); /* Do not clear the display, wake is not required */
115}
116
117#define XO 10
118
119void drawLogo(void)
120{
121
122 u8g2.setFontMode(1); // Transparent
123 u8g2.setFontDirection(0);
124 u8g2.setFont(u8g2_font_inb24_mf);
125 u8g2.drawStr(0+XO, 30, "U");
126
127 u8g2.setFontDirection(1);
128 u8g2.setFont(u8g2_font_inb30_mn);
129 u8g2.drawStr(21+XO,8,"8");
130
131 u8g2.setFontDirection(0);
132 u8g2.setFont(u8g2_font_inb24_mf);
133 u8g2.drawStr(51+XO,30,"g");
134 u8g2.drawStr(67+XO,30,"\xb2");
135
136 u8g2.drawHLine(2+XO, 35, 47);
137 u8g2.drawHLine(3+XO, 36, 47);
138 u8g2.drawVLine(45+XO, 32, 12);
139 u8g2.drawVLine(46+XO, 33, 12);
140}
141
142void drawURL(void)
143{
144 u8g2.setFont(u8g2_font_6x12_tr);
145 u8g2.drawStr(1+XO,54,"github.com/olikraus/u8g2");
146}
147
148void loop(void) {
149 u8g2.firstPage();
150 do {
151 drawLogo();
152 drawURL();
153
154 /* worst case heating test */
155 u8g2.drawRBox(4,90,384-8,20, 8);
156
157 /* heating test with some text */
158 u8g2.setFont(u8g2_font_inb24_mf);
159 u8g2.drawStr(10,160,"Hello World!");
160
161 /* draw a frame around the picture */
162 u8g2.drawFrame(0,0,384,240);
163 u8g2.drawFrame(1,1,384-2,240-2);
164 } while ( u8g2.nextPage() );
165 delay(1000);
166}
167