summaryrefslogtreecommitdiffstats
path: root/rbutil
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 /rbutil
parent3d41c1c466e4f9f1521ac6164e41f393a16402ff (diff)
downloadrockbox-fc2526644003e80346d231b3904aa10340e7d9b2.tar.gz
rockbox-fc2526644003e80346d231b3904aa10340e7d9b2.tar.bz2
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
Diffstat (limited to 'rbutil')
-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 @@
#include "autodetection.h"
-#if defined(Q_OS_LINUX)
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
#include <stdio.h>
#include <mntent.h>
+#include <usb.h>
#endif
Autodetection::Autodetection(QObject* parent): QObject(parent)
@@ -33,6 +34,9 @@ bool Autodetection::detect()
{
m_device = "";
m_mountpoint = "";
+ m_errdev = "";
+
+ detectUsb();
// Try detection via rockbox.info / rbutil.log
QStringList mountpoints = getMountpoints();
@@ -48,7 +52,8 @@ bool Autodetection::detect()
QSettings log(mountpoints.at(i) + "/.rockbox/rbutil.log",
QSettings::IniFormat, this);
if(!log.value("platform").toString().isEmpty()) {
- m_device = log.value("platform").toString();
+ if(m_device.isEmpty())
+ m_device = log.value("platform").toString();
m_mountpoint = mountpoints.at(i);
qDebug() << "rbutil.log detected:" << m_device << m_mountpoint;
return true;
@@ -64,7 +69,8 @@ bool Autodetection::detect()
if(line.startsWith("Target: "))
{
line.remove("Target: ");
- m_device = line.trimmed(); // trim whitespaces
+ if(m_device.isEmpty())
+ m_device = line.trimmed(); // trim whitespaces
m_mountpoint = mountpoints.at(i);
qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint;
return true;
@@ -133,7 +139,9 @@ bool Autodetection::detect()
return true;
}
- return false;
+ if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty())
+ return false;
+ return true;
}
@@ -192,3 +200,74 @@ QString Autodetection::resolveMountPoint(QString device)
return QString("");
}
+
+
+/** @brief detect devices based on usb pid / vid.
+ * @return true upon success, false otherwise.
+ */
+bool Autodetection::detectUsb()
+{
+ // autodetection only uses the buildin device settings only
+ QSettings dev(":/ini/rbutil.ini", QSettings::IniFormat, this);
+
+ // get a list of ID -> target name
+ QStringList platforms;
+ dev.beginGroup("platforms");
+ platforms = dev.childKeys();
+ dev.endGroup();
+
+ // usbids holds the mapping in the form
+ // ((VID<<16)|(PID)), targetname
+ // the ini file needs to hold the IDs as hex values.
+ QMap<int, QString> usbids;
+ QMap<int, QString> usberror;
+
+ for(int i = 0; i < platforms.size(); i++) {
+ dev.beginGroup("platforms");
+ QString target = dev.value(platforms.at(i)).toString();
+ dev.endGroup();
+ dev.beginGroup(target);
+ if(!dev.value("usbid").toString().isEmpty())
+ usbids.insert(dev.value("usbid").toString().toInt(0, 16), target);
+ if(!dev.value("usberror").toString().isEmpty())
+ usberror.insert(dev.value("usberror").toString().toInt(0, 16), target);
+ dev.endGroup();
+ }
+
+ // usb pid detection
+#if defined(Q_OS_LINUX) | defined(Q_OS_MACX)
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+ struct usb_bus *b;
+ b = usb_get_busses();
+
+ while(b) {
+ qDebug() << "bus:" << b->dirname << b->devices;
+ if(b->devices) {
+ qDebug() << "devices present.";
+ struct usb_device *u;
+ u = b->devices;
+ while(u) {
+ uint32_t id;
+ id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;
+ qDebug("%x", id);
+
+ if(usbids.contains(id)) {
+ m_device = usbids.value(id);
+ return true;
+ }
+ if(usberror.contains(id)) {
+ m_errdev = usberror.value(id);
+ // we detected something, so return true
+ qDebug() << "detected device with problems via usb!";
+ return true;
+ }
+ u = u->next;
+ }
+ }
+ b = b->next;
+ }
+#endif
+ return false;
+}
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:
QString getDevice() {return m_device;}
QString getMountPoint() {return m_mountpoint;}
+ QString errdev(void) { return m_errdev; }
private:
QStringList getMountpoints(void);
QString resolveMountPoint(QString);
+ bool detectUsb(void);
QString m_device;
QString m_mountpoint;
-
+ QString m_errdev;
};
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()
}
}
+ if(!detector.errdev().isEmpty()) {
+ QString text;
+ if(detector.errdev() == "sansae200")
+ text = tr("Sansa e200 in MTP mode found!\n"
+ "You need to change your player to MSC mode for installation. ");
+ if(detector.errdev() == "h10")
+ text = tr("H10 20GB in MTP mode found!\n"
+ "You need to change your player to UMS mode for installation. ");
+ text += tr("Unless you changed this installation will fail!");
+
+ QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
+ return;
+ }
+
if(detector.getMountPoint() != "" )
{
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
resolution=160x128x2
manualname=rockbox-h100
brand=Iriver
+usbid=0x10063001
[h120]
name="iHP120 / iHP140 / H120 / H140"
@@ -153,6 +154,7 @@ bootloadername=bootloader-h120.bin
resolution=160x128x2
manualname=rockbox-h100
brand=Iriver
+usbid=0x10063002
[h300]
name="H320 / H340"
@@ -164,6 +166,7 @@ bootloadername=bootloader-h300.bin
resolution=220x176x16
manualname=rockbox-h300
brand=Iriver
+usbid=0x10063003
[h10_5gbums]
name="H10 (5 / 6GB) UMS"
@@ -175,6 +178,7 @@ bootloadername=H10.mi4
resolution=128x128x16
manualname=
brand=Iriver
+usbid=0x41022002
[h10_5gbmtp]
name="H10 (5 / 6GB) MTP"
@@ -186,6 +190,7 @@ bootloadername=H10_5GB-MTP/H10.mi4
resolution=128x128x16
manualname=
brand=Iriver
+usbid=0x41022105
[h10]
name="H10 (20GB)"
@@ -197,6 +202,8 @@ bootloadername=H10_20GC.mi4
resolution=160x128x16
manualname=
brand=Iriver
+usbid=0x0b7000ba
+usberror=0x41022101
[ipod1g2g]
name="Ipod (1st / 2nd gen)"
@@ -230,6 +237,7 @@ bootloadername=ipodnano
resolution=176x132x16
manualname=
brand=Apple
+usbid=0x05ac120a
[ipod4gray]
name="Ipod (4th gen, greyscale)"
@@ -274,6 +282,7 @@ bootloadername=ipod3g
resolution=160x128x2
manualname=
brand=Apple
+usbid=0x05ac1201
[ipodmini1g]
name="Ipod Mini (1st gen)"
@@ -307,6 +316,8 @@ bootloadername=x5_fw.bin
resolution=160x128x16
manualname=
brand=Cowon
+usbid=0x0e210510
+usbid=0x0e210513
[iaudiox5v]
name="iAudio X5V"
@@ -329,6 +340,7 @@ bootloadername=m5_fw.bin
resolution=160x128x16
manualname=
brand=Cowon
+usbid=0x0e210520
[gigabeatf]
name="Gigabeat F / X"
@@ -339,6 +351,7 @@ bootloadername=FWIMG01.DAT
resolution=240x320x16
manualname=
brand=Toshiba
+usbid=0x09300009
[sansae200]
name="Sansa E200"
@@ -350,6 +363,8 @@ bootloadername=PP5022.mi4
resolution=176x220x16
manualname=
brand=Sandisk
+usbid=0x07817421
+usberror=0x07810720
[encoders]
encpreset01 = "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)
QSettings::UserScope, "rockbox.org", "RockboxUtility");
qDebug() << "config: system";
}
-
+
// manual tab
updateManual();
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 {
QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
CONFIG+=x86 ppc
}
+unix {
+ LIBS += -lusb
+}
static {
QTPLUGIN += qtaccessiblewidgets