Removed 220-http_address_binding.patch as it does not work for the moment. Closes...
[openwrt.git] / package / lcd4linux / patches / 130-nec_fc.patch
1 diff -urN lcd4linux.old/Makefile.in lcd4linux.dev/Makefile.in
2 --- lcd4linux.old/Makefile.in   2006-01-20 03:52:18.414424750 +0100
3 +++ lcd4linux.dev/Makefile.in   2006-01-20 07:59:02.782678750 +0100
4 @@ -104,7 +104,7 @@
5  lcd4linux_SOURCES =  lcd4linux.c                 cfg.c         cfg.h         debug.c       debug.h       drv.c         drv.h         evaluator.c   evaluator.h   hash.c        hash.h        layout.c      layout.h      pid.c         pid.h         timer.c       timer.h       thread.c      thread.h      udelay.c      udelay.h      qprintf.c     qprintf.h                                 widget.c      widget.h      widget_text.c widget_text.h widget_bar.c  widget_bar.h  widget_icon.c widget_icon.h                             plugin.c      plugin.h      plugin_cfg.c                plugin_math.c               plugin_string.c             plugin_test.c               plugin_time.c
6  
7  
8 -EXTRA_lcd4linux_SOURCES =  drv_generic_text.c          drv_generic_text.h          drv_generic_graphic.c       drv_generic_graphic.h       drv_generic_serial.c        drv_generic_serial.h        drv_generic_parport.c       drv_generic_parport.h       drv_generic_i2c.c           drv_generic_i2c.h           drv_BeckmannEgle.c          drv_BWCT.c                  drv_Crystalfontz.c          drv_Curses.c                drv_Cwlinux.c               drv_HD44780.c               drv_Image.c                 drv_LCDLinux.c              drv_LCDLinux.h              drv_LCDTerm.c               drv_M50530.c                drv_MatrixOrbital.c         drv_MilfordInstruments.c    drv_Noritake.c              drv_NULL.c                  drv_RouterBoard.c           drv_serdisplib.c            drv_SimpleLCD.c             drv_T6963.c                 drv_Trefon.c                drv_USBLCD.c                drv_X11.c                                               font_6x8.h                                              lcd4linux_i2c.h                                         plugin_apm.c                plugin_cpuinfo.c            plugin_diskstats.c          plugin_dvb.c                plugin_exec.c               plugin_i2c_sensors.c        plugin_imon.c               plugin_isdn.c               plugin_loadavg.c            plugin_meminfo.c            plugin_mysql.c              plugin_netdev.c             plugin_pop3.c               plugin_ppp.c                plugin_proc_stat.c          plugin_python.c             plugin_seti.c               plugin_statfs.c             plugin_uname.c              plugin_uptime.c             plugin_wireless.c           plugin_xmms.c
9 +EXTRA_lcd4linux_SOURCES =  drv_generic_text.c          drv_generic_text.h          drv_generic_graphic.c       drv_generic_graphic.h       drv_generic_serial.c        drv_generic_serial.h        drv_generic_parport.c       drv_generic_parport.h       drv_generic_i2c.c           drv_generic_i2c.h           drv_BeckmannEgle.c          drv_BWCT.c                  drv_Crystalfontz.c          drv_Curses.c                drv_Cwlinux.c               drv_HD44780.c               drv_Image.c                 drv_LCDLinux.c              drv_LCDLinux.h              drv_LCDTerm.c               drv_M50530.c                drv_MatrixOrbital.c          drv_FC-NEC.c             drv_MilfordInstruments.c    drv_Noritake.c              drv_NULL.c                  drv_RouterBoard.c           drv_serdisplib.c            drv_SimpleLCD.c             drv_T6963.c                 drv_Trefon.c                drv_USBLCD.c                drv_X11.c                                               font_6x8.h                                              lcd4linux_i2c.h                                         plugin_apm.c                plugin_cpuinfo.c            plugin_diskstats.c          plugin_dvb.c                plugin_exec.c               plugin_i2c_sensors.c        plugin_imon.c               plugin_isdn.c               plugin_loadavg.c            plugin_meminfo.c            plugin_mysql.c              plugin_netdev.c             plugin_pop3.c               plugin_ppp.c                plugin_proc_stat.c          plugin_python.c             plugin_seti.c               plugin_statfs.c             plugin_uname.c              plugin_uptime.c             plugin_wireless.c           plugin_xmms.c
10  
11  
12  EXTRA_DIST =  lcd4linux.conf.sample       lcd4kde.conf                lcd4linux.kdelnk            lcd4linux.xpm               lcd4linux.lsm               curses.m4                   AUTHORS                     CREDITS                     FAQ                         NEWS                        TODO                        README                      README.Drivers              README.Plugins              README.KDE                  plugin_sample.c
13 @@ -362,6 +362,9 @@
14  drv_M50530.o: drv_M50530.c config.h debug.h cfg.h qprintf.h udelay.h \
15         plugin.h evaluator.h widget.h widget_text.h widget_icon.h \
16         widget_bar.h drv.h drv_generic_text.h drv_generic_parport.h
17 +drv_NEC-FC.o: drv_NEC-FC.c config.h debug.h cfg.h plugin.h \
18 +       evaluator.h widget.h widget_text.h widget_icon.h widget_bar.h \
19 +       drv.h drv_generic_text.h drv_generic_serial.h
20  drv_MatrixOrbital.o: drv_MatrixOrbital.c config.h debug.h cfg.h plugin.h \
21         evaluator.h widget.h widget_text.h widget_icon.h widget_bar.h \
22         drv.h drv_generic_text.h drv_generic_serial.h
23 diff -urN lcd4linux.old/config.h.in lcd4linux.dev/config.h.in
24 --- lcd4linux.old/config.h.in   2006-01-20 03:52:18.418423000 +0100
25 +++ lcd4linux.dev/config.h.in   2006-01-20 08:01:07.332164500 +0100
26 @@ -368,6 +368,9 @@
27  /* MatrixOrbital driver */
28  #undef WITH_MATRIXORBITAL
29  
30 +/* NEC-FC driver */
31 +#undef WITH_NEC_FC
32 +
33  /* Milford Instruments driver */
34  #undef WITH_MILINST
35  
36 diff -urN lcd4linux.old/configure lcd4linux.dev/configure
37 --- lcd4linux.old/configure     2006-01-20 03:52:18.418423000 +0100
38 +++ lcd4linux.dev/configure     2006-01-20 08:00:27.973391500 +0100
39 @@ -872,7 +872,7 @@
40                            HD44780, LCDLinux, LCDTerm, M50530, MatrixOrbital,
41                            MilfordInstruments, Noritake, NULL, PNG, PPM,
42                            RouterBoard, serdisplib, SimpleLCD, T6963, Trefon,
43 -                          USBLCD, X11
44 +                          USBLCD, X11, NEC-FC
45    --with-plugins=<list>   choose which plugins to compile.
46                            type --with-plugins=list for a list
47                            of avaible plugins
48 @@ -5888,6 +5888,7 @@
49           LCDTERM="yes"
50           M50530="yes"
51           MATRIXORBITAL="yes"
52 +         NEC_FC="yes"
53           MILINST="yes"
54           NORITAKE="yes"
55           NULL="yes"
56 @@ -5930,6 +5931,9 @@
57           ;;
58        MatrixOrbital)
59           MATRIXORBITAL=$val
60 +                ;;
61 +      NEC-FC)
62 +         NEC_FC=$val
63           ;;
64        MilfordInstruments)
65           MILINST=$val
66 @@ -6109,6 +6113,16 @@
67  
68  fi
69  
70 +if test "$NEC_FC" = "yes"; then
71 +   SERIAL="yes"
72 +   DRIVERS="$DRIVERS drv_NEC-FC.o"
73 +
74 +cat >>confdefs.h <<\_ACEOF
75 +#define WITH_NEC_FC 1
76 +_ACEOF
77 +
78 +fi
79 +
80  if test "$MILINST" = "yes"; then
81     DRIVERS="$DRIVERS drv_MilfordInstruments.o"
82  
83 diff -urN lcd4linux.old/drv.c lcd4linux.dev/drv.c
84 --- lcd4linux.old/drv.c 2006-01-20 03:52:18.422421250 +0100
85 +++ lcd4linux.dev/drv.c 2006-01-20 08:02:30.895589500 +0100
86 @@ -207,6 +207,7 @@
87  extern DRIVER drv_LCDLinux;
88  extern DRIVER drv_LCDTerm;
89  extern DRIVER drv_M50530;
90 +extern DRIVER drv_NEC_FC;
91  extern DRIVER drv_MatrixOrbital;
92  extern DRIVER drv_MilfordInstruments;
93  extern DRIVER drv_Noritake;
94 @@ -259,6 +260,9 @@
95  #ifdef WITH_MATRIXORBITAL
96      &drv_MatrixOrbital,
97  #endif
98 +#ifdef WITH_NEC_FC
99 +    &drv_NEC_FC,
100 +#endif
101  #ifdef WITH_MILINST
102      &drv_MilfordInstruments,
103  #endif
104 diff -urN lcd4linux.old/drv_NEC-FC.c lcd4linux.dev/drv_NEC-FC.c
105 --- lcd4linux.old/drv_NEC-FC.c  1970-01-01 01:00:00.000000000 +0100
106 +++ lcd4linux.dev/drv_NEC-FC.c  2006-01-20 09:32:19.632985000 +0100
107 @@ -0,0 +1,328 @@
108 +/* $Id$
109 + *
110 + * Driver for NEC FC20X2JA
111 + * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
112 + *
113 + * Based on MatrixOrbital driver
114 + *
115 + * LCD4Linux is free software; you can redistribute it and/or modify
116 + * it under the terms of the GNU General Public License as published by
117 + * the Free Software Foundation; either version 2, or (at your option)
118 + * any later version.
119 + *
120 + * LCD4Linux is distributed in the hope that it will be useful,
121 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
122 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
123 + * GNU General Public License for more details.
124 + *
125 + * You should have received a copy of the GNU General Public License
126 + * along with this program; if not, write to the Free Software
127 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
128 + *
129 + */
130 +
131 +/* 
132 + *
133 + * exported fuctions:
134 + *
135 + * struct DRIVER drv_NEC_FC_
136 + *
137 + */
138 +
139 +#include "config.h"
140 +
141 +#include <stdlib.h>
142 +#include <stdio.h>
143 +#include <string.h>
144 +#include <unistd.h>
145 +
146 +#include "debug.h"
147 +#include "cfg.h"
148 +#include "plugin.h"
149 +#include "widget.h"
150 +#include "widget_text.h"
151 +#include "widget_icon.h"
152 +#include "widget_bar.h"
153 +#include "drv.h"
154 +#include "drv_generic_text.h"
155 +#include "drv_generic_serial.h"
156 +
157 +
158 +static char Name[] = "NEC-FC";
159 +static int cur_pos = 0;
160 +static int Model;
161 +static int Protocol;
162 +
163 +/* Fixme: GPO's not yet implemented */
164 +/* static int GPO[8]; */
165 +static int GPOS;
166 +
167 +
168 +typedef struct {
169 +    int type;
170 +    char *name;
171 +    int rows;
172 +    int cols;
173 +    int gpos;
174 +    int protocol;
175 +} MODEL;
176 +
177 +/* Fixme #1: number of gpo's should be verified */
178 +/* Fixme #2: protocol should be verified */
179 +
180 +static MODEL Models[] = {
181 +    {0x01, "FC20X2JA", 2, 20, 0, 1},
182 +    {0xff, "Unknown", -1, -1, 0, 0}
183 +};
184 +
185 +
186 +/****************************************/
187 +/***  hardware dependant functions    ***/
188 +/****************************************/
189 +
190 +static void drv_FC_clear(void)
191 +{
192 +       drv_generic_serial_write("\014", 1);    /* Clear Screen */
193 +       cur_pos = 0;
194 +}
195 +
196 +
197 +static void drv_FC_write(const int row, const int col, const char *data, const int len)
198 +{
199 +       int i;
200 +       int target = (row * DCOLS) + col;
201 +       target -= cur_pos;
202 +       char *buf;
203 +
204 +       buf = malloc(len + 1);
205 +       memcpy(buf, data, len);
206 +       buf[len] = 0;
207 +
208 +       if (target < 0)
209 +               for (i = 0; i < -target; i++)
210 +               drv_generic_serial_write("\x08", 1);
211 +       else
212 +               for (i = 0; i < target; i++)
213 +                   drv_generic_serial_write("\x09", 1);
214 +       
215 +       cur_pos += target + len;
216 +       if (cur_pos >= (DROWS * DCOLS))
217 +               cur_pos = 0;
218 +
219 +    drv_generic_serial_write(data, len);
220 +}
221 +
222 +
223 +static void drv_FC_defchar(const int ascii, const unsigned char *matrix)
224 +{
225 +    int i;
226 +    char cmd[11] = "\x1aN";
227 +
228 +    cmd[2] = (char) ascii;
229 +    for (i = 0; i < 8; i++) {
230 +       cmd[i + 3] = matrix[i] & 0x1f;
231 +    }
232 +    drv_generic_serial_write(cmd, 11);
233 +}
234 +
235 +
236 +static int drv_FC_contrast(int contrast)
237 +{
238 +       char c = (char) contrast;
239 +       c >>= 6;
240 +       c &= 2;
241 +       c = 4 - c;
242 +
243 +    drv_generic_serial_write(&c, 1);
244 +    return contrast;
245 +}
246 +
247 +
248 +static int drv_FC_start(const char *section, const int quiet)
249 +{
250 +    int i;
251 +    char *model;
252 +    char buffer[256];
253 +
254 +    model = cfg_get(section, "Model", NULL);
255 +    if (model != NULL && *model != '\0') {
256 +       for (i = 0; Models[i].type != 0xff; i++) {
257 +           if (strcasecmp(Models[i].name, model) == 0)
258 +               break;
259 +       }
260 +       if (Models[i].type == 0xff) {
261 +           error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source());
262 +           return -1;
263 +       }
264 +       Model = i;
265 +       info("%s: using model '%s'", Name, Models[Model].name);
266 +    } else {
267 +       info("%s: no '%s.Model' entry from %s, auto-dedecting", Name, section, cfg_source());
268 +       Model = -1;
269 +    }
270 +
271 +
272 +    if (drv_generic_serial_open(section, Name, 0) < 0)
273 +       return -1;
274 +
275 +    /* initialize global variables */
276 +    DROWS = Models[Model].rows;
277 +    DCOLS = Models[Model].cols;
278 +    GPOS = Models[Model].gpos;
279 +    Protocol = Models[Model].protocol;
280 +
281 +    drv_FC_clear();
282 +
283 +    drv_generic_serial_write("\x01", 1);       /* 100% lum */
284 +    drv_generic_serial_write("\x14", 1);       /* cursor on */
285 +    drv_generic_serial_write("\x11", 1);    /* scroll write */
286 +
287 +    /* set contrast */
288 +    if (cfg_number(section, "Contrast", 0, 0, 255, &i) > 0) {
289 +       drv_FC_contrast(i);
290 +    }
291 +
292 +    return 0;
293 +}
294 +
295 +
296 +/****************************************/
297 +/***            plugins               ***/
298 +/****************************************/
299 +
300 +
301 +static void plugin_contrast(RESULT * result, const int argc, RESULT * argv[])
302 +{
303 +    double contrast;
304 +
305 +    switch (argc) {
306 +    case 0:
307 +       contrast = drv_FC_contrast(-1);
308 +       SetResult(&result, R_NUMBER, &contrast);
309 +       break;
310 +    case 1:
311 +       contrast = drv_FC_contrast(R2N(argv[0]));
312 +       SetResult(&result, R_NUMBER, &contrast);
313 +       break;
314 +    default:
315 +       error("%s::contrast(): wrong number of parameters", Name);
316 +       SetResult(&result, R_STRING, "");
317 +    }
318 +}
319 +
320 +
321 +
322 +/****************************************/
323 +/***        widget callbacks          ***/
324 +/****************************************/
325 +
326 +/* using drv_generic_text_draw(W) */
327 +/* using drv_generic_text_icon_draw(W) */
328 +/* using drv_generic_text_bar_draw(W) */
329 +
330 +
331 +/****************************************/
332 +/***        exported functions        ***/
333 +/****************************************/
334 +
335 +
336 +/* list models */
337 +int drv_FC_list(void)
338 +{
339 +    int i;
340 +
341 +    for (i = 0; Models[i].type != 0xff; i++) {
342 +       printf("%s ", Models[i].name);
343 +    }
344 +    return 0;
345 +}
346 +
347 +
348 +/* initialize driver & display */
349 +int drv_FC_init(const char *section, const int quiet)
350 +{
351 +    WIDGET_CLASS wc;
352 +    int ret;
353 +
354 +    /* display preferences */
355 +    XRES = 5;                  /* pixel width of one char  */
356 +    YRES = 8;                  /* pixel height of one char  */
357 +    CHARS = 8;                 /* number of user-defineable characters */
358 +    CHAR0 = 0;                 /* ASCII of first user-defineable char */
359 +    GOTO_COST = 4;             /* number of bytes a goto command requires */
360 +
361 +    /* real worker functions */
362 +    drv_generic_text_real_write = drv_FC_write;
363 +    drv_generic_text_real_defchar = drv_FC_defchar;
364 +
365 +
366 +    /* start display */
367 +    if ((ret = drv_FC_start(section, quiet)) != 0)
368 +       return ret;
369 +
370 +    /* initialize generic text driver */
371 +    if ((ret = drv_generic_text_init(section, Name)) != 0)
372 +       return ret;
373 +
374 +    /* initialize generic icon driver */
375 +    if ((ret = drv_generic_text_icon_init()) != 0)
376 +       return ret;
377 +
378 +    /* initialize generic bar driver */
379 +    if ((ret = drv_generic_text_bar_init(0)) != 0)
380 +       return ret;
381 +
382 +    /* add fixed chars to the bar driver */
383 +    drv_generic_text_bar_add_segment(0, 0, 255, 32);   /* ASCII  32 = blank */
384 +    drv_generic_text_bar_add_segment(255, 255, 255, 255);      /* ASCII 255 = block */
385 +
386 +    /* register text widget */
387 +    wc = Widget_Text;
388 +    wc.draw = drv_generic_text_draw;
389 +    widget_register(&wc);
390 +
391 +    /* register icon widget */
392 +    wc = Widget_Icon;
393 +    wc.draw = drv_generic_text_icon_draw;
394 +    widget_register(&wc);
395 +
396 +    /* register bar widget */
397 +    wc = Widget_Bar;
398 +    wc.draw = drv_generic_text_bar_draw;
399 +    widget_register(&wc);
400 +
401 +    /* register plugins */
402 +    AddFunction("LCD::contrast", -1, plugin_contrast);
403 +
404 +    return 0;
405 +}
406 +
407 +
408 +/* close driver & display */
409 +int drv_FC_quit(const int quiet)
410 +{
411 +
412 +    info("%s: shutting down.", Name);
413 +
414 +    drv_generic_text_quit();
415 +
416 +    /* clear display */
417 +    drv_FC_clear();
418 +
419 +    /* say goodbye... */
420 +    if (!quiet) {
421 +       drv_generic_text_greet("goodbye!", NULL);
422 +    }
423 +
424 +    drv_generic_serial_close();
425 +
426 +    return (0);
427 +}
428 +
429 +
430 +DRIVER drv_NEC_FC = {
431 +  name:Name,
432 +  list:drv_FC_list,
433 +  init:drv_FC_init,
434 +  quit:drv_FC_quit,
435 +};