Line 0
Link Here
|
|
|
1 |
/** |
2 |
* Driver for Ahanix/Soundgraph IMON IR/VFD Module |
3 |
* |
4 |
* (C) 2004, Venky Raju <dev@venky.ws> |
5 |
* |
6 |
* This source code is being released under the GPL. |
7 |
* Please see the file COPYING in this package for details. |
8 |
* |
9 |
* Inspired by: |
10 |
* TextMode driver (LCDproc authors?) |
11 |
* Sasem driver (Oliver Stabel) |
12 |
*/ |
13 |
|
14 |
#include <stdlib.h> |
15 |
#include <stdio.h> |
16 |
#include <unistd.h> |
17 |
#include <termios.h> |
18 |
#include <fcntl.h> |
19 |
#include <string.h> |
20 |
#include <sys/errno.h> |
21 |
#include <syslog.h> |
22 |
|
23 |
#include "lcd.h" |
24 |
#include "imon.h" |
25 |
#include "drv_base.h" |
26 |
#include "shared/report.h" |
27 |
#include "configfile.h" |
28 |
|
29 |
#define PAD '#' |
30 |
#define DEFAULT_DEVICE "/dev/usb/lcd" |
31 |
#define DEFAULT_SIZE "16x2" |
32 |
|
33 |
/** |
34 |
* Function prototypes |
35 |
*/ |
36 |
static void imon_close (); |
37 |
static void imon_clear (); |
38 |
static void imon_flush (); |
39 |
static void imon_string (int x, int y, char string[]); |
40 |
static void imon_chr (int x, int y, char c); |
41 |
/* static int imon_contrast (int contrast); */ |
42 |
/* static void imon_backlight (int on); */ |
43 |
/* static void imon_init_vbar (); */ |
44 |
/* static void imon_init_hbar (); */ |
45 |
/* static void imon_init_num (); */ |
46 |
static void imon_vbar (int x, int len); |
47 |
static void imon_hbar (int x, int y, int len); |
48 |
/* static void imon_num (int x, int num); */ |
49 |
/* static void imon_set_char (int n, char *dat); */ |
50 |
/* static void imon_flush_box (int lft, int top, int rgt, int bot); */ |
51 |
static void imon_draw_frame (char *dat); |
52 |
|
53 |
lcd_logical_driver *imon; |
54 |
static int imon_fd; |
55 |
|
56 |
|
57 |
/* The two value below are fake, we don't support custom char. */ |
58 |
#define VFD_DEFAULT_CELL_WIDTH 5 |
59 |
#define VFD_DEFAULT_CELL_HEIGHT 8 |
60 |
|
61 |
int imon_init (lcd_logical_driver * driver, char *args) |
62 |
{ |
63 |
char buf[256]; |
64 |
int width=0, height=0; |
65 |
|
66 |
imon = driver; |
67 |
|
68 |
/* TODO?: replace DriverName with driver->name when that field exists.*/ |
69 |
#define DriverName "imon" |
70 |
|
71 |
/* Get settings from config file*/ |
72 |
|
73 |
/* Get device */ |
74 |
strncpy (buf, config_get_string (DriverName, "device", 0, DEFAULT_DEVICE), sizeof (buf)); |
75 |
buf [sizeof(buf)-1] = 0; |
76 |
report (RPT_INFO, "imon: using device %s", buf); |
77 |
|
78 |
/* Open device for writing */ |
79 |
if ((imon_fd = open (buf, O_WRONLY)) < 0) { |
80 |
|
81 |
report (RPT_ERR, "imon: error opening %s (%s)", buf, strerror (errno)); |
82 |
return -1; |
83 |
} |
84 |
|
85 |
/* Get size settings*/ |
86 |
strncpy (buf, config_get_string (DriverName , "Size" , 0 , DEFAULT_SIZE), sizeof(buf)); |
87 |
buf[sizeof(buf)-1] = 0; |
88 |
if (sscanf(buf , "%dx%d", &width, &height ) != 2 || (width <= 0) || (height <= 0)) { |
89 |
report (RPT_WARNING, "imon: cannot read size: %s. Using default value %s.\n", |
90 |
buf, DEFAULT_SIZE); |
91 |
sscanf (DEFAULT_SIZE , "%dx%d", &width, &height ); |
92 |
} |
93 |
|
94 |
imon->wid = width; |
95 |
imon->hgt = height; |
96 |
|
97 |
/* Make sure the frame buffer is there... */ |
98 |
if (!imon->framebuf) |
99 |
imon->framebuf = (unsigned char *) malloc (imon->wid * imon->hgt); |
100 |
memset (imon->framebuf, ' ', imon->wid * imon->hgt); |
101 |
|
102 |
imon->cellwid = VFD_DEFAULT_CELL_WIDTH; |
103 |
imon->cellhgt = VFD_DEFAULT_CELL_HEIGHT; |
104 |
|
105 |
/* Set the functions the driver supports */ |
106 |
imon->clear = imon_clear; |
107 |
imon->string = imon_string; |
108 |
imon->chr = imon_chr; |
109 |
imon->vbar = imon_vbar; |
110 |
imon->hbar = imon_hbar; |
111 |
/* imon->init_vbar = NULL; */ |
112 |
/* imon->init_hbar = NULL; */ |
113 |
/* imon->num = imon_num; */ |
114 |
/* imon->init_num = NULL; */ |
115 |
imon->init = imon_init; |
116 |
imon->close = imon_close; |
117 |
imon->flush = imon_flush; |
118 |
/* imon->flush_box = NULL; */ |
119 |
/* imon->contrast = NULL; */ |
120 |
/* imon->backlight = NULL; */ |
121 |
/* imon->set_char = NULL; */ |
122 |
/* imon->icon = NULL; */ |
123 |
imon->draw_frame = imon_draw_frame; |
124 |
/* imon->getkey = NULL; */ |
125 |
|
126 |
return !0; |
127 |
} |
128 |
|
129 |
static void imon_close () |
130 |
{ |
131 |
if (imon->framebuf != NULL) |
132 |
free (imon->framebuf); |
133 |
|
134 |
imon->framebuf = NULL; |
135 |
close (imon_fd); |
136 |
} |
137 |
|
138 |
/** |
139 |
* Clears the VFD screen |
140 |
*/ |
141 |
static void imon_clear () |
142 |
{ |
143 |
memset (imon->framebuf, ' ', imon->wid * imon->hgt); |
144 |
} |
145 |
|
146 |
/** |
147 |
* Flushes all output to the VFD... |
148 |
*/ |
149 |
static void imon_flush () |
150 |
{ |
151 |
imon_draw_frame (imon->framebuf); |
152 |
} |
153 |
|
154 |
/** |
155 |
* Prints a string on the VFD display, at position (x,y). |
156 |
* The upper-left is (1,1) and the lower right is (16, 2). |
157 |
*/ |
158 |
static void imon_string (int x, int y, char string[]) |
159 |
{ |
160 |
int i; |
161 |
|
162 |
for (i = 0; string[i]; i++) |
163 |
imon_chr (x+i, y, string [i]); |
164 |
} |
165 |
|
166 |
|
167 |
/** |
168 |
* Prints a character on the VFD display, at position (x,y). |
169 |
* The upper-left is (1,1) and the lower right is (16,2). |
170 |
*/ |
171 |
static void imon_chr (int x, int y, char ch) |
172 |
{ |
173 |
y--; x--; |
174 |
|
175 |
switch (ch) { |
176 |
|
177 |
case 0: |
178 |
case -1: |
179 |
ch = PAD; |
180 |
break; |
181 |
default: |
182 |
; |
183 |
} |
184 |
|
185 |
imon->framebuf[(y * imon->wid) + x] = ch; |
186 |
} |
187 |
|
188 |
/** |
189 |
* Draws a vertical bar; erases entire column onscreen. |
190 |
*/ |
191 |
static void imon_vbar (int x, int len) |
192 |
{ |
193 |
int y; |
194 |
for (y = imon->hgt; y > 0 && len > 0; y--) { |
195 |
|
196 |
imon_chr (x, y, '|'); |
197 |
len -= imon->cellhgt; |
198 |
} |
199 |
|
200 |
} |
201 |
|
202 |
/** |
203 |
* Draws a horizontal bar to the right. |
204 |
*/ |
205 |
static void imon_hbar (int x, int y, int len) |
206 |
{ |
207 |
for (; x <= imon->wid && len > 0; x++) { |
208 |
|
209 |
imon_chr (x, y, '-'); |
210 |
len -= imon->cellwid; |
211 |
} |
212 |
|
213 |
} |
214 |
|
215 |
static void imon_flush_box (int lft, int top, int rgt, int bot) |
216 |
{ |
217 |
imon_flush (); |
218 |
} |
219 |
|
220 |
static void imon_draw_frame (char *dat) |
221 |
{ |
222 |
write (imon_fd, dat, 32); |
223 |
} |
224 |
|