author | zecke <zecke> | 2004-11-04 21:53:57 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-11-04 21:53:57 (UTC) |
commit | 37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba (patch) (unidiff) | |
tree | b261ff83d2f7b77f8663d433b08b005aabd8c184 | |
parent | 5f56ab623c99c12ce246f775e065632fbfbbfc1f (diff) | |
download | opie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.zip opie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.tar.gz opie-37ff6dd391e4b6e0c537cd1d74e226dfdf1b86ba.tar.bz2 |
Use QTextStream and QFile instead of read/sscanf for parsing
ChipSelect3 (cs3). This should make it more robust
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index 9fde7f9..2e54216 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp | |||
@@ -1,402 +1,400 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_simpad.h" | 30 | #include "odevice_simpad.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | #include <qwidgetlist.h> | 37 | #include <qwidgetlist.h> |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/sound.h> | 42 | #include <qpe/sound.h> |
43 | #include <qpe/qcopenvelope_qws.h> | 43 | #include <qpe/qcopenvelope_qws.h> |
44 | #include <opie2/okeyfilter.h> | 44 | #include <opie2/okeyfilter.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | #include <fcntl.h> | 47 | #include <fcntl.h> |
48 | #include <math.h> | 48 | #include <math.h> |
49 | #include <stdlib.h> | 49 | #include <stdlib.h> |
50 | #include <signal.h> | 50 | #include <signal.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | #include <sys/time.h> | 52 | #include <sys/time.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #ifndef QT_NO_SOUND | 54 | #ifndef QT_NO_SOUND |
55 | #include <linux/soundcard.h> | 55 | #include <linux/soundcard.h> |
56 | #endif | 56 | #endif |
57 | 57 | ||
58 | namespace Opie { | 58 | namespace Opie { |
59 | namespace Core { | 59 | namespace Core { |
60 | namespace Internal { | 60 | namespace Internal { |
61 | namespace { | 61 | namespace { |
62 | struct s_button { | 62 | struct s_button { |
63 | uint model; | 63 | uint model; |
64 | Qt::Key code; | 64 | Qt::Key code; |
65 | char *utext; | 65 | char *utext; |
66 | char *pix; | 66 | char *pix; |
67 | char *fpressedservice; | 67 | char *fpressedservice; |
68 | char *fpressedaction; | 68 | char *fpressedaction; |
69 | char *fheldservice; | 69 | char *fheldservice; |
70 | char *fheldaction; | 70 | char *fheldaction; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static struct s_button simpad_buttons [] = { | 73 | static struct s_button simpad_buttons [] = { |
74 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 74 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
75 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), | 75 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), |
76 | "devicebuttons/simpad_lower_up", | 76 | "devicebuttons/simpad_lower_up", |
77 | "datebook", "nextView()", | 77 | "datebook", "nextView()", |
78 | "today", "raise()" }, | 78 | "today", "raise()" }, |
79 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 79 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
80 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), | 80 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), |
81 | "devicebuttons/simpad_lower_down", | 81 | "devicebuttons/simpad_lower_down", |
82 | "addressbook", "raise()", | 82 | "addressbook", "raise()", |
83 | "addressbook", "beamBusinessCard()" }, | 83 | "addressbook", "beamBusinessCard()" }, |
84 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 84 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
85 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), | 85 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), |
86 | "devicebuttons/simpad_lower_right", | 86 | "devicebuttons/simpad_lower_right", |
87 | "QPE/TaskBar", "toggleMenu()", | 87 | "QPE/TaskBar", "toggleMenu()", |
88 | "QPE/TaskBar", "toggleStartMenu()" }, | 88 | "QPE/TaskBar", "toggleStartMenu()" }, |
89 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 89 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
90 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), | 90 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), |
91 | "devicebuttons/simpad_lower_left", | 91 | "devicebuttons/simpad_lower_left", |
92 | "opiemail", "raise()", | 92 | "opiemail", "raise()", |
93 | "opiemail", "newMail()" }, | 93 | "opiemail", "newMail()" }, |
94 | 94 | ||
95 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 95 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
96 | Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), | 96 | Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), |
97 | "devicebuttons/simpad_upper_up", | 97 | "devicebuttons/simpad_upper_up", |
98 | "QPE/Launcher", "home()", | 98 | "QPE/Launcher", "home()", |
99 | "buttonsettings", "raise()" }, | 99 | "buttonsettings", "raise()" }, |
100 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 100 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
101 | Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), | 101 | Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), |
102 | "devicebuttons/simpad_upper_down", | 102 | "devicebuttons/simpad_upper_down", |
103 | "addressbook", "raise()", | 103 | "addressbook", "raise()", |
104 | "addressbook", "beamBusinessCard()" }, | 104 | "addressbook", "beamBusinessCard()" }, |
105 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 105 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
106 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), | 106 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), |
107 | "devicebuttons/simpad_upper_right", | 107 | "devicebuttons/simpad_upper_right", |
108 | "QPE/TaskBar", "toggleMenu()", | 108 | "QPE/TaskBar", "toggleMenu()", |
109 | "QPE/TaskBar", "toggleStartMenu()" }, | 109 | "QPE/TaskBar", "toggleStartMenu()" }, |
110 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 110 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
111 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), | 111 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), |
112 | "devicebuttons/simpad_upper_left", | 112 | "devicebuttons/simpad_upper_left", |
113 | "QPE/Rotation", "flip()", | 113 | "QPE/Rotation", "flip()", |
114 | "QPE/Rotation", "flip()" }, | 114 | "QPE/Rotation", "flip()" }, |
115 | /* | 115 | /* |
116 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 116 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
117 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | 117 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), |
118 | "devicebuttons/simpad_lower_upper", | 118 | "devicebuttons/simpad_lower_upper", |
119 | "QPE/Launcher", "home()", | 119 | "QPE/Launcher", "home()", |
120 | "buttonsettings", "raise()" }, | 120 | "buttonsettings", "raise()" }, |
121 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 121 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
122 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | 122 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), |
123 | "devicebuttons/simpad_upper_lower", | 123 | "devicebuttons/simpad_upper_lower", |
124 | "QPE/Launcher", "home()", | 124 | "QPE/Launcher", "home()", |
125 | "buttonsettings", "raise()" }, | 125 | "buttonsettings", "raise()" }, |
126 | */ | 126 | */ |
127 | }; | 127 | }; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | void SIMpad::init(const QString&) | 131 | void SIMpad::init(const QString&) |
132 | { | 132 | { |
133 | d->m_vendorstr = "SIEMENS"; | 133 | d->m_vendorstr = "SIEMENS"; |
134 | d->m_vendor = Vendor_SIEMENS; | 134 | d->m_vendor = Vendor_SIEMENS; |
135 | 135 | ||
136 | 136 | ||
137 | //TODO Implement model checking | 137 | //TODO Implement model checking |
138 | //FIXME For now we assume an SL4 | 138 | //FIXME For now we assume an SL4 |
139 | 139 | ||
140 | d->m_modelstr = "SL4"; | 140 | d->m_modelstr = "SL4"; |
141 | d->m_model = Model_SIMpad_SL4; | 141 | d->m_model = Model_SIMpad_SL4; |
142 | 142 | ||
143 | switch ( d->m_model ) { | 143 | switch ( d->m_model ) { |
144 | default: | 144 | default: |
145 | d->m_rotation = Rot0; | 145 | d->m_rotation = Rot0; |
146 | d->m_direction = CCW; | 146 | d->m_direction = CCW; |
147 | d->m_holdtime = 1000; // 1000ms | 147 | d->m_holdtime = 1000; // 1000ms |
148 | 148 | ||
149 | break; | 149 | break; |
150 | } | 150 | } |
151 | 151 | ||
152 | //Distribution detecting code is now in base class | 152 | //Distribution detecting code is now in base class |
153 | m_leds [0] = m_leds [1] = Led_Off; | 153 | m_leds [0] = m_leds [1] = Led_Off; |
154 | 154 | ||
155 | m_power_timer = 0; | 155 | m_power_timer = 0; |
156 | 156 | ||
157 | } | 157 | } |
158 | 158 | ||
159 | void SIMpad::initButtons() | 159 | void SIMpad::initButtons() |
160 | { | 160 | { |
161 | if ( d->m_buttons ) | 161 | if ( d->m_buttons ) |
162 | return; | 162 | return; |
163 | 163 | ||
164 | d->m_buttons = new QValueList <ODeviceButton>; | 164 | d->m_buttons = new QValueList <ODeviceButton>; |
165 | 165 | ||
166 | uint size = sizeof(simpad_buttons)/sizeof(s_button); | 166 | uint size = sizeof(simpad_buttons)/sizeof(s_button); |
167 | for ( uint i = 0; i < size; i++ ) { | 167 | for ( uint i = 0; i < size; i++ ) { |
168 | s_button *sb = simpad_buttons + i; | 168 | s_button *sb = simpad_buttons + i; |
169 | ODeviceButton b; | 169 | ODeviceButton b; |
170 | 170 | ||
171 | if (( sb->model & d->m_model ) == d->m_model ) { | 171 | if (( sb->model & d->m_model ) == d->m_model ) { |
172 | b. setKeycode ( sb->code ); | 172 | b. setKeycode ( sb->code ); |
173 | b. setUserText ( QObject::tr ( "Button", sb->utext )); | 173 | b. setUserText ( QObject::tr ( "Button", sb->utext )); |
174 | b. setPixmap ( Resource::loadPixmap ( sb->pix )); | 174 | b. setPixmap ( Resource::loadPixmap ( sb->pix )); |
175 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); | 175 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); |
176 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); | 176 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); |
177 | 177 | ||
178 | d->m_buttons->append ( b ); | 178 | d->m_buttons->append ( b ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | reloadButtonMapping(); | 181 | reloadButtonMapping(); |
182 | } | 182 | } |
183 | 183 | ||
184 | // SIMpad boardcontrol register CS3 | 184 | // SIMpad boardcontrol register CS3 |
185 | #define SIMPAD_BOARDCONTROL "/proc/cs3" | 185 | #define SIMPAD_BOARDCONTROL "/proc/cs3" |
186 | #define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA | 186 | #define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA |
187 | #define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA | 187 | #define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA |
188 | #define SIMPAD_EN1 0x0004 // This is only for EPROM's | 188 | #define SIMPAD_EN1 0x0004 // This is only for EPROM's |
189 | #define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V | 189 | #define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V |
190 | #define SIMPAD_DISPLAY_ON 0x0010 | 190 | #define SIMPAD_DISPLAY_ON 0x0010 |
191 | #define SIMPAD_PCMCIA_BUFF_DIS 0x0020 | 191 | #define SIMPAD_PCMCIA_BUFF_DIS 0x0020 |
192 | #define SIMPAD_MQ_RESET 0x0040 | 192 | #define SIMPAD_MQ_RESET 0x0040 |
193 | #define SIMPAD_PCMCIA_RESET 0x0080 | 193 | #define SIMPAD_PCMCIA_RESET 0x0080 |
194 | #define SIMPAD_DECT_POWER_ON 0x0100 | 194 | #define SIMPAD_DECT_POWER_ON 0x0100 |
195 | #define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave | 195 | #define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave |
196 | #define SIMPAD_RS232_ON 0x0400 | 196 | #define SIMPAD_RS232_ON 0x0400 |
197 | #define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave | 197 | #define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave |
198 | #define SIMPAD_LED2_ON 0x1000 | 198 | #define SIMPAD_LED2_ON 0x1000 |
199 | #define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode | 199 | #define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode |
200 | #define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit | 200 | #define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit |
201 | #define SIMPAD_RESET_SIMCARD 0x8000 | 201 | #define SIMPAD_RESET_SIMCARD 0x8000 |
202 | 202 | ||
203 | //SIMpad touchscreen backlight strength control | 203 | //SIMpad touchscreen backlight strength control |
204 | #define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/backlight" | 204 | #define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/backlight" |
205 | 205 | ||
206 | 206 | ||
207 | /* | 207 | /* |
208 | * The SIMpad exposes ChipSelect3 to userspace | 208 | * The SIMpad exposes ChipSelect3 to userspace |
209 | * via a proc filesystem file. Using this register | 209 | * via a proc filesystem file. Using this register |
210 | * one can toggle power of serial, irda, dect circuits | 210 | * one can toggle power of serial, irda, dect circuits |
211 | * change the video driver and display status and | 211 | * change the video driver and display status and |
212 | * many more things. | 212 | * many more things. |
213 | * To not lose the current setting we read the current | 213 | * To not lose the current setting we read the current |
214 | * cs3 setting and toggle the necessary bits and then | 214 | * cs3 setting and toggle the necessary bits and then |
215 | * write it. | 215 | * write it. |
216 | */ | 216 | */ |
217 | static bool setCS3Bit( bool bitset, int bit ) { | 217 | static bool setCS3Bit( bool bitset, int bit ) { |
218 | int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY ); | 218 | QFile file( SIMPAD_BOARDCONTROL ); |
219 | 219 | if ( !file.open( IO_ReadOnly ) ) | |
220 | if ( cs3_fd < 0 ) | ||
221 | return false; | 220 | return false; |
222 | 221 | ||
223 | static char line[32]; | 222 | unsigned int val = 0; |
224 | int val = 0; | 223 | bool ok = false; |
225 | bool ok = false; | 224 | QTextStream stream( &file ); |
226 | 225 | ||
227 | /* | 226 | /* |
228 | * try to read and parse the Chipselect3 status | 227 | * Use QFile and QTextStream for parsing to be more |
229 | * be paranoid and make sure line[31] is null | 228 | * robust |
230 | * terminated | ||
231 | */ | 229 | */ |
232 | while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) { | 230 | while ( !stream.atEnd() ) { |
233 | line[31] = '\0'; | 231 | QString line = stream.readLine(); |
234 | if (::sscanf(line, "Chipselect3 : %x", &val )) | 232 | if ( line.startsWith( "Chipselect3 : " ) ) { |
233 | val = line.mid( 15 ).toUInt( 0, 16 ); | ||
235 | ok = true; | 234 | ok = true; |
235 | break; | ||
236 | } | ||
236 | } | 237 | } |
237 | 238 | ||
238 | ::close(cs3_fd); | ||
239 | |||
240 | /* | ||
241 | * we were not able to find the current value | ||
242 | * and as a result we won't set it | ||
243 | */ | ||
244 | if ( !ok ) | 239 | if ( !ok ) |
245 | return false; | 240 | return false; |
246 | 241 | ||
242 | file.close(); | ||
243 | |||
247 | /* | 244 | /* |
248 | * change the value | 245 | * change the value |
249 | */ | 246 | */ |
250 | val = bitset ? (val | bit) : (val & ~bit); | 247 | val = bitset ? (val | bit) : (val & ~bit); |
251 | 248 | ||
252 | /* | 249 | /* |
253 | * write it back | 250 | * write it back |
254 | */ | 251 | */ |
255 | cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY ); | 252 | int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY ); |
256 | if ( cs3_fd < 0 ) | 253 | if ( cs3_fd < 0 ) |
257 | return false; | 254 | return false; |
258 | 255 | ||
256 | char line[32]; | ||
259 | ::snprintf(line, sizeof(line), "0x%04x\n", val); | 257 | ::snprintf(line, sizeof(line), "0x%04x\n", val); |
260 | ::write(cs3_fd, line, strlen(line)); | 258 | ::write(cs3_fd, line, strlen(line)); |
261 | ::close(cs3_fd); | 259 | ::close(cs3_fd); |
262 | 260 | ||
263 | return true; | 261 | return true; |
264 | } | 262 | } |
265 | 263 | ||
266 | 264 | ||
267 | QValueList <OLed> SIMpad::ledList() const | 265 | QValueList <OLed> SIMpad::ledList() const |
268 | { | 266 | { |
269 | QValueList <OLed> vl; | 267 | QValueList <OLed> vl; |
270 | vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? | 268 | vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? |
271 | //vl << Led_Mail; //TODO find out if LED1 is accessible anyway | 269 | //vl << Led_Mail; //TODO find out if LED1 is accessible anyway |
272 | return vl; | 270 | return vl; |
273 | } | 271 | } |
274 | 272 | ||
275 | QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const | 273 | QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const |
276 | { | 274 | { |
277 | QValueList <OLedState> vl; | 275 | QValueList <OLedState> vl; |
278 | 276 | ||
279 | if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? | 277 | if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? |
280 | vl << Led_Off << Led_On; | 278 | vl << Led_Off << Led_On; |
281 | //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway | 279 | //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway |
282 | //vl << Led_Off; | 280 | //vl << Led_Off; |
283 | return vl; | 281 | return vl; |
284 | } | 282 | } |
285 | 283 | ||
286 | OLedState SIMpad::ledState ( OLed l ) const | 284 | OLedState SIMpad::ledState ( OLed l ) const |
287 | { | 285 | { |
288 | switch ( l ) { | 286 | switch ( l ) { |
289 | case Led_Power: | 287 | case Led_Power: |
290 | return m_leds [0]; | 288 | return m_leds [0]; |
291 | //case Led_Mail: | 289 | //case Led_Mail: |
292 | // return m_leds [1]; | 290 | // return m_leds [1]; |
293 | default: | 291 | default: |
294 | return Led_Off; | 292 | return Led_Off; |
295 | } | 293 | } |
296 | } | 294 | } |
297 | 295 | ||
298 | bool SIMpad::setLedState ( OLed l, OLedState st ) | 296 | bool SIMpad::setLedState ( OLed l, OLedState st ) |
299 | { | 297 | { |
300 | if ( l == Led_Power ) { | 298 | if ( l == Led_Power ) { |
301 | m_leds [0] = st; | 299 | m_leds [0] = st; |
302 | setCS3Bit(st == Led_On, SIMPAD_LED2_ON); | 300 | setCS3Bit(st == Led_On, SIMPAD_LED2_ON); |
303 | return true; | 301 | return true; |
304 | } | 302 | } |
305 | 303 | ||
306 | return false; | 304 | return false; |
307 | } | 305 | } |
308 | 306 | ||
309 | void SIMpad::timerEvent ( QTimerEvent * ) | 307 | void SIMpad::timerEvent ( QTimerEvent * ) |
310 | { | 308 | { |
311 | killTimer ( m_power_timer ); | 309 | killTimer ( m_power_timer ); |
312 | m_power_timer = 0; | 310 | m_power_timer = 0; |
313 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 311 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
314 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 312 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
315 | } | 313 | } |
316 | 314 | ||
317 | 315 | ||
318 | void SIMpad::playAlarmSound() | 316 | void SIMpad::playAlarmSound() |
319 | { | 317 | { |
320 | #ifndef QT_NO_SOUND | 318 | #ifndef QT_NO_SOUND |
321 | static Sound snd ( "alarm" ); | 319 | static Sound snd ( "alarm" ); |
322 | if(!snd.isFinished()) | 320 | if(!snd.isFinished()) |
323 | return; | 321 | return; |
324 | 322 | ||
325 | /* save as the Sound is static! */ | 323 | /* save as the Sound is static! */ |
326 | changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd); | 324 | changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd); |
327 | snd. play(); | 325 | snd. play(); |
328 | #endif | 326 | #endif |
329 | } | 327 | } |
330 | 328 | ||
331 | 329 | ||
332 | bool SIMpad::suspend() // Must override because SIMpad does NOT have apm | 330 | bool SIMpad::suspend() // Must override because SIMpad does NOT have apm |
333 | { | 331 | { |
334 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 332 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
335 | return false; | 333 | return false; |
336 | 334 | ||
337 | bool res = ODevice::suspend(); | 335 | bool res = ODevice::suspend(); |
338 | 336 | ||
339 | /* | 337 | /* |
340 | * restore the screen content if we really | 338 | * restore the screen content if we really |
341 | * supended the device | 339 | * supended the device |
342 | */ | 340 | */ |
343 | if ( res ) | 341 | if ( res ) |
344 | updateAllWidgets(); | 342 | updateAllWidgets(); |
345 | 343 | ||
346 | return res; | 344 | return res; |
347 | } | 345 | } |
348 | 346 | ||
349 | bool SIMpad::setDisplayStatus ( bool on ) | 347 | bool SIMpad::setDisplayStatus ( bool on ) |
350 | { | 348 | { |
351 | qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); | 349 | qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); |
352 | 350 | ||
353 | return setCS3Bit(on, SIMPAD_DISPLAY_ON); | 351 | return setCS3Bit(on, SIMPAD_DISPLAY_ON); |
354 | } | 352 | } |
355 | 353 | ||
356 | 354 | ||
357 | bool SIMpad::setDisplayBrightness ( int bright ) | 355 | bool SIMpad::setDisplayBrightness ( int bright ) |
358 | { | 356 | { |
359 | qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); | 357 | qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); |
360 | bool res = false; | 358 | bool res = false; |
361 | int fd; | 359 | int fd; |
362 | 360 | ||
363 | if ( bright > 255 ) | 361 | if ( bright > 255 ) |
364 | bright = 255; | 362 | bright = 255; |
365 | if ( bright < 1 ) | 363 | if ( bright < 1 ) |
366 | bright = 0; | 364 | bright = 0; |
367 | 365 | ||
368 | if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { | 366 | if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { |
369 | QCString str = QFile::encodeName( QString::number(bright)); | 367 | QCString str = QFile::encodeName( QString::number(bright)); |
370 | res = ( ::write(fd, str, str.length()) != -1 ); | 368 | res = ( ::write(fd, str, str.length()) != -1 ); |
371 | ::close ( fd ); | 369 | ::close ( fd ); |
372 | } | 370 | } |
373 | return res; | 371 | return res; |
374 | } | 372 | } |
375 | 373 | ||
376 | 374 | ||
377 | int SIMpad::displayBrightnessResolution() const | 375 | int SIMpad::displayBrightnessResolution() const |
378 | { | 376 | { |
379 | return 255; // All SIMpad models share the same display | 377 | return 255; // All SIMpad models share the same display |
380 | } | 378 | } |
381 | 379 | ||
382 | 380 | ||
383 | /* | 381 | /* |
384 | * The MQ200 DRAM content is lost during suspend | 382 | * The MQ200 DRAM content is lost during suspend |
385 | * so we will just repaint every widget on resume | 383 | * so we will just repaint every widget on resume |
386 | */ | 384 | */ |
387 | void SIMpad::updateAllWidgets() { | 385 | void SIMpad::updateAllWidgets() { |
388 | QWidgetList *list = QApplication::allWidgets(); | 386 | QWidgetList *list = QApplication::allWidgets(); |
389 | QWidgetListIt it( *list ); | 387 | QWidgetListIt it( *list ); |
390 | QWidget *wid; | 388 | QWidget *wid; |
391 | 389 | ||
392 | while ((wid=it.current()) != 0 ) { | 390 | while ((wid=it.current()) != 0 ) { |
393 | wid->update(); | 391 | wid->update(); |
394 | ++it; | 392 | ++it; |
395 | } | 393 | } |
396 | 394 | ||
397 | delete list; | 395 | delete list; |
398 | } | 396 | } |
399 | 397 | ||
400 | } | 398 | } |
401 | } | 399 | } |
402 | } | 400 | } |