I need to write a script to detect if the physical touchscreen is connected to my Android device at boot time.
I tried to list the content of the folder /dev/input via adb and I obtain the following output:
root#q88:/dev/input # ls
event0
event1
event2
event3
event4
mice
If I am not mistaken, event0 identifies the touchscreen, but it is visible in both case the touchscreen is connected or not.
Is there a way to detect if the touchscreen is connected to the device?
Thanks in advance.
You can read /proc/bus/input/devices to get details of your existing input devices.
Depending on your hardware's name, you could do something like that and check if there is any output:
cat /proc/bus/input/devices | grep "Name=" | grep "Touch"
This is the full output of /proc/bus/input/devices:
I: Bus=0011 Vendor=0002 Product=0008 Version=2222
N: Name="AlpsPS/2 ALPS DualPoint TouchPad"
P: Phys=isa0060/serio1/input0
S: Sysfs=/class/input/input2
H: Handlers=mouse1 event2 ts1
B: EV=f
B: KEY=420 0 70000 0 0 0 0 0 0 0 0
B: REL=3
B: ABS=1000003
[...] (blank line, next device)
The B in front stands for bitmap, N, P, S, U, H are simply first
letter in corresponding name value and I is for ID. In ordered
fashion:
I → #id: id of the device (struct input_id)
Bus → id.bustype
Vendor → id.vendor
Product → id.product
Version → id.version
N → name of the device
P → physical path to the device in the system hierarchy
S → sysfs path
U → unique identification code for the device (if device has it)
H → list of input handles associated with the device
B → bitmaps
PROP → device properties and quirks
EV → types of events supported by the device
KEY → keys/buttons this device has
MSC → miscellaneous events supported by the device
LED → leds present on the device
REL → relative address
ABS → absolute address
To test if the device is actually attached, you can try simulating events and see if you get any errors:
input tap [x] [y]
Android comes with an input command-line tool that can simulate miscellaneous input events.
input → The command line tool to send events
tap → the action
[x] → X coordinate on the screen
[y] → Y coordinate on the screen
Find a driver name for the touch controller of your device. Then check its sysfs location. There will be few files mapped to the internal variables which were populated with data read from the physical touchscreen device during its initialization. For example most touchscreen controllers have updateable firmware and provide a way to query its current version.
One of my devices uses atmel_mxt_ts touchscreen controller and its sysfs location is /sys/bus/i2c/drivers/atmel_mxt_ts/1-004a/. There is a fw_version file in that folder. If the physical touchscreen is connected that file would contain the current firmware label. The empty file would mean that there is no touchscreen.
Related
I would like to send data from my Windows computer to my Android Mobile.
For this, I need to activate the Accessory mode of the Android device and the USB Host mode on the Windows device.
On my Windows computer, I have a USB Composite device for the Android Mobile. This Composite USB device bundles several interfaces: Enumeration of USB Composite Devices.
Unfortunately, I can't find information how I can access the single devices of a Composite device.
I want to get a device id / path, which I can open with CreateFile to use the created HANDLE for opening a WinUsb handle with WinUsb_Initialize.
But if I try to open a Composite USB device with CreateFile, I get a ERROR_NOT_ENOUGH_MEMORY result.
I'm using this code:
_deviceHandle = CreateFile(
deviceId, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_NONE, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
... with the filename "\?\USB#VID_04E8&PID_6864#RF8NB0NMT0X#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"
It's a GUID_DEVINTERFACE_USB_DEVICE device id for a Samsung Galaxy mobile with enabled USB debugging.
As the driver Windows uses ssudbus2.sys, Version 2.17.16.0 (2021-09-14) from Samsung Electronics Co. Ltd.
The app MyPhoneExplorer can access to my mobile. So it a solution without a special driver must be possible.
How can I get this device id / path of the single USB devices inside a Composite USB device?
The filename you are using represents the overall USB device; it doesn't represent any particular instance. A filename that represents interface will have something like &mi_01 right after the product name, where 1 is the 0-based interface number.
You might be able to just insert the appropriate &mi_xx string into your filename at the appropriate place and get it work. I think you'd also need to modify the GUID at the end of the string, which is the device interface GUID.
The more standard way to find the filename in code is to use the SetupAPI and the configuration manager (CM) API to iterate through all the child devices of your USB device. Look for a child whose device instance ID (retrieved with CM_Get_Device_ID) contains MI_xx where xx is the two-digit interface number you are looking for.
It takes a lot of effort to write up this code in standalone form, and test it, and debug it, so I will not be presenting you with a working code example. Instead, I encourage you to look at the working code in the get_interface_composite function of libusbp which does what you need to do:
https://github.com/pololu/libusbp/blob/759f48d/src/windows/interface_windows.c#L86
There are some more steps to get the path of that device node. And then the code that actually calls CreateFile and WinUsb_Initialize is here:
https://github.com/pololu/libusbp/blob/759f48d/src/windows/generic_handle_windows.c#L56-L77
I developed an android app that sends data (text, binary, hex..etc) using bluetooth communication. I want to test my app, what methods are there?
Is there a method on mac to receive what is sent ?
There is an app called LightBlue on the Mac (and iOS) App Stores which is very useful when developing with BLE. It allows you to scan, see advertisement data (iOS version only), connect, list services and characteristics, subscribe to a notify / indicate characteristic and read or write a characteristic's value.
For classic Bluetooth, if using SPP you will need a serial terminal. First you need to connect to your device from the Bluetooth System Preferences. This will create a device file in /dev, its name follows the pattern /dev/cu.<DEVICE_NAME>-SPPDev where DEVICE_NAME is the advertised Local Name. This is a character device that you can use with any program that can read(2) and write(2) to a file. For instance the simplest way with default tools, if your device file is /dev/cu.XXXX, is to run cat /dev/cu.XXXX in one terminal window (or cat /dev/cu.XXXX | hexdump -C for hex output), then in another terminal window run echo -n "my command" > /dev/cu.XXXX. Then in the first terminal window you will see the response from your device. For hex input you can use the -e switch and backslash escapes, for instance to send 0x01 0x02, you would run echo -ne "\x01\x02" > /dev/cu.XXXX.
There are programs that are specialized in this sort of communication, called serial terminals. These also let you change the serial port configuration, although the one selected by osx is generally good. I personally use cutecom for this. In cutecom, you need to input the device file name (/dev/cu.XXXX) in the "Device" text field, then configure the desired serial port parameters. To use those that osx selected, just uncheck the "Apply settings when opening" checkbox. Then click on "Open device". You can then input text or hex and see output as text or hex also. If you get gibberish on the output that means that the serial port parameters are not good. If you don't know the right parameters for your device you can experiment, but a typical configuration would be Baud rate : 115200; Data bits : 8; Stop bits : 1; Parity : None, and no handshake.
I have a ViewSonic touch screen display connected to an Android PC (kernel 3.0.36+) via HDMI & USB. The display shows everything correctly. Furthermore, the Linux kernel recognizes it.
dmesg:
<6>[ 99.699034] usb 2-1.2.3: new full speed USB device number 8 using usb20_host
<6>[ 99.800896] usb 2-1.2.3: New USB device found, idVendor=0408, idProduct=3008
<6>[ 99.800993] usb 2-1.2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=4
<6>[ 99.801099] usb 2-1.2.3: Product: OpticalTouchScreen
<6>[ 99.801169] usb 2-1.2.3: Manufacturer: Quanta
<6>[ 99.801226] usb 2-1.2.3: SerialNumber: 0000
<4>[ 99.805402] quirks: 0x00000000
The problem is that the screen, while I can touch anywhere, only registers the tap at the curser location (wireless keyboard/mouse connected). If I move the cursor and tap anywhere on the screen, the new location receives the tap. If I remove the keyboard/mouse dongle the behavior remains, but now I can't move the cursor.
The USB connection to the monitor is being displayed (highlighted) in dev/usb:
Input device configuration file located in /system/usr/idc/Vendor_0408_Product_3008.idc
# Input device configuration file.
# This is an external device, attached to the USB or Bluetooth bus.
device.internal = 0
# The device should behave as a touch screen, which uses the same orientation
# as the built-in display.
touch.deviceType = touchScreen
touch.orientationAware = 0
touch.gestureMode = spots
# Orientation
touch.orientation.calibration = vector
# Output Ranges
output.width = 1920
output.height = 1080
output.diag = sqrt(output.width ^2 + output.height ^2)
Any guidance or suggestions are appreciated!
Is there any "universal" vendor ID that I can use so that ADB can detect my China-made Tablet? I can't find the vendor ID of the manufacturer. When I look into Device Manager in Windows the Vendor is a string and not a number. The device is a Cherry Mobile Fusion Bolt tablet.
Try this tool if you are on a windows machine- lsusb Link
If you are on a linux machine, you can run the lsusb command.
The tool is for windows platform. Run it while your tablet is connected through a USB. It may show your Vendor ID. If it does, you can try manually adding it to [USER_DIRECTORY] / .android / adb_usb.ini.
The vendor ID of the device can not be modified without replacing the software on the device (read a new AOSP installation). To use the Google driver, the Vendor ID of the product needs to be known.
Finding Vendor ID in Windows
Start Device Manager
In the Hardware tree, right-click the hardware entry for the device for which the Vendor ID is to be determined.
On the Details tab, set the property drop-down to be "Hardware Ids". The Vendor ID is the 4 character hexadecimal number following the letters VID_. In the case below, the Vendor ID is 18D1:
The PID_, which follows, is the Product ID. It also has a 4-digit hexadecimal number.
Is there a way to determine if a smart phone or tablet (iOS or Android), is plugged into a computer?
Either the phone/tablet perspective (i.e. isConnectedToComputer) or the computer perspective (i.e. connectedDevices) would be fine.
If it's from the computer perspective, it would specifically have to be via a Mac OS X app.
If it's from the phone/tablet perspective, it would need to be differentiated from simply charging.
The general idea is to determine when a user is at their computer.
Note: In order to make this determination, I need to identify the device. For iOS, the device UUID (similar to that used in APNS) is used. In Android, a combination hardware and software IDs are combined. So if the solution in from the computer perspective, I need to be able to obtain these strings. Otherwise, I need to be able to pass them to the computer.
Bonus: It would be fantastic if Wi-Fi syncing could also be taken into account as "connected".
Simple Solution
Consider using system_profiler SPUSBDataType through NSTask.
When my iPhone is connected the following is included in the result:
iPhone:
Product ID: 0x1292
Vendor ID: 0x05ac (Apple Inc.)
Version: 0.01
Serial Number:
Speed: Up to 480 Mb/sec
Manufacturer: Apple Inc.
Location ID: 0xfa140000 / 6
Current Available (mA): 500
Current Required (mA): 500
Extra Operating Current (mA): 500
Use system_profiler SPUSBDataType -xml to output the result in XML format:
<dict>
<key>_name</key>
<string>iPhone</string>
<key>a_product_id</key>
<string>0x1292</string>
<key>b_vendor_id</key>
<string>apple_vendor_id</string>
<key>c_bcd_device</key>
<string> 0.01</string>
<key>d_serial_num</key>
<string></string>
<key>e_device_speed</key>
<string>high_speed</string>
<key>f_manufacturer</key>
<string>Apple Inc.</string>
<key>g_location_id</key>
<string>0xfa140000 / 6</string>
<key>h_bus_power</key>
<string>500</string>
<key>j_bus_power_used</key>
<string>500</string>
<key>k_extra_current_used</key>
<string>500</string>
</dict>
Simply parse the XML to determine wether the device of interest is connected or not.