|
1 /* |
|
2 |
|
3 u8x8_d_a2printer.c |
|
4 |
|
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
6 |
|
7 Copyright (c) 2016, olikraus@gmail.com |
|
8 All rights reserved. |
|
9 |
|
10 Redistribution and use in source and binary forms, with or without modification, |
|
11 are permitted provided that the following conditions are met: |
|
12 |
|
13 * Redistributions of source code must retain the above copyright notice, this list |
|
14 of conditions and the following disclaimer. |
|
15 |
|
16 * Redistributions in binary form must reproduce the above copyright notice, this |
|
17 list of conditions and the following disclaimer in the documentation and/or other |
|
18 materials provided with the distribution. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
33 |
|
34 |
|
35 Use DC2 bitmap command of the A2 Micro panel termal printer |
|
36 double stroke |
|
37 |
|
38 |
|
39 */ |
|
40 |
|
41 |
|
42 #include "u8x8.h" |
|
43 |
|
44 #define LINE_MIN_DELAY_MS 15 |
|
45 /* higher values improve quality */ |
|
46 /* however if the value is too high (>=5) then form feed does not work any more */ |
|
47 #define LINE_EXTRA_8PIXEL_DELAY_MS 3 |
|
48 /* this must be a power of two and between 1 and 8 */ |
|
49 /* best quality only with 1 */ |
|
50 #define NO_OF_LINES_TO_SEND_WITHOUT_DELAY 1 |
|
51 |
|
52 /* calculates the delay, based on the number of black pixel */ |
|
53 /* actually only "none-zero" bytes are calculated which is, of course not so accurate, but should be good enough */ |
|
54 uint16_t get_delay_in_milliseconds(uint8_t cnt, uint8_t *data) |
|
55 { |
|
56 uint8_t i; |
|
57 uint16_t time = LINE_MIN_DELAY_MS; |
|
58 for ( i = 0; i < cnt; i++ ) |
|
59 if ( data[i] != 0 ) |
|
60 time += LINE_EXTRA_8PIXEL_DELAY_MS; |
|
61 return time; |
|
62 } |
|
63 |
|
64 uint8_t u8x8_d_a2printer_common(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, void *arg_ptr) |
|
65 { |
|
66 uint8_t c, i, j; |
|
67 uint8_t *ptr; |
|
68 uint16_t delay_in_milliseconds; |
|
69 switch(msg) |
|
70 { |
|
71 /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */ |
|
72 /* |
|
73 case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
|
74 break; |
|
75 */ |
|
76 case U8X8_MSG_DISPLAY_INIT: |
|
77 u8x8_d_helper_display_init(u8x8); |
|
78 // no setup required |
|
79 // u8x8_cad_SendSequence(u8x8, u8x8_d_a2printer_init_seq); |
|
80 break; |
|
81 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
82 // no powersave |
|
83 break; |
|
84 case U8X8_MSG_DISPLAY_DRAW_TILE: |
|
85 u8x8_cad_StartTransfer(u8x8); |
|
86 |
|
87 u8x8_cad_SendCmd(u8x8, 27); /* ESC */ |
|
88 u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */ |
|
89 /* increasing the "max printing dots" requires a good power supply, but LINE_EXTRA_8PIXEL_DELAY_MS could be reduced then */ |
|
90 u8x8_cad_SendCmd(u8x8, 0); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1) ... lower values improve, probably my current supply is not sufficient */ |
|
91 u8x8_cad_SendCmd(u8x8, 200); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
|
92 u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us) ... does not have much influence */ |
|
93 |
|
94 //c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */ |
|
95 c = u8x8->display_info->tile_width; |
|
96 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */ |
|
97 |
|
98 u8x8_cad_SendCmd(u8x8, 18); /* DC2 */ |
|
99 u8x8_cad_SendCmd(u8x8, 42 ); /* * */ |
|
100 u8x8_cad_SendCmd(u8x8, 8 ); /* height */ |
|
101 u8x8_cad_SendCmd(u8x8, c ); /* c, u8x8->display_info->tile_width */ |
|
102 |
|
103 for( j = 0; j < 8 / NO_OF_LINES_TO_SEND_WITHOUT_DELAY; j ++ ) |
|
104 { |
|
105 |
|
106 delay_in_milliseconds = 0; |
|
107 for( i = 0; i < NO_OF_LINES_TO_SEND_WITHOUT_DELAY; i++ ) |
|
108 { |
|
109 u8x8_cad_SendData(u8x8, c, ptr); /* c, note: SendData can not handle more than 255 bytes, send one line of data */ |
|
110 delay_in_milliseconds += get_delay_in_milliseconds(c, ptr); |
|
111 ptr += c; |
|
112 } |
|
113 |
|
114 while( delay_in_milliseconds > 200 ) |
|
115 { |
|
116 u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, 200, NULL); |
|
117 delay_in_milliseconds -= 200; |
|
118 } |
|
119 u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, delay_in_milliseconds, NULL); |
|
120 } |
|
121 |
|
122 /* set parameters back to their default values */ |
|
123 u8x8_cad_SendCmd(u8x8, 27); /* ESC */ |
|
124 u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */ |
|
125 u8x8_cad_SendCmd(u8x8, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/ |
|
126 u8x8_cad_SendCmd(u8x8, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
|
127 u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/ |
|
128 |
|
129 u8x8_cad_EndTransfer(u8x8); |
|
130 |
|
131 break; |
|
132 default: |
|
133 return 0; |
|
134 } |
|
135 return 1; |
|
136 } |
|
137 |
|
138 |
|
139 static const u8x8_display_info_t u8x8_a2printer_384x240_display_info = |
|
140 { |
|
141 /* most of the settings are not required, because this is a serial RS232 printer */ |
|
142 |
|
143 /* chip_enable_level = */ 1, |
|
144 /* chip_disable_level = */ 0, |
|
145 |
|
146 /* post_chip_enable_wait_ns = */ 5, |
|
147 /* pre_chip_disable_wait_ns = */ 5, |
|
148 /* reset_pulse_width_ms = */ 1, |
|
149 /* post_reset_wait_ms = */ 6, |
|
150 /* sda_setup_time_ns = */ 20, |
|
151 /* sck_pulse_width_ns = */ 140, |
|
152 /* sck_clock_hz = */ 1000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
|
153 /* spi_mode = */ 0, /* old: sck_takeover_edge, new: active high (bit 1), rising edge (bit 0) */ |
|
154 /* i2c_bus_clock_100kHz = */ 4, |
|
155 /* data_setup_time_ns = */ 30, |
|
156 /* write_pulse_width_ns = */ 40, |
|
157 /* tile_width = */ 48, |
|
158 /* tile_hight = */ 30, |
|
159 /* default_x_offset = */ 0, |
|
160 /* flipmode_x_offset = */ 0, |
|
161 /* pixel_width = */ 384, |
|
162 /* pixel_height = */ 240 |
|
163 }; |
|
164 |
|
165 uint8_t u8x8_d_a2printer_384x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
166 { |
|
167 switch(msg) |
|
168 { |
|
169 case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
|
170 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_a2printer_384x240_display_info); |
|
171 break; |
|
172 default: |
|
173 return u8x8_d_a2printer_common(u8x8, msg, arg_int, arg_ptr); |
|
174 } |
|
175 return 1; |
|
176 } |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |