1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dominik Riebeling 2007-09-14 20:52:38 +00:00
parent 3d41c1c466
commit fc25266440
6 changed files with 119 additions and 6 deletions

View file

@ -19,9 +19,10 @@
#include "autodetection.h" #include "autodetection.h"
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
#include <stdio.h> #include <stdio.h>
#include <mntent.h> #include <mntent.h>
#include <usb.h>
#endif #endif
Autodetection::Autodetection(QObject* parent): QObject(parent) Autodetection::Autodetection(QObject* parent): QObject(parent)
@ -33,6 +34,9 @@ bool Autodetection::detect()
{ {
m_device = ""; m_device = "";
m_mountpoint = ""; m_mountpoint = "";
m_errdev = "";
detectUsb();
// Try detection via rockbox.info / rbutil.log // Try detection via rockbox.info / rbutil.log
QStringList mountpoints = getMountpoints(); QStringList mountpoints = getMountpoints();
@ -48,6 +52,7 @@ bool Autodetection::detect()
QSettings log(mountpoints.at(i) + "/.rockbox/rbutil.log", QSettings log(mountpoints.at(i) + "/.rockbox/rbutil.log",
QSettings::IniFormat, this); QSettings::IniFormat, this);
if(!log.value("platform").toString().isEmpty()) { if(!log.value("platform").toString().isEmpty()) {
if(m_device.isEmpty())
m_device = log.value("platform").toString(); m_device = log.value("platform").toString();
m_mountpoint = mountpoints.at(i); m_mountpoint = mountpoints.at(i);
qDebug() << "rbutil.log detected:" << m_device << m_mountpoint; qDebug() << "rbutil.log detected:" << m_device << m_mountpoint;
@ -64,6 +69,7 @@ bool Autodetection::detect()
if(line.startsWith("Target: ")) if(line.startsWith("Target: "))
{ {
line.remove("Target: "); line.remove("Target: ");
if(m_device.isEmpty())
m_device = line.trimmed(); // trim whitespaces m_device = line.trimmed(); // trim whitespaces
m_mountpoint = mountpoints.at(i); m_mountpoint = mountpoints.at(i);
qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint; qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint;
@ -133,7 +139,9 @@ bool Autodetection::detect()
return true; return true;
} }
if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty())
return false; return false;
return true;
} }
@ -192,3 +200,74 @@ QString Autodetection::resolveMountPoint(QString device)
return QString(""); 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;
}

View file

@ -40,14 +40,16 @@ public:
QString getDevice() {return m_device;} QString getDevice() {return m_device;}
QString getMountPoint() {return m_mountpoint;} QString getMountPoint() {return m_mountpoint;}
QString errdev(void) { return m_errdev; }
private: private:
QStringList getMountpoints(void); QStringList getMountpoints(void);
QString resolveMountPoint(QString); QString resolveMountPoint(QString);
bool detectUsb(void);
QString m_device; QString m_device;
QString m_mountpoint; QString m_mountpoint;
QString m_errdev;
}; };

View file

@ -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() != "" ) if(detector.getMountPoint() != "" )
{ {
ui.mountPoint->setText(detector.getMountPoint()); ui.mountPoint->setText(detector.getMountPoint());

View file

@ -142,6 +142,7 @@ bootloadername=bootloader-h100.bin
resolution=160x128x2 resolution=160x128x2
manualname=rockbox-h100 manualname=rockbox-h100
brand=Iriver brand=Iriver
usbid=0x10063001
[h120] [h120]
name="iHP120 / iHP140 / H120 / H140" name="iHP120 / iHP140 / H120 / H140"
@ -153,6 +154,7 @@ bootloadername=bootloader-h120.bin
resolution=160x128x2 resolution=160x128x2
manualname=rockbox-h100 manualname=rockbox-h100
brand=Iriver brand=Iriver
usbid=0x10063002
[h300] [h300]
name="H320 / H340" name="H320 / H340"
@ -164,6 +166,7 @@ bootloadername=bootloader-h300.bin
resolution=220x176x16 resolution=220x176x16
manualname=rockbox-h300 manualname=rockbox-h300
brand=Iriver brand=Iriver
usbid=0x10063003
[h10_5gbums] [h10_5gbums]
name="H10 (5 / 6GB) UMS" name="H10 (5 / 6GB) UMS"
@ -175,6 +178,7 @@ bootloadername=H10.mi4
resolution=128x128x16 resolution=128x128x16
manualname= manualname=
brand=Iriver brand=Iriver
usbid=0x41022002
[h10_5gbmtp] [h10_5gbmtp]
name="H10 (5 / 6GB) MTP" name="H10 (5 / 6GB) MTP"
@ -186,6 +190,7 @@ bootloadername=H10_5GB-MTP/H10.mi4
resolution=128x128x16 resolution=128x128x16
manualname= manualname=
brand=Iriver brand=Iriver
usbid=0x41022105
[h10] [h10]
name="H10 (20GB)" name="H10 (20GB)"
@ -197,6 +202,8 @@ bootloadername=H10_20GC.mi4
resolution=160x128x16 resolution=160x128x16
manualname= manualname=
brand=Iriver brand=Iriver
usbid=0x0b7000ba
usberror=0x41022101
[ipod1g2g] [ipod1g2g]
name="Ipod (1st / 2nd gen)" name="Ipod (1st / 2nd gen)"
@ -230,6 +237,7 @@ bootloadername=ipodnano
resolution=176x132x16 resolution=176x132x16
manualname= manualname=
brand=Apple brand=Apple
usbid=0x05ac120a
[ipod4gray] [ipod4gray]
name="Ipod (4th gen, greyscale)" name="Ipod (4th gen, greyscale)"
@ -274,6 +282,7 @@ bootloadername=ipod3g
resolution=160x128x2 resolution=160x128x2
manualname= manualname=
brand=Apple brand=Apple
usbid=0x05ac1201
[ipodmini1g] [ipodmini1g]
name="Ipod Mini (1st gen)" name="Ipod Mini (1st gen)"
@ -307,6 +316,8 @@ bootloadername=x5_fw.bin
resolution=160x128x16 resolution=160x128x16
manualname= manualname=
brand=Cowon brand=Cowon
usbid=0x0e210510
usbid=0x0e210513
[iaudiox5v] [iaudiox5v]
name="iAudio X5V" name="iAudio X5V"
@ -329,6 +340,7 @@ bootloadername=m5_fw.bin
resolution=160x128x16 resolution=160x128x16
manualname= manualname=
brand=Cowon brand=Cowon
usbid=0x0e210520
[gigabeatf] [gigabeatf]
name="Gigabeat F / X" name="Gigabeat F / X"
@ -339,6 +351,7 @@ bootloadername=FWIMG01.DAT
resolution=240x320x16 resolution=240x320x16
manualname= manualname=
brand=Toshiba brand=Toshiba
usbid=0x09300009
[sansae200] [sansae200]
name="Sansa E200" name="Sansa E200"
@ -350,6 +363,8 @@ bootloadername=PP5022.mi4
resolution=176x220x16 resolution=176x220x16
manualname= manualname=
brand=Sandisk brand=Sandisk
usbid=0x07817421
usberror=0x07810720
[encoders] [encoders]
encpreset01 = "Lame (default)" encpreset01 = "Lame (default)"

View file

@ -124,6 +124,9 @@ macx {
QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
CONFIG+=x86 ppc CONFIG+=x86 ppc
} }
unix {
LIBS += -lusb
}
static { static {
QTPLUGIN += qtaccessiblewidgets QTPLUGIN += qtaccessiblewidgets