improve usb driver voltage handling
This commit is contained in:
parent
c211709344
commit
1f9a9d5f22
2 changed files with 7 additions and 11 deletions
|
@ -85,14 +85,10 @@ data class UsbCcidDescription(
|
|||
private fun hasFeature(feature: Int): Boolean =
|
||||
(dwFeatures and feature) != 0
|
||||
|
||||
val voltages: Array<Voltage>
|
||||
val voltages: List<Voltage>
|
||||
get() {
|
||||
if (hasFeature(FEATURE_AUTOMATIC_VOLTAGE)) {
|
||||
return arrayOf(Voltage.AUTO)
|
||||
}
|
||||
return Voltage.entries
|
||||
.mapNotNull { if ((it.mask.toInt() and bVoltageSupport.toInt()) != 0) it else null }
|
||||
.toTypedArray()
|
||||
if (hasFeature(FEATURE_AUTOMATIC_VOLTAGE)) return listOf(Voltage.AUTO)
|
||||
return Voltage.entries.filter { (it.mask.toInt() and bVoltageSupport.toInt()) != 0 }
|
||||
}
|
||||
|
||||
val hasAutomaticPps: Boolean
|
||||
|
|
|
@ -287,13 +287,13 @@ class UsbCcidTransceiver(
|
|||
val startTime = SystemClock.elapsedRealtime()
|
||||
skipAvailableInput()
|
||||
var response: CcidDataBlock? = null
|
||||
for (v in usbCcidDescription.voltages) {
|
||||
Log.v(TAG, "CCID: attempting to power on with voltage $v")
|
||||
for (voltage in usbCcidDescription.voltages) {
|
||||
Log.v(TAG, "CCID: attempting to power on with voltage $voltage")
|
||||
response = try {
|
||||
iccPowerOnVoltage(v.powerOnValue)
|
||||
iccPowerOnVoltage(voltage.powerOnValue)
|
||||
} catch (e: UsbCcidErrorException) {
|
||||
if (e.errorResponse.bError.toInt() == 7) { // Power select error
|
||||
Log.v(TAG, "CCID: failed to power on with voltage $v")
|
||||
Log.v(TAG, "CCID: failed to power on with voltage $voltage")
|
||||
iccPowerOff()
|
||||
Log.v(TAG, "CCID: powered off")
|
||||
continue
|
||||
|
|
Loading…
Add table
Reference in a new issue