summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2007-09-14 20:52:38 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2007-09-14 20:52:38 +0000
commitfc2526644003e80346d231b3904aa10340e7d9b2 (patch)
tree98242a2dabfd09d464885aac230444f3ff5af083
parent3d41c1c466e4f9f1521ac6164e41f393a16402ff (diff)
downloadrockbox-fc2526644003e80346d231b3904aa10340e7d9b2.tar.gz
rockbox-fc2526644003e80346d231b3904aa10340e7d9b2.zip
Device detection based on USB PIDs. This is currently linux only and requires libusb. There is also no way to figure the mount point from the USB PID so the old methods are tried for this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14698 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/autodetection.cpp87
-rw-r--r--rbutil/rbutilqt/autodetection.h4
-rw-r--r--rbutil/rbutilqt/configure.cpp14
-rw-r--r--rbutil/rbutilqt/rbutil.ini15
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp2
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro3
6 files changed, 119 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp
index f29df535ab..c16b6976cc 100644
--- a/rbutil/rbutilqt/autodetection.cpp
+++ b/rbutil/rbutilqt/autodetection.cpp
@@ -19,9 +19,10 @@
19 19
20#include "autodetection.h" 20#include "autodetection.h"
21 21
22#if defined(Q_OS_LINUX) 22#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
23#include <stdio.h> 23#include <stdio.h>
24#include <mntent.h> 24#include <mntent.h>
25#include <usb.h>
25#endif 26#endif
26 27
27Autodetection::Autodetection(QObject* parent): QObject(parent) 28Autodetection::Autodetection(QObject* parent): QObject(parent)
@@ -33,6 +34,9 @@ bool Autodetection::detect()
33{ 34{
34 m_device = ""; 35 m_device = "";
35 m_mountpoint = ""; 36 m_mountpoint = "";
37 m_errdev = "";
38
39 detectUsb();
36 40
37 // Try detection via rockbox.info / rbutil.log 41 // Try detection via rockbox.info / rbutil.log
38 QStringList mountpoints = getMountpoints(); 42 QStringList mountpoints = getMountpoints();
@@ -48,7 +52,8 @@ bool Autodetection::detect()
48 QSettings log(mountpoints.at(i) + "/.rockbox/rbutil.log", 52 QSettings log(mountpoints.at(i) + "/.rockbox/rbutil.log",
49 QSettings::IniFormat, this); 53 QSettings::IniFormat, this);
50 if(!log.value("platform").toString().isEmpty()) { 54 if(!log.value("platform").toString().isEmpty()) {
51 m_device = log.value("platform").toString(); 55 if(m_device.isEmpty())
56 m_device = log.value("platform").toString();
52 m_mountpoint = mountpoints.at(i); 57 m_mountpoint = mountpoints.at(i);
53 qDebug() << "rbutil.log detected:" << m_device << m_mountpoint; 58 qDebug() << "rbutil.log detected:" << m_device << m_mountpoint;
54 return true; 59 return true;
@@ -64,7 +69,8 @@ bool Autodetection::detect()
64 if(line.startsWith("Target: ")) 69 if(line.startsWith("Target: "))
65 { 70 {
66 line.remove("Target: "); 71 line.remove("Target: ");
67 m_device = line.trimmed(); // trim whitespaces 72 if(m_device.isEmpty())
73 m_device = line.trimmed(); // trim whitespaces
68 m_mountpoint = mountpoints.at(i); 74 m_mountpoint = mountpoints.at(i);
69 qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint; 75 qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint;
70 return true; 76 return true;
@@ -133,7 +139,9 @@ bool Autodetection::detect()
133 return true; 139 return true;
134 } 140 }
135 141
136 return false; 142 if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty())
143 return false;
144 return true;
137} 145}
138 146
139 147
@@ -192,3 +200,74 @@ QString Autodetection::resolveMountPoint(QString device)
192 return QString(""); 200 return QString("");
193 201
194} 202}
203
204
205/** @brief detect devices based on usb pid / vid.
206 * @return true upon success, false otherwise.
207 */
208bool Autodetection::detectUsb()
209{
210 // autodetection only uses the buildin device settings only
211 QSettings dev(":/ini/rbutil.ini", QSettings::IniFormat, this);
212
213 // get a list of ID -> target name
214 QStringList platforms;
215 dev.beginGroup("platforms");
216 platforms = dev.childKeys();
217 dev.endGroup();
218
219 // usbids holds the mapping in the form
220 // ((VID<<16)|(PID)), targetname
221 // the ini file needs to hold the IDs as hex values.
222 QMap<int, QString> usbids;
223 QMap<int, QString> usberror;
224
225 for(int i = 0; i < platforms.size(); i++) {
226 dev.beginGroup("platforms");
227 QString target = dev.value(platforms.at(i)).toString();
228 dev.endGroup();
229 dev.beginGroup(target);
230 if(!dev.value("usbid").toString().isEmpty())
231 usbids.insert(dev.value("usbid").toString().toInt(0, 16), target);
232 if(!dev.value("usberror").toString().isEmpty())
233 usberror.insert(dev.value("usberror").toString().toInt(0, 16), target);
234 dev.endGroup();
235 }
236
237 // usb pid detection
238#if defined(Q_OS_LINUX) | defined(Q_OS_MACX)
239 usb_init();
240 usb_find_busses();
241 usb_find_devices();
242 struct usb_bus *b;
243 b = usb_get_busses();
244
245 while(b) {
246 qDebug() << "bus:" << b->dirname << b->devices;
247 if(b->devices) {
248 qDebug() << "devices present.";
249 struct usb_device *u;
250 u = b->devices;
251 while(u) {
252 uint32_t id;
253 id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
254 qDebug("%x", id);
255
256 if(usbids.contains(id)) {
257 m_device = usbids.value(id);
258 return true;
259 }
260 if(usberror.contains(id)) {
261 m_errdev = usberror.value(id);
262 // we detected something, so return true
263 qDebug() << "detected device with problems via usb!";
264 return true;
265 }
266 u = u->next;
267 }
268 }
269 b = b->next;
270 }
271#endif
272 return false;
273}
diff --git a/rbutil/rbutilqt/autodetection.h b/rbutil/rbutilqt/autodetection.h
index 2443b442f4..85b69045ef 100644
--- a/rbutil/rbutilqt/autodetection.h
+++ b/rbutil/rbutilqt/autodetection.h
@@ -40,14 +40,16 @@ public:
40 40
41 QString getDevice() {return m_device;} 41 QString getDevice() {return m_device;}
42 QString getMountPoint() {return m_mountpoint;} 42 QString getMountPoint() {return m_mountpoint;}
43 QString errdev(void) { return m_errdev; }
43 44
44private: 45private:
45 QStringList getMountpoints(void); 46 QStringList getMountpoints(void);
46 QString resolveMountPoint(QString); 47 QString resolveMountPoint(QString);
48 bool detectUsb(void);
47 49
48 QString m_device; 50 QString m_device;
49 QString m_mountpoint; 51 QString m_mountpoint;
50 52 QString m_errdev;
51}; 53};
52 54
53 55
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index b67d454e82..07947691e5 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -565,6 +565,20 @@ void Config::autodetect()
565 } 565 }
566 } 566 }
567 567
568 if(!detector.errdev().isEmpty()) {
569 QString text;
570 if(detector.errdev() == "sansae200")
571 text = tr("Sansa e200 in MTP mode found!\n"
572 "You need to change your player to MSC mode for installation. ");
573 if(detector.errdev() == "h10")
574 text = tr("H10 20GB in MTP mode found!\n"
575 "You need to change your player to UMS mode for installation. ");
576 text += tr("Unless you changed this installation will fail!");
577
578 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
579 return;
580 }
581
568 if(detector.getMountPoint() != "" ) 582 if(detector.getMountPoint() != "" )
569 { 583 {
570 ui.mountPoint->setText(detector.getMountPoint()); 584 ui.mountPoint->setText(detector.getMountPoint());
diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini
index 68c371e142..0ece567eba 100644
--- a/rbutil/rbutilqt/rbutil.ini
+++ b/rbutil/rbutilqt/rbutil.ini
@@ -142,6 +142,7 @@ bootloadername=bootloader-h100.bin
142resolution=160x128x2 142resolution=160x128x2
143manualname=rockbox-h100 143manualname=rockbox-h100
144brand=Iriver 144brand=Iriver
145usbid=0x10063001
145 146
146[h120] 147[h120]
147name="iHP120 / iHP140 / H120 / H140" 148name="iHP120 / iHP140 / H120 / H140"
@@ -153,6 +154,7 @@ bootloadername=bootloader-h120.bin
153resolution=160x128x2 154resolution=160x128x2
154manualname=rockbox-h100 155manualname=rockbox-h100
155brand=Iriver 156brand=Iriver
157usbid=0x10063002
156 158
157[h300] 159[h300]
158name="H320 / H340" 160name="H320 / H340"
@@ -164,6 +166,7 @@ bootloadername=bootloader-h300.bin
164resolution=220x176x16 166resolution=220x176x16
165manualname=rockbox-h300 167manualname=rockbox-h300
166brand=Iriver 168brand=Iriver
169usbid=0x10063003
167 170
168[h10_5gbums] 171[h10_5gbums]
169name="H10 (5 / 6GB) UMS" 172name="H10 (5 / 6GB) UMS"
@@ -175,6 +178,7 @@ bootloadername=H10.mi4
175resolution=128x128x16 178resolution=128x128x16
176manualname= 179manualname=
177brand=Iriver 180brand=Iriver
181usbid=0x41022002
178 182
179[h10_5gbmtp] 183[h10_5gbmtp]
180name="H10 (5 / 6GB) MTP" 184name="H10 (5 / 6GB) MTP"
@@ -186,6 +190,7 @@ bootloadername=H10_5GB-MTP/H10.mi4
186resolution=128x128x16 190resolution=128x128x16
187manualname= 191manualname=
188brand=Iriver 192brand=Iriver
193usbid=0x41022105
189 194
190[h10] 195[h10]
191name="H10 (20GB)" 196name="H10 (20GB)"
@@ -197,6 +202,8 @@ bootloadername=H10_20GC.mi4
197resolution=160x128x16 202resolution=160x128x16
198manualname= 203manualname=
199brand=Iriver 204brand=Iriver
205usbid=0x0b7000ba
206usberror=0x41022101
200 207
201[ipod1g2g] 208[ipod1g2g]
202name="Ipod (1st / 2nd gen)" 209name="Ipod (1st / 2nd gen)"
@@ -230,6 +237,7 @@ bootloadername=ipodnano
230resolution=176x132x16 237resolution=176x132x16
231manualname= 238manualname=
232brand=Apple 239brand=Apple
240usbid=0x05ac120a
233 241
234[ipod4gray] 242[ipod4gray]
235name="Ipod (4th gen, greyscale)" 243name="Ipod (4th gen, greyscale)"
@@ -274,6 +282,7 @@ bootloadername=ipod3g
274resolution=160x128x2 282resolution=160x128x2
275manualname= 283manualname=
276brand=Apple 284brand=Apple
285usbid=0x05ac1201
277 286
278[ipodmini1g] 287[ipodmini1g]
279name="Ipod Mini (1st gen)" 288name="Ipod Mini (1st gen)"
@@ -307,6 +316,8 @@ bootloadername=x5_fw.bin
307resolution=160x128x16 316resolution=160x128x16
308manualname= 317manualname=
309brand=Cowon 318brand=Cowon
319usbid=0x0e210510
320usbid=0x0e210513
310 321
311[iaudiox5v] 322[iaudiox5v]
312name="iAudio X5V" 323name="iAudio X5V"
@@ -329,6 +340,7 @@ bootloadername=m5_fw.bin
329resolution=160x128x16 340resolution=160x128x16
330manualname= 341manualname=
331brand=Cowon 342brand=Cowon
343usbid=0x0e210520
332 344
333[gigabeatf] 345[gigabeatf]
334name="Gigabeat F / X" 346name="Gigabeat F / X"
@@ -339,6 +351,7 @@ bootloadername=FWIMG01.DAT
339resolution=240x320x16 351resolution=240x320x16
340manualname= 352manualname=
341brand=Toshiba 353brand=Toshiba
354usbid=0x09300009
342 355
343[sansae200] 356[sansae200]
344name="Sansa E200" 357name="Sansa E200"
@@ -350,6 +363,8 @@ bootloadername=PP5022.mi4
350resolution=176x220x16 363resolution=176x220x16
351manualname= 364manualname=
352brand=Sandisk 365brand=Sandisk
366usbid=0x07817421
367usberror=0x07810720
353 368
354[encoders] 369[encoders]
355encpreset01 = "Lame (default)" 370encpreset01 = "Lame (default)"
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index f5376b5185..6a561e1b85 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -66,7 +66,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
66 QSettings::UserScope, "rockbox.org", "RockboxUtility"); 66 QSettings::UserScope, "rockbox.org", "RockboxUtility");
67 qDebug() << "config: system"; 67 qDebug() << "config: system";
68 } 68 }
69 69
70 // manual tab 70 // manual tab
71 updateManual(); 71 updateManual();
72 updateDevice(); 72 updateDevice();
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index e45560c124..2d0bd7633b 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -124,6 +124,9 @@ macx {
124 QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk 124 QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
125 CONFIG+=x86 ppc 125 CONFIG+=x86 ppc
126} 126}
127unix {
128 LIBS += -lusb
129}
127 130
128static { 131static {
129 QTPLUGIN += qtaccessiblewidgets 132 QTPLUGIN += qtaccessiblewidgets