author | zecke <zecke> | 2004-07-13 13:24:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-13 13:24:59 (UTC) |
commit | 74f19a502a513258f88a75e057a5998393e3c7f6 (patch) (unidiff) | |
tree | 3e905a7b2dd6776e4e1f1204510b95599477965f | |
parent | 4a31bc0d4c9a30583200e866f21340448d41d1c2 (diff) | |
download | opie-74f19a502a513258f88a75e057a5998393e3c7f6.zip opie-74f19a502a513258f88a75e057a5998393e3c7f6.tar.gz opie-74f19a502a513258f88a75e057a5998393e3c7f6.tar.bz2 |
Use snprintf to just be sure that we don't go over the buffer limit
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index 76f03a0..e62ea18 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp | |||
@@ -230,141 +230,141 @@ bool SIMpad::setLedState ( OLed l, OLedState st ) | |||
230 | static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); | 230 | static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); |
231 | 231 | ||
232 | /*TODO Implement this like that: | 232 | /*TODO Implement this like that: |
233 | read from cs3 | 233 | read from cs3 |
234 | && with SIMPAD_LED2_ON | 234 | && with SIMPAD_LED2_ON |
235 | write to cs3 */ | 235 | write to cs3 */ |
236 | m_leds [0] = st; | 236 | m_leds [0] = st; |
237 | return true; | 237 | return true; |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | #endif | 242 | #endif |
243 | return false; | 243 | return false; |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 247 | bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
248 | { | 248 | { |
249 | //TODO | 249 | //TODO |
250 | return false; | 250 | return false; |
251 | } | 251 | } |
252 | 252 | ||
253 | void SIMpad::timerEvent ( QTimerEvent * ) | 253 | void SIMpad::timerEvent ( QTimerEvent * ) |
254 | { | 254 | { |
255 | killTimer ( m_power_timer ); | 255 | killTimer ( m_power_timer ); |
256 | m_power_timer = 0; | 256 | m_power_timer = 0; |
257 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 257 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
258 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 258 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
259 | } | 259 | } |
260 | 260 | ||
261 | 261 | ||
262 | void SIMpad::playAlarmSound() | 262 | void SIMpad::playAlarmSound() |
263 | { | 263 | { |
264 | #ifndef QT_NO_SOUND | 264 | #ifndef QT_NO_SOUND |
265 | static Sound snd ( "alarm" ); | 265 | static Sound snd ( "alarm" ); |
266 | int fd; | 266 | int fd; |
267 | int vol; | 267 | int vol; |
268 | bool vol_reset = false; | 268 | bool vol_reset = false; |
269 | 269 | ||
270 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | 270 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { |
271 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 271 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
272 | Config cfg ( "qpe" ); | 272 | Config cfg ( "qpe" ); |
273 | cfg. setGroup ( "Volume" ); | 273 | cfg. setGroup ( "Volume" ); |
274 | 274 | ||
275 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 275 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
276 | if ( volalarm < 0 ) | 276 | if ( volalarm < 0 ) |
277 | volalarm = 0; | 277 | volalarm = 0; |
278 | else if ( volalarm > 100 ) | 278 | else if ( volalarm > 100 ) |
279 | volalarm = 100; | 279 | volalarm = 100; |
280 | volalarm |= ( volalarm << 8 ); | 280 | volalarm |= ( volalarm << 8 ); |
281 | 281 | ||
282 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | 282 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) |
283 | vol_reset = true; | 283 | vol_reset = true; |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | snd. play(); | 287 | snd. play(); |
288 | while ( !snd. isFinished()) | 288 | while ( !snd. isFinished()) |
289 | qApp->processEvents(); | 289 | qApp->processEvents(); |
290 | 290 | ||
291 | if ( fd >= 0 ) { | 291 | if ( fd >= 0 ) { |
292 | if ( vol_reset ) | 292 | if ( vol_reset ) |
293 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | 293 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); |
294 | ::close ( fd ); | 294 | ::close ( fd ); |
295 | } | 295 | } |
296 | #endif | 296 | #endif |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | bool SIMpad::suspend() // Must override because SIMpad does NOT have apm | 300 | bool SIMpad::suspend() // Must override because SIMpad does NOT have apm |
301 | { | 301 | { |
302 | qDebug( "ODevice for SIMpad: suspend()" ); | 302 | qDebug( "ODevice for SIMpad: suspend()" ); |
303 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 303 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
304 | return false; | 304 | return false; |
305 | 305 | ||
306 | bool res = false; | 306 | bool res = false; |
307 | ODevice::sendSuspendmsg(); | 307 | ODevice::sendSuspendmsg(); |
308 | 308 | ||
309 | struct timeval tvs, tvn; | 309 | struct timeval tvs, tvn; |
310 | ::gettimeofday ( &tvs, 0 ); | 310 | ::gettimeofday ( &tvs, 0 ); |
311 | 311 | ||
312 | ::sync(); // flush fs caches | 312 | ::sync(); // flush fs caches |
313 | res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :) | 313 | res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :) |
314 | 314 | ||
315 | return res; | 315 | return res; |
316 | } | 316 | } |
317 | 317 | ||
318 | 318 | ||
319 | bool SIMpad::setSoftSuspend ( bool soft ) | 319 | bool SIMpad::setSoftSuspend ( bool soft ) |
320 | { | 320 | { |
321 | qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); | 321 | qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); |
322 | return false; | 322 | return false; |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | bool SIMpad::setDisplayStatus ( bool on ) | 326 | bool SIMpad::setDisplayStatus ( bool on ) |
327 | { | 327 | { |
328 | qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); | 328 | qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); |
329 | 329 | ||
330 | bool res = false; | 330 | bool res = false; |
331 | int fd; | 331 | int fd; |
332 | 332 | ||
333 | QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) | 333 | QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) |
334 | 334 | ||
335 | res = ( ::system( (const char*) cmdline ) == 0 ); | 335 | res = ( ::system( (const char*) cmdline ) == 0 ); |
336 | 336 | ||
337 | return res; | 337 | return res; |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | bool SIMpad::setDisplayBrightness ( int bright ) | 341 | bool SIMpad::setDisplayBrightness ( int bright ) |
342 | { | 342 | { |
343 | qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); | 343 | qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); |
344 | bool res = false; | 344 | bool res = false; |
345 | int fd; | 345 | int fd; |
346 | 346 | ||
347 | if ( bright > 255 ) | 347 | if ( bright > 255 ) |
348 | bright = 255; | 348 | bright = 255; |
349 | if ( bright < 1 ) | 349 | if ( bright < 1 ) |
350 | bright = 0; | 350 | bright = 0; |
351 | 351 | ||
352 | if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { | 352 | if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { |
353 | int value = 255 - bright; | 353 | int value = 255 - bright; |
354 | const int mask = SIMPAD_BACKLIGHT_MASK; | 354 | const int mask = SIMPAD_BACKLIGHT_MASK; |
355 | value = value << 8; | 355 | value = value << 8; |
356 | value += mask; | 356 | value += mask; |
357 | char writeCommand[100]; | 357 | char writeCommand[100]; |
358 | const int count = sprintf( writeCommand, "0x%x\n", value ); | 358 | const int count = snprintf( writeCommand, sizeof(writeCommand), "0x%x\n", value ); |
359 | res = ( ::write ( fd, writeCommand, count ) != -1 ); | 359 | res = ( ::write ( fd, writeCommand, count ) != -1 ); |
360 | ::close ( fd ); | 360 | ::close ( fd ); |
361 | } | 361 | } |
362 | return res; | 362 | return res; |
363 | } | 363 | } |
364 | 364 | ||
365 | 365 | ||
366 | int SIMpad::displayBrightnessResolution() const | 366 | int SIMpad::displayBrightnessResolution() const |
367 | { | 367 | { |
368 | return 255; // All SIMpad models share the same display | 368 | return 255; // All SIMpad models share the same display |
369 | } | 369 | } |
370 | 370 | ||