add some characters to NumericalTextInput
[enigma2.git] / lib / gdi / lcd.cpp
1 #include <lib/gdi/lcd.h>
2
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6
7 #include <dbox/fp.h>
8 #include <dbox/lcd-ks0713.h>
9
10 #include <lib/gdi/esize.h>
11 #include <lib/base/init.h>
12 #include <lib/base/init_num.h>
13 #include <lib/gdi/glcddc.h>
14
15 eDBoxLCD *eDBoxLCD::instance;
16
17 eLCD::eLCD(eSize size): res(size)
18 {
19         locked=0;
20         _buffer=new unsigned char[res.height()*res.width()];
21         _stride=res.width();
22 }
23
24 eLCD::~eLCD()
25 {
26         delete [] _buffer;
27 }
28
29 int eLCD::lock()
30 {
31         if (locked)
32                 return -1;
33
34         locked=1;
35         return lcdfd;
36 }
37
38 void eLCD::unlock()
39 {
40         read( lcdfd, NULL, 0);
41         if ( errno == 9 )
42         {
43                 eDebug("reopen lcd");
44                 lcdfd=open("/dev/dbox/lcd0", O_RDWR);  // reopen device
45         }
46         else
47                 eDebug("do not reopen lcd.. errno = %d", errno);
48     
49         locked=0;
50 }
51
52 eDBoxLCD::eDBoxLCD(): eLCD(eSize(128, 64))
53 {
54 #ifndef NO_LCD
55         lcdfd=open("/dev/dbox/lcd0", O_RDWR);
56 #else
57         lcdfd=-1;
58 #endif
59         instance=this;
60
61         if (lcdfd<0)
62                 eDebug("couldn't open LCD - load lcd.o!");
63         else
64         {
65                 int i=LCD_MODE_BIN;
66                 ioctl(lcdfd, LCD_IOCTL_ASC_MODE, &i);
67                 inverted=0;
68         }
69 }
70
71 void eDBoxLCD::setInverted(unsigned char inv)
72 {
73         inverted=inv;
74         update();       
75 }
76
77 int eDBoxLCD::setLCDContrast(int contrast)
78 {
79         int fp;
80         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
81         {
82                 eDebug("[LCD] can't open /dev/dbox/fp0");
83                 return(-1);
84         }
85
86         if(ioctl(lcdfd, LCD_IOCTL_SRV, &contrast))
87         {
88                 eDebug("[LCD] can't set lcd contrast");
89         }
90         return(0);
91 }
92
93 int eDBoxLCD::setLCDBrightness(int brightness)
94 {
95         int fp;
96         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
97         {
98                 eDebug("[LCD] can't open /dev/dbox/fp0");
99                 return(-1);
100         }
101
102         if(ioctl(fp, FP_IOCTL_LCD_DIMM, &brightness))
103         {
104                 eDebug("[LCD] can't set lcd brightness");
105         }
106         return(0);
107 }
108
109 eDBoxLCD::~eDBoxLCD()
110 {
111         if (lcdfd>0)
112         {
113                 close(lcdfd);
114                 lcdfd=0;
115         }
116 }
117
118 eDBoxLCD *eDBoxLCD::getInstance()
119 {
120         return instance;
121 }
122
123 void eDBoxLCD::update()
124 {
125         unsigned char raw[120*8];
126         int x, y, yy;
127         for (y=0; y<8; y++)
128         {
129                 for (x=0; x<120; x++)
130                 {
131                         int pix=0;
132                         for (yy=0; yy<8; yy++)
133                         {
134                                 pix|=(_buffer[(y*8+yy)*128+x]>=108)<<yy;
135                         }
136                         raw[y*120+x]=(pix^inverted);
137                 }
138         }
139         if (lcdfd>0)
140                 write(lcdfd, raw, 120*8);
141 }
142