added ActionMap prio - im sure tmbinc will this ;-)
[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                 int lcdbrightness=0, lcdcontrast=0;
68
69                 lcdbrightness=130;
70                 lcdcontrast=32;
71                 setLCDParameter(lcdbrightness, lcdcontrast);
72                 inverted=0;
73         }
74 }
75
76 void eDBoxLCD::setInverted(unsigned char inv)
77 {
78         inverted=inv;
79         update();       
80 }
81
82 int eDBoxLCD::setLCDParameter(int brightness, int contrast)
83 {
84         int fp;
85         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
86         {
87                 eDebug("[LCD] can't open /dev/dbox/fp0");
88                 return(-1);
89         }
90
91         if(ioctl(lcdfd, LCD_IOCTL_SRV, &contrast))
92         {
93                 eDebug("[LCD] can't set lcd contrast");
94         }
95
96         if(ioctl(fp, FP_IOCTL_LCD_DIMM, &brightness))
97         {
98                 eDebug("[LCD] can't set lcd brightness");
99         }
100         eDebug("[LCD] set brightness %d, contrast %d", brightness, contrast);
101         return(0);
102 }
103
104 eDBoxLCD::~eDBoxLCD()
105 {
106         if (lcdfd>0)
107         {
108                 close(lcdfd);
109                 lcdfd=0;
110         }
111 }
112
113 eDBoxLCD *eDBoxLCD::getInstance()
114 {
115         return instance;
116 }
117
118 void eDBoxLCD::update()
119 {
120         unsigned char raw[120*8];
121         int x, y, yy;
122         for (y=0; y<8; y++)
123         {
124                 for (x=0; x<120; x++)
125                 {
126                         int pix=0;
127                         for (yy=0; yy<8; yy++)
128                         {
129                                 pix|=(_buffer[(y*8+yy)*128+x]>=108)<<yy;
130                         }
131                         raw[y*120+x]=(pix^inverted);
132                 }
133         }
134         if (lcdfd>0)
135                 write(lcdfd, raw, 120*8);
136 }
137