Diffstat (limited to 'libopie2/opiecore/device/odevice_jornada.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiecore/device/odevice_jornada.cpp | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice_jornada.cpp b/libopie2/opiecore/device/odevice_jornada.cpp new file mode 100644 index 0000000..bcd03ed --- a/dev/null +++ b/libopie2/opiecore/device/odevice_jornada.cpp | |||
@@ -0,0 +1,214 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
4 | =. | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
30 | #include "odevice.h" | ||
31 | |||
32 | /* QT */ | ||
33 | #include <qapplication.h> | ||
34 | #include <qfile.h> | ||
35 | #include <qtextstream.h> | ||
36 | #include <qwindowsystem_qws.h> | ||
37 | |||
38 | /* OPIE */ | ||
39 | #include <qpe/config.h> | ||
40 | #include <qpe/resource.h> | ||
41 | #include <qpe/sound.h> | ||
42 | #include <qpe/qcopenvelope_qws.h> | ||
43 | |||
44 | /* STD */ | ||
45 | #include <fcntl.h> | ||
46 | #include <math.h> | ||
47 | #include <stdlib.h> | ||
48 | #include <signal.h> | ||
49 | #include <sys/ioctl.h> | ||
50 | #include <sys/time.h> | ||
51 | #include <unistd.h> | ||
52 | #ifndef QT_NO_SOUND | ||
53 | #include <linux/soundcard.h> | ||
54 | #endif | ||
55 | |||
56 | #ifndef ARRAY_SIZE | ||
57 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | ||
58 | #endif | ||
59 | |||
60 | // _IO and friends are only defined in kernel headers ... | ||
61 | |||
62 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | ||
63 | |||
64 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | ||
65 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | ||
66 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | ||
67 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | ||
68 | |||
69 | typedef struct { | ||
70 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | ||
71 | unsigned char TotalTime; /* Units of 5 seconds */ | ||
72 | unsigned char OnTime; /* units of 100m/s */ | ||
73 | unsigned char OffTime; /* units of 100m/s */ | ||
74 | } LED_IN; | ||
75 | |||
76 | typedef struct { | ||
77 | unsigned char mode; | ||
78 | unsigned char pwr; | ||
79 | unsigned char brightness; | ||
80 | } FLITE_IN; | ||
81 | |||
82 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | ||
83 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | ||
84 | |||
85 | using namespace Opie; | ||
86 | |||
87 | class Jornada : public ODevice | ||
88 | { | ||
89 | |||
90 | protected: | ||
91 | virtual void init(); | ||
92 | |||
93 | public: | ||
94 | virtual bool setSoftSuspend ( bool soft ); | ||
95 | virtual bool setDisplayBrightness ( int b ); | ||
96 | virtual int displayBrightnessResolution() const; | ||
97 | static bool isJornada(); | ||
98 | }; | ||
99 | |||
100 | |||
101 | bool Jornada::isJornada() | ||
102 | { | ||
103 | QFile f( "/proc/cpuinfo" ); | ||
104 | if ( f. open ( IO_ReadOnly ) ) { | ||
105 | QTextStream ts ( &f ); | ||
106 | QString line; | ||
107 | while( line = ts. readLine() ) { | ||
108 | if ( line. left ( 8 ) == "Hardware" ) { | ||
109 | int loc = line. find ( ":" ); | ||
110 | if ( loc != -1 ) { | ||
111 | QString model = line.mid( loc + 2 ).simplifyWhiteSpace( ); | ||
112 | return ( model == "HP Jornada 56x" ); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | return false; | ||
118 | } | ||
119 | |||
120 | void Jornada::init() | ||
121 | { | ||
122 | d->m_vendorstr = "HP"; | ||
123 | d->m_vendor = Vendor_HP; | ||
124 | d->m_modelstr = "Jornada 56x"; | ||
125 | d->m_model = Model_Jornada_56x; | ||
126 | d->m_systemstr = "Familiar"; | ||
127 | d->m_system = System_Familiar; | ||
128 | d->m_rotation = Rot0; | ||
129 | |||
130 | QFile f ( "/etc/familiar-version" ); | ||
131 | f. setName ( "/etc/familiar-version" ); | ||
132 | if ( f. open ( IO_ReadOnly )) { | ||
133 | |||
134 | QTextStream ts ( &f ); | ||
135 | d->m_sysverstr = ts. readLine(). mid ( 10 ); | ||
136 | |||
137 | f. close(); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | #if 0 | ||
142 | void Jornada::initButtons() | ||
143 | { | ||
144 | if ( d->m_buttons ) | ||
145 | return; | ||
146 | |||
147 | // Simulation uses iPAQ 3660 device buttons | ||
148 | |||
149 | qDebug ( "init Buttons" ); | ||
150 | d->m_buttons = new QValueList <ODeviceButton>; | ||
151 | |||
152 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
153 | i_button *ib = ipaq_buttons + i; | ||
154 | ODeviceButton b; | ||
155 | |||
156 | if (( ib->model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | ||
157 | b. setKeycode ( ib->code ); | ||
158 | b. setUserText ( QObject::tr ( "Button", ib->utext )); | ||
159 | b. setPixmap ( Resource::loadPixmap ( ib->pix )); | ||
160 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); | ||
161 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); | ||
162 | d->m_buttons->append ( b ); | ||
163 | } | ||
164 | } | ||
165 | reloadButtonMapping(); | ||
166 | |||
167 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
168 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | ||
169 | } | ||
170 | #endif | ||
171 | |||
172 | int Jornada::displayBrightnessResolution() const | ||
173 | { | ||
174 | } | ||
175 | |||
176 | bool Jornada::setDisplayBrightness( int bright ) | ||
177 | { | ||
178 | bool res = false; | ||
179 | int fd; | ||
180 | |||
181 | if ( bright > 255 ) | ||
182 | bright = 255; | ||
183 | if ( bright < 0 ) | ||
184 | bright = 0; | ||
185 | |||
186 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | ||
187 | FLITE_IN bl; | ||
188 | bl. mode = 1; | ||
189 | bl. pwr = bright ? 1 : 0; | ||
190 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | ||
191 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | ||
192 | ::close ( fd ); | ||
193 | } | ||
194 | return res; | ||
195 | } | ||
196 | |||
197 | bool Jornada::setSoftSuspend( bool soft ) | ||
198 | { | ||
199 | bool res = false; | ||
200 | int fd; | ||
201 | |||
202 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | ||
203 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | ||
204 | res = true; | ||
205 | else | ||
206 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | ||
207 | |||
208 | ::close ( fd ); | ||
209 | } | ||
210 | else | ||
211 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | ||
212 | |||
213 | return res; | ||
214 | } | ||