author | erik <erik> | 2007-02-08 01:15:31 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-08 01:15:31 (UTC) |
commit | c36a2e25a8875a31957968482ba8a0831a8b0aba (patch) (unidiff) | |
tree | 73c5f9231d3fe7157d814d8a948f27e31eb87c81 | |
parent | c4aaefcbe64cecb35f1f1bfa10337e95d8ae439c (diff) | |
download | opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.zip opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.tar.gz opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.tar.bz2 |
This commit provides support for any iPAQ handheld that runs a 2.6 kernel
and follows the backlight class in sysfs. This patch was originally done
by an unknown poster and maintained by Paul S. Thanks all who contributed.
-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 101 |
1 files changed, 44 insertions, 57 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 16ecc27..02b685a 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp | |||
@@ -16,527 +16,514 @@ | |||
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_ipaq.h" | 30 | #include "odevice_ipaq.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qdir.h> | 34 | #include <qdir.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
37 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | #include <opie2/okeyfilter.h> | 44 | #include <opie2/okeyfilter.h> |
45 | #include <opie2/oresource.h> | 45 | #include <opie2/oresource.h> |
46 | 46 | ||
47 | /* STD */ | 47 | /* STD */ |
48 | #include <fcntl.h> | 48 | #include <fcntl.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <signal.h> | 51 | #include <signal.h> |
52 | #include <sys/ioctl.h> | 52 | #include <sys/ioctl.h> |
53 | #include <sys/time.h> | 53 | #include <sys/time.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #ifndef QT_NO_SOUND | 55 | #ifndef QT_NO_SOUND |
56 | #include <linux/soundcard.h> | 56 | #include <linux/soundcard.h> |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | using namespace Opie::Core; | 60 | using namespace Opie::Core; |
61 | using namespace Opie::Core::Internal; | 61 | using namespace Opie::Core::Internal; |
62 | 62 | ||
63 | /* KERNEL */ | 63 | /* KERNEL */ |
64 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 64 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
65 | 65 | ||
66 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 66 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
67 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 67 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
68 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 68 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
69 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 69 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
70 | 70 | ||
71 | typedef struct { | 71 | typedef struct { |
72 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 72 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
73 | unsigned char TotalTime; /* Units of 5 seconds */ | 73 | unsigned char TotalTime; /* Units of 5 seconds */ |
74 | unsigned char OnTime; /* units of 100m/s */ | 74 | unsigned char OnTime; /* units of 100m/s */ |
75 | unsigned char OffTime; /* units of 100m/s */ | 75 | unsigned char OffTime; /* units of 100m/s */ |
76 | } LED_IN; | 76 | } LED_IN; |
77 | 77 | ||
78 | typedef struct { | 78 | typedef struct { |
79 | unsigned char mode; | 79 | unsigned char mode; |
80 | unsigned char pwr; | 80 | unsigned char pwr; |
81 | unsigned char brightness; | 81 | unsigned char brightness; |
82 | } FLITE_IN; | 82 | } FLITE_IN; |
83 | 83 | ||
84 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 84 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
85 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 85 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
86 | 86 | ||
87 | #define Model_Keyboardless_2_6 (Model_iPAQ_H191x | Model_iPAQ_H22xx | Model_iPAQ_HX4700 | Model_iPAQ_H4xxx) | 87 | #define Model_Keyboardless_2_6 (Model_iPAQ_H191x | Model_iPAQ_H22xx | Model_iPAQ_HX4700 | Model_iPAQ_H4xxx) |
88 | 88 | ||
89 | struct i_button ipaq_buttons [] = { | 89 | struct i_button ipaq_buttons [] = { |
90 | 90 | ||
91 | // Common button map for all keyboardless devices with 2.6 kernel | 91 | // Common button map for all keyboardless devices with 2.6 kernel |
92 | { Model_Keyboardless_2_6, | 92 | { Model_Keyboardless_2_6, |
93 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 93 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
94 | "devicebuttons/ipaq_calendar", | 94 | "devicebuttons/ipaq_calendar", |
95 | "datebook", "nextView()", | 95 | "datebook", "nextView()", |
96 | "today", "raise()" }, | 96 | "today", "raise()" }, |
97 | { Model_Keyboardless_2_6, | 97 | { Model_Keyboardless_2_6, |
98 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 98 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
99 | "devicebuttons/ipaq_contact", | 99 | "devicebuttons/ipaq_contact", |
100 | "addressbook", "raise()", | 100 | "addressbook", "raise()", |
101 | "addressbook", "beamBusinessCard()" }, | 101 | "addressbook", "beamBusinessCard()" }, |
102 | { Model_Keyboardless_2_6, | 102 | { Model_Keyboardless_2_6, |
103 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 103 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
104 | "devicebuttons/ipaq_mail", | 104 | "devicebuttons/ipaq_mail", |
105 | "opiemail", "raise()", | 105 | "opiemail", "raise()", |
106 | "opiemail", "newMail()" }, | 106 | "opiemail", "newMail()" }, |
107 | { Model_Keyboardless_2_6, | 107 | { Model_Keyboardless_2_6, |
108 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 108 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
109 | "devicebuttons/ipaq_home", | 109 | "devicebuttons/ipaq_home", |
110 | "QPE/Launcher", "home()", | 110 | "QPE/Launcher", "home()", |
111 | "buttonsettings", "raise()" }, | 111 | "buttonsettings", "raise()" }, |
112 | { Model_Keyboardless_2_6, | 112 | { Model_Keyboardless_2_6, |
113 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 113 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
114 | "devicebuttons/ipaq_record", | 114 | "devicebuttons/ipaq_record", |
115 | "QPE/VMemo", "toggleRecord()", | 115 | "QPE/VMemo", "toggleRecord()", |
116 | "sound", "raise()" }, | 116 | "sound", "raise()" }, |
117 | 117 | ||
118 | // Devices with 2.4 kernel | 118 | // Devices with 2.4 kernel |
119 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 119 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
120 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 120 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
121 | "devicebuttons/ipaq_calendar", | 121 | "devicebuttons/ipaq_calendar", |
122 | "datebook", "nextView()", | 122 | "datebook", "nextView()", |
123 | "today", "raise()" }, | 123 | "today", "raise()" }, |
124 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 124 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
125 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 125 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
126 | "devicebuttons/ipaq_contact", | 126 | "devicebuttons/ipaq_contact", |
127 | "addressbook", "raise()", | 127 | "addressbook", "raise()", |
128 | "addressbook", "beamBusinessCard()" }, | 128 | "addressbook", "beamBusinessCard()" }, |
129 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, | 129 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, |
130 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 130 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
131 | "devicebuttons/ipaq_menu", | 131 | "devicebuttons/ipaq_menu", |
132 | "QPE/TaskBar", "toggleMenu()", | 132 | "QPE/TaskBar", "toggleMenu()", |
133 | "QPE/TaskBar", "toggleStartMenu()" }, | 133 | "QPE/TaskBar", "toggleStartMenu()" }, |
134 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 134 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
135 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 135 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
136 | "devicebuttons/ipaq_mail", | 136 | "devicebuttons/ipaq_mail", |
137 | "opiemail", "raise()", | 137 | "opiemail", "raise()", |
138 | "opiemail", "newMail()" }, | 138 | "opiemail", "newMail()" }, |
139 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 139 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
140 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 140 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
141 | "devicebuttons/ipaq_home", | 141 | "devicebuttons/ipaq_home", |
142 | "QPE/Launcher", "home()", | 142 | "QPE/Launcher", "home()", |
143 | "buttonsettings", "raise()" }, | 143 | "buttonsettings", "raise()" }, |
144 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 144 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
145 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 145 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
146 | "devicebuttons/ipaq_record", | 146 | "devicebuttons/ipaq_record", |
147 | "QPE/VMemo", "toggleRecord()", | 147 | "QPE/VMemo", "toggleRecord()", |
148 | "sound", "raise()" }, | 148 | "sound", "raise()" }, |
149 | 149 | ||
150 | }; | 150 | }; |
151 | 151 | ||
152 | void iPAQ::init(const QString& model) | 152 | void iPAQ::init(const QString& model) |
153 | { | 153 | { |
154 | d->m_vendorstr = "HP"; | 154 | d->m_vendorstr = "HP"; |
155 | d->m_vendor = Vendor_HP; | 155 | d->m_vendor = Vendor_HP; |
156 | 156 | ||
157 | d->m_modelstr = model.mid(model.findRev('H')); | 157 | d->m_modelstr = model.mid(model.findRev('H')); |
158 | 158 | ||
159 | if ( d->m_modelstr == "H3100" ) | 159 | if ( d->m_modelstr == "H3100" ) |
160 | d->m_model = Model_iPAQ_H31xx; | 160 | d->m_model = Model_iPAQ_H31xx; |
161 | else if ( d->m_modelstr == "H3600" ) | 161 | else if ( d->m_modelstr == "H3600" ) |
162 | d->m_model = Model_iPAQ_H36xx; | 162 | d->m_model = Model_iPAQ_H36xx; |
163 | else if ( d->m_modelstr == "H3700" ) | 163 | else if ( d->m_modelstr == "H3700" ) |
164 | d->m_model = Model_iPAQ_H37xx; | 164 | d->m_model = Model_iPAQ_H37xx; |
165 | else if ( d->m_modelstr == "H3800" ) | 165 | else if ( d->m_modelstr == "H3800" ) |
166 | d->m_model = Model_iPAQ_H38xx; | 166 | d->m_model = Model_iPAQ_H38xx; |
167 | else if ( d->m_modelstr == "H3900" ) | 167 | else if ( d->m_modelstr == "H3900" ) |
168 | d->m_model = Model_iPAQ_H39xx; | 168 | d->m_model = Model_iPAQ_H39xx; |
169 | else if ( d->m_modelstr == "H5400" ) | 169 | else if ( d->m_modelstr == "H5400" ) |
170 | d->m_model = Model_iPAQ_H5xxx; | 170 | d->m_model = Model_iPAQ_H5xxx; |
171 | else if ( d->m_modelstr == "H2200" ) | 171 | else if ( d->m_modelstr == "H2200" ) |
172 | d->m_model = Model_iPAQ_H22xx; | 172 | d->m_model = Model_iPAQ_H22xx; |
173 | else if ( d->m_modelstr == "H1910" ) | 173 | else if ( d->m_modelstr == "H1910" ) |
174 | d->m_model = Model_iPAQ_H191x; | 174 | d->m_model = Model_iPAQ_H191x; |
175 | else if ( d->m_modelstr == "H1940" ) | 175 | else if ( d->m_modelstr == "H1940" ) |
176 | d->m_model = Model_iPAQ_H1940; | 176 | d->m_model = Model_iPAQ_H1940; |
177 | else if ( d->m_modelstr == "HX4700" ) | 177 | else if ( d->m_modelstr == "HX4700" ) |
178 | d->m_model = Model_iPAQ_HX4700; | 178 | d->m_model = Model_iPAQ_HX4700; |
179 | else if ( d->m_modelstr == "H4000" ) | 179 | else if ( d->m_modelstr == "H4000" ) |
180 | d->m_model = Model_iPAQ_H4xxx; | 180 | d->m_model = Model_iPAQ_H4xxx; |
181 | 181 | ||
182 | else | 182 | else |
183 | d->m_model = Model_Unknown; | 183 | d->m_model = Model_Unknown; |
184 | 184 | ||
185 | switch ( d->m_model ) { | 185 | switch ( d->m_model ) { |
186 | case Model_iPAQ_H31xx: | 186 | case Model_iPAQ_H31xx: |
187 | case Model_iPAQ_H38xx: | 187 | case Model_iPAQ_H38xx: |
188 | d->m_rotation = Rot90; | 188 | d->m_rotation = Rot90; |
189 | break; | 189 | break; |
190 | case Model_iPAQ_H5xxx: | 190 | case Model_iPAQ_H5xxx: |
191 | case Model_iPAQ_H22xx: | 191 | case Model_iPAQ_H22xx: |
192 | case Model_iPAQ_H191x: | 192 | case Model_iPAQ_H191x: |
193 | case Model_iPAQ_H1940: | 193 | case Model_iPAQ_H1940: |
194 | case Model_iPAQ_HX4700: | 194 | case Model_iPAQ_HX4700: |
195 | case Model_iPAQ_H4xxx: | 195 | case Model_iPAQ_H4xxx: |
196 | d->m_rotation = Rot0; | 196 | d->m_rotation = Rot0; |
197 | break; | 197 | break; |
198 | case Model_iPAQ_H36xx: | 198 | case Model_iPAQ_H36xx: |
199 | case Model_iPAQ_H37xx: | 199 | case Model_iPAQ_H37xx: |
200 | case Model_iPAQ_H39xx: | 200 | case Model_iPAQ_H39xx: |
201 | default: | 201 | default: |
202 | d->m_rotation = Rot270; | 202 | d->m_rotation = Rot270; |
203 | break; | 203 | break; |
204 | 204 | ||
205 | } | 205 | } |
206 | 206 | ||
207 | m_leds [0] = m_leds [1] = Led_Off; | 207 | m_leds [0] = m_leds [1] = Led_Off; |
208 | 208 | ||
209 | m_power_timer = 0; | 209 | m_power_timer = 0; |
210 | 210 | ||
211 | } | 211 | } |
212 | 212 | ||
213 | void iPAQ::initButtons() | 213 | void iPAQ::initButtons() |
214 | { | 214 | { |
215 | if ( d->m_buttons ) | 215 | if ( d->m_buttons ) |
216 | return; | 216 | return; |
217 | 217 | ||
218 | if ( isQWS( ) ) { | 218 | if ( isQWS( ) ) { |
219 | addPreHandler(this); | 219 | addPreHandler(this); |
220 | } | 220 | } |
221 | 221 | ||
222 | d->m_buttons = new QValueList <ODeviceButton>; | 222 | d->m_buttons = new QValueList <ODeviceButton>; |
223 | 223 | ||
224 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 224 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
225 | i_button *ib = ipaq_buttons + i; | 225 | i_button *ib = ipaq_buttons + i; |
226 | ODeviceButton b; | 226 | ODeviceButton b; |
227 | 227 | ||
228 | if (( ib->model & d->m_model ) == d->m_model ) { | 228 | if (( ib->model & d->m_model ) == d->m_model ) { |
229 | b. setKeycode ( ib->code ); | 229 | b. setKeycode ( ib->code ); |
230 | b. setUserText ( QObject::tr ( "Button", ib->utext )); | 230 | b. setUserText ( QObject::tr ( "Button", ib->utext )); |
231 | b. setPixmap ( OResource::loadPixmap ( ib->pix )); | 231 | b. setPixmap ( OResource::loadPixmap ( ib->pix )); |
232 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); | 232 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); |
233 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); | 233 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); |
234 | 234 | ||
235 | d->m_buttons->append ( b ); | 235 | d->m_buttons->append ( b ); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | reloadButtonMapping(); | 238 | reloadButtonMapping(); |
239 | } | 239 | } |
240 | 240 | ||
241 | QValueList <OLed> iPAQ::ledList() const | 241 | QValueList <OLed> iPAQ::ledList() const |
242 | { | 242 | { |
243 | QValueList <OLed> vl; | 243 | QValueList <OLed> vl; |
244 | vl << Led_Power; | 244 | vl << Led_Power; |
245 | 245 | ||
246 | if ( d->m_model == Model_iPAQ_H38xx ) | 246 | if ( d->m_model == Model_iPAQ_H38xx ) |
247 | vl << Led_BlueTooth; | 247 | vl << Led_BlueTooth; |
248 | return vl; | 248 | return vl; |
249 | } | 249 | } |
250 | 250 | ||
251 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | 251 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const |
252 | { | 252 | { |
253 | QValueList <OLedState> vl; | 253 | QValueList <OLedState> vl; |
254 | 254 | ||
255 | if ( l == Led_Power ) | 255 | if ( l == Led_Power ) |
256 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | 256 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; |
257 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) | 257 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) |
258 | vl << Led_Off; // << Led_On << ??? | 258 | vl << Led_Off; // << Led_On << ??? |
259 | 259 | ||
260 | return vl; | 260 | return vl; |
261 | } | 261 | } |
262 | 262 | ||
263 | OLedState iPAQ::ledState ( OLed l ) const | 263 | OLedState iPAQ::ledState ( OLed l ) const |
264 | { | 264 | { |
265 | switch ( l ) { | 265 | switch ( l ) { |
266 | case Led_Power: | 266 | case Led_Power: |
267 | return m_leds [0]; | 267 | return m_leds [0]; |
268 | case Led_BlueTooth: | 268 | case Led_BlueTooth: |
269 | return m_leds [1]; | 269 | return m_leds [1]; |
270 | default: | 270 | default: |
271 | return Led_Off; | 271 | return Led_Off; |
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
275 | bool iPAQ::setLedState ( OLed l, OLedState st ) | 275 | bool iPAQ::setLedState ( OLed l, OLedState st ) |
276 | { | 276 | { |
277 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); | 277 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); |
278 | 278 | ||
279 | if ( l == Led_Power ) { | 279 | if ( l == Led_Power ) { |
280 | if ( fd >= 0 ) { | 280 | if ( fd >= 0 ) { |
281 | LED_IN leds; | 281 | LED_IN leds; |
282 | ::memset ( &leds, 0, sizeof( leds )); | 282 | ::memset ( &leds, 0, sizeof( leds )); |
283 | leds. TotalTime = 0; | 283 | leds. TotalTime = 0; |
284 | leds. OnTime = 0; | 284 | leds. OnTime = 0; |
285 | leds. OffTime = 1; | 285 | leds. OffTime = 1; |
286 | leds. OffOnBlink = 2; | 286 | leds. OffOnBlink = 2; |
287 | 287 | ||
288 | switch ( st ) { | 288 | switch ( st ) { |
289 | case Led_Off : leds. OffOnBlink = 0; break; | 289 | case Led_Off : leds. OffOnBlink = 0; break; |
290 | case Led_On : leds. OffOnBlink = 1; break; | 290 | case Led_On : leds. OffOnBlink = 1; break; |
291 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | 291 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; |
292 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | 292 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; |
293 | } | 293 | } |
294 | 294 | ||
295 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | 295 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { |
296 | m_leds [0] = st; | 296 | m_leds [0] = st; |
297 | return true; | 297 | return true; |
298 | } | 298 | } |
299 | } | 299 | } |
300 | } | 300 | } |
301 | return false; | 301 | return false; |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 305 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
306 | { | 306 | { |
307 | int newkeycode = keycode; | 307 | int newkeycode = keycode; |
308 | 308 | ||
309 | switch ( keycode ) { | 309 | switch ( keycode ) { |
310 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key | 310 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key |
311 | case HardKey_Menu: { | 311 | case HardKey_Menu: { |
312 | if (( d->m_model == Model_iPAQ_H38xx ) || | 312 | if (( d->m_model == Model_iPAQ_H38xx ) || |
313 | ( d->m_model == Model_iPAQ_H39xx ) || | 313 | ( d->m_model == Model_iPAQ_H39xx ) || |
314 | ( d->m_model == Model_iPAQ_H5xxx)) { | 314 | ( d->m_model == Model_iPAQ_H5xxx)) { |
315 | newkeycode = HardKey_Mail; | 315 | newkeycode = HardKey_Mail; |
316 | } | 316 | } |
317 | break; | 317 | break; |
318 | } | 318 | } |
319 | 319 | ||
320 | // Rotate cursor keys 180 or 270 | 320 | // Rotate cursor keys 180 or 270 |
321 | case Key_Left : | 321 | case Key_Left : |
322 | case Key_Right: | 322 | case Key_Right: |
323 | case Key_Up : | 323 | case Key_Up : |
324 | case Key_Down : { | 324 | case Key_Down : { |
325 | if (( d->m_model == Model_iPAQ_H31xx ) || | 325 | if (( d->m_model == Model_iPAQ_H31xx ) || |
326 | ( d->m_model == Model_iPAQ_H38xx )) { | 326 | ( d->m_model == Model_iPAQ_H38xx )) { |
327 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; | 327 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; |
328 | } | 328 | } |
329 | // Rotate the cursor keys by 270 | 329 | // Rotate the cursor keys by 270 |
330 | // keycode - Key_Left = position of the button starting from left clockwise | 330 | // keycode - Key_Left = position of the button starting from left clockwise |
331 | // add the rotation to it and modolo. No we've the original offset | 331 | // add the rotation to it and modolo. No we've the original offset |
332 | // add the offset to the Key_Left key | 332 | // add the offset to the Key_Left key |
333 | if (( d->m_model == Model_iPAQ_H5xxx ) || | 333 | if (( d->m_model == Model_iPAQ_H5xxx ) || |
334 | ( d->m_model == Model_iPAQ_H191x ) || | 334 | ( d->m_model == Model_iPAQ_H191x ) || |
335 | ( d->m_model == Model_iPAQ_H4xxx ) || | 335 | ( d->m_model == Model_iPAQ_H4xxx ) || |
336 | ( d->m_model == Model_iPAQ_H1940 )) | 336 | ( d->m_model == Model_iPAQ_H1940 )) |
337 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; | 337 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; |
338 | break; | 338 | break; |
339 | } | 339 | } |
340 | 340 | ||
341 | // map Power Button short/long press to F34/F35 | 341 | // map Power Button short/long press to F34/F35 |
342 | case HardKey_Suspend: // Hope we don't have infinite recursion here | 342 | case HardKey_Suspend: // Hope we don't have infinite recursion here |
343 | case Key_SysReq: { | 343 | case Key_SysReq: { |
344 | if ( isPress ) { | 344 | if ( isPress ) { |
345 | if ( m_power_timer ) | 345 | if ( m_power_timer ) |
346 | killTimer ( m_power_timer ); | 346 | killTimer ( m_power_timer ); |
347 | m_power_timer = startTimer ( 500 ); | 347 | m_power_timer = startTimer ( 500 ); |
348 | } | 348 | } |
349 | else if ( m_power_timer ) { | 349 | else if ( m_power_timer ) { |
350 | killTimer ( m_power_timer ); | 350 | killTimer ( m_power_timer ); |
351 | m_power_timer = 0; | 351 | m_power_timer = 0; |
352 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 352 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
353 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 353 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
354 | } | 354 | } |
355 | newkeycode = Key_unknown; | 355 | newkeycode = Key_unknown; |
356 | break; | 356 | break; |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | if ( newkeycode != keycode ) { | 360 | if ( newkeycode != keycode ) { |
361 | if ( newkeycode != Key_unknown ) | 361 | if ( newkeycode != Key_unknown ) |
362 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 362 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
363 | return true; | 363 | return true; |
364 | } | 364 | } |
365 | else | 365 | else |
366 | return false; | 366 | return false; |
367 | } | 367 | } |
368 | 368 | ||
369 | void iPAQ::timerEvent ( QTimerEvent * ) | 369 | void iPAQ::timerEvent ( QTimerEvent * ) |
370 | { | 370 | { |
371 | killTimer ( m_power_timer ); | 371 | killTimer ( m_power_timer ); |
372 | m_power_timer = 0; | 372 | m_power_timer = 0; |
373 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 373 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
374 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 374 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
378 | void iPAQ::playAlarmSound() | 378 | void iPAQ::playAlarmSound() |
379 | { | 379 | { |
380 | #ifndef QT_NO_SOUND | 380 | #ifndef QT_NO_SOUND |
381 | static Sound snd ( "alarm" ); | 381 | static Sound snd ( "alarm" ); |
382 | if(!snd.isFinished()) | 382 | if(!snd.isFinished()) |
383 | return; | 383 | return; |
384 | 384 | ||
385 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | 385 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); |
386 | snd. play(); | 386 | snd. play(); |
387 | #endif | 387 | #endif |
388 | } | 388 | } |
389 | 389 | ||
390 | bool iPAQ::setDisplayBrightness ( int bright ) | 390 | bool iPAQ::setDisplayBrightness ( int bright ) |
391 | { | 391 | { |
392 | bool res = false; | 392 | bool res = false; |
393 | int fd; | 393 | int fd; |
394 | 394 | ||
395 | if ( bright > 255 ) | 395 | if ( bright > 255 ) |
396 | bright = 255; | 396 | bright = 255; |
397 | if ( bright < 0 ) | 397 | if ( bright < 0 ) |
398 | bright = 0; | 398 | bright = 0; |
399 | 399 | ||
400 | QString cmdline; | 400 | QDir sysClass( "/sys/class/backlight/" ); |
401 | 401 | sysClass.setFilter(QDir::Dirs); | |
402 | switch ( model()) { | 402 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
403 | case Model_iPAQ_H191x: | 403 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); |
404 | case Model_iPAQ_H4xxx: | 404 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
405 | { | 405 | if ( fd ) { |
406 | QDir sysClass( "/sys/class/backlight/pxafb/" ); | 406 | char buf[100]; |
407 | sysClass.setFilter(QDir::Dirs); | 407 | int val = bright * displayBrightnessResolution() / 255; |
408 | int fd; | 408 | int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); |
409 | if ( sysClass.exists() ) { | 409 | res = ( ::write( fd, &buf[0], len ) == 0 ); |
410 | QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); | 410 | ::close( fd ); |
411 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | 411 | } |
412 | if ( fd ) { | 412 | } else { |
413 | char buf[10]; | ||
414 | buf[0] = bright ? 0 : 4; | ||
415 | buf[1] = '\0'; | ||
416 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | ||
417 | ::close( fd ); | ||
418 | } | ||
419 | sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" ); | ||
420 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | ||
421 | if ( fd ) { | ||
422 | char buf[100]; | ||
423 | int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); | ||
424 | res = ( ::write( fd, &buf[0], len ) == 0 ); | ||
425 | ::close( fd ); | ||
426 | } | ||
427 | } | ||
428 | } | ||
429 | break; | ||
430 | |||
431 | case Model_iPAQ_HX4700: | ||
432 | cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright ); | ||
433 | // No Global::shellQuote as we gurantee it to be sane | ||
434 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | ||
435 | break; | ||
436 | |||
437 | |||
438 | default: | ||
439 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 413 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
440 | FLITE_IN bl; | 414 | FLITE_IN bl; |
441 | bl. mode = 1; | 415 | bl. mode = 1; |
442 | bl. pwr = bright ? 1 : 0; | 416 | bl. pwr = bright ? 1 : 0; |
443 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | 417 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; |
444 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 418 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
445 | ::close ( fd ); | 419 | ::close ( fd ); |
446 | } | 420 | } |
447 | } | 421 | } |
422 | |||
448 | return res; | 423 | return res; |
449 | } | 424 | } |
450 | 425 | ||
451 | int iPAQ::displayBrightnessResolution() const | 426 | int iPAQ::displayBrightnessResolution() const |
452 | { | 427 | { |
428 | int res = 16; | ||
429 | |||
430 | QDir sysClass( "/sys/class/backlight/" ); | ||
431 | sysClass.setFilter(QDir::Dirs); | ||
432 | if ( sysClass.exists() && sysClass.count() > 2 ) { | ||
433 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); | ||
434 | int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK ); | ||
435 | if ( fd ) { | ||
436 | char buf[100]; | ||
437 | if ( ::read( fd, &buf[0], sizeof buf ) ) | ||
438 | ::sscanf( &buf[0], "%d", &res ); | ||
439 | ::close( fd ); | ||
440 | } | ||
441 | return res; | ||
442 | } | ||
443 | |||
453 | switch ( model()) { | 444 | switch ( model()) { |
454 | case Model_iPAQ_H31xx: | 445 | case Model_iPAQ_H31xx: |
455 | case Model_iPAQ_H36xx: | 446 | case Model_iPAQ_H36xx: |
456 | case Model_iPAQ_H37xx: | 447 | case Model_iPAQ_H37xx: |
457 | return 128; // really 256, but >128 could damage the LCD | 448 | return 128; // really 256, but >128 could damage the LCD |
458 | 449 | ||
459 | case Model_iPAQ_H38xx: | 450 | case Model_iPAQ_H38xx: |
460 | case Model_iPAQ_H39xx: | 451 | case Model_iPAQ_H39xx: |
461 | return 64; | 452 | return 64; |
462 | case Model_iPAQ_H5xxx: | 453 | case Model_iPAQ_H5xxx: |
463 | case Model_iPAQ_HX4700: | 454 | case Model_iPAQ_HX4700: |
464 | case Model_iPAQ_H4xxx: | 455 | case Model_iPAQ_H4xxx: |
465 | return 255; | 456 | return 255; |
466 | case Model_iPAQ_H191x: | 457 | case Model_iPAQ_H191x: |
467 | return 7; | 458 | return 7; |
468 | case Model_iPAQ_H1940: | 459 | case Model_iPAQ_H1940: |
469 | return 44; | 460 | return 44; |
470 | default: | 461 | default: |
471 | return 2; | 462 | return 2; |
472 | } | 463 | } |
473 | } | 464 | } |
474 | 465 | ||
475 | bool iPAQ::setDisplayStatus ( bool on ) | 466 | bool iPAQ::setDisplayStatus ( bool on ) |
476 | { | 467 | { |
477 | bool res = false; | 468 | bool res = false; |
478 | 469 | ||
479 | QString cmdline; | 470 | QString cmdline; |
480 | 471 | ||
481 | if ( model() == Model_iPAQ_H191x ) { | 472 | QDir sysClass( "/sys/class/lcd/" ); |
482 | QDir sysClass( "/sys/class/lcd/pxafb/" ); | 473 | sysClass.setFilter(QDir::Dirs); |
483 | sysClass.setFilter(QDir::Dirs); | 474 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
484 | if ( sysClass.exists() ) { | 475 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); |
485 | QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); | 476 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
486 | int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | 477 | if ( fd ) { |
487 | if ( fd ) { | 478 | char buf[10]; |
488 | char buf[10]; | 479 | buf[0] = on ? 0 : 4; |
489 | buf[0] = on ? 0 : 4; | 480 | buf[1] = '\0'; |
490 | buf[1] = '\0'; | 481 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); |
491 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | 482 | ::close( fd ); |
492 | ::close( fd ); | 483 | } |
493 | } | ||
494 | } | ||
495 | return res; | ||
496 | } else { | 484 | } else { |
497 | return OAbstractMobileDevice::setDisplayStatus(on); | 485 | res = OAbstractMobileDevice::setDisplayStatus(on); |
498 | } | 486 | } |
499 | 487 | ||
500 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | ||
501 | |||
502 | return res; | 488 | return res; |
503 | } | 489 | } |
504 | 490 | ||
505 | bool iPAQ::hasLightSensor() const | 491 | bool iPAQ::hasLightSensor() const |
506 | { | 492 | { |
507 | switch (model()) { | 493 | switch (model()) { |
508 | case Model_iPAQ_H191x: | 494 | case Model_iPAQ_H191x: |
495 | case Model_iPAQ_H22xx: | ||
509 | case Model_iPAQ_H4xxx: | 496 | case Model_iPAQ_H4xxx: |
510 | return false; | 497 | return false; |
511 | default: | 498 | default: |
512 | return true; | 499 | return true; |
513 | } | 500 | } |
514 | } | 501 | } |
515 | 502 | ||
516 | int iPAQ::readLightSensor() | 503 | int iPAQ::readLightSensor() |
517 | { | 504 | { |
518 | int fd; | 505 | int fd; |
519 | int val = -1; | 506 | int val = -1; |
520 | 507 | ||
521 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 508 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
522 | char buffer [8]; | 509 | char buffer [8]; |
523 | 510 | ||
524 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | 511 | if ( ::read ( fd, buffer, 5 ) == 5 ) { |
525 | char *endptr; | 512 | char *endptr; |
526 | 513 | ||
527 | buffer [4] = 0; | 514 | buffer [4] = 0; |
528 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 515 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
529 | 516 | ||
530 | if ( *endptr != 0 ) | 517 | if ( *endptr != 0 ) |
531 | val = -1; | 518 | val = -1; |
532 | } | 519 | } |
533 | ::close ( fd ); | 520 | ::close ( fd ); |
534 | } | 521 | } |
535 | 522 | ||
536 | return val; | 523 | return val; |
537 | } | 524 | } |
538 | 525 | ||
539 | int iPAQ::lightSensorResolution() const | 526 | int iPAQ::lightSensorResolution() const |
540 | { | 527 | { |
541 | return 256; | 528 | return 256; |
542 | } | 529 | } |