summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-15 00:03:10 (UTC)
committer zecke <zecke>2004-09-15 00:03:10 (UTC)
commitedc1f329044600c15cdccdacce2b2d6a776ca4ce (patch) (unidiff)
tree20cd9eebfd75e5c163f128adb7724c61adef1e27
parentd46a01de16c8ad65b00c76beda547970f7972b62 (diff)
downloadopie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.zip
opie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.tar.gz
opie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.tar.bz2
Patch by Till Harbum for SIMpad to more properly use the ChipSelect3
proc filesystem interface. Method introduced: setCS3Bit This method reads the current CS3 Bits before setting the new bit. Using this function allows to toggle the display without overwriting other CS3 bits for example the DECT_ON bit
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp87
1 files changed, 68 insertions, 19 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp
index 2d0160d..fd46b95 100644
--- a/libopie2/opiecore/device/odevice_simpad.cpp
+++ b/libopie2/opiecore/device/odevice_simpad.cpp
@@ -1,349 +1,398 @@
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 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/config.h> 39#include <qpe/config.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41#include <qpe/sound.h> 41#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#include <opie2/okeyfilter.h> 43#include <opie2/okeyfilter.h>
44 44
45/* STD */ 45/* STD */
46#include <fcntl.h> 46#include <fcntl.h>
47#include <math.h> 47#include <math.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <signal.h> 49#include <signal.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/time.h> 51#include <sys/time.h>
52#include <unistd.h> 52#include <unistd.h>
53#ifndef QT_NO_SOUND 53#ifndef QT_NO_SOUND
54#include <linux/soundcard.h> 54#include <linux/soundcard.h>
55#endif 55#endif
56 56
57using namespace Opie::Core; 57using namespace Opie::Core;
58using namespace Opie::Core::Internal; 58using namespace Opie::Core::Internal;
59 59
60struct s_button simpad_buttons [] = { 60struct s_button simpad_buttons [] = {
61 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 61 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
62 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), 62 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"),
63 "devicebuttons/simpad_lower_up", 63 "devicebuttons/simpad_lower_up",
64 "datebook", "nextView()", 64 "datebook", "nextView()",
65 "today", "raise()" }, 65 "today", "raise()" },
66 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 66 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
67 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), 67 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"),
68 "devicebuttons/simpad_lower_down", 68 "devicebuttons/simpad_lower_down",
69 "addressbook", "raise()", 69 "addressbook", "raise()",
70 "addressbook", "beamBusinessCard()" }, 70 "addressbook", "beamBusinessCard()" },
71 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 71 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
72 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), 72 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"),
73 "devicebuttons/simpad_lower_right", 73 "devicebuttons/simpad_lower_right",
74 "QPE/TaskBar", "toggleMenu()", 74 "QPE/TaskBar", "toggleMenu()",
75 "QPE/TaskBar", "toggleStartMenu()" }, 75 "QPE/TaskBar", "toggleStartMenu()" },
76 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 76 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
77 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), 77 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"),
78 "devicebuttons/simpad_lower_left", 78 "devicebuttons/simpad_lower_left",
79 "opiemail", "raise()", 79 "opiemail", "raise()",
80 "opiemail", "newMail()" }, 80 "opiemail", "newMail()" },
81 81
82 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 82 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
83 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), 83 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"),
84 "devicebuttons/simpad_upper_up", 84 "devicebuttons/simpad_upper_up",
85 "QPE/Launcher", "home()", 85 "QPE/Launcher", "home()",
86 "buttonsettings", "raise()" }, 86 "buttonsettings", "raise()" },
87 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 87 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
88 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), 88 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"),
89 "devicebuttons/simpad_upper_down", 89 "devicebuttons/simpad_upper_down",
90 "addressbook", "raise()", 90 "addressbook", "raise()",
91 "addressbook", "beamBusinessCard()" }, 91 "addressbook", "beamBusinessCard()" },
92 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 92 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
93 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), 93 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"),
94 "devicebuttons/simpad_upper_right", 94 "devicebuttons/simpad_upper_right",
95 "QPE/TaskBar", "toggleMenu()", 95 "QPE/TaskBar", "toggleMenu()",
96 "QPE/TaskBar", "toggleStartMenu()" }, 96 "QPE/TaskBar", "toggleStartMenu()" },
97 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 97 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
98 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), 98 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"),
99 "devicebuttons/simpad_upper_left", 99 "devicebuttons/simpad_upper_left",
100 "QPE/Rotation", "flip()", 100 "QPE/Rotation", "flip()",
101 "QPE/Rotation", "flip()" }, 101 "QPE/Rotation", "flip()" },
102 /* 102 /*
103 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 103 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
104 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 104 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
105 "devicebuttons/simpad_lower_upper", 105 "devicebuttons/simpad_lower_upper",
106 "QPE/Launcher", "home()", 106 "QPE/Launcher", "home()",
107 "buttonsettings", "raise()" }, 107 "buttonsettings", "raise()" },
108 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 108 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
109 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 109 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
110 "devicebuttons/simpad_upper_lower", 110 "devicebuttons/simpad_upper_lower",
111 "QPE/Launcher", "home()", 111 "QPE/Launcher", "home()",
112 "buttonsettings", "raise()" }, 112 "buttonsettings", "raise()" },
113 */ 113 */
114}; 114};
115 115
116void SIMpad::init(const QString&) 116void SIMpad::init(const QString&)
117{ 117{
118 d->m_vendorstr = "SIEMENS"; 118 d->m_vendorstr = "SIEMENS";
119 d->m_vendor = Vendor_SIEMENS; 119 d->m_vendor = Vendor_SIEMENS;
120 120
121 121
122 //TODO Implement model checking 122 //TODO Implement model checking
123 //FIXME For now we assume an SL4 123 //FIXME For now we assume an SL4
124 124
125 d->m_modelstr = "SL4"; 125 d->m_modelstr = "SL4";
126 d->m_model = Model_SIMpad_SL4; 126 d->m_model = Model_SIMpad_SL4;
127 127
128 switch ( d->m_model ) { 128 switch ( d->m_model ) {
129 default: 129 default:
130 d->m_rotation = Rot0; 130 d->m_rotation = Rot0;
131 d->m_direction = CCW; 131 d->m_direction = CCW;
132 d->m_holdtime = 1000; // 1000ms 132 d->m_holdtime = 1000; // 1000ms
133 133
134 break; 134 break;
135 } 135 }
136 136
137 //Distribution detecting code is now in base class 137 //Distribution detecting code is now in base class
138 m_leds [0] = m_leds [1] = Led_Off; 138 m_leds [0] = m_leds [1] = Led_Off;
139 139
140 m_power_timer = 0; 140 m_power_timer = 0;
141 141
142} 142}
143 143
144void SIMpad::initButtons() 144void SIMpad::initButtons()
145{ 145{
146 if ( d->m_buttons ) 146 if ( d->m_buttons )
147 return; 147 return;
148 148
149 if ( isQWS( ) ) { 149 if ( isQWS( ) ) {
150 addPreHandler(this); 150 addPreHandler(this);
151 } 151 }
152 152
153 153
154 d->m_buttons = new QValueList <ODeviceButton>; 154 d->m_buttons = new QValueList <ODeviceButton>;
155 155
156 for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { 156 for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) {
157 s_button *sb = simpad_buttons + i; 157 s_button *sb = simpad_buttons + i;
158 ODeviceButton b; 158 ODeviceButton b;
159 159
160 if (( sb->model & d->m_model ) == d->m_model ) { 160 if (( sb->model & d->m_model ) == d->m_model ) {
161 b. setKeycode ( sb->code ); 161 b. setKeycode ( sb->code );
162 b. setUserText ( QObject::tr ( "Button", sb->utext )); 162 b. setUserText ( QObject::tr ( "Button", sb->utext ));
163 b. setPixmap ( Resource::loadPixmap ( sb->pix )); 163 b. setPixmap ( Resource::loadPixmap ( sb->pix ));
164 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); 164 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction ));
165 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); 165 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction ));
166 166
167 d->m_buttons->append ( b ); 167 d->m_buttons->append ( b );
168 } 168 }
169 } 169 }
170 reloadButtonMapping(); 170 reloadButtonMapping();
171 171
172 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 172 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
173 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); 173 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&)));
174} 174}
175 175
176// SIMpad boardcontrol register CS3 176// SIMpad boardcontrol register CS3
177#define SIMPAD_BOARDCONTROL "/proc/cs3" 177#define SIMPAD_BOARDCONTROL "/proc/cs3"
178#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA 178#define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA
179#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA 179#define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA
180#define SIMPAD_EN1 0x0004 // This is only for EPROM's 180#define SIMPAD_EN1 0x0004 // This is only for EPROM's
181#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V 181#define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V
182#define SIMPAD_DISPLAY_ON 0x0010 182#define SIMPAD_DISPLAY_ON 0x0010
183#define SIMPAD_PCMCIA_BUFF_DIS 0x0020 183#define SIMPAD_PCMCIA_BUFF_DIS 0x0020
184#define SIMPAD_MQ_RESET 0x0040 184#define SIMPAD_MQ_RESET 0x0040
185#define SIMPAD_PCMCIA_RESET 0x0080 185#define SIMPAD_PCMCIA_RESET 0x0080
186#define SIMPAD_DECT_POWER_ON 0x0100 186#define SIMPAD_DECT_POWER_ON 0x0100
187#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave 187#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave
188#define SIMPAD_RS232_ON 0x0400 188#define SIMPAD_RS232_ON 0x0400
189#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave 189#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave
190#define SIMPAD_LED2_ON 0x1000 190#define SIMPAD_LED2_ON 0x1000
191#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode 191#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode
192#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit 192#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit
193#define SIMPAD_RESET_SIMCARD 0x8000 193#define SIMPAD_RESET_SIMCARD 0x8000
194 194
195//SIMpad touchscreen backlight strength control 195//SIMpad touchscreen backlight strength control
196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" 196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL"
197#define SIMPAD_BACKLIGHT_MASK 0x00a10044 197#define SIMPAD_BACKLIGHT_MASK 0x00a10044
198 198
199
200/*
201 * The SIMpad exposes ChipSelect3 to userspace
202 * via a proc filesystem file. Using this register
203 * one can toggle power of serial, irda, dect circuits
204 * change the video driver and display status and
205 * many more things.
206 * To not lose the current setting we read the current
207 * cs3 setting and toggle the necessary bits and then
208 * write it.
209 */
210static bool setCS3Bit( bool bitset, int bit ) {
211 int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY );
212
213 if ( cs3_fd < 0 )
214 return false;
215
216 static char line[32];
217 int val = 0;
218 bool ok = false;
219
220 /*
221 * try to read and parse the Chipselect3 status
222 * be paranoid and make sure line[31] is null
223 * terminated
224 */
225 while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) {
226 line[31] = '\0';
227 if (::sscanf(line, "Chipselect3 : %x", &val ))
228 ok = true;
229 }
230
231 ::close(cs3_fd);
232
233 /*
234 * we were not able to find the current value
235 * and as a result we won't set it
236 */
237 if ( !ok )
238 return false;
239
240 /*
241 * change the value
242 */
243 val = bitset ? (val | bit) : (val & ~bit);
244
245 /*
246 * write it back
247 */
248 cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY );
249 if ( cs3_fd < 0 )
250 return false;
251
252 ::snprintf(line, sizeof(line), "0x%04x\n", val);
253 ::write(cs3_fd, line, strlen(line));
254 ::close(cs3_fd);
255
256 return true;
257}
258
259
199QValueList <OLed> SIMpad::ledList() const 260QValueList <OLed> SIMpad::ledList() const
200{ 261{
201 QValueList <OLed> vl; 262 QValueList <OLed> vl;
202 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? 263 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one?
203 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway 264 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway
204 return vl; 265 return vl;
205} 266}
206 267
207QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const 268QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const
208{ 269{
209 QValueList <OLedState> vl; 270 QValueList <OLedState> vl;
210 271
211 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? 272 if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one?
212 vl << Led_Off << Led_On; 273 vl << Led_Off << Led_On;
213 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway 274 //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway
214 //vl << Led_Off; 275 //vl << Led_Off;
215 return vl; 276 return vl;
216} 277}
217 278
218OLedState SIMpad::ledState ( OLed l ) const 279OLedState SIMpad::ledState ( OLed l ) const
219{ 280{
220 switch ( l ) { 281 switch ( l ) {
221 case Led_Power: 282 case Led_Power:
222 return m_leds [0]; 283 return m_leds [0];
223 //case Led_Mail: 284 //case Led_Mail:
224 // return m_leds [1]; 285 // return m_leds [1];
225 default: 286 default:
226 return Led_Off; 287 return Led_Off;
227 } 288 }
228} 289}
229 290
230bool SIMpad::setLedState ( OLed l, OLedState st ) 291bool SIMpad::setLedState ( OLed l, OLedState st )
231{ 292{
232#if 0 293 if ( l == Led_Power ) {
233 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); 294 m_leds [0] = st;
234 295 setCS3Bit(st == Led_On, SIMPAD_LED2_ON);
235 /*TODO Implement this like that: 296 return true;
236 read from cs3 297 }
237 && with SIMPAD_LED2_ON 298
238 write to cs3 */
239 m_leds [0] = st;
240 return true;
241 // }
242// }
243#else
244 Q_UNUSED( l )
245 Q_UNUSED( st )
246#endif
247 return false; 299 return false;
248} 300}
249 301
250 302
251bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ ) 303bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ )
252{ 304{
253 //TODO 305 //TODO
254 return false; 306 return false;
255} 307}
256 308
257void SIMpad::timerEvent ( QTimerEvent * ) 309void SIMpad::timerEvent ( QTimerEvent * )
258{ 310{
259 killTimer ( m_power_timer ); 311 killTimer ( m_power_timer );
260 m_power_timer = 0; 312 m_power_timer = 0;
261 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 313 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
262 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 314 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
263} 315}
264 316
265 317
266void SIMpad::playAlarmSound() 318void SIMpad::playAlarmSound()
267{ 319{
268#ifndef QT_NO_SOUND 320#ifndef QT_NO_SOUND
269 static Sound snd ( "alarm" ); 321 static Sound snd ( "alarm" );
270 322
271 /* save as the Sound is static! */ 323 /* save as the Sound is static! */
272 changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd); 324 changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd);
273 snd. play(); 325 snd. play();
274#endif 326#endif
275} 327}
276 328
277 329
278bool SIMpad::suspend() // Must override because SIMpad does NOT have apm 330bool SIMpad::suspend() // Must override because SIMpad does NOT have apm
279{ 331{
280 qDebug( "ODevice for SIMpad: suspend()" ); 332 qDebug( "ODevice for SIMpad: suspend()" );
281 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 333 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
282 return false; 334 return false;
283 335
284 /* 336 /*
285 * we need to save the screen content 337 * we need to save the screen content
286 * then go to suspend using ODevice::suspend 338 * then go to suspend using ODevice::suspend
287 * and finally restore the screen content 339 * and finally restore the screen content
288 */ 340 */
289 (void)::system( "cat /dev/fb/0 > /tmp/.buffer" ); 341 (void)::system( "cat /dev/fb/0 > /tmp/.buffer" );
290 bool res = ODevice::suspend(); 342 bool res = ODevice::suspend();
291 343
292 /* 344 /*
293 * restore 345 * restore
294 */ 346 */
295 if ( res ) 347 if ( res )
296 ::system( "cat /tmp/.buffer > /dev/fb/0" ); 348 ::system( "cat /tmp/.buffer > /dev/fb/0" );
297 349
298 return res; 350 return res;
299} 351}
300 352
301 353
302bool SIMpad::setSoftSuspend ( bool soft ) 354bool SIMpad::setSoftSuspend ( bool soft )
303{ 355{
304 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); 356 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" );
305 return false; 357 return false;
306} 358}
307 359
308 360
309bool SIMpad::setDisplayStatus ( bool on ) 361bool SIMpad::setDisplayStatus ( bool on )
310{ 362{
311 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 363 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
312 364
313 365 return setCS3Bit(on, SIMPAD_DISPLAY_ON);
314 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
315
316 return ( ::system( (const char*) cmdline ) == 0 );
317} 366}
318 367
319 368
320bool SIMpad::setDisplayBrightness ( int bright ) 369bool SIMpad::setDisplayBrightness ( int bright )
321{ 370{
322 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); 371 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright );
323 bool res = false; 372 bool res = false;
324 int fd; 373 int fd;
325 374
326 if ( bright > 255 ) 375 if ( bright > 255 )
327 bright = 255; 376 bright = 255;
328 if ( bright < 1 ) 377 if ( bright < 1 )
329 bright = 0; 378 bright = 0;
330 379
331 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { 380 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) {
332 int value = 255 - bright; 381 int value = 255 - bright;
333 const int mask = SIMPAD_BACKLIGHT_MASK; 382 const int mask = SIMPAD_BACKLIGHT_MASK;
334 value = value << 8; 383 value = value << 8;
335 value += mask; 384 value += mask;
336 char writeCommand[100]; 385 char writeCommand[100];
337 const int count = snprintf( writeCommand, sizeof(writeCommand), "0x%x\n", value ); 386 const int count = snprintf( writeCommand, sizeof(writeCommand), "0x%x\n", value );
338 res = ( ::write ( fd, writeCommand, count ) != -1 ); 387 res = ( ::write ( fd, writeCommand, count ) != -1 );
339 ::close ( fd ); 388 ::close ( fd );
340 } 389 }
341 return res; 390 return res;
342} 391}
343 392
344 393
345int SIMpad::displayBrightnessResolution() const 394int SIMpad::displayBrightnessResolution() const
346{ 395{
347 return 255; // All SIMpad models share the same display 396 return 255; // All SIMpad models share the same display
348} 397}
349 398