-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 36 |
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 | |||
@@ -214,49 +214,47 @@ void SIMpad::initButtons() | |||
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 | */ |
217 | static bool setCS3Bit( bool bitset, int bit ) { | 217 | static 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 | ||