iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_dev_a2_micro_printer.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_dev_a2_micro_printer_ds.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Use DC2 bitmap command of the A2 Micro panel termal printer |
iforce2d | 0:972874f31c98 | 6 | double stroke |
iforce2d | 0:972874f31c98 | 7 | |
iforce2d | 0:972874f31c98 | 8 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Copyright (c) 2013, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 11 | All rights reserved. |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 14 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 17 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 18 | |
iforce2d | 0:972874f31c98 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 20 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 21 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 22 | |
iforce2d | 0:972874f31c98 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | |
iforce2d | 0:972874f31c98 | 38 | */ |
iforce2d | 0:972874f31c98 | 39 | |
iforce2d | 0:972874f31c98 | 40 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 41 | |
iforce2d | 0:972874f31c98 | 42 | #define WIDTH 240 |
iforce2d | 0:972874f31c98 | 43 | #define HEIGHT 128 |
iforce2d | 0:972874f31c98 | 44 | #define PAGE_HEIGHT 8 |
iforce2d | 0:972874f31c98 | 45 | |
iforce2d | 0:972874f31c98 | 46 | #define LINE_DELAY 40 |
iforce2d | 0:972874f31c98 | 47 | |
iforce2d | 0:972874f31c98 | 48 | |
iforce2d | 0:972874f31c98 | 49 | uint8_t u8g_dev_a2_micro_printer_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 50 | { |
iforce2d | 0:972874f31c98 | 51 | switch(msg) |
iforce2d | 0:972874f31c98 | 52 | { |
iforce2d | 0:972874f31c98 | 53 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 54 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); |
iforce2d | 0:972874f31c98 | 55 | break; |
iforce2d | 0:972874f31c98 | 56 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 57 | break; |
iforce2d | 0:972874f31c98 | 58 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 59 | { |
iforce2d | 0:972874f31c98 | 60 | uint8_t y, i, j; |
iforce2d | 0:972874f31c98 | 61 | uint8_t *ptr; |
iforce2d | 0:972874f31c98 | 62 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 63 | |
iforce2d | 0:972874f31c98 | 64 | y = pb->p.page_y0; |
iforce2d | 0:972874f31c98 | 65 | ptr = pb->buf; |
iforce2d | 0:972874f31c98 | 66 | |
iforce2d | 0:972874f31c98 | 67 | u8g_WriteByte(u8g, dev, 27); /* ESC */ |
iforce2d | 0:972874f31c98 | 68 | u8g_WriteByte(u8g, dev, 55 ); /* parameter command */ |
iforce2d | 0:972874f31c98 | 69 | u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/ |
iforce2d | 0:972874f31c98 | 70 | u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
iforce2d | 0:972874f31c98 | 71 | u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/ |
iforce2d | 0:972874f31c98 | 72 | |
iforce2d | 0:972874f31c98 | 73 | u8g_WriteByte(u8g, dev, 18); /* DC2 */ |
iforce2d | 0:972874f31c98 | 74 | u8g_WriteByte(u8g, dev, 42 ); /* * */ |
iforce2d | 0:972874f31c98 | 75 | u8g_WriteByte(u8g, dev, pb->p.page_height ); |
iforce2d | 0:972874f31c98 | 76 | u8g_WriteByte(u8g, dev, pb->width/8 ); |
iforce2d | 0:972874f31c98 | 77 | |
iforce2d | 0:972874f31c98 | 78 | for( i = 0; i < pb->p.page_height; i ++ ) |
iforce2d | 0:972874f31c98 | 79 | { |
iforce2d | 0:972874f31c98 | 80 | for( j = 0; j < pb->width/8; j++ ) |
iforce2d | 0:972874f31c98 | 81 | { |
iforce2d | 0:972874f31c98 | 82 | u8g_WriteByte(u8g, dev, *ptr); |
iforce2d | 0:972874f31c98 | 83 | ptr++; |
iforce2d | 0:972874f31c98 | 84 | } |
iforce2d | 0:972874f31c98 | 85 | u8g_Delay(LINE_DELAY); |
iforce2d | 0:972874f31c98 | 86 | y++; |
iforce2d | 0:972874f31c98 | 87 | } |
iforce2d | 0:972874f31c98 | 88 | |
iforce2d | 0:972874f31c98 | 89 | /* set parameters back to their default values */ |
iforce2d | 0:972874f31c98 | 90 | u8g_WriteByte(u8g, dev, 27); /* ESC */ |
iforce2d | 0:972874f31c98 | 91 | u8g_WriteByte(u8g, dev, 55 ); /* parameter command */ |
iforce2d | 0:972874f31c98 | 92 | u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/ |
iforce2d | 0:972874f31c98 | 93 | u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
iforce2d | 0:972874f31c98 | 94 | u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/ |
iforce2d | 0:972874f31c98 | 95 | |
iforce2d | 0:972874f31c98 | 96 | } |
iforce2d | 0:972874f31c98 | 97 | break; |
iforce2d | 0:972874f31c98 | 98 | } |
iforce2d | 0:972874f31c98 | 99 | return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); |
iforce2d | 0:972874f31c98 | 100 | } |
iforce2d | 0:972874f31c98 | 101 | |
iforce2d | 0:972874f31c98 | 102 | static uint8_t u8g_dev_expand4(uint8_t val) |
iforce2d | 0:972874f31c98 | 103 | { |
iforce2d | 0:972874f31c98 | 104 | uint8_t a,b,c,d; |
iforce2d | 0:972874f31c98 | 105 | a = val&1; |
iforce2d | 0:972874f31c98 | 106 | b = (val&2)<<1; |
iforce2d | 0:972874f31c98 | 107 | c = (val&4)<<2; |
iforce2d | 0:972874f31c98 | 108 | d = (val&8)<<3; |
iforce2d | 0:972874f31c98 | 109 | a |=b; |
iforce2d | 0:972874f31c98 | 110 | a |=c; |
iforce2d | 0:972874f31c98 | 111 | a |=d; |
iforce2d | 0:972874f31c98 | 112 | a |= a<<1; |
iforce2d | 0:972874f31c98 | 113 | return a; |
iforce2d | 0:972874f31c98 | 114 | } |
iforce2d | 0:972874f31c98 | 115 | |
iforce2d | 0:972874f31c98 | 116 | uint8_t u8g_dev_a2_micro_printer_double_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 117 | { |
iforce2d | 0:972874f31c98 | 118 | switch(msg) |
iforce2d | 0:972874f31c98 | 119 | { |
iforce2d | 0:972874f31c98 | 120 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 121 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); |
iforce2d | 0:972874f31c98 | 122 | break; |
iforce2d | 0:972874f31c98 | 123 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 124 | break; |
iforce2d | 0:972874f31c98 | 125 | case U8G_DEV_MSG_PAGE_FIRST: |
iforce2d | 0:972874f31c98 | 126 | { |
iforce2d | 0:972874f31c98 | 127 | //u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 128 | //u8g_WriteByte(u8g, dev, 18); /* DC2 */ |
iforce2d | 0:972874f31c98 | 129 | //u8g_WriteByte(u8g, dev, 42 ); /* * */ |
iforce2d | 0:972874f31c98 | 130 | //u8g_WriteByte(u8g, dev, pb->p.total_height*2 ); |
iforce2d | 0:972874f31c98 | 131 | //u8g_WriteByte(u8g, dev, pb->width/8*2 ); |
iforce2d | 0:972874f31c98 | 132 | } |
iforce2d | 0:972874f31c98 | 133 | break; |
iforce2d | 0:972874f31c98 | 134 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 135 | { |
iforce2d | 0:972874f31c98 | 136 | uint8_t y, i, j; |
iforce2d | 0:972874f31c98 | 137 | uint8_t *ptr; |
iforce2d | 0:972874f31c98 | 138 | uint8_t *p2; |
iforce2d | 0:972874f31c98 | 139 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 140 | |
iforce2d | 0:972874f31c98 | 141 | y = pb->p.page_y0; |
iforce2d | 0:972874f31c98 | 142 | ptr = pb->buf; |
iforce2d | 0:972874f31c98 | 143 | //u8g_WriteByte(u8g, dev, 18); /* DC2 */ |
iforce2d | 0:972874f31c98 | 144 | //u8g_WriteByte(u8g, dev, 35 ); /* # */ |
iforce2d | 0:972874f31c98 | 145 | //u8g_WriteByte(u8g, dev, 0x0ff ); /* max */ |
iforce2d | 0:972874f31c98 | 146 | |
iforce2d | 0:972874f31c98 | 147 | u8g_WriteByte(u8g, dev, 27); /* ESC */ |
iforce2d | 0:972874f31c98 | 148 | u8g_WriteByte(u8g, dev, 55 ); /* parameter command */ |
iforce2d | 0:972874f31c98 | 149 | u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/ |
iforce2d | 0:972874f31c98 | 150 | u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
iforce2d | 0:972874f31c98 | 151 | u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/ |
iforce2d | 0:972874f31c98 | 152 | |
iforce2d | 0:972874f31c98 | 153 | u8g_WriteByte(u8g, dev, 18); /* DC2 */ |
iforce2d | 0:972874f31c98 | 154 | u8g_WriteByte(u8g, dev, 42 ); /* * */ |
iforce2d | 0:972874f31c98 | 155 | u8g_WriteByte(u8g, dev, pb->p.page_height*2 ); |
iforce2d | 0:972874f31c98 | 156 | u8g_WriteByte(u8g, dev, pb->width/8*2 ); |
iforce2d | 0:972874f31c98 | 157 | |
iforce2d | 0:972874f31c98 | 158 | for( i = 0; i < pb->p.page_height; i ++ ) |
iforce2d | 0:972874f31c98 | 159 | { |
iforce2d | 0:972874f31c98 | 160 | p2 = ptr; |
iforce2d | 0:972874f31c98 | 161 | for( j = 0; j < pb->width/8; j++ ) |
iforce2d | 0:972874f31c98 | 162 | { |
iforce2d | 0:972874f31c98 | 163 | u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4)); |
iforce2d | 0:972874f31c98 | 164 | u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15)); |
iforce2d | 0:972874f31c98 | 165 | p2++; |
iforce2d | 0:972874f31c98 | 166 | } |
iforce2d | 0:972874f31c98 | 167 | u8g_Delay(LINE_DELAY); |
iforce2d | 0:972874f31c98 | 168 | p2 = ptr; |
iforce2d | 0:972874f31c98 | 169 | for( j = 0; j < pb->width/8; j++ ) |
iforce2d | 0:972874f31c98 | 170 | { |
iforce2d | 0:972874f31c98 | 171 | u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4)); |
iforce2d | 0:972874f31c98 | 172 | u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15)); |
iforce2d | 0:972874f31c98 | 173 | p2++; |
iforce2d | 0:972874f31c98 | 174 | } |
iforce2d | 0:972874f31c98 | 175 | u8g_Delay(LINE_DELAY); |
iforce2d | 0:972874f31c98 | 176 | ptr += pb->width/8; |
iforce2d | 0:972874f31c98 | 177 | y++; |
iforce2d | 0:972874f31c98 | 178 | } |
iforce2d | 0:972874f31c98 | 179 | |
iforce2d | 0:972874f31c98 | 180 | /* set parameters back to their default values */ |
iforce2d | 0:972874f31c98 | 181 | u8g_WriteByte(u8g, dev, 27); /* ESC */ |
iforce2d | 0:972874f31c98 | 182 | u8g_WriteByte(u8g, dev, 55 ); /* parameter command */ |
iforce2d | 0:972874f31c98 | 183 | u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/ |
iforce2d | 0:972874f31c98 | 184 | u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */ |
iforce2d | 0:972874f31c98 | 185 | u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/ |
iforce2d | 0:972874f31c98 | 186 | |
iforce2d | 0:972874f31c98 | 187 | } |
iforce2d | 0:972874f31c98 | 188 | break; |
iforce2d | 0:972874f31c98 | 189 | } |
iforce2d | 0:972874f31c98 | 190 | return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); |
iforce2d | 0:972874f31c98 | 191 | } |
iforce2d | 0:972874f31c98 | 192 | |
iforce2d | 0:972874f31c98 | 193 | #if defined(U8G_16BIT) |
iforce2d | 0:972874f31c98 | 194 | U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 384, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn); |
iforce2d | 0:972874f31c98 | 195 | #else |
iforce2d | 0:972874f31c98 | 196 | U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 240, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn); |
iforce2d | 0:972874f31c98 | 197 | #endif |
iforce2d | 0:972874f31c98 | 198 | |
iforce2d | 0:972874f31c98 | 199 | U8G_PB_DEV(u8g_dev_a2_micro_printer_192x120_ds, 192, 120, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn); |
iforce2d | 0:972874f31c98 | 200 |