| 1 | /* $Id$ |
|---|
| 2 | * $URL$ |
|---|
| 3 | * |
|---|
| 4 | * driver for Milford Instruments 'BPK' piggy-back serial interface board |
|---|
| 5 | * for standard Hitachi 44780 compatible lcd modules. |
|---|
| 6 | * |
|---|
| 7 | * Copyright (C) 2003, 2004 Andy Baxter <andy@earthsong.free-online.co.uk> |
|---|
| 8 | * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> |
|---|
| 9 | * |
|---|
| 10 | * based on the MatrixOrbital driver which is |
|---|
| 11 | * Copyright (C) 1999, 2000 Michael Reinelt <reinelt@eunet.at> |
|---|
| 12 | * |
|---|
| 13 | * This file is part of LCD4Linux. |
|---|
| 14 | * |
|---|
| 15 | * LCD4Linux is free software; you can redistribute it and/or modify |
|---|
| 16 | * it under the terms of the GNU General Public License as published by |
|---|
| 17 | * the Free Software Foundation; either version 2, or (at your option) |
|---|
| 18 | * any later version. |
|---|
| 19 | * |
|---|
| 20 | * LCD4Linux is distributed in the hope that it will be useful, |
|---|
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | * GNU General Public License for more details. |
|---|
| 24 | * |
|---|
| 25 | * You should have received a copy of the GNU General Public License |
|---|
| 26 | * along with this program; if not, write to the Free Software |
|---|
| 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 28 | * |
|---|
| 29 | */ |
|---|
| 30 | |
|---|
| 31 | /* |
|---|
| 32 | * |
|---|
| 33 | * exported fuctions: |
|---|
| 34 | * |
|---|
| 35 | * struct DRIVER drv_MilfordInstruments |
|---|
| 36 | * |
|---|
| 37 | */ |
|---|
| 38 | |
|---|
| 39 | #include "config.h" |
|---|
| 40 | |
|---|
| 41 | #include <stdlib.h> |
|---|
| 42 | #include <stdio.h> |
|---|
| 43 | #include <string.h> |
|---|
| 44 | #include <unistd.h> |
|---|
| 45 | |
|---|
| 46 | #include "debug.h" |
|---|
| 47 | #include "cfg.h" |
|---|
| 48 | #include "plugin.h" |
|---|
| 49 | #include "widget.h" |
|---|
| 50 | #include "widget_text.h" |
|---|
| 51 | #include "widget_icon.h" |
|---|
| 52 | #include "widget_bar.h" |
|---|
| 53 | #include "drv.h" |
|---|
| 54 | #include "drv_generic_text.h" |
|---|
| 55 | #include "drv_generic_serial.h" |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | static char Name[] = "MilfordInstruments"; |
|---|
| 59 | |
|---|
| 60 | typedef struct { |
|---|
| 61 | int type; |
|---|
| 62 | char *name; |
|---|
| 63 | int rows; |
|---|
| 64 | int cols; |
|---|
| 65 | } MODEL; |
|---|
| 66 | |
|---|
| 67 | static MODEL Models[] = { |
|---|
| 68 | {216, "MI216", 2, 16}, |
|---|
| 69 | {220, "MI220", 2, 20}, |
|---|
| 70 | {240, "MI240", 2, 40}, |
|---|
| 71 | {420, "MI420", 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_MI_clear(void) |
|---|
| 83 | { |
|---|
| 84 | drv_generic_serial_write("\376\001", 2); /* clear screen */ |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | static void drv_MI_write(const int row, const int col, const char *data, const int len) |
|---|
| 89 | { |
|---|
| 90 | char cmd[2] = "\376x"; |
|---|
| 91 | int ddbase = 128; |
|---|
| 92 | if (row & 1) { /* i.e. if row is 1 or 3 */ |
|---|
| 93 | ddbase += 64; |
|---|
| 94 | } |
|---|
| 95 | if (row & 2) { /* i.e. if row is 0 or 2. */ |
|---|
| 96 | ddbase += 20; |
|---|
| 97 | } |
|---|
| 98 | cmd[1] = (char) (ddbase + col); |
|---|
| 99 | drv_generic_serial_write(cmd, 2); |
|---|
| 100 | |
|---|
| 101 | drv_generic_serial_write(data, len); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | static void drv_MI_defchar(const int ascii, const unsigned char *matrix) |
|---|
| 106 | { |
|---|
| 107 | int i; |
|---|
| 108 | char cmd[10] = "\376x"; |
|---|
| 109 | |
|---|
| 110 | if (ascii < 8) { |
|---|
| 111 | cmd[1] = (char) (64 + ascii * 8); |
|---|
| 112 | for (i = 0; i < 8; i++) { |
|---|
| 113 | cmd[i + 2] = matrix[i] & 0x1f; |
|---|
| 114 | }; |
|---|
| 115 | drv_generic_serial_write(cmd, 10); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | static int drv_MI_start(const char *section, const int quiet) |
|---|
| 121 | { |
|---|
| 122 | int i; |
|---|
| 123 | char *model; |
|---|
| 124 | |
|---|
| 125 | model = cfg_get(section, "Model", NULL); |
|---|
| 126 | if (model == NULL && *model == '\0') { |
|---|
| 127 | error("%s: no '%s.Model' entry from %s", Name, section, cfg_source()); |
|---|
| 128 | return -1; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | for (i = 0; Models[i].type != 0xff; i++) { |
|---|
| 132 | if (strcasecmp(Models[i].name, model) == 0) |
|---|
| 133 | break; |
|---|
| 134 | } |
|---|
| 135 | if (Models[i].type == 0xff) { |
|---|
| 136 | error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source()); |
|---|
| 137 | return -1; |
|---|
| 138 | } |
|---|
| 139 | Model = i; |
|---|
| 140 | info("%s: using model '%s'", Name, Models[Model].name); |
|---|
| 141 | |
|---|
| 142 | if (drv_generic_serial_open(section, Name, 0) < 0) |
|---|
| 143 | return -1; |
|---|
| 144 | |
|---|
| 145 | /* initialize global variables */ |
|---|
| 146 | DROWS = Models[Model].rows; |
|---|
| 147 | DCOLS = Models[Model].cols; |
|---|
| 148 | |
|---|
| 149 | drv_MI_clear(); |
|---|
| 150 | drv_generic_serial_write("\376\014", 2); /* cursor off */ |
|---|
| 151 | |
|---|
| 152 | if (!quiet) { |
|---|
| 153 | if (drv_generic_text_greet(Models[Model].name, "Milford Instruments")) { |
|---|
| 154 | sleep(3); |
|---|
| 155 | drv_MI_clear(); |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | return 0; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | /****************************************/ |
|---|
| 164 | /*** plugins ***/ |
|---|
| 165 | /****************************************/ |
|---|
| 166 | |
|---|
| 167 | /* none at the moment... */ |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | /****************************************/ |
|---|
| 171 | /*** widget callbacks ***/ |
|---|
| 172 | /****************************************/ |
|---|
| 173 | |
|---|
| 174 | /* using drv_generic_text_draw(W) */ |
|---|
| 175 | /* using drv_generic_text_icon_draw(W) */ |
|---|
| 176 | /* using drv_generic_text_bar_draw(W) */ |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | /****************************************/ |
|---|
| 180 | /*** exported functions ***/ |
|---|
| 181 | /****************************************/ |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | /* list models */ |
|---|
| 185 | int drv_MI_list(void) |
|---|
| 186 | { |
|---|
| 187 | int i; |
|---|
| 188 | |
|---|
| 189 | for (i = 0; Models[i].type > 0; i++) { |
|---|
| 190 | printf("%s ", Models[i].name); |
|---|
| 191 | } |
|---|
| 192 | return 0; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | /* initialize driver & display */ |
|---|
| 197 | int drv_MI_init(const char *section, const int quiet) |
|---|
| 198 | { |
|---|
| 199 | WIDGET_CLASS wc; |
|---|
| 200 | int ret; |
|---|
| 201 | |
|---|
| 202 | info("%s: %s", Name, "$Rev$"); |
|---|
| 203 | |
|---|
| 204 | /* display preferences */ |
|---|
| 205 | XRES = 5; /* pixel width of one char */ |
|---|
| 206 | YRES = 8; /* pixel height of one char */ |
|---|
| 207 | CHARS = 8; /* number of user-defineable characters */ |
|---|
| 208 | CHAR0 = 0; /* ASCII of first user-defineable char */ |
|---|
| 209 | GOTO_COST = 4; /* number of bytes a goto command requires */ |
|---|
| 210 | |
|---|
| 211 | /* real worker functions */ |
|---|
| 212 | drv_generic_text_real_write = drv_MI_write; |
|---|
| 213 | drv_generic_text_real_defchar = drv_MI_defchar; |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | /* start display */ |
|---|
| 217 | if ((ret = drv_MI_start(section, quiet)) != 0) |
|---|
| 218 | return ret; |
|---|
| 219 | |
|---|
| 220 | /* initialize generic text driver */ |
|---|
| 221 | if ((ret = drv_generic_text_init(section, Name)) != 0) |
|---|
| 222 | return ret; |
|---|
| 223 | |
|---|
| 224 | /* initialize generic icon driver */ |
|---|
| 225 | if ((ret = drv_generic_text_icon_init()) != 0) |
|---|
| 226 | return ret; |
|---|
| 227 | |
|---|
| 228 | /* initialize generic bar driver */ |
|---|
| 229 | if ((ret = drv_generic_text_bar_init(0)) != 0) |
|---|
| 230 | return ret; |
|---|
| 231 | |
|---|
| 232 | /* add fixed chars to the bar driver */ |
|---|
| 233 | drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ |
|---|
| 234 | drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */ |
|---|
| 235 | |
|---|
| 236 | /* register text widget */ |
|---|
| 237 | wc = Widget_Text; |
|---|
| 238 | wc.draw = drv_generic_text_draw; |
|---|
| 239 | widget_register(&wc); |
|---|
| 240 | |
|---|
| 241 | /* register icon widget */ |
|---|
| 242 | wc = Widget_Icon; |
|---|
| 243 | wc.draw = drv_generic_text_icon_draw; |
|---|
| 244 | widget_register(&wc); |
|---|
| 245 | |
|---|
| 246 | /* register bar widget */ |
|---|
| 247 | wc = Widget_Bar; |
|---|
| 248 | wc.draw = drv_generic_text_bar_draw; |
|---|
| 249 | widget_register(&wc); |
|---|
| 250 | |
|---|
| 251 | /* register plugins */ |
|---|
| 252 | /* none at the moment... */ |
|---|
| 253 | |
|---|
| 254 | return 0; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | /* close driver & display */ |
|---|
| 259 | int drv_MI_quit(const int quiet) |
|---|
| 260 | { |
|---|
| 261 | |
|---|
| 262 | info("%s: shutting down.", Name); |
|---|
| 263 | |
|---|
| 264 | drv_generic_text_quit(); |
|---|
| 265 | |
|---|
| 266 | /* clear display */ |
|---|
| 267 | drv_MI_clear(); |
|---|
| 268 | |
|---|
| 269 | /* say goodbye... */ |
|---|
| 270 | if (!quiet) { |
|---|
| 271 | drv_generic_text_greet("goodbye!", NULL); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | drv_generic_serial_close(); |
|---|
| 275 | |
|---|
| 276 | return (0); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | DRIVER drv_MilfordInstruments = { |
|---|
| 281 | .name = Name, |
|---|
| 282 | .list = drv_MI_list, |
|---|
| 283 | .init = drv_MI_init, |
|---|
| 284 | .quit = drv_MI_quit, |
|---|
| 285 | }; |
|---|