summaryrefslogtreecommitdiff
authorsandman <sandman>2002-07-27 22:45:04 (UTC)
committer sandman <sandman>2002-07-27 22:45:04 (UTC)
commit9cc89b6a54ee267953b0422c4607097d075ecab9 (patch) (unidiff)
tree4bde48d162a97ef74cf9e276c0194b8138fb4e0c
parentdac5c073c3e04ceb6900aeb72e53cf6d7350c3c9 (diff)
downloadopie-9cc89b6a54ee267953b0422c4607097d075ecab9.zip
opie-9cc89b6a54ee267953b0422c4607097d075ecab9.tar.gz
opie-9cc89b6a54ee267953b0422c4607097d075ecab9.tar.bz2
Small extension to read the system version
(currently only functional for familiar)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp16
-rw-r--r--libopie/odevice.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 9931684..bc8014a 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,279 +1,293 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qfile.h> 20#include <qfile.h>
21#include <qtextstream.h> 21#include <qtextstream.h>
22#include <qpe/sound.h> 22#include <qpe/sound.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25 25
26#include "odevice.h" 26#include "odevice.h"
27 27
28 28
29class ODeviceData { 29class ODeviceData {
30public: 30public:
31 QString m_vendorstr; 31 QString m_vendorstr;
32 OVendor m_vendor; 32 OVendor m_vendor;
33 33
34 QString m_modelstr; 34 QString m_modelstr;
35 OModel m_model; 35 OModel m_model;
36 36
37 QString m_systemstr; 37 QString m_systemstr;
38 OSystem m_system; 38 OSystem m_system;
39 39
40 QString m_sysverstr;
41
40 OLedState m_leds [4]; // just for convenience ... 42 OLedState m_leds [4]; // just for convenience ...
41}; 43};
42 44
43class ODeviceIPAQ : public ODevice { 45class ODeviceIPAQ : public ODevice {
44protected: 46protected:
45 virtual void init ( ); 47 virtual void init ( );
46 48
47public: 49public:
48 virtual void alarmSound ( ); 50 virtual void alarmSound ( );
49 51
50 virtual uint hasLeds ( ) const; 52 virtual uint hasLeds ( ) const;
51 virtual OLedState led ( uint which ) const; 53 virtual OLedState led ( uint which ) const;
52 virtual bool setLed ( uint which, OLedState st ); 54 virtual bool setLed ( uint which, OLedState st );
53}; 55};
54 56
55class ODeviceZaurus : public ODevice { 57class ODeviceZaurus : public ODevice {
56protected: 58protected:
57 virtual void init ( ); 59 virtual void init ( );
58 60
59 public: 61 public:
60 virtual void alarmSound ( ); 62 virtual void alarmSound ( );
61 virtual void keySound ( ); 63 virtual void keySound ( );
62 virtual void touchSound ( ); 64 virtual void touchSound ( );
63 65
64 virtual uint hasLeds ( ) const; 66 virtual uint hasLeds ( ) const;
65 virtual OLedState led ( uint which ) const; 67 virtual OLedState led ( uint which ) const;
66 virtual bool setLed ( uint which, OLedState st ); 68 virtual bool setLed ( uint which, OLedState st );
67 69
68protected: 70protected:
69 virtual void buzzer ( int snd ); 71 virtual void buzzer ( int snd );
70}; 72};
71 73
72 74
73 75
74 76
75ODevice *ODevice::inst ( ) 77ODevice *ODevice::inst ( )
76{ 78{
77 static ODevice *dev = 0; 79 static ODevice *dev = 0;
78 80
79 if ( !dev ) { 81 if ( !dev ) {
80 if ( QFile::exists ( "/proc/hal/model" )) 82 if ( QFile::exists ( "/proc/hal/model" ))
81 dev = new ODeviceIPAQ ( ); 83 dev = new ODeviceIPAQ ( );
82 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 84 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
83 dev = new ODeviceZaurus ( ); 85 dev = new ODeviceZaurus ( );
84 else 86 else
85 dev = new ODevice ( ); 87 dev = new ODevice ( );
86 88
87 dev-> init ( ); 89 dev-> init ( );
88 } 90 }
89 return dev; 91 return dev;
90} 92}
91 93
92ODevice::ODevice ( ) 94ODevice::ODevice ( )
93{ 95{
94 d = new ODeviceData; 96 d = new ODeviceData;
95 97
96 d-> m_modelstr = "Unknown"; 98 d-> m_modelstr = "Unknown";
97 d-> m_model = OMODEL_Unknown; 99 d-> m_model = OMODEL_Unknown;
98 d-> m_vendorstr = "Unkown"; 100 d-> m_vendorstr = "Unkown";
99 d-> m_vendor = OVENDOR_Unknown; 101 d-> m_vendor = OVENDOR_Unknown;
100 d-> m_systemstr = "Unkown"; 102 d-> m_systemstr = "Unkown";
101 d-> m_system = OSYSTEM_Unknown; 103 d-> m_system = OSYSTEM_Unknown;
104 d-> m_sysverstr = "0.0";
102} 105}
103 106
104void ODevice::init ( ) 107void ODevice::init ( )
105{ 108{
106} 109}
107 110
108ODevice::~ODevice ( ) 111ODevice::~ODevice ( )
109{ 112{
110 delete d; 113 delete d;
111} 114}
112 115
113QString ODevice::vendorString ( ) 116QString ODevice::vendorString ( )
114{ 117{
115 return d-> m_vendorstr; 118 return d-> m_vendorstr;
116} 119}
117 120
118OVendor ODevice::vendor ( ) 121OVendor ODevice::vendor ( )
119{ 122{
120 return d-> m_vendor; 123 return d-> m_vendor;
121} 124}
122 125
123QString ODevice::modelString ( ) 126QString ODevice::modelString ( )
124{ 127{
125 return d-> m_modelstr; 128 return d-> m_modelstr;
126} 129}
127 130
128OModel ODevice::model ( ) 131OModel ODevice::model ( )
129{ 132{
130 return d-> m_model; 133 return d-> m_model;
131} 134}
132 135
133QString ODevice::systemString ( ) 136QString ODevice::systemString ( )
134{ 137{
135 return d-> m_systemstr; 138 return d-> m_systemstr;
136} 139}
137 140
138OSystem ODevice::system ( ) 141OSystem ODevice::system ( )
139{ 142{
140 return d-> m_system; 143 return d-> m_system;
141} 144}
142 145
146QString ODevice::systemVersionString ( )
147{
148 return d-> m_sysverstr;
149}
150
143void ODevice::alarmSound ( ) 151void ODevice::alarmSound ( )
144{ 152{
145#ifndef QT_QWS_EBX 153#ifndef QT_QWS_EBX
146#ifndef QT_NO_SOUND 154#ifndef QT_NO_SOUND
147 static Sound snd ( "alarm" ); 155 static Sound snd ( "alarm" );
148 156
149 if ( snd. isFinished ( )) 157 if ( snd. isFinished ( ))
150 snd. play ( ); 158 snd. play ( );
151#endif 159#endif
152#endif 160#endif
153} 161}
154 162
155void ODevice::keySound ( ) 163void ODevice::keySound ( )
156{ 164{
157#ifndef QT_QWS_EBX 165#ifndef QT_QWS_EBX
158#ifndef QT_NO_SOUND 166#ifndef QT_NO_SOUND
159 static Sound snd ( "keysound" ); 167 static Sound snd ( "keysound" );
160 168
161 if ( snd. isFinished ( )) 169 if ( snd. isFinished ( ))
162 snd. play ( ); 170 snd. play ( );
163#endif 171#endif
164#endif 172#endif
165} 173}
166 174
167void ODevice::touchSound ( ) 175void ODevice::touchSound ( )
168{ 176{
169 177
170#ifndef QT_QWS_EBX 178#ifndef QT_QWS_EBX
171#ifndef QT_NO_SOUND 179#ifndef QT_NO_SOUND
172 static Sound snd ( "touchsound" ); 180 static Sound snd ( "touchsound" );
173//qDebug("touchSound"); 181//qDebug("touchSound");
174 if ( snd. isFinished ( )) { 182 if ( snd. isFinished ( )) {
175 snd. play ( ); 183 snd. play ( );
176 // qDebug("sound should play"); 184 // qDebug("sound should play");
177 } 185 }
178#endif 186#endif
179#endif 187#endif
180} 188}
181 189
182uint ODevice::hasLeds ( ) const 190uint ODevice::hasLeds ( ) const
183{ 191{
184 return 0; 192 return 0;
185} 193}
186 194
187OLedState ODevice::led ( uint /*which*/ ) const 195OLedState ODevice::led ( uint /*which*/ ) const
188{ 196{
189 return OLED_Off; 197 return OLED_Off;
190} 198}
191 199
192bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) 200bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
193{ 201{
194 return false; 202 return false;
195} 203}
196 204
197 205
198 206
199 207
200//#if defined( QT_QWS_IPAQ ) // IPAQ 208//#if defined( QT_QWS_IPAQ ) // IPAQ
201 209
202 210
203void ODeviceIPAQ::init ( ) 211void ODeviceIPAQ::init ( )
204{ 212{
205 d-> m_vendorstr = "HP"; 213 d-> m_vendorstr = "HP";
206 d-> m_vendor = OVENDOR_HP; 214 d-> m_vendor = OVENDOR_HP;
207 215
208 QFile f ( "/proc/hal/model" ); 216 QFile f ( "/proc/hal/model" );
209 217
210 if ( f. open ( IO_ReadOnly )) { 218 if ( f. open ( IO_ReadOnly )) {
211 QTextStream ts ( &f ); 219 QTextStream ts ( &f );
212 220
213 d-> m_modelstr = "H" + ts. readLine ( ); 221 d-> m_modelstr = "H" + ts. readLine ( );
214 222
215 if ( d-> m_modelstr == "H3100" ) 223 if ( d-> m_modelstr == "H3100" )
216 d-> m_model = OMODEL_iPAQ_H31xx; 224 d-> m_model = OMODEL_iPAQ_H31xx;
217 else if ( d-> m_modelstr == "H3600" ) 225 else if ( d-> m_modelstr == "H3600" )
218 d-> m_model = OMODEL_iPAQ_H36xx; 226 d-> m_model = OMODEL_iPAQ_H36xx;
219 else if ( d-> m_modelstr == "H3700" ) 227 else if ( d-> m_modelstr == "H3700" )
220 d-> m_model = OMODEL_iPAQ_H37xx; 228 d-> m_model = OMODEL_iPAQ_H37xx;
221 else if ( d-> m_modelstr == "H3800" ) 229 else if ( d-> m_modelstr == "H3800" )
222 d-> m_model = OMODEL_iPAQ_H38xx; 230 d-> m_model = OMODEL_iPAQ_H38xx;
223 else 231 else
224 d-> m_model = OMODEL_Unknown; 232 d-> m_model = OMODEL_Unknown;
225 233
226 f. close ( ); 234 f. close ( );
227 } 235 }
228 236
229 if ( QFile::exists ( "/etc/familiar-version" )) { 237 f. setName ( "/etc/familiar-version" );
238 if ( f. open ( IO_ReadOnly )) {
230 d-> m_systemstr = "Familiar"; 239 d-> m_systemstr = "Familiar";
231 d-> m_system = OSYSTEM_Familiar; 240 d-> m_system = OSYSTEM_Familiar;
241
242 QTextStream ts ( &f );
243 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
244
245 f. close ( );
232 } 246 }
233 247
234 d-> m_leds [0] = OLED_Off; 248 d-> m_leds [0] = OLED_Off;
235} 249}
236 250
237#include <unistd.h> 251#include <unistd.h>
238#include <fcntl.h> 252#include <fcntl.h>
239#include <sys/ioctl.h> 253#include <sys/ioctl.h>
240#include <linux/soundcard.h> 254#include <linux/soundcard.h>
241#include <qapplication.h> 255#include <qapplication.h>
242#include <qpe/config.h> 256#include <qpe/config.h>
243 257
244//#include <linux/h3600_ts.h> // including kernel headers is evil ... 258//#include <linux/h3600_ts.h> // including kernel headers is evil ...
245 259
246typedef struct h3600_ts_led { 260typedef struct h3600_ts_led {
247 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 261 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
248 unsigned char TotalTime; /* Units of 5 seconds */ 262 unsigned char TotalTime; /* Units of 5 seconds */
249 unsigned char OnTime; /* units of 100m/s */ 263 unsigned char OnTime; /* units of 100m/s */
250 unsigned char OffTime; /* units of 100m/s */ 264 unsigned char OffTime; /* units of 100m/s */
251} LED_IN; 265} LED_IN;
252 266
253 267
254// #define IOC_H3600_TS_MAGIC 'f' 268// #define IOC_H3600_TS_MAGIC 'f'
255// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) 269// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led)
256#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( 270#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :(
257 271
258 272
259void ODeviceIPAQ::alarmSound ( ) 273void ODeviceIPAQ::alarmSound ( )
260{ 274{
261#if defined( QT_QWS_IPAQ ) // IPAQ 275#if defined( QT_QWS_IPAQ ) // IPAQ
262#ifndef QT_NO_SOUND 276#ifndef QT_NO_SOUND
263 static Sound snd ( "alarm" ); 277 static Sound snd ( "alarm" );
264 int fd; 278 int fd;
265 int vol; 279 int vol;
266 bool vol_reset = false; 280 bool vol_reset = false;
267 281
268 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || 282 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) ||
269 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { 283 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) {
270 284
271 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 285 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
272 Config cfg ( "qpe" ); 286 Config cfg ( "qpe" );
273 cfg. setGroup ( "Volume" ); 287 cfg. setGroup ( "Volume" );
274 288
275 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 289 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
276 if ( volalarm < 0 ) 290 if ( volalarm < 0 )
277 volalarm = 0; 291 volalarm = 0;
278 else if ( volalarm > 100 ) 292 else if ( volalarm > 100 )
279 volalarm = 100; 293 volalarm = 100;
diff --git a/libopie/odevice.h b/libopie/odevice.h
index b40abe7..b54e576 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -33,75 +33,76 @@ enum OModel {
33 OMODEL_iPAQ_H37xx, 33 OMODEL_iPAQ_H37xx,
34 OMODEL_iPAQ_H38xx, 34 OMODEL_iPAQ_H38xx,
35 35
36 OMODEL_Zaurus_SL5000 36 OMODEL_Zaurus_SL5000
37}; 37};
38 38
39 enum OVendor { 39 enum OVendor {
40 OVENDOR_Unknown, 40 OVENDOR_Unknown,
41 41
42 OVENDOR_HP, 42 OVENDOR_HP,
43 OVENDOR_Sharp 43 OVENDOR_Sharp
44 }; 44 };
45 45
46enum OSystem { 46enum OSystem {
47 OSYSTEM_Unknown, 47 OSYSTEM_Unknown,
48 48
49 OSYSTEM_Familiar, 49 OSYSTEM_Familiar,
50 OSYSTEM_Zaurus, 50 OSYSTEM_Zaurus,
51 OSYSTEM_OpenZaurus 51 OSYSTEM_OpenZaurus
52}; 52};
53 53
54enum OLedState { 54enum OLedState {
55 OLED_Off, 55 OLED_Off,
56 OLED_On, 56 OLED_On,
57 OLED_BlinkSlow, 57 OLED_BlinkSlow,
58 OLED_BlinkFast 58 OLED_BlinkFast
59}; 59};
60 60
61 61
62class ODevice 62class ODevice
63{ 63{
64public: 64public:
65 65
66public: 66public:
67 static ODevice *inst ( ); 67 static ODevice *inst ( );
68 68
69 69
70// information 70// information
71 71
72 QString modelString ( ); 72 QString modelString ( );
73 OModel model ( ); 73 OModel model ( );
74 74
75 QString vendorString ( ); 75 QString vendorString ( );
76 OVendor vendor ( ); 76 OVendor vendor ( );
77 77
78 QString systemString ( ); 78 QString systemString ( );
79 OSystem system ( ); 79 OSystem system ( );
80 80
81 QString systemVersionString ( );
81 82
82// input / output 83// input / output
83 84
84 virtual void alarmSound ( ); 85 virtual void alarmSound ( );
85 virtual void keySound ( ); 86 virtual void keySound ( );
86 virtual void touchSound ( ); 87 virtual void touchSound ( );
87 88
88 virtual uint hasLeds ( ) const; 89 virtual uint hasLeds ( ) const;
89 virtual OLedState led ( uint which ) const; 90 virtual OLedState led ( uint which ) const;
90 virtual bool setLed ( uint which, OLedState st ); 91 virtual bool setLed ( uint which, OLedState st );
91 92
92 virtual ~ODevice ( ); 93 virtual ~ODevice ( );
93 94
94protected: 95protected:
95 ODevice ( ); 96 ODevice ( );
96 virtual void init ( ); 97 virtual void init ( );
97 98
98 ODeviceData *d; 99 ODeviceData *d;
99 100
100private: 101private:
101 ODevice ( const ODevice & ); 102 ODevice ( const ODevice & );
102 103
103}; 104};
104 105
105#endif 106#endif
106 107
107 108