| 1 | /* $Id: drv_MilfordInstruments.c,v 1.14 2005/05/08 04:32:44 reinelt Exp $ |
|---|
| 2 | * |
|---|
| 3 | * driver for Milford Instruments 'BPK' piggy-back serial interface board |
|---|
| 4 | * for standard Hitachi 44780 compatible lcd modules. |
|---|
| 5 | * |
|---|
| 6 | * Copyright (C) 2003, 2004 Andy Baxter <andy@earthsong.free-online.co.uk> |
|---|
| 7 | * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> |
|---|
| 8 | * |
|---|
| 9 | * based on the MatrixOrbital driver which is |
|---|
| 10 | * Copyright (C) 1999, 2000 Michael Reinelt <reinelt@eunet.at> |
|---|
| 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 | * $Log: drv_MilfordInstruments.c,v $ |
|---|
| 30 | * Revision 1.14 2005/05/08 04:32:44 reinelt |
|---|
| 31 | * CodingStyle added and applied |
|---|
| 32 | * |
|---|
| 33 | * Revision 1.13 2005/01/18 06:30:23 reinelt |
|---|
| 34 | * added (C) to all copyright statements |
|---|
| 35 | * |
|---|
| 36 | * Revision 1.12 2004/06/26 12:04:59 reinelt |
|---|
| 37 | * |
|---|
| 38 | * uh-oh... the last CVS log message messed up things a lot... |
|---|
| 39 | * |
|---|
| 40 | * Revision 1.11 2004/06/26 09:27:21 reinelt |
|---|
| 41 | * |
|---|
| 42 | * added '-W' to CFLAGS |
|---|
| 43 | * changed all C++ comments to C ones |
|---|
| 44 | * cleaned up a lot of signed/unsigned mistakes |
|---|
| 45 | * |
|---|
| 46 | * Revision 1.10 2004/06/20 10:09:54 reinelt |
|---|
| 47 | * |
|---|
| 48 | * 'const'ified the whole source |
|---|
| 49 | * |
|---|
| 50 | * Revision 1.9 2004/06/06 06:51:59 reinelt |
|---|
| 51 | * |
|---|
| 52 | * do not display end splash screen if quiet=1 |
|---|
| 53 | * |
|---|
| 54 | * Revision 1.8 2004/06/05 06:41:40 reinelt |
|---|
| 55 | * |
|---|
| 56 | * chancged splash screen again |
|---|
| 57 | * |
|---|
| 58 | * Revision 1.7 2004/06/05 06:13:12 reinelt |
|---|
| 59 | * |
|---|
| 60 | * splash screen for all text-based display drivers |
|---|
| 61 | * |
|---|
| 62 | * Revision 1.6 2004/06/02 09:41:19 reinelt |
|---|
| 63 | * |
|---|
| 64 | * prepared support for startup splash screen |
|---|
| 65 | * |
|---|
| 66 | * Revision 1.5 2004/05/31 05:38:02 reinelt |
|---|
| 67 | * |
|---|
| 68 | * fixed possible bugs with user-defined chars (clear high bits) |
|---|
| 69 | * thanks to Andy Baxter for debugging the MilfordInstruments driver! |
|---|
| 70 | * |
|---|
| 71 | * Revision 1.4 2004/05/31 01:31:01 andy-b |
|---|
| 72 | * |
|---|
| 73 | * |
|---|
| 74 | * fixed bug in Milford Instruments driver which drew extra graphics chars in |
|---|
| 75 | * odd places when drawing double bars. (the display doesn't like it if you put |
|---|
| 76 | * the escape character 0xfe inside a define char sequence). |
|---|
| 77 | * |
|---|
| 78 | * Revision 1.1 2004/05/26 05:03:27 reinelt |
|---|
| 79 | * |
|---|
| 80 | * MilfordInstruments driver ported |
|---|
| 81 | * |
|---|
| 82 | */ |
|---|
| 83 | |
|---|
| 84 | /* |
|---|
| 85 | * |
|---|
| 86 | * exported fuctions: |
|---|
| 87 | * |
|---|
| 88 | * struct DRIVER drv_MilfordInstruments |
|---|
| 89 | * |
|---|
| 90 | */ |
|---|
| 91 | |
|---|
| 92 | #include "config.h" |
|---|
| 93 | |
|---|
| 94 | #include <stdlib.h> |
|---|
| 95 | #include <stdio.h> |
|---|
| 96 | #include <string.h> |
|---|
| 97 | #include <unistd.h> |
|---|
| 98 | |
|---|
| 99 | #include "debug.h" |
|---|
| 100 | #include "cfg.h" |
|---|
| 101 | #include "plugin.h" |
|---|
| 102 | #include "widget.h" |
|---|
| 103 | #include "widget_text.h" |
|---|
| 104 | #include "widget_icon.h" |
|---|
| 105 | #include "widget_bar.h" |
|---|
| 106 | #include "drv.h" |
|---|
| 107 | #include "drv_generic_text.h" |
|---|
| 108 | #include "drv_generic_serial.h" |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | static char Name[] = "MilfordInstruments"; |
|---|
| 112 | |
|---|
| 113 | typedef struct { |
|---|
| 114 | int type; |
|---|
| 115 | char *name; |
|---|
| 116 | int rows; |
|---|
| 117 | int cols; |
|---|
| 118 | } MODEL; |
|---|
| 119 | |
|---|
| 120 | static MODEL Models[] = { |
|---|
| 121 | {216, "MI216", 2, 16}, |
|---|
| 122 | {220, "MI220", 2, 20}, |
|---|
| 123 | {240, "MI240", 2, 40}, |
|---|
| 124 | {420, "MI420", 4, 20}, |
|---|
| 125 | {-1, "unknown", -1, -1}, |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | static int Model; |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | /****************************************/ |
|---|
| 132 | /*** hardware dependant functions ***/ |
|---|
| 133 | /****************************************/ |
|---|
| 134 | |
|---|
| 135 | static void drv_MI_clear(void) |
|---|
| 136 | { |
|---|
| 137 | drv_generic_serial_write("\376\001", 2); /* clear screen */ |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | static void drv_MI_write(const int row, const int col, const char *data, const int len) |
|---|
| 142 | { |
|---|
| 143 | char cmd[2] = "\376x"; |
|---|
| 144 | int ddbase = 128; |
|---|
| 145 | if (row & 1) { /* i.e. if row is 1 or 3 */ |
|---|
| 146 | ddbase += 64; |
|---|
| 147 | } |
|---|
| 148 | if (row & 2) { /* i.e. if row is 0 or 2. */ |
|---|
| 149 | ddbase += 20; |
|---|
| 150 | } |
|---|
| 151 | cmd[1] = (char) (ddbase + col); |
|---|
| 152 | drv_generic_serial_write(cmd, 2); |
|---|
| 153 | |
|---|
| 154 | drv_generic_serial_write(data, len); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | static void drv_MI_defchar(const int ascii, const unsigned char *matrix) |
|---|
| 159 | { |
|---|
| 160 | int i; |
|---|
| 161 | char cmd[10] = "\376x"; |
|---|
| 162 | |
|---|
| 163 | if (ascii < 8) { |
|---|
| 164 | cmd[1] = (char) (64 + ascii * 8); |
|---|
| 165 | for (i = 0; i < 8; i++) { |
|---|
| 166 | cmd[i + 2] = matrix[i] & 0x1f; |
|---|
| 167 | }; |
|---|
| 168 | drv_generic_serial_write(cmd, 10); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | static int drv_MI_start(const char *section, const int quiet) |
|---|
| 174 | { |
|---|
| 175 | int i; |
|---|
| 176 | char *model; |
|---|
| 177 | |
|---|
| 178 | model = cfg_get(section, "Model", NULL); |
|---|
| 179 | if (model == NULL && *model == '\0') { |
|---|
| 180 | error("%s: no '%s.Model' entry from %s", Name, section, cfg_source()); |
|---|
| 181 | return -1; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | for (i = 0; Models[i].type != 0xff; i++) { |
|---|
| 185 | if (strcasecmp(Models[i].name, model) == 0) |
|---|
| 186 | break; |
|---|
| 187 | } |
|---|
| 188 | if (Models[i].type == 0xff) { |
|---|
| 189 | error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source()); |
|---|
| 190 | return -1; |
|---|
| 191 | } |
|---|
| 192 | Model = i; |
|---|
| 193 | info("%s: using model '%s'", Name, Models[Model].name); |
|---|
| 194 | |
|---|
| 195 | if (drv_generic_serial_open(section, Name, 0) < 0) |
|---|
| 196 | return -1; |
|---|
| 197 | |
|---|
| 198 | /* initialize global variables */ |
|---|
| 199 | DROWS = Models[Model].rows; |
|---|
| 200 | DCOLS = Models[Model].cols; |
|---|
| 201 | |
|---|
| 202 | drv_MI_clear(); |
|---|
| 203 | drv_generic_serial_write("\376\014", 2); /* cursor off */ |
|---|
| 204 | |
|---|
| 205 | if (!quiet) { |
|---|
| 206 | if (drv_generic_text_greet(Models[Model].name, "Milford Instruments")) { |
|---|
| 207 | sleep(3); |
|---|
| 208 | drv_MI_clear(); |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | return 0; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | /****************************************/ |
|---|
| 217 | /*** plugins ***/ |
|---|
| 218 | /****************************************/ |
|---|
| 219 | |
|---|
| 220 | /* none at the moment... */ |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | /****************************************/ |
|---|
| 224 | /*** widget callbacks ***/ |
|---|
| 225 | /****************************************/ |
|---|
| 226 | |
|---|
| 227 | /* using drv_generic_text_draw(W) */ |
|---|
| 228 | /* using drv_generic_text_icon_draw(W) */ |
|---|
| 229 | /* using drv_generic_text_bar_draw(W) */ |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | /****************************************/ |
|---|
| 233 | /*** exported functions ***/ |
|---|
| 234 | /****************************************/ |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | /* list models */ |
|---|
| 238 | int drv_MI_list(void) |
|---|
| 239 | { |
|---|
| 240 | int i; |
|---|
| 241 | |
|---|
| 242 | for (i = 0; Models[i].type > 0; i++) { |
|---|
| 243 | printf("%s ", Models[i].name); |
|---|
| 244 | } |
|---|
| 245 | return 0; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | /* initialize driver & display */ |
|---|
| 250 | int drv_MI_init(const char *section, const int quiet) |
|---|
| 251 | { |
|---|
| 252 | WIDGET_CLASS wc; |
|---|
| 253 | int ret; |
|---|
| 254 | |
|---|
| 255 | /* display preferences */ |
|---|
| 256 | XRES = 5; /* pixel width of one char */ |
|---|
| 257 | YRES = 8; /* pixel height of one char */ |
|---|
| 258 | CHARS = 8; /* number of user-defineable characters */ |
|---|
| 259 | CHAR0 = 0; /* ASCII of first user-defineable char */ |
|---|
| 260 | GOTO_COST = 4; /* number of bytes a goto command requires */ |
|---|
| 261 | |
|---|
| 262 | /* real worker functions */ |
|---|
| 263 | drv_generic_text_real_write = drv_MI_write; |
|---|
| 264 | drv_generic_text_real_defchar = drv_MI_defchar; |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /* start display */ |
|---|
| 268 | if ((ret = drv_MI_start(section, quiet)) != 0) |
|---|
| 269 | return ret; |
|---|
| 270 | |
|---|
| 271 | /* initialize generic text driver */ |
|---|
| 272 | if ((ret = drv_generic_text_init(section, Name)) != 0) |
|---|
| 273 | return ret; |
|---|
| 274 | |
|---|
| 275 | /* initialize generic icon driver */ |
|---|
| 276 | if ((ret = drv_generic_text_icon_init()) != 0) |
|---|
| 277 | return ret; |
|---|
| 278 | |
|---|
| 279 | /* initialize generic bar driver */ |
|---|
| 280 | if ((ret = drv_generic_text_bar_init(0)) != 0) |
|---|
| 281 | return ret; |
|---|
| 282 | |
|---|
| 283 | /* add fixed chars to the bar driver */ |
|---|
| 284 | drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ |
|---|
| 285 | drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */ |
|---|
| 286 | |
|---|
| 287 | /* register text widget */ |
|---|
| 288 | wc = Widget_Text; |
|---|
| 289 | wc.draw = drv_generic_text_draw; |
|---|
| 290 | widget_register(&wc); |
|---|
| 291 | |
|---|
| 292 | /* register icon widget */ |
|---|
| 293 | wc = Widget_Icon; |
|---|
| 294 | wc.draw = drv_generic_text_icon_draw; |
|---|
| 295 | widget_register(&wc); |
|---|
| 296 | |
|---|
| 297 | /* register bar widget */ |
|---|
| 298 | wc = Widget_Bar; |
|---|
| 299 | wc.draw = drv_generic_text_bar_draw; |
|---|
| 300 | widget_register(&wc); |
|---|
| 301 | |
|---|
| 302 | /* register plugins */ |
|---|
| 303 | /* none at the moment... */ |
|---|
| 304 | |
|---|
| 305 | return 0; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | /* close driver & display */ |
|---|
| 310 | int drv_MI_quit(const int quiet) |
|---|
| 311 | { |
|---|
| 312 | |
|---|
| 313 | info("%s: shutting down.", Name); |
|---|
| 314 | |
|---|
| 315 | drv_generic_text_quit(); |
|---|
| 316 | |
|---|
| 317 | /* clear display */ |
|---|
| 318 | drv_MI_clear(); |
|---|
| 319 | |
|---|
| 320 | /* say goodbye... */ |
|---|
| 321 | if (!quiet) { |
|---|
| 322 | drv_generic_text_greet("goodbye!", NULL); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | drv_generic_serial_close(); |
|---|
| 326 | |
|---|
| 327 | return (0); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | DRIVER drv_MilfordInstruments = { |
|---|
| 332 | name:Name, |
|---|
| 333 | list:drv_MI_list, |
|---|
| 334 | init:drv_MI_init, |
|---|
| 335 | quit:drv_MI_quit, |
|---|
| 336 | }; |
|---|