| 1 | /* $Id$ |
|---|
| 2 | * $URL$ |
|---|
| 3 | * |
|---|
| 4 | * driver for WincorNixdorf serial cashier displays BA63 and BA66 |
|---|
| 5 | * |
|---|
| 6 | * Copyright (C) 2005 Michael Reinelt <reinelt@eunet.at> |
|---|
| 7 | * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> |
|---|
| 8 | * |
|---|
| 9 | * based on the SimpleLCD driver which is |
|---|
| 10 | * Copyright (C) 2005 Julien Aube <ob@obconseil.net> |
|---|
| 11 | * |
|---|
| 12 | * This file is part of LCD4Linux. |
|---|
| 13 | * |
|---|
| 14 | * LCD4Linux is free software; you can redistribute it and/or modify |
|---|
| 15 | * it under the terms of the GNU General Public License as published by |
|---|
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
|---|
| 17 | * any later version. |
|---|
| 18 | * |
|---|
| 19 | * LCD4Linux is distributed in the hope that it will be useful, |
|---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | * GNU General Public License for more details. |
|---|
| 23 | * |
|---|
| 24 | * You should have received a copy of the GNU General Public License |
|---|
| 25 | * along with this program; if not, write to the Free Software |
|---|
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 27 | * |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | /* |
|---|
| 31 | * |
|---|
| 32 | * exported fuctions: |
|---|
| 33 | * |
|---|
| 34 | * struct DRIVER drv_WincorNixdorf |
|---|
| 35 | * |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include "config.h" |
|---|
| 39 | |
|---|
| 40 | #include <stdlib.h> |
|---|
| 41 | #include <string.h> |
|---|
| 42 | #include <unistd.h> |
|---|
| 43 | #include <termios.h> |
|---|
| 44 | |
|---|
| 45 | #include "debug.h" |
|---|
| 46 | #include "cfg.h" |
|---|
| 47 | #include "qprintf.h" |
|---|
| 48 | #include "plugin.h" |
|---|
| 49 | #include "widget.h" |
|---|
| 50 | #include "widget_text.h" |
|---|
| 51 | #include "widget_bar.h" |
|---|
| 52 | #include "drv.h" |
|---|
| 53 | #include "drv_generic_text.h" |
|---|
| 54 | #include "drv_generic_serial.h" |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | #define ESC "\033" |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | static char Name[] = "WincorNixdorf"; |
|---|
| 61 | |
|---|
| 62 | typedef struct { |
|---|
| 63 | int type; |
|---|
| 64 | char *name; |
|---|
| 65 | int rows; |
|---|
| 66 | int cols; |
|---|
| 67 | } MODEL; |
|---|
| 68 | |
|---|
| 69 | static MODEL Models[] = { |
|---|
| 70 | {63, "BA63", 2, 20}, |
|---|
| 71 | {66, "BA66", 4, 20}, |
|---|
| 72 | {-1, "unknown", -1, -1}, |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | static int Model; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | /****************************************/ |
|---|
| 79 | /*** hardware dependant functions ***/ |
|---|
| 80 | /****************************************/ |
|---|
| 81 | |
|---|
| 82 | static void drv_WN_clear(void) |
|---|
| 83 | { |
|---|
| 84 | drv_generic_serial_write(ESC "[2J", 4); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | static void drv_WN_write(const int row, const int col, const char *data, int len) |
|---|
| 89 | { |
|---|
| 90 | char cmd[8] = ESC "[r;ccH"; |
|---|
| 91 | |
|---|
| 92 | cmd[2] = '1' + row; |
|---|
| 93 | cmd[4] = '0' + (col / 10); |
|---|
| 94 | cmd[5] = '1' + (col % 10); |
|---|
| 95 | |
|---|
| 96 | drv_generic_serial_write(cmd, 7); |
|---|
| 97 | drv_generic_serial_write(data, len); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | static int drv_WN_start(const char *section, const int quiet) |
|---|
| 102 | { |
|---|
| 103 | int i, len; |
|---|
| 104 | int selftest; |
|---|
| 105 | char *model = NULL; |
|---|
| 106 | char buffer[32]; |
|---|
| 107 | |
|---|
| 108 | model = cfg_get(section, "Model", NULL); |
|---|
| 109 | if (model == NULL && *model == '\0') { |
|---|
| 110 | error("%s: no '%s.Model' entry from %s", Name, section, cfg_source()); |
|---|
| 111 | return -1; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | for (i = 0; Models[i].type != -1; i++) { |
|---|
| 115 | if (strcasecmp(Models[i].name, model) == 0) |
|---|
| 116 | break; |
|---|
| 117 | } |
|---|
| 118 | if (Models[i].type == -1) { |
|---|
| 119 | error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source()); |
|---|
| 120 | return -1; |
|---|
| 121 | } |
|---|
| 122 | Model = i; |
|---|
| 123 | info("%s: using model '%s'", Name, Models[Model].name); |
|---|
| 124 | |
|---|
| 125 | /* initialize global variables */ |
|---|
| 126 | DROWS = Models[Model].rows; |
|---|
| 127 | DCOLS = Models[Model].cols; |
|---|
| 128 | |
|---|
| 129 | if (drv_generic_serial_open(section, Name, CS8 | PARENB | PARODD) < 0) |
|---|
| 130 | return -1; |
|---|
| 131 | |
|---|
| 132 | /* real worker functions */ |
|---|
| 133 | drv_generic_text_real_write = drv_WN_write; |
|---|
| 134 | |
|---|
| 135 | cfg_number(section, "SelfTest", 0, 0, 1, &selftest); |
|---|
| 136 | if (selftest) { |
|---|
| 137 | info("%s: initiating display selftest sequence", Name); |
|---|
| 138 | |
|---|
| 139 | /* read display identification */ |
|---|
| 140 | drv_generic_serial_write(ESC "[0c", 4); |
|---|
| 141 | usleep(100 * 1000); |
|---|
| 142 | |
|---|
| 143 | if ((len = drv_generic_serial_read(buffer, -1 * (int) sizeof(buffer))) > 0) { |
|---|
| 144 | info("%s: waiting 15 seconds for selftest", Name); |
|---|
| 145 | drv_generic_serial_write(buffer, len); |
|---|
| 146 | sleep(15); |
|---|
| 147 | info("%s: selftest finished", Name); |
|---|
| 148 | } else { |
|---|
| 149 | info("%s: selftest initiation failed", Name); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | /* clear display */ |
|---|
| 154 | drv_WN_clear(); |
|---|
| 155 | |
|---|
| 156 | if (!quiet) { |
|---|
| 157 | char buffer[40]; |
|---|
| 158 | qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); |
|---|
| 159 | if (drv_generic_text_greet(buffer, NULL)) { |
|---|
| 160 | sleep(3); |
|---|
| 161 | drv_WN_clear(); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | return 0; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | /****************************************/ |
|---|
| 170 | /*** plugins ***/ |
|---|
| 171 | /****************************************/ |
|---|
| 172 | |
|---|
| 173 | /* none */ |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | /****************************************/ |
|---|
| 177 | /*** widget callbacks ***/ |
|---|
| 178 | /****************************************/ |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | /* using drv_generic_text_draw(W) */ |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | /****************************************/ |
|---|
| 185 | /*** exported functions ***/ |
|---|
| 186 | /****************************************/ |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | /* list models */ |
|---|
| 190 | int drv_WN_list(void) |
|---|
| 191 | { |
|---|
| 192 | printf("BA63 BA66"); |
|---|
| 193 | return 0; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | /* initialize driver & display */ |
|---|
| 198 | int drv_WN_init(const char *section, const int quiet) |
|---|
| 199 | { |
|---|
| 200 | WIDGET_CLASS wc; |
|---|
| 201 | int ascii; |
|---|
| 202 | int ret; |
|---|
| 203 | |
|---|
| 204 | info("%s: %s", Name, "$Rev$"); |
|---|
| 205 | |
|---|
| 206 | /* display preferences */ |
|---|
| 207 | XRES = 5; /* pixel width of one char */ |
|---|
| 208 | YRES = 7; /* pixel height of one char */ |
|---|
| 209 | CHARS = 0; /* number of user-defineable characters */ |
|---|
| 210 | CHAR0 = 0; /* ASCII of first user-defineable char */ |
|---|
| 211 | ICONS = 0; /* number of user-defineable characters reserved for icons */ |
|---|
| 212 | GOTO_COST = 6; /* number of bytes a goto command requires */ |
|---|
| 213 | |
|---|
| 214 | /* start display */ |
|---|
| 215 | if ((ret = drv_WN_start(section, quiet)) != 0) |
|---|
| 216 | return ret; |
|---|
| 217 | |
|---|
| 218 | /* initialize generic text driver */ |
|---|
| 219 | if ((ret = drv_generic_text_init(section, Name)) != 0) |
|---|
| 220 | return ret; |
|---|
| 221 | |
|---|
| 222 | /* initialize generic bar driver */ |
|---|
| 223 | if ((ret = drv_generic_text_bar_init(1)) != 0) |
|---|
| 224 | return ret; |
|---|
| 225 | |
|---|
| 226 | cfg_number(section, "BarChar", '*', 1, 255, &ascii); |
|---|
| 227 | |
|---|
| 228 | /* add fixed chars to the bar driver */ |
|---|
| 229 | drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ |
|---|
| 230 | drv_generic_text_bar_add_segment(255, 255, 255, ascii); |
|---|
| 231 | |
|---|
| 232 | /* register text widget */ |
|---|
| 233 | wc = Widget_Text; |
|---|
| 234 | wc.draw = drv_generic_text_draw; |
|---|
| 235 | widget_register(&wc); |
|---|
| 236 | |
|---|
| 237 | /* register bar widget */ |
|---|
| 238 | wc = Widget_Bar; |
|---|
| 239 | wc.draw = drv_generic_text_bar_draw; |
|---|
| 240 | widget_register(&wc); |
|---|
| 241 | |
|---|
| 242 | /* register plugins */ |
|---|
| 243 | /* none */ |
|---|
| 244 | |
|---|
| 245 | return 0; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | /* close driver & display */ |
|---|
| 250 | int drv_WN_quit(const int quiet) |
|---|
| 251 | { |
|---|
| 252 | |
|---|
| 253 | info("%s: shutting down.", Name); |
|---|
| 254 | |
|---|
| 255 | drv_generic_text_quit(); |
|---|
| 256 | |
|---|
| 257 | /* clear display */ |
|---|
| 258 | drv_WN_clear(); |
|---|
| 259 | |
|---|
| 260 | /* say goodbye... */ |
|---|
| 261 | if (!quiet) { |
|---|
| 262 | drv_generic_text_greet("goodbye!", NULL); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | drv_generic_serial_close(); |
|---|
| 266 | |
|---|
| 267 | return (0); |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | DRIVER drv_WincorNixdorf = { |
|---|
| 272 | .name = Name, |
|---|
| 273 | .list = drv_WN_list, |
|---|
| 274 | .init = drv_WN_init, |
|---|
| 275 | .quit = drv_WN_quit, |
|---|
| 276 | }; |
|---|