show bskyb HD services in channelselection
[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         lcdfd = -1;
20         locked=0;
21         _buffer=new unsigned char[res.height()*res.width()];
22         memset(_buffer, 0, res.height()*res.width());
23         _stride=res.width();
24 }
25
26 eLCD::~eLCD()
27 {
28         delete [] _buffer;
29 }
30
31 int eLCD::lock()
32 {
33         if (locked)
34                 return -1;
35
36         locked=1;
37         return lcdfd;
38 }
39
40 void eLCD::unlock()
41 {
42         locked=0;
43 }
44
45 eDBoxLCD::eDBoxLCD(): eLCD(eSize(132, 64))
46 {
47 #ifndef NO_LCD
48         lcdfd = open("/dev/dbox/oled0", O_RDWR);
49         if (lcdfd < 0)
50         {
51                 lcdfd = open("/dev/dbox/lcd0", O_RDWR);
52                 is_oled = 0;
53         } else
54         {
55                 eDebug("found OLED display!");
56                 is_oled = 1;
57         }
58 #else
59         lcdfd = -1;
60 #endif
61         instance=this;
62
63         if (lcdfd<0)
64                 eDebug("couldn't open LCD - load lcd.o!");
65         else
66         {
67                 int i=LCD_MODE_BIN;
68                 ioctl(lcdfd, LCD_IOCTL_ASC_MODE, &i);
69                 inverted=0;
70         }
71 }
72
73 void eDBoxLCD::setInverted(unsigned char inv)
74 {
75         inverted=inv;
76         update();       
77 }
78
79 int eDBoxLCD::setLCDContrast(int contrast)
80 {
81         int fp;
82         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
83         {
84                 eDebug("[LCD] can't open /dev/dbox/fp0");
85                 return(-1);
86         }
87
88         if(ioctl(lcdfd, LCD_IOCTL_SRV, &contrast))
89         {
90                 eDebug("[LCD] can't set lcd contrast");
91         }
92         close(fp);
93         return(0);
94 }
95
96 int eDBoxLCD::setLCDBrightness(int brightness)
97 {
98         int fp;
99         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
100         {
101                 eDebug("[LCD] can't open /dev/dbox/fp0");
102                 return(-1);
103         }
104
105         if(ioctl(fp, FP_IOCTL_LCD_DIMM, &brightness))
106         {
107                 eDebug("[LCD] can't set lcd brightness");
108         }
109         close(fp);
110         return(0);
111 }
112
113 eDBoxLCD::~eDBoxLCD()
114 {
115         if (lcdfd>=0)
116         {
117                 close(lcdfd);
118                 lcdfd=-1;
119         }
120 }
121
122 eDBoxLCD *eDBoxLCD::getInstance()
123 {
124         return instance;
125 }
126
127 void eDBoxLCD::update()
128 {
129         if (!is_oled)
130         {
131                 unsigned char raw[132*8];
132                 int x, y, yy;
133                 for (y=0; y<8; y++)
134                 {
135                         for (x=0; x<132; x++)
136                         {
137                                 int pix=0;
138                                 for (yy=0; yy<8; yy++)
139                                 {
140                                         pix|=(_buffer[(y*8+yy)*132+x]>=108)<<yy;
141                                 }
142                                 raw[y*132+x]=(pix^inverted);
143                         }
144                 }
145                 if (lcdfd >= 0)
146                         write(lcdfd, raw, 132*8);
147         } else
148         {
149                 unsigned char raw[64*64];
150                 int x, y;
151                 memset(raw, 0, 64*64);
152                 for (y=0; y<64; y++)
153                 {
154                         for (x=0; x<128 / 2; x++)
155                                 raw[y*64+x] = (_buffer[y*132 + x * 2 + 2] & 0xF0) |(_buffer[y*132 + x * 2 + 1 + 2] >> 4);
156                 }
157                 if (lcdfd >= 0)
158                         write(lcdfd, raw, 64*64);
159         }
160 }
161