author | zecke <zecke> | 2004-02-19 01:01:30 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-19 01:01:30 (UTC) |
commit | 3b4b9e070f84ce884a98b4112eaee2cef7530308 (patch) (unidiff) | |
tree | a63b57ec3368e41ea1482a37a41b4b9df2f30fd4 /libopie2 | |
parent | ab41e301eb7f06af0869844d197e38a7838f3f2d (diff) | |
download | opie-3b4b9e070f84ce884a98b4112eaee2cef7530308.zip opie-3b4b9e070f84ce884a98b4112eaee2cef7530308.tar.gz opie-3b4b9e070f84ce884a98b4112eaee2cef7530308.tar.bz2 |
The hardware keys on the H5xxx are rotated by 270°
so rotate the key events
-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index d20ea4d..cc4b01a 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp | |||
@@ -105,371 +105,377 @@ struct i_button ipaq_buttons [] = { | |||
105 | "buttonsettings", "raise()" }, | 105 | "buttonsettings", "raise()" }, |
106 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 106 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
107 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 107 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
108 | "devicebuttons/ipaq_record", | 108 | "devicebuttons/ipaq_record", |
109 | "QPE/VMemo", "toggleRecord()", | 109 | "QPE/VMemo", "toggleRecord()", |
110 | "sound", "raise()" }, | 110 | "sound", "raise()" }, |
111 | }; | 111 | }; |
112 | 112 | ||
113 | void iPAQ::init() | 113 | void iPAQ::init() |
114 | { | 114 | { |
115 | d->m_vendorstr = "HP"; | 115 | d->m_vendorstr = "HP"; |
116 | d->m_vendor = Vendor_HP; | 116 | d->m_vendor = Vendor_HP; |
117 | 117 | ||
118 | QFile f ( "/proc/hal/model" ); | 118 | QFile f ( "/proc/hal/model" ); |
119 | 119 | ||
120 | if ( f. open ( IO_ReadOnly )) { | 120 | if ( f. open ( IO_ReadOnly )) { |
121 | QTextStream ts ( &f ); | 121 | QTextStream ts ( &f ); |
122 | 122 | ||
123 | d->m_modelstr = "H" + ts. readLine(); | 123 | d->m_modelstr = "H" + ts. readLine(); |
124 | 124 | ||
125 | if ( d->m_modelstr == "H3100" ) | 125 | if ( d->m_modelstr == "H3100" ) |
126 | d->m_model = Model_iPAQ_H31xx; | 126 | d->m_model = Model_iPAQ_H31xx; |
127 | else if ( d->m_modelstr == "H3600" ) | 127 | else if ( d->m_modelstr == "H3600" ) |
128 | d->m_model = Model_iPAQ_H36xx; | 128 | d->m_model = Model_iPAQ_H36xx; |
129 | else if ( d->m_modelstr == "H3700" ) | 129 | else if ( d->m_modelstr == "H3700" ) |
130 | d->m_model = Model_iPAQ_H37xx; | 130 | d->m_model = Model_iPAQ_H37xx; |
131 | else if ( d->m_modelstr == "H3800" ) | 131 | else if ( d->m_modelstr == "H3800" ) |
132 | d->m_model = Model_iPAQ_H38xx; | 132 | d->m_model = Model_iPAQ_H38xx; |
133 | else if ( d->m_modelstr == "H3900" ) | 133 | else if ( d->m_modelstr == "H3900" ) |
134 | d->m_model = Model_iPAQ_H39xx; | 134 | d->m_model = Model_iPAQ_H39xx; |
135 | else if ( d->m_modelstr == "H5400" ) | 135 | else if ( d->m_modelstr == "H5400" ) |
136 | d->m_model = Model_iPAQ_H5xxx; | 136 | d->m_model = Model_iPAQ_H5xxx; |
137 | else | 137 | else |
138 | d->m_model = Model_Unknown; | 138 | d->m_model = Model_Unknown; |
139 | 139 | ||
140 | f. close(); | 140 | f. close(); |
141 | } | 141 | } |
142 | 142 | ||
143 | switch ( d->m_model ) { | 143 | switch ( d->m_model ) { |
144 | case Model_iPAQ_H31xx: | 144 | case Model_iPAQ_H31xx: |
145 | case Model_iPAQ_H38xx: | 145 | case Model_iPAQ_H38xx: |
146 | d->m_rotation = Rot90; | 146 | d->m_rotation = Rot90; |
147 | break; | 147 | break; |
148 | case Model_iPAQ_H36xx: | 148 | case Model_iPAQ_H36xx: |
149 | case Model_iPAQ_H37xx: | 149 | case Model_iPAQ_H37xx: |
150 | case Model_iPAQ_H39xx: | 150 | case Model_iPAQ_H39xx: |
151 | 151 | ||
152 | default: | 152 | default: |
153 | d->m_rotation = Rot270; | 153 | d->m_rotation = Rot270; |
154 | break; | 154 | break; |
155 | case Model_iPAQ_H5xxx: | 155 | case Model_iPAQ_H5xxx: |
156 | d->m_rotation = Rot0; | 156 | d->m_rotation = Rot0; |
157 | } | 157 | } |
158 | 158 | ||
159 | f. setName ( "/etc/familiar-version" ); | 159 | f. setName ( "/etc/familiar-version" ); |
160 | if ( f. open ( IO_ReadOnly )) { | 160 | if ( f. open ( IO_ReadOnly )) { |
161 | d->m_systemstr = "Familiar"; | 161 | d->m_systemstr = "Familiar"; |
162 | d->m_system = System_Familiar; | 162 | d->m_system = System_Familiar; |
163 | 163 | ||
164 | QTextStream ts ( &f ); | 164 | QTextStream ts ( &f ); |
165 | d->m_sysverstr = ts. readLine(). mid ( 10 ); | 165 | d->m_sysverstr = ts. readLine(). mid ( 10 ); |
166 | 166 | ||
167 | f. close(); | 167 | f. close(); |
168 | } else { | 168 | } else { |
169 | f. setName ( "/etc/oz_version" ); | 169 | f. setName ( "/etc/oz_version" ); |
170 | 170 | ||
171 | if ( f. open ( IO_ReadOnly )) { | 171 | if ( f. open ( IO_ReadOnly )) { |
172 | d->m_systemstr = "OpenEmbedded/iPaq"; | 172 | d->m_systemstr = "OpenEmbedded/iPaq"; |
173 | d->m_system = System_Familiar; | 173 | d->m_system = System_Familiar; |
174 | 174 | ||
175 | QTextStream ts ( &f ); | 175 | QTextStream ts ( &f ); |
176 | ts.setDevice ( &f ); | 176 | ts.setDevice ( &f ); |
177 | d->m_sysverstr = ts. readLine(); | 177 | d->m_sysverstr = ts. readLine(); |
178 | f. close(); | 178 | f. close(); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | m_leds [0] = m_leds [1] = Led_Off; | 182 | m_leds [0] = m_leds [1] = Led_Off; |
183 | 183 | ||
184 | m_power_timer = 0; | 184 | m_power_timer = 0; |
185 | 185 | ||
186 | } | 186 | } |
187 | 187 | ||
188 | void iPAQ::initButtons() | 188 | void iPAQ::initButtons() |
189 | { | 189 | { |
190 | if ( d->m_buttons ) | 190 | if ( d->m_buttons ) |
191 | return; | 191 | return; |
192 | 192 | ||
193 | if ( isQWS( ) ) | 193 | if ( isQWS( ) ) |
194 | QWSServer::setKeyboardFilter ( this ); | 194 | QWSServer::setKeyboardFilter ( this ); |
195 | 195 | ||
196 | d->m_buttons = new QValueList <ODeviceButton>; | 196 | d->m_buttons = new QValueList <ODeviceButton>; |
197 | 197 | ||
198 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 198 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
199 | i_button *ib = ipaq_buttons + i; | 199 | i_button *ib = ipaq_buttons + i; |
200 | ODeviceButton b; | 200 | ODeviceButton b; |
201 | 201 | ||
202 | if (( ib->model & d->m_model ) == d->m_model ) { | 202 | if (( ib->model & d->m_model ) == d->m_model ) { |
203 | b. setKeycode ( ib->code ); | 203 | b. setKeycode ( ib->code ); |
204 | b. setUserText ( QObject::tr ( "Button", ib->utext )); | 204 | b. setUserText ( QObject::tr ( "Button", ib->utext )); |
205 | b. setPixmap ( Resource::loadPixmap ( ib->pix )); | 205 | b. setPixmap ( Resource::loadPixmap ( ib->pix )); |
206 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); | 206 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); |
207 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); | 207 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); |
208 | 208 | ||
209 | d->m_buttons->append ( b ); | 209 | d->m_buttons->append ( b ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | reloadButtonMapping(); | 212 | reloadButtonMapping(); |
213 | 213 | ||
214 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 214 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
215 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | 215 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); |
216 | } | 216 | } |
217 | 217 | ||
218 | QValueList <OLed> iPAQ::ledList() const | 218 | QValueList <OLed> iPAQ::ledList() const |
219 | { | 219 | { |
220 | QValueList <OLed> vl; | 220 | QValueList <OLed> vl; |
221 | vl << Led_Power; | 221 | vl << Led_Power; |
222 | 222 | ||
223 | if ( d->m_model == Model_iPAQ_H38xx ) | 223 | if ( d->m_model == Model_iPAQ_H38xx ) |
224 | vl << Led_BlueTooth; | 224 | vl << Led_BlueTooth; |
225 | return vl; | 225 | return vl; |
226 | } | 226 | } |
227 | 227 | ||
228 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | 228 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const |
229 | { | 229 | { |
230 | QValueList <OLedState> vl; | 230 | QValueList <OLedState> vl; |
231 | 231 | ||
232 | if ( l == Led_Power ) | 232 | if ( l == Led_Power ) |
233 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | 233 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; |
234 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) | 234 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) |
235 | vl << Led_Off; // << Led_On << ??? | 235 | vl << Led_Off; // << Led_On << ??? |
236 | 236 | ||
237 | return vl; | 237 | return vl; |
238 | } | 238 | } |
239 | 239 | ||
240 | OLedState iPAQ::ledState ( OLed l ) const | 240 | OLedState iPAQ::ledState ( OLed l ) const |
241 | { | 241 | { |
242 | switch ( l ) { | 242 | switch ( l ) { |
243 | case Led_Power: | 243 | case Led_Power: |
244 | return m_leds [0]; | 244 | return m_leds [0]; |
245 | case Led_BlueTooth: | 245 | case Led_BlueTooth: |
246 | return m_leds [1]; | 246 | return m_leds [1]; |
247 | default: | 247 | default: |
248 | return Led_Off; | 248 | return Led_Off; |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | bool iPAQ::setLedState ( OLed l, OLedState st ) | 252 | bool iPAQ::setLedState ( OLed l, OLedState st ) |
253 | { | 253 | { |
254 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); | 254 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); |
255 | 255 | ||
256 | if ( l == Led_Power ) { | 256 | if ( l == Led_Power ) { |
257 | if ( fd >= 0 ) { | 257 | if ( fd >= 0 ) { |
258 | LED_IN leds; | 258 | LED_IN leds; |
259 | ::memset ( &leds, 0, sizeof( leds )); | 259 | ::memset ( &leds, 0, sizeof( leds )); |
260 | leds. TotalTime = 0; | 260 | leds. TotalTime = 0; |
261 | leds. OnTime = 0; | 261 | leds. OnTime = 0; |
262 | leds. OffTime = 1; | 262 | leds. OffTime = 1; |
263 | leds. OffOnBlink = 2; | 263 | leds. OffOnBlink = 2; |
264 | 264 | ||
265 | switch ( st ) { | 265 | switch ( st ) { |
266 | case Led_Off : leds. OffOnBlink = 0; break; | 266 | case Led_Off : leds. OffOnBlink = 0; break; |
267 | case Led_On : leds. OffOnBlink = 1; break; | 267 | case Led_On : leds. OffOnBlink = 1; break; |
268 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | 268 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; |
269 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | 269 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; |
270 | } | 270 | } |
271 | 271 | ||
272 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | 272 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { |
273 | m_leds [0] = st; | 273 | m_leds [0] = st; |
274 | return true; | 274 | return true; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | return false; | 278 | return false; |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 282 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
283 | { | 283 | { |
284 | int newkeycode = keycode; | 284 | int newkeycode = keycode; |
285 | 285 | ||
286 | switch ( keycode ) { | 286 | switch ( keycode ) { |
287 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key | 287 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key |
288 | case HardKey_Menu: { | 288 | case HardKey_Menu: { |
289 | if (( d->m_model == Model_iPAQ_H38xx ) || | 289 | if (( d->m_model == Model_iPAQ_H38xx ) || |
290 | ( d->m_model == Model_iPAQ_H39xx ) || | 290 | ( d->m_model == Model_iPAQ_H39xx ) || |
291 | ( d->m_model == Model_iPAQ_H5xxx)) { | 291 | ( d->m_model == Model_iPAQ_H5xxx)) { |
292 | newkeycode = HardKey_Mail; | 292 | newkeycode = HardKey_Mail; |
293 | } | 293 | } |
294 | break; | 294 | break; |
295 | } | 295 | } |
296 | 296 | ||
297 | // Rotate cursor keys 180° | 297 | // Rotate cursor keys 180° or 270° |
298 | case Key_Left : | 298 | case Key_Left : |
299 | case Key_Right: | 299 | case Key_Right: |
300 | case Key_Up : | 300 | case Key_Up : |
301 | case Key_Down : { | 301 | case Key_Down : { |
302 | if (( d->m_model == Model_iPAQ_H31xx ) || | 302 | if (( d->m_model == Model_iPAQ_H31xx ) || |
303 | ( d->m_model == Model_iPAQ_H38xx )) { | 303 | ( d->m_model == Model_iPAQ_H38xx )) { |
304 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; | 304 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; |
305 | } | 305 | } |
306 | // Rotate the cursor keys by 270° | ||
307 | // keycode - Key_Left = position of the button starting from left clockwise | ||
308 | // add the rotation to it and modolo. No we've the original offset | ||
309 | // add the offset to the Key_Left key | ||
310 | if ( d-> m_model == Model_iPAQ_H5xxx ) | ||
311 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; | ||
306 | break; | 312 | break; |
307 | } | 313 | } |
308 | 314 | ||
309 | // map Power Button short/long press to F34/F35 | 315 | // map Power Button short/long press to F34/F35 |
310 | case Key_SysReq: { | 316 | case Key_SysReq: { |
311 | if ( isPress ) { | 317 | if ( isPress ) { |
312 | if ( m_power_timer ) | 318 | if ( m_power_timer ) |
313 | killTimer ( m_power_timer ); | 319 | killTimer ( m_power_timer ); |
314 | m_power_timer = startTimer ( 500 ); | 320 | m_power_timer = startTimer ( 500 ); |
315 | } | 321 | } |
316 | else if ( m_power_timer ) { | 322 | else if ( m_power_timer ) { |
317 | killTimer ( m_power_timer ); | 323 | killTimer ( m_power_timer ); |
318 | m_power_timer = 0; | 324 | m_power_timer = 0; |
319 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 325 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
320 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 326 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
321 | } | 327 | } |
322 | newkeycode = Key_unknown; | 328 | newkeycode = Key_unknown; |
323 | break; | 329 | break; |
324 | } | 330 | } |
325 | } | 331 | } |
326 | 332 | ||
327 | if ( newkeycode != keycode ) { | 333 | if ( newkeycode != keycode ) { |
328 | if ( newkeycode != Key_unknown ) | 334 | if ( newkeycode != Key_unknown ) |
329 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 335 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
330 | return true; | 336 | return true; |
331 | } | 337 | } |
332 | else | 338 | else |
333 | return false; | 339 | return false; |
334 | } | 340 | } |
335 | 341 | ||
336 | void iPAQ::timerEvent ( QTimerEvent * ) | 342 | void iPAQ::timerEvent ( QTimerEvent * ) |
337 | { | 343 | { |
338 | killTimer ( m_power_timer ); | 344 | killTimer ( m_power_timer ); |
339 | m_power_timer = 0; | 345 | m_power_timer = 0; |
340 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 346 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
341 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 347 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
342 | } | 348 | } |
343 | 349 | ||
344 | 350 | ||
345 | void iPAQ::playAlarmSound() | 351 | void iPAQ::playAlarmSound() |
346 | { | 352 | { |
347 | #ifndef QT_NO_SOUND | 353 | #ifndef QT_NO_SOUND |
348 | static Sound snd ( "alarm" ); | 354 | static Sound snd ( "alarm" ); |
349 | int fd; | 355 | int fd; |
350 | int vol; | 356 | int vol; |
351 | bool vol_reset = false; | 357 | bool vol_reset = false; |
352 | 358 | ||
353 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | 359 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { |
354 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 360 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
355 | Config cfg ( "qpe" ); | 361 | Config cfg ( "qpe" ); |
356 | cfg. setGroup ( "Volume" ); | 362 | cfg. setGroup ( "Volume" ); |
357 | 363 | ||
358 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 364 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
359 | if ( volalarm < 0 ) | 365 | if ( volalarm < 0 ) |
360 | volalarm = 0; | 366 | volalarm = 0; |
361 | else if ( volalarm > 100 ) | 367 | else if ( volalarm > 100 ) |
362 | volalarm = 100; | 368 | volalarm = 100; |
363 | volalarm |= ( volalarm << 8 ); | 369 | volalarm |= ( volalarm << 8 ); |
364 | 370 | ||
365 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | 371 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) |
366 | vol_reset = true; | 372 | vol_reset = true; |
367 | } | 373 | } |
368 | } | 374 | } |
369 | 375 | ||
370 | snd. play(); | 376 | snd. play(); |
371 | while ( !snd. isFinished()) | 377 | while ( !snd. isFinished()) |
372 | qApp->processEvents(); | 378 | qApp->processEvents(); |
373 | 379 | ||
374 | if ( fd >= 0 ) { | 380 | if ( fd >= 0 ) { |
375 | if ( vol_reset ) | 381 | if ( vol_reset ) |
376 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | 382 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); |
377 | ::close ( fd ); | 383 | ::close ( fd ); |
378 | } | 384 | } |
379 | #endif | 385 | #endif |
380 | } | 386 | } |
381 | 387 | ||
382 | 388 | ||
383 | bool iPAQ::setSoftSuspend ( bool soft ) | 389 | bool iPAQ::setSoftSuspend ( bool soft ) |
384 | { | 390 | { |
385 | bool res = false; | 391 | bool res = false; |
386 | int fd; | 392 | int fd; |
387 | 393 | ||
388 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | 394 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { |
389 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | 395 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) |
390 | res = true; | 396 | res = true; |
391 | else | 397 | else |
392 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | 398 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); |
393 | 399 | ||
394 | ::close ( fd ); | 400 | ::close ( fd ); |
395 | } | 401 | } |
396 | else | 402 | else |
397 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | 403 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); |
398 | 404 | ||
399 | return res; | 405 | return res; |
400 | } | 406 | } |
401 | 407 | ||
402 | 408 | ||
403 | bool iPAQ::setDisplayBrightness ( int bright ) | 409 | bool iPAQ::setDisplayBrightness ( int bright ) |
404 | { | 410 | { |
405 | bool res = false; | 411 | bool res = false; |
406 | int fd; | 412 | int fd; |
407 | 413 | ||
408 | if ( bright > 255 ) | 414 | if ( bright > 255 ) |
409 | bright = 255; | 415 | bright = 255; |
410 | if ( bright < 0 ) | 416 | if ( bright < 0 ) |
411 | bright = 0; | 417 | bright = 0; |
412 | 418 | ||
413 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 419 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
414 | FLITE_IN bl; | 420 | FLITE_IN bl; |
415 | bl. mode = 1; | 421 | bl. mode = 1; |
416 | bl. pwr = bright ? 1 : 0; | 422 | bl. pwr = bright ? 1 : 0; |
417 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | 423 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; |
418 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 424 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
419 | ::close ( fd ); | 425 | ::close ( fd ); |
420 | } | 426 | } |
421 | return res; | 427 | return res; |
422 | } | 428 | } |
423 | 429 | ||
424 | int iPAQ::displayBrightnessResolution() const | 430 | int iPAQ::displayBrightnessResolution() const |
425 | { | 431 | { |
426 | switch ( model()) { | 432 | switch ( model()) { |
427 | case Model_iPAQ_H31xx: | 433 | case Model_iPAQ_H31xx: |
428 | case Model_iPAQ_H36xx: | 434 | case Model_iPAQ_H36xx: |
429 | case Model_iPAQ_H37xx: | 435 | case Model_iPAQ_H37xx: |
430 | return 128; // really 256, but >128 could damage the LCD | 436 | return 128; // really 256, but >128 could damage the LCD |
431 | 437 | ||
432 | case Model_iPAQ_H38xx: | 438 | case Model_iPAQ_H38xx: |
433 | case Model_iPAQ_H39xx: | 439 | case Model_iPAQ_H39xx: |
434 | return 64; | 440 | return 64; |
435 | case Model_iPAQ_H5xxx: | 441 | case Model_iPAQ_H5xxx: |
436 | return 255; | 442 | return 255; |
437 | 443 | ||
438 | default: | 444 | default: |
439 | return 2; | 445 | return 2; |
440 | } | 446 | } |
441 | } | 447 | } |
442 | 448 | ||
443 | 449 | ||
444 | bool iPAQ::hasLightSensor() const | 450 | bool iPAQ::hasLightSensor() const |
445 | { | 451 | { |
446 | return true; | 452 | return true; |
447 | } | 453 | } |
448 | 454 | ||
449 | int iPAQ::readLightSensor() | 455 | int iPAQ::readLightSensor() |
450 | { | 456 | { |
451 | int fd; | 457 | int fd; |
452 | int val = -1; | 458 | int val = -1; |
453 | 459 | ||
454 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 460 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
455 | char buffer [8]; | 461 | char buffer [8]; |
456 | 462 | ||
457 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | 463 | if ( ::read ( fd, buffer, 5 ) == 5 ) { |
458 | char *endptr; | 464 | char *endptr; |
459 | 465 | ||
460 | buffer [4] = 0; | 466 | buffer [4] = 0; |
461 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 467 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
462 | 468 | ||
463 | if ( *endptr != 0 ) | 469 | if ( *endptr != 0 ) |
464 | val = -1; | 470 | val = -1; |
465 | } | 471 | } |
466 | ::close ( fd ); | 472 | ::close ( fd ); |
467 | } | 473 | } |
468 | 474 | ||
469 | return val; | 475 | return val; |
470 | } | 476 | } |
471 | 477 | ||
472 | int iPAQ::lightSensorResolution() const | 478 | int iPAQ::lightSensorResolution() const |
473 | { | 479 | { |
474 | return 256; | 480 | return 256; |
475 | } | 481 | } |