summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp83
1 files changed, 66 insertions, 17 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp
index 2d0160d..fd46b95 100644
--- a/libopie2/opiecore/device/odevice_simpad.cpp
+++ b/libopie2/opiecore/device/odevice_simpad.cpp
@@ -196,6 +196,67 @@ void SIMpad::initButtons()
196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" 196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL"
197#define SIMPAD_BACKLIGHT_MASK 0x00a10044 197#define SIMPAD_BACKLIGHT_MASK 0x00a10044
198 198
199
200/*
201 * The SIMpad exposes ChipSelect3 to userspace
202 * via a proc filesystem file. Using this register
203 * one can toggle power of serial, irda, dect circuits
204 * change the video driver and display status and
205 * many more things.
206 * To not lose the current setting we read the current
207 * cs3 setting and toggle the necessary bits and then
208 * write it.
209 */
210static bool setCS3Bit( bool bitset, int bit ) {
211 int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY );
212
213 if ( cs3_fd < 0 )
214 return false;
215
216 static char line[32];
217 int val = 0;
218 bool ok = false;
219
220 /*
221 * try to read and parse the Chipselect3 status
222 * be paranoid and make sure line[31] is null
223 * terminated
224 */
225 while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) {
226 line[31] = '\0';
227 if (::sscanf(line, "Chipselect3 : %x", &val ))
228 ok = true;
229 }
230
231 ::close(cs3_fd);
232
233 /*
234 * we were not able to find the current value
235 * and as a result we won't set it
236 */
237 if ( !ok )
238 return false;
239
240 /*
241 * change the value
242 */
243 val = bitset ? (val | bit) : (val & ~bit);
244
245 /*
246 * write it back
247 */
248 cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY );
249 if ( cs3_fd < 0 )
250 return false;
251
252 ::snprintf(line, sizeof(line), "0x%04x\n", val);
253 ::write(cs3_fd, line, strlen(line));
254 ::close(cs3_fd);
255
256 return true;
257}
258
259
199QValueList <OLed> SIMpad::ledList() const 260QValueList <OLed> SIMpad::ledList() const
200{ 261{
201 QValueList <OLed> vl; 262 QValueList <OLed> vl;
@@ -229,21 +290,12 @@ OLedState SIMpad::ledState ( OLed l ) const
229 290
230bool SIMpad::setLedState ( OLed l, OLedState st ) 291bool SIMpad::setLedState ( OLed l, OLedState st )
231{ 292{
232#if 0 293 if ( l == Led_Power ) {
233 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK );
234
235 /*TODO Implement this like that:
236 read from cs3
237 && with SIMPAD_LED2_ON
238 write to cs3 */
239 m_leds [0] = st; 294 m_leds [0] = st;
295 setCS3Bit(st == Led_On, SIMPAD_LED2_ON);
240 return true; 296 return true;
241 // } 297 }
242// } 298
243#else
244 Q_UNUSED( l )
245 Q_UNUSED( st )
246#endif
247 return false; 299 return false;
248} 300}
249 301
@@ -310,10 +362,7 @@ bool SIMpad::setDisplayStatus ( bool on )
310{ 362{
311 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 363 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
312 364
313 365 return setCS3Bit(on, SIMPAD_DISPLAY_ON);
314 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
315
316 return ( ::system( (const char*) cmdline ) == 0 );
317} 366}
318 367
319 368