summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp87
1 files changed, 68 insertions, 19 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
@@ -198,2 +198,63 @@ void SIMpad::initButtons()
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
@@ -231,17 +292,8 @@ bool 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 ); 294 m_leds [0] = st;
234 295 setCS3Bit(st == Led_On, SIMPAD_LED2_ON);
235 /*TODO Implement this like that: 296 return true;
236 read from cs3 297 }
237 && with SIMPAD_LED2_ON 298
238 write to cs3 */
239 m_leds [0] = st;
240 return true;
241 // }
242// }
243#else
244 Q_UNUSED( l )
245 Q_UNUSED( st )
246#endif
247 return false; 299 return false;
@@ -312,6 +364,3 @@ bool SIMpad::setDisplayStatus ( bool on )
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}