summaryrefslogtreecommitdiff
authorzecke <zecke>2004-11-04 21:53:57 (UTC)
committer zecke <zecke>2004-11-04 21:53:57 (UTC)
commit37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba (patch) (unidiff)
treeb261ff83d2f7b77f8663d433b08b005aabd8c184
parent5f56ab623c99c12ce246f775e065632fbfbbfc1f (diff)
downloadopie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.zip
opie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.tar.gz
opie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.tar.bz2
Use QTextStream and QFile instead of read/sscanf for parsing
ChipSelect3 (cs3). This should make it more robust
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp
index 9fde7f9..2e54216 100644
--- a/libopie2/opiecore/device/odevice_simpad.cpp
+++ b/libopie2/opiecore/device/odevice_simpad.cpp
@@ -186,105 +186,103 @@ void SIMpad::initButtons()
186#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA 186#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA
187#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA 187#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA
188#define SIMPAD_EN1 0x0004 // This is only for EPROM's 188#define SIMPAD_EN1 0x0004 // This is only for EPROM's
189#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V 189#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V
190#define SIMPAD_DISPLAY_ON 0x0010 190#define SIMPAD_DISPLAY_ON 0x0010
191#define SIMPAD_PCMCIA_BUFF_DIS 0x0020 191#define SIMPAD_PCMCIA_BUFF_DIS 0x0020
192#define SIMPAD_MQ_RESET 0x0040 192#define SIMPAD_MQ_RESET 0x0040
193#define SIMPAD_PCMCIA_RESET 0x0080 193#define SIMPAD_PCMCIA_RESET 0x0080
194#define SIMPAD_DECT_POWER_ON 0x0100 194#define SIMPAD_DECT_POWER_ON 0x0100
195#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave 195#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave
196#define SIMPAD_RS232_ON 0x0400 196#define SIMPAD_RS232_ON 0x0400
197#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave 197#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave
198#define SIMPAD_LED2_ON 0x1000 198#define SIMPAD_LED2_ON 0x1000
199#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode 199#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode
200#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit 200#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit
201#define SIMPAD_RESET_SIMCARD 0x8000 201#define SIMPAD_RESET_SIMCARD 0x8000
202 202
203//SIMpad touchscreen backlight strength control 203//SIMpad touchscreen backlight strength control
204#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/backlight" 204#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/backlight"
205 205
206 206
207/* 207/*
208 * The SIMpad exposes ChipSelect3 to userspace 208 * The SIMpad exposes ChipSelect3 to userspace
209 * via a proc filesystem file. Using this register 209 * via a proc filesystem file. Using this register
210 * one can toggle power of serial, irda, dect circuits 210 * one can toggle power of serial, irda, dect circuits
211 * change the video driver and display status and 211 * change the video driver and display status and
212 * many more things. 212 * many more things.
213 * To not lose the current setting we read the current 213 * To not lose the current setting we read the current
214 * cs3 setting and toggle the necessary bits and then 214 * cs3 setting and toggle the necessary bits and then
215 * write it. 215 * write it.
216 */ 216 */
217static bool setCS3Bit( bool bitset, int bit ) { 217static bool setCS3Bit( bool bitset, int bit ) {
218 int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY ); 218 QFile file( SIMPAD_BOARDCONTROL );
219 219 if ( !file.open( IO_ReadOnly ) )
220 if ( cs3_fd < 0 )
221 return false; 220 return false;
222 221
223 static char line[32]; 222 unsigned int val = 0;
224 int val = 0; 223 bool ok = false;
225 bool ok = false; 224 QTextStream stream( &file );
226 225
227 /* 226 /*
228 * try to read and parse the Chipselect3 status 227 * Use QFile and QTextStream for parsing to be more
229 * be paranoid and make sure line[31] is null 228 * robust
230 * terminated
231 */ 229 */
232 while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) { 230 while ( !stream.atEnd() ) {
233 line[31] = '\0'; 231 QString line = stream.readLine();
234 if (::sscanf(line, "Chipselect3 : %x", &val )) 232 if ( line.startsWith( "Chipselect3 : " ) ) {
233 val = line.mid( 15 ).toUInt( 0, 16 );
235 ok = true; 234 ok = true;
235 break;
236 }
236 } 237 }
237 238
238 ::close(cs3_fd);
239
240 /*
241 * we were not able to find the current value
242 * and as a result we won't set it
243 */
244 if ( !ok ) 239 if ( !ok )
245 return false; 240 return false;
246 241
242 file.close();
243
247 /* 244 /*
248 * change the value 245 * change the value
249 */ 246 */
250 val = bitset ? (val | bit) : (val & ~bit); 247 val = bitset ? (val | bit) : (val & ~bit);
251 248
252 /* 249 /*
253 * write it back 250 * write it back
254 */ 251 */
255 cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY ); 252 int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY );
256 if ( cs3_fd < 0 ) 253 if ( cs3_fd < 0 )
257 return false; 254 return false;
258 255
256 char line[32];
259 ::snprintf(line, sizeof(line), "0x%04x\n", val); 257 ::snprintf(line, sizeof(line), "0x%04x\n", val);
260 ::write(cs3_fd, line, strlen(line)); 258 ::write(cs3_fd, line, strlen(line));
261 ::close(cs3_fd); 259 ::close(cs3_fd);
262 260
263 return true; 261 return true;
264} 262}
265 263
266 264
267QValueList <OLed> SIMpad::ledList() const 265QValueList <OLed> SIMpad::ledList() const
268{ 266{
269 QValueList <OLed> vl; 267 QValueList <OLed> vl;
270 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? 268 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one?
271 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway 269 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway
272 return vl; 270 return vl;
273} 271}
274 272
275QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const 273QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const
276{ 274{
277 QValueList <OLedState> vl; 275 QValueList <OLedState> vl;
278 276
279 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? 277 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one?
280 vl << Led_Off << Led_On; 278 vl << Led_Off << Led_On;
281 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway 279 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway
282 //vl << Led_Off; 280 //vl << Led_Off;
283 return vl; 281 return vl;
284} 282}
285 283
286OLedState SIMpad::ledState ( OLed l ) const 284OLedState SIMpad::ledState ( OLed l ) const
287{ 285{
288 switch ( l ) { 286 switch ( l ) {
289 case Led_Power: 287 case Led_Power:
290 return m_leds [0]; 288 return m_leds [0];