diff --git a/ReadMe.txt b/ReadMe.txt index edc212b..b9e8caf 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -55,19 +55,19 @@ LINKS CHANGES -Version 2.3 (2021-02-xx) +Version 2.3 (2021-09-xx) - 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: 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 No issue with Prolific PL2303GT3 Not reproducible! - FIX: No 'No driver' on real device 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 - 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). - 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. diff --git a/app/src/main/assets/ReadMe.txt b/app/src/main/assets/ReadMe.txt index adb5505..19a3478 100644 --- a/app/src/main/assets/ReadMe.txt +++ b/app/src/main/assets/ReadMe.txt @@ -55,14 +55,10 @@ LINKS CHANGES -Version 2.3 (2021-02-xx) +Version 2.3 (2021-09-xx) - Add the serial port support (via USB OTG). - TODO: When stop the app, Serial exception seems to delay the save of the calc state!!!! - 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). +- 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. - Open an external web browser when you click an external links in the Help. diff --git a/app/src/main/cpp/emu-jni.c b/app/src/main/cpp/emu-jni.c index 862dd2c..be894af 100644 --- a/app/src/main/cpp/emu-jni.c +++ b/app/src/main/cpp/emu-jni.c @@ -1297,7 +1297,7 @@ JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_setConfiguration(J SwitchToState(nOldState); } } 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; _tcsncpy(szSerialWire, newSerialWire, sizeof(szSerialWire)); if(bCommInit && serialWireChanged) { @@ -1305,7 +1305,7 @@ JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_setConfiguration(J bCommInit = CommOpen(szSerialWire, szSerialIr); } } 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; _tcsncpy(szSerialIr, newSerialIr, sizeof(szSerialIr)); if(bCommInit && serialIrChanged) { diff --git a/app/src/main/java/org/emulator/calculator/Serial.java b/app/src/main/java/org/emulator/calculator/Serial.java index e7770f8..f18c8f9 100644 --- a/app/src/main/java/org/emulator/calculator/Serial.java +++ b/app/src/main/java/org/emulator/calculator/Serial.java @@ -73,24 +73,37 @@ public class Serial { public synchronized boolean connect(String 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); if (m.find()) { - String deviceText = m.group(1); - String portText = m.group(2); - int deviceId = 0; - try { - deviceId = Integer.parseInt(deviceText); - } catch (NumberFormatException ex) { - // Catch bad number format + String vendorIdText = m.group(1); + String productIdText = m.group(2); + String portText = m.group(3); + int vendorId = 0; + if(vendorIdText != null) { + try { + 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; - try { - portNum = Integer.parseInt(portText); - } catch (NumberFormatException ex) { - // Catch bad number format + if(portText != null) { + try { + portNum = Integer.parseInt(portText); + } catch (NumberFormatException ex) { + // Catch bad number format + } } - return connect(deviceId, portNum); + return connect(vendorId, productId, portNum); } return false; } @@ -99,14 +112,16 @@ public class Serial { return connectionStatus; } - public synchronized boolean connect(int deviceId, int portNum) { - if(debug) Log.d(TAG, "connect(deviceId: " + deviceId + ", portNum" + portNum + ")"); + public synchronized boolean connect(int vendorId, int productId, int portNum) { + if(debug) Log.d(TAG, String.format("connect('%04X:%04X', portNum: %d)", vendorId, productId, portNum)); UsbDevice device = null; UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); for(UsbDevice v : usbManager.getDeviceList().values()) - if(v.getDeviceId() == deviceId) + if(v.getVendorId() == vendorId && v.getProductId() == productId) { device = v; + break; + } if(device == null) { connectionStatus = "serial_connection_failed_device_not_found"; if(debug) Log.d(TAG, "connectionStatus = " + connectionStatus); @@ -127,7 +142,7 @@ public class Serial { return false; } usbSerialPort = driver.getPorts().get(portNum); - UsbDeviceConnection usbConnection = null; + UsbDeviceConnection usbConnection; try { usbConnection = usbManager.openDevice(driver.getDevice()); } catch (SecurityException e) { diff --git a/app/src/main/java/org/emulator/calculator/usbserial/DevicesFragment.java b/app/src/main/java/org/emulator/calculator/usbserial/DevicesFragment.java index d9a7ebf..d6a1010 100644 --- a/app/src/main/java/org/emulator/calculator/usbserial/DevicesFragment.java +++ b/app/src/main/java/org/emulator/calculator/usbserial/DevicesFragment.java @@ -106,21 +106,18 @@ public class DevicesFragment extends ListFragment { } public static class SerialConnectParameters { - public int deviceId; public int port; public int vendorId; public int productId; public String modelName; public SerialConnectParameters() { - this.deviceId = 0; this.port = 0; this.vendorId = 0; this.productId = 0; this.modelName = ""; } - public SerialConnectParameters(int device, int port, int vendorId, int productId, String modelName) { - this.deviceId = device; + public SerialConnectParameters(int port, int vendorId, int productId, String modelName) { this.port = port; this.vendorId = vendorId; this.productId = productId; @@ -128,18 +125,18 @@ public class DevicesFragment extends ListFragment { } 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() { - 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) { - 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")); 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) { @@ -149,19 +146,13 @@ public class DevicesFragment extends ListFragment { } 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); if (m.find()) { - String deviceText = m.group(1); - String portText = m.group(2); - String vendorIdText = m.group(3); - String productIdText = m.group(4); - modelName = m.group(5); - try { - deviceId = Integer.parseInt(deviceText); - } catch (NumberFormatException ex) { - // Catch bad number format - } + String portText = m.group(1); + String vendorIdText = m.group(2); + String productIdText = m.group(3); + modelName = m.group(4); try { port = Integer.parseInt(portText); } catch (NumberFormatException ex) { @@ -207,12 +198,12 @@ public class DevicesFragment extends ListFragment { if(item.driver == null) { Toast.makeText(getActivity(), getString(Utils.resId(this, "string", "serial_ports_device_no_driver")), Toast.LENGTH_SHORT).show(); if(onSerialDeviceClickedListener != null) - onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(0, 0, + onSerialDeviceClickedListener.onSerialDeviceClicked(new SerialConnectParameters(0, 0, 0, "")); } else if(item.device != 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.driver.getClass().getSimpleName().replace("SerialDriver",""))); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb53dda..0fab206 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -131,7 +131,7 @@ USB Devices USB Devices no USB devices found - %s (%04X:%04X) [%d,%d] + %s (%04X:%04X) [%d] No driver %s, Port %d Vendor %04X, Product %04X @@ -218,8 +218,8 @@ Use Real Replay Speed Manual Replay Speed - Serial Ports + Serial Ports (Please allow USB OTG) Wire - Infrared (2400 baud) + Infrared (2400 baud only)