-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
1,588 additions
and
1,080 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.codecrete.usb.examples</groupId> | ||
<artifactId>kotlin</artifactId> | ||
<version>0.6.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>kotlin</name> | ||
<url>https://github.com/manuelbl/JavaDoesUSB/examples/kotlin</url> | ||
|
||
<properties> | ||
<kotlin.version>1.9.10</kotlin.version> | ||
<kotlin.compiler.incremental>true</kotlin.compiler.incremental> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.codecrete.usb</groupId> | ||
<artifactId>java-does-usb</artifactId> | ||
<version>0.7.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.tinylog</groupId> | ||
<artifactId>tinylog-api</artifactId> | ||
<version>2.6.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.tinylog</groupId> | ||
<artifactId>tinylog-impl</artifactId> | ||
<version>2.6.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.tinylog</groupId> | ||
<artifactId>jsl-tinylog</artifactId> | ||
<version>2.6.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
95 changes: 95 additions & 0 deletions
95
examples/enumerate_kotlin/src/main/kotlin/net/codecrete/usb/examples/Enumerate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package net.codecrete.usb.examples | ||
|
||
import net.codecrete.usb.* | ||
import kotlin.math.min | ||
|
||
|
||
fun main() { | ||
Enumerate().enumerate() | ||
} | ||
|
||
class Enumerate { | ||
|
||
private var classInfo = UsbClassInfo() | ||
|
||
fun enumerate() { | ||
for (device in Usb.getDevices()) { | ||
printDevice(device) | ||
} | ||
} | ||
|
||
private fun printDevice(device: UsbDevice) { | ||
println("Device:") | ||
System.out.printf(" VID: 0x%04x%n", device.vendorId) | ||
System.out.printf(" PID: 0x%04x%n", device.productId) | ||
if (device.manufacturer != null) System.out.printf(" Manufacturer: %s%n", device.manufacturer) | ||
if (device.product != null) System.out.printf(" Product name: %s%n", device.product) | ||
if (device.serialNumber != null) System.out.printf(" Serial number: %s%n", device.serialNumber) | ||
System.out.printf(" Device class: 0x%02x", device.classCode) | ||
printInParens(classInfo.lookupClass(device.classCode)) | ||
System.out.printf(" Device subclass: 0x%02x", device.subclassCode) | ||
printInParens(classInfo.lookupSubclass(device.classCode, device.subclassCode)) | ||
System.out.printf(" Device protocol: 0x%02x", device.protocolCode) | ||
printInParens(classInfo.lookupProtocol(device.classCode, device.subclassCode, device.protocolCode)) | ||
for (intf in device.interfaces) printInterface(intf) | ||
printRawDescriptor("Device descriptor", device.deviceDescriptor) | ||
printRawDescriptor("Configuration descriptor", device.configurationDescriptor) | ||
println() | ||
println() | ||
} | ||
|
||
private fun printInParens(text: String?) { | ||
if (text != null) { | ||
System.out.printf(" (%s)%n", text) | ||
} else { | ||
println() | ||
} | ||
} | ||
|
||
private fun printInterface(intf: UsbInterface) { | ||
for (alt in intf.alternates) printAlternate(alt, intf.number, alt === intf.currentAlternate) | ||
} | ||
|
||
private fun printAlternate(alt: UsbAlternateInterface, intferfaceNumber: Int, isDefault: Boolean) { | ||
println() | ||
if (isDefault) { | ||
System.out.printf(" Interface %d%n", intferfaceNumber) | ||
} else { | ||
System.out.printf(" Interface %d (alternate %d)%n", intferfaceNumber, alt.number) | ||
} | ||
System.out.printf(" Interface class: 0x%02x", alt.classCode) | ||
printInParens(classInfo.lookupClass(alt.classCode)) | ||
System.out.printf(" Interface subclass: 0x%02x", alt.subclassCode) | ||
printInParens(classInfo.lookupProtocol(alt.classCode, alt.subclassCode, alt.protocolCode)) | ||
System.out.printf(" Interface protocol: 0x%02x", alt.protocolCode) | ||
printInParens(classInfo.lookupProtocol(alt.classCode, alt.subclassCode, alt.protocolCode)) | ||
for (endpoint in alt.endpoints) | ||
printEndpoint(endpoint) | ||
} | ||
|
||
private fun printEndpoint(endpoint: UsbEndpoint) { | ||
println() | ||
System.out.printf(" Endpoint %d%n", endpoint.number) | ||
System.out.printf(" Direction: %s%n", endpoint.direction.name) | ||
System.out.printf(" Transfer type: %s%n", endpoint.transferType.name) | ||
System.out.printf(" Packet size: %d bytes%n", endpoint.packetSize) | ||
} | ||
|
||
private fun printRawDescriptor(title: String, descriptor: ByteArray) { | ||
println() | ||
println(title) | ||
val len = descriptor.size | ||
var i = 0 | ||
while (i < len) { | ||
System.out.printf("%04x ", i) | ||
var j = i | ||
while (j < min(i + 16, len)) { | ||
System.out.printf(" %02x", descriptor[j].toInt() and 255) | ||
j += 1 | ||
} | ||
println() | ||
i += 16 | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.