Diffstat (limited to 'libopie2/opiecore/device/odevice_mypal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.cpp | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp index 7e1245a..7eb8d1d 100644 --- a/libopie2/opiecore/device/odevice_mypal.cpp +++ b/libopie2/opiecore/device/odevice_mypal.cpp | |||
@@ -10,48 +10,49 @@ | |||
10 | - . .-<_> .<> Foundation; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_mypal.h" | 30 | #include "odevice_mypal.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qdir.h> | ||
34 | #include <qfile.h> | 35 | #include <qfile.h> |
35 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
37 | 38 | ||
38 | /* OPIE */ | 39 | /* OPIE */ |
39 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
40 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
41 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
42 | 43 | ||
43 | #include <opie2/okeyfilter.h> | 44 | #include <opie2/okeyfilter.h> |
44 | #include <opie2/oresource.h> | 45 | #include <opie2/oresource.h> |
45 | 46 | ||
46 | /* STD */ | 47 | /* STD */ |
47 | #include <fcntl.h> | 48 | #include <fcntl.h> |
48 | #include <math.h> | 49 | #include <math.h> |
49 | #include <stdlib.h> | 50 | #include <stdlib.h> |
50 | #include <signal.h> | 51 | #include <signal.h> |
51 | #include <sys/ioctl.h> | 52 | #include <sys/ioctl.h> |
52 | #include <sys/time.h> | 53 | #include <sys/time.h> |
53 | #include <unistd.h> | 54 | #include <unistd.h> |
54 | #ifndef QT_NO_SOUND | 55 | #ifndef QT_NO_SOUND |
55 | #include <linux/soundcard.h> | 56 | #include <linux/soundcard.h> |
56 | #endif | 57 | #endif |
57 | 58 | ||
@@ -185,68 +186,80 @@ void MyPal::timerEvent ( QTimerEvent * ) | |||
185 | } | 186 | } |
186 | 187 | ||
187 | 188 | ||
188 | void MyPal::playAlarmSound() | 189 | void MyPal::playAlarmSound() |
189 | { | 190 | { |
190 | #ifndef QT_NO_SOUND | 191 | #ifndef QT_NO_SOUND |
191 | static Sound snd ( "alarm" ); | 192 | static Sound snd ( "alarm" ); |
192 | if(!snd.isFinished()) | 193 | if(!snd.isFinished()) |
193 | return; | 194 | return; |
194 | 195 | ||
195 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | 196 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); |
196 | snd. play(); | 197 | snd. play(); |
197 | #endif | 198 | #endif |
198 | } | 199 | } |
199 | 200 | ||
200 | bool MyPal::setDisplayBrightness ( int bright ) | 201 | bool MyPal::setDisplayBrightness ( int bright ) |
201 | { | 202 | { |
202 | bool res = false; | 203 | bool res = false; |
203 | 204 | ||
204 | if ( bright > 255 ) | 205 | if ( bright > 255 ) |
205 | bright = 255; | 206 | bright = 255; |
206 | if ( bright < 0 ) | 207 | if ( bright < 0 ) |
207 | bright = 0; | 208 | bright = 0; |
208 | 209 | ||
209 | QString cmdline; | 210 | QDir sysClass( "/sys/class/backlight/pxafb/" ); |
210 | 211 | sysClass.setFilter(QDir::Dirs); | |
211 | switch ( model()) { | 212 | int fd; |
212 | case Model_MyPal_716: | 213 | if ( sysClass.exists() ) { |
213 | if ( !bright ) | 214 | QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); |
214 | cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); | 215 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); |
215 | else | 216 | if ( fd ) { |
216 | cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); | 217 | char buf[10]; |
217 | // No Global::shellQuote as we gurantee it to be sane | 218 | buf[0] = bright ? 0 : 4; |
218 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | 219 | buf[1] = '\0'; |
219 | break; | 220 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); |
220 | default: | 221 | ::close( fd ); |
221 | res = OAbstractMobileDevice::setDisplayBrightness(bright); | 222 | } |
223 | sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" ); | ||
224 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | ||
225 | if ( fd ) { | ||
226 | char buf[100]; | ||
227 | int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); | ||
228 | res = ( ::write( fd, &buf[0], len ) == 0 ); | ||
229 | ::close( fd ); | ||
230 | } | ||
222 | } | 231 | } |
223 | 232 | ||
224 | return res; | 233 | return res; |
225 | } | 234 | } |
226 | 235 | ||
227 | int MyPal::displayBrightnessResolution() const | 236 | int MyPal::displayBrightnessResolution() const |
228 | { | 237 | { |
229 | switch ( model()) { | 238 | switch ( model()) { |
230 | case Model_MyPal_716: | 239 | case Model_MyPal_716: |
231 | return 7; | 240 | return 7; |
232 | default: | 241 | default: |
233 | return OAbstractMobileDevice::displayBrightnessResolution(); | 242 | return OAbstractMobileDevice::displayBrightnessResolution(); |
234 | } | 243 | } |
235 | } | 244 | } |
236 | 245 | ||
237 | bool MyPal::setDisplayStatus ( bool on ) | 246 | bool MyPal::setDisplayStatus ( bool on ) |
238 | { | 247 | { |
239 | bool res = false; | 248 | bool res = false; |
240 | 249 | ||
241 | QString cmdline; | 250 | QDir sysClass( "/sys/class/lcd/" ); |
242 | 251 | sysClass.setFilter(QDir::Dirs); | |
243 | if ( model() == Model_MyPal_716 ) { | 252 | if ( sysClass.exists() ) { |
244 | cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" ); | 253 | QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); |
245 | } else { | 254 | int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); |
246 | return OAbstractMobileDevice::setDisplayStatus(on); | 255 | if ( fd ) { |
256 | char buf[10]; | ||
257 | buf[0] = on ? 0 : 4; | ||
258 | buf[1] = '\0'; | ||
259 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | ||
260 | ::close( fd ); | ||
261 | } | ||
247 | } | 262 | } |
248 | 263 | ||
249 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | ||
250 | |||
251 | return res; | 264 | return res; |
252 | } | 265 | } |