问题描述
我考虑尝试编译某C-PROGRAMM它允许GEMBIRD SilverShield电源插座的控制通过USB为Android。在我的Android HDMI电视棒,这将是非常有用的。这里是一个开放的项目这个。它能在Linux和依赖的libusb。目标平台是Android的ICS。我想开发在Ubuntu Linux。什么是我得到它的工作的可能性有多大?需要什么样的步骤。安装Android SDK中,NDK,交叉编译...
还有一个老问题,here,有关libusb的Android上,但没有信息的方式。
是它可能更容易移植应用到机器人自己的USB库?
I consider trying to compile a certain C-programm which allows the control of Gembird SilverShield power outlets via USB for android. On my android HDMI TV-stick this would be very useful. There is an open project for this. It works under Linux and depends on libusb. The target platform is android ICS. I want to develop on Ubuntu Linux. What are the chances I get it working? What are the required steps. Setup android SDK, NDK, crosscompiler ...
There is an older question here, related to libusb on android but no information how.
Is it maybe easier to port the application to androids own usb library?
推荐答案
的libusb可以在一个无根的Android合作(提供设备支持USB主机...这是非常重要的,因为不是所有的设备都)。您需要使用标准的Android USB协议栈。然后,您可以从USBDevice一个设备描述符,并且在传递给libusb的。
Libusb can work on a non-rooted android (provided the device supports USB host ... this is VERY important as not all devices do). You need to use the standard android USB stack. You can then get a device descriptor from the USBDevice and pass that over to libusb.
不幸的是,你还需要修改的libusb。幸运的是其他人解释你如何需要修改的libusb。
Unfortunately you also need to modify libusb. Fortunately other people have explained how you need to modify LibUSB.
的libusb已被修改here.
LibUSB has been modified here.
祝你好运!
修改的
Edit:
首先,您需要定义一个广播接收器:
First you need to define a broadcast receiver:
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action))
{
synchronized (this)
{
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false))
{
if(device != null)
{
UsbDeviceConnection deviceConnection = mUsbManager.openDevice( device );
Log.d( "USB", deviceConnection.getSerial() );
}
}
else
{
Log.d( "USB", "permission denied for device " + device);
}
}
}
}
}
现在你需要创建一个USBManager和枚举的设备:
Now you need to create a USBManager and enumerate the devices:
mUsbManager = (UsbManager) getSystemService( Context.USB_SERVICE );
HashMap< String, UsbDevice > stringDeviceMap = mUsbManager.getDeviceList();
Collection< UsbDevice > usbDevices = stringDeviceMap.values();
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent( ACTION_USB_PERMISSION ), 0 );
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver( mUsbReceiver, filter );
Iterator< UsbDevice > usbDeviceIter = usbDevices.iterator();
while( usbDeviceIter.hasNext() )
{
if ( USBDeviceValid( usbDevice ) )
{
// Request permission to access the device.
mUsbManager.requestPermission( usbDevice, mPermissionIntent );
// Open the device.
UsbDeviceConnection connection = mUsbManager.openDevice( usbDevice );
int fd = connection.getFileDescriptor();
// Now pass the file descriptor to libusb through a native call.
}
}
修改2 的
Edit 2:
获取libusb的建设是把文件放在方便(我把它们放在JNI / libusb的),然后添加以下行到你的Android.mk的只是一个问题:
Getting libusb to build is just a matter of putting the files somewhere handy (I put them in jni/libusb) and then adding the following lines to your Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := libusb
LOCAL_SRC_FILES := libusb/core.c libusb/descriptor.c libusb/io.c libusb/sync.c libusb/os/linux_usbfs.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
这篇关于编译和链接反对的libusb为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!