mirror of
https://github.com/dgis/emu48android
synced 2024-12-26 09:58:49 +01:00
Use USB VendorId:ProductId instead of the deviceId for the Serial USB.
This commit is contained in:
parent
e7a7503151
commit
e22e7f36a5
6 changed files with 55 additions and 53 deletions
|
@ -55,19 +55,19 @@ LINKS
|
||||||
|
|
||||||
CHANGES
|
CHANGES
|
||||||
|
|
||||||
Version 2.3 (2021-02-xx)
|
Version 2.3 (2021-09-xx)
|
||||||
|
|
||||||
- Add the serial port support (via USB OTG).
|
- Add the serial port support (via USB OTG).
|
||||||
FIX: When stop the app, Serial exception seems to delay the save of the calc state!!!!
|
FIX: When stop the app, Serial exception seems to delay the save of the calc state!!!!
|
||||||
FIX: Inform if the connection is not possible.
|
FIX: Inform if the connection is not possible.
|
||||||
|
FIX: No 'No driver' on real device
|
||||||
|
FIX: ID change -> replace id by vendor:device ids?
|
||||||
BUG: From Windows to Android with HP49G QINHENG CH340 -> all character at once bug
|
BUG: From Windows to Android with HP49G QINHENG CH340 -> all character at once bug
|
||||||
No issue with Prolific PL2303GT3
|
No issue with Prolific PL2303GT3
|
||||||
Not reproducible!
|
Not reproducible!
|
||||||
FIX: No 'No driver' on real device
|
|
||||||
BUG: When openIO on real device, 1st OPENIO failed, 2nd OPENIO succeeded
|
BUG: When openIO on real device, 1st OPENIO failed, 2nd OPENIO succeeded
|
||||||
BUG: ID change -> replace id by vendor:device ids?
|
|
||||||
TEST: With real HP48SX
|
TEST: With real HP48SX
|
||||||
TODO: Check the self test about UART (http://regis.cosnier.free.fr/private/private.php?journal=HP48&index=-4637&nomenu)
|
TODO: Check the self test about UART
|
||||||
- Allows pressing a calculator button with the right button of the mouse and prevents its release to allow the On+A+F key combination (with Android version >= 5.0).
|
- Allows pressing a calculator button with the right button of the mouse and prevents its release to allow the On+A+F key combination (with Android version >= 5.0).
|
||||||
- Update the embedded help file "Emu48.html" to the latest version.
|
- Update the embedded help file "Emu48.html" to the latest version.
|
||||||
- Open an external web browser when you click an external links in the Help.
|
- Open an external web browser when you click an external links in the Help.
|
||||||
|
|
|
@ -55,14 +55,10 @@ LINKS
|
||||||
|
|
||||||
CHANGES
|
CHANGES
|
||||||
|
|
||||||
Version 2.3 (2021-02-xx)
|
Version 2.3 (2021-09-xx)
|
||||||
|
|
||||||
- Add the serial port support (via USB OTG).
|
- Add the serial port support (via USB OTG).
|
||||||
TODO: When stop the app, Serial exception seems to delay the save of the calc state!!!!
|
- Allows pressing a calculator button with the right button of the mouse and prevents its release to allow the On+A+F key combination (with Android version >= 5.0).
|
||||||
TODO: Inform if the connection is not possible.
|
|
||||||
TODO: What's happen if I hot unplug?
|
|
||||||
TODO: Check the self test about UART (http://regis.cosnier.free.fr/private/private.php?journal=HP48&index=-4637&nomenu)
|
|
||||||
- Allows pressing a calculator button with the right button of the mouse but prevents its release to allow the On+A+F key combination (with Android version >= 5.0).
|
|
||||||
- Update the embedded help file "Emu48.html" to the latest version.
|
- Update the embedded help file "Emu48.html" to the latest version.
|
||||||
- Open an external web browser when you click an external links in the Help.
|
- Open an external web browser when you click an external links in the Help.
|
||||||
|
|
||||||
|
|
|
@ -1297,7 +1297,7 @@ JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_setConfiguration(J
|
||||||
SwitchToState(nOldState);
|
SwitchToState(nOldState);
|
||||||
}
|
}
|
||||||
} else if(_tcscmp(_T("settings_serial_ports_wire"), configKey) == 0) {
|
} else if(_tcscmp(_T("settings_serial_ports_wire"), configKey) == 0) {
|
||||||
const char * newSerialWire = _tcscmp(_T("0,0"), configStringValue) == 0 ? NO_SERIAL : configStringValue;
|
const char * newSerialWire = _tcscmp(_T("0000:0000,0"), configStringValue) == 0 ? NO_SERIAL : configStringValue;
|
||||||
BOOL serialWireChanged = _tcscmp(szSerialWire, newSerialWire) != 0;
|
BOOL serialWireChanged = _tcscmp(szSerialWire, newSerialWire) != 0;
|
||||||
_tcsncpy(szSerialWire, newSerialWire, sizeof(szSerialWire));
|
_tcsncpy(szSerialWire, newSerialWire, sizeof(szSerialWire));
|
||||||
if(bCommInit && serialWireChanged) {
|
if(bCommInit && serialWireChanged) {
|
||||||
|
@ -1305,7 +1305,7 @@ JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_setConfiguration(J
|
||||||
bCommInit = CommOpen(szSerialWire, szSerialIr);
|
bCommInit = CommOpen(szSerialWire, szSerialIr);
|
||||||
}
|
}
|
||||||
} else if(_tcscmp(_T("settings_serial_ports_ir"), configKey) == 0) {
|
} else if(_tcscmp(_T("settings_serial_ports_ir"), configKey) == 0) {
|
||||||
const char * newSerialIr = _tcscmp(_T("0,0"), configStringValue) == 0 ? NO_SERIAL : configStringValue;
|
const char * newSerialIr = _tcscmp(_T("0000:0000,0"), configStringValue) == 0 ? NO_SERIAL : configStringValue;
|
||||||
BOOL serialIrChanged = _tcscmp(szSerialIr, newSerialIr) != 0;
|
BOOL serialIrChanged = _tcscmp(szSerialIr, newSerialIr) != 0;
|
||||||
_tcsncpy(szSerialIr, newSerialIr, sizeof(szSerialIr));
|
_tcsncpy(szSerialIr, newSerialIr, sizeof(szSerialIr));
|
||||||
if(bCommInit && serialIrChanged) {
|
if(bCommInit && serialIrChanged) {
|
||||||
|
|
|
@ -73,24 +73,37 @@ public class Serial {
|
||||||
public synchronized boolean connect(String serialPort) {
|
public synchronized boolean connect(String serialPort) {
|
||||||
if(debug) Log.d(TAG, "connect( " + serialPort + ")");
|
if(debug) Log.d(TAG, "connect( " + serialPort + ")");
|
||||||
|
|
||||||
Pattern patternSerialPort = Pattern.compile("\\\\.\\\\(\\d+),(\\d+)");
|
Pattern patternSerialPort = Pattern.compile("\\\\.\\\\([0-9a-fA-F]+):([0-9a-fA-F]+),(\\d+)");
|
||||||
Matcher m = patternSerialPort.matcher(serialPort);
|
Matcher m = patternSerialPort.matcher(serialPort);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
String deviceText = m.group(1);
|
String vendorIdText = m.group(1);
|
||||||
String portText = m.group(2);
|
String productIdText = m.group(2);
|
||||||
int deviceId = 0;
|
String portText = m.group(3);
|
||||||
try {
|
int vendorId = 0;
|
||||||
deviceId = Integer.parseInt(deviceText);
|
if(vendorIdText != null) {
|
||||||
} catch (NumberFormatException ex) {
|
try {
|
||||||
// Catch bad number format
|
vendorId = Integer.parseInt(vendorIdText, 16);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int productId = 0;
|
||||||
|
if(productIdText != null) {
|
||||||
|
try {
|
||||||
|
productId = Integer.parseInt(productIdText, 16);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int portNum = 0;
|
int portNum = 0;
|
||||||
try {
|
if(portText != null) {
|
||||||
portNum = Integer.parseInt(portText);
|
try {
|
||||||
} catch (NumberFormatException ex) {
|
portNum = Integer.parseInt(portText);
|
||||||
// Catch bad number format
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return connect(deviceId, portNum);
|
return connect(vendorId, productId, portNum);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -99,14 +112,16 @@ public class Serial {
|
||||||
return connectionStatus;
|
return connectionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean connect(int deviceId, int portNum) {
|
public synchronized boolean connect(int vendorId, int productId, int portNum) {
|
||||||
if(debug) Log.d(TAG, "connect(deviceId: " + deviceId + ", portNum" + portNum + ")");
|
if(debug) Log.d(TAG, String.format("connect('%04X:%04X', portNum: %d)", vendorId, productId, portNum));
|
||||||
|
|
||||||
UsbDevice device = null;
|
UsbDevice device = null;
|
||||||
UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
||||||
for(UsbDevice v : usbManager.getDeviceList().values())
|
for(UsbDevice v : usbManager.getDeviceList().values())
|
||||||
if(v.getDeviceId() == deviceId)
|
if(v.getVendorId() == vendorId && v.getProductId() == productId) {
|
||||||
device = v;
|
device = v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(device == null) {
|
if(device == null) {
|
||||||
connectionStatus = "serial_connection_failed_device_not_found";
|
connectionStatus = "serial_connection_failed_device_not_found";
|
||||||
if(debug) Log.d(TAG, "connectionStatus = " + connectionStatus);
|
if(debug) Log.d(TAG, "connectionStatus = " + connectionStatus);
|
||||||
|
@ -127,7 +142,7 @@ public class Serial {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
usbSerialPort = driver.getPorts().get(portNum);
|
usbSerialPort = driver.getPorts().get(portNum);
|
||||||
UsbDeviceConnection usbConnection = null;
|
UsbDeviceConnection usbConnection;
|
||||||
try {
|
try {
|
||||||
usbConnection = usbManager.openDevice(driver.getDevice());
|
usbConnection = usbManager.openDevice(driver.getDevice());
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
|
|
|
@ -106,21 +106,18 @@ public class DevicesFragment extends ListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SerialConnectParameters {
|
public static class SerialConnectParameters {
|
||||||
public int deviceId;
|
|
||||||
public int port;
|
public int port;
|
||||||
public int vendorId;
|
public int vendorId;
|
||||||
public int productId;
|
public int productId;
|
||||||
public String modelName;
|
public String modelName;
|
||||||
|
|
||||||
public SerialConnectParameters() {
|
public SerialConnectParameters() {
|
||||||
this.deviceId = 0;
|
|
||||||
this.port = 0;
|
this.port = 0;
|
||||||
this.vendorId = 0;
|
this.vendorId = 0;
|
||||||
this.productId = 0;
|
this.productId = 0;
|
||||||
this.modelName = "";
|
this.modelName = "";
|
||||||
}
|
}
|
||||||
public SerialConnectParameters(int device, int port, int vendorId, int productId, String modelName) {
|
public SerialConnectParameters(int port, int vendorId, int productId, String modelName) {
|
||||||
this.deviceId = device;
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.vendorId = vendorId;
|
this.vendorId = vendorId;
|
||||||
this.productId = productId;
|
this.productId = productId;
|
||||||
|
@ -128,18 +125,18 @@ public class DevicesFragment extends ListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toSettingsString() {
|
public String toSettingsString() {
|
||||||
return String.format(Locale.US, "%d,%d,%d,%d,%s", deviceId, port, vendorId, productId, modelName);
|
return String.format(Locale.US, "%d,%d,%d,%s", port, vendorId, productId, modelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toWin32String() {
|
public String toWin32String() {
|
||||||
return String.format(Locale.US, "%d,%d", deviceId, port);
|
return String.format(Locale.US, "%04X:%04X,%d", vendorId, productId, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toDisplayString(Context context) {
|
public String toDisplayString(Context context) {
|
||||||
if(deviceId == 0 && port == 0)
|
if(vendorId == 0 && productId == 0 && port == 0)
|
||||||
return context.getResources().getString(Utils.resId(context, "string", "serial_ports_device_no_driver"));
|
return context.getResources().getString(Utils.resId(context, "string", "serial_ports_device_no_driver"));
|
||||||
else
|
else
|
||||||
return String.format(Locale.US, context.getResources().getString(Utils.resId(context, "string", "serial_ports_device")), modelName, vendorId, productId, deviceId, port);
|
return String.format(Locale.US, context.getResources().getString(Utils.resId(context, "string", "serial_ports_device")), modelName, vendorId, productId, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SerialConnectParameters fromSettingsString(String serialPorts) {
|
public static SerialConnectParameters fromSettingsString(String serialPorts) {
|
||||||
|
@ -149,19 +146,13 @@ public class DevicesFragment extends ListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fromSettingsStringExtractor(String serialPorts) {
|
private void fromSettingsStringExtractor(String serialPorts) {
|
||||||
Pattern patternSerialPort = Pattern.compile("(\\d+),(\\d+),(\\d+),(\\d+),([^,]+)");
|
Pattern patternSerialPort = Pattern.compile("(\\d+),(\\d+),(\\d+),([^,]+)");
|
||||||
Matcher m = patternSerialPort.matcher(serialPorts);
|
Matcher m = patternSerialPort.matcher(serialPorts);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
String deviceText = m.group(1);
|
String portText = m.group(1);
|
||||||
String portText = m.group(2);
|
String vendorIdText = m.group(2);
|
||||||
String vendorIdText = m.group(3);
|
String productIdText = m.group(3);
|
||||||
String productIdText = m.group(4);
|
modelName = m.group(4);
|
||||||
modelName = m.group(5);
|
|
||||||
try {
|
|
||||||
deviceId = Integer.parseInt(deviceText);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
// Catch bad number format
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
port = Integer.parseInt(portText);
|
port = Integer.parseInt(portText);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
|
@ -207,12 +198,12 @@ public class DevicesFragment extends ListFragment {
|
||||||
if(item.driver == null) {
|
if(item.driver == null) {
|
||||||
Toast.makeText(getActivity(), getString(Utils.resId(this, "string", "serial_ports_device_no_driver")), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), getString(Utils.resId(this, "string", "serial_ports_device_no_driver")), Toast.LENGTH_SHORT).show();
|
||||||
if(onSerialDeviceClickedListener != null)
|
if(onSerialDeviceClickedListener != null)
|
||||||
onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(0, 0,
|
onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(0,
|
||||||
0, 0,
|
0, 0,
|
||||||
""));
|
""));
|
||||||
} else if(item.device != null) {
|
} else if(item.device != null) {
|
||||||
if(onSerialDeviceClickedListener != null)
|
if(onSerialDeviceClickedListener != null)
|
||||||
onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(item.device.getDeviceId(), item.port,
|
onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(item.port,
|
||||||
item.device.getVendorId(), item.device.getProductId(),
|
item.device.getVendorId(), item.device.getProductId(),
|
||||||
item.driver.getClass().getSimpleName().replace("SerialDriver","")));
|
item.driver.getClass().getSimpleName().replace("SerialDriver","")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@
|
||||||
<string name="serial_fragment_title">USB Devices</string>
|
<string name="serial_fragment_title">USB Devices</string>
|
||||||
<string name="serial_device_list_header">USB Devices</string>
|
<string name="serial_device_list_header">USB Devices</string>
|
||||||
<string name="serial_no_device">no USB devices found</string>
|
<string name="serial_no_device">no USB devices found</string>
|
||||||
<string name="serial_ports_device">%s (%04X:%04X) [%d,%d]</string>
|
<string name="serial_ports_device">%s (%04X:%04X) [%d]</string>
|
||||||
<string name="serial_ports_device_no_driver">No driver</string>
|
<string name="serial_ports_device_no_driver">No driver</string>
|
||||||
<string name="serial_ports_device_item_title">%s, Port %d</string>
|
<string name="serial_ports_device_item_title">%s, Port %d</string>
|
||||||
<string name="serial_ports_device_item_description">Vendor %04X, Product %04X</string>
|
<string name="serial_ports_device_item_description">Vendor %04X, Product %04X</string>
|
||||||
|
@ -218,8 +218,8 @@
|
||||||
<string name="settings_macro_real_speed_title">Use Real Replay Speed</string>
|
<string name="settings_macro_real_speed_title">Use Real Replay Speed</string>
|
||||||
<string name="settings_macro_manual_speed_title">Manual Replay Speed</string>
|
<string name="settings_macro_manual_speed_title">Manual Replay Speed</string>
|
||||||
|
|
||||||
<string name="settings_category_serial_ports_title">Serial Ports</string>
|
<string name="settings_category_serial_ports_title">Serial Ports (Please allow USB OTG)</string>
|
||||||
<string name="settings_serial_ports_wire_title">Wire</string>
|
<string name="settings_serial_ports_wire_title">Wire</string>
|
||||||
<string name="settings_serial_ports_ir_title">Infrared (2400 baud)</string>
|
<string name="settings_serial_ports_ir_title">Infrared (2400 baud only)</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue