Skip to content

Commit 7975a44

Browse files
committed
Some changes for testing Teensy4IoIoOtg
1 parent 82be1e0 commit 7975a44

File tree

7 files changed

+104
-12
lines changed

7 files changed

+104
-12
lines changed

ioio/ioio/src/main/java/ioio/smallbasic/IOIOImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void sync() {
5959
lock.invoke(IOIO::sync);
6060
}
6161

62-
public void waitForConnect(int latency) {
62+
public void waitForConnect() {
6363
IOUtil.setError(null);
6464
IOService.getInstance().start();
6565
handleError();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ioio.smallbasic.pc;
2+
3+
public class HexDump {
4+
private int index;
5+
private final String prefix;
6+
7+
HexDump(String prefix) {
8+
this.index = 0;
9+
this.prefix = prefix;
10+
}
11+
12+
void print(int data) {
13+
if (index % 16 == 0) {
14+
if (index != 0) {
15+
System.out.println();
16+
}
17+
System.out.printf(" %08x ", index);
18+
}
19+
System.out.printf("%s:%02x ", prefix, data);
20+
index++;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ioio.smallbasic.pc;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
public class LoggingInputStream extends InputStream {
7+
private static final int DEBUG_OUT = 0x24;
8+
private final InputStream wrappedStream;
9+
private final HexDump hexDump;
10+
11+
public LoggingInputStream(InputStream wrappedStream) {
12+
this.wrappedStream = wrappedStream;
13+
this.hexDump = new HexDump("RX");
14+
}
15+
16+
@Override
17+
public int read() throws IOException {
18+
// see: IOIOLibCore/src/main/java/ioio/lib/impl/IOIOProtocol.java
19+
int data = wrappedStream.read();
20+
if (data == DEBUG_OUT) {
21+
System.out.print("[FIRMWARE] ");
22+
data = wrappedStream.read();
23+
while (data != '\n') {
24+
System.out.print(Character.valueOf((char) data));
25+
data = wrappedStream.read();
26+
}
27+
System.out.println();
28+
data = read();
29+
} else {
30+
hexDump.print(data);
31+
}
32+
return data;
33+
}
34+
35+
@Override
36+
public void close() throws IOException {
37+
wrappedStream.close();
38+
}
39+
}
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ioio.smallbasic.pc;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
6+
public class LoggingOutputStream extends OutputStream {
7+
private final OutputStream wrappedStream;
8+
private final HexDump hexDump;
9+
10+
public LoggingOutputStream(OutputStream outputStream) {
11+
this.wrappedStream = outputStream;
12+
this.hexDump = new HexDump("TX");
13+
}
14+
15+
@Override
16+
public void write(int b) throws IOException {
17+
wrappedStream.write(b);
18+
hexDump.print(b);
19+
}
20+
21+
@Override
22+
public void flush() throws IOException {
23+
wrappedStream.flush();
24+
}
25+
26+
@Override
27+
public void close() throws IOException {
28+
wrappedStream.close();
29+
}
30+
}

ioio/ioio/src/main/java/ioio/smallbasic/pc/SerialPortIOIOConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public OutputStream getOutputStream() throws ConnectionLostException {
6262
@Override
6363
public void waitForConnect() throws ConnectionLostException {
6464
if (!abort && serialPort.openPort()) {
65-
inputStream = serialPort.getInputStream();
66-
outputStream = serialPort.getOutputStream();
65+
inputStream = new LoggingInputStream(serialPort.getInputStream());
66+
outputStream = new LoggingOutputStream(serialPort.getOutputStream());
6767
serialPort.setDTR();
6868
} else {
6969
throw new ConnectionLostException();

ioio/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ FUNC_SIG lib_proc[] = {
244244
{0, 0, "HARDRESET", cmd_ioio_hardreset},
245245
{0, 0, "SOFTRESET", cmd_ioio_softreset},
246246
{0, 0, "SYNC", cmd_ioio_sync},
247-
{1, 1, "WAITFORCONNECT", cmd_ioio_waitforconnect},
247+
{0, 0, "WAITFORCONNECT", cmd_ioio_waitforconnect},
248248
{0, 0, "WAITFORDISCONNECT", cmd_ioio_waitfordisconnect},
249249
};
250250

@@ -261,7 +261,7 @@ SBLIB_API int sblib_func_count() {
261261
//
262262
int sblib_init(const char *sourceFile) {
263263
#if defined(DESKTOP_MODULE)
264-
int result = createJVM("-Djava.class.path=./ioio-1.0-jar-with-dependencies.jar", "-Dioio.SerialPorts=IOIO0", false);
264+
int result = createJVM("-Djava.class.path=./ioio-1.0-jar-with-dependencies.jar", "-Dioio.SerialPorts=ttyACM0", false);
265265
#else
266266
int result = 1;
267267
#endif

ioio/samples/led.bas

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import ioio
22

3-
out = ioio.openDigitalOutput(0)
3+
out = ioio.openDigitalOutput(13)
44

5-
print "wait for connect"
6-
ioio.waitForConnect(10)
7-
print "ready!!!"
5+
'print "wait for connect"
6+
ioio.waitForConnect()
7+
'print "ready!!!"
88

99
value = false
1010
for i = 0 to 5
1111
out.write(value)
1212
value = !value
13-
delay 1000
13+
delay 2000
1414
next
1515

1616
for i = 0 to 5
1717
out.write(value)
1818
value = !value
19-
delay 100
19+
delay 3000
2020
next
2121

22-
print "done"
22+
'print "done"

0 commit comments

Comments
 (0)