Skip to content

Commit 562effe

Browse files
committed
Experimental ioio-otg support
Nothing to see here just yet. Moving development from my workstation to my laptop where for some reason the board actually works.
1 parent 5ab2915 commit 562effe

17 files changed

Lines changed: 933 additions & 0 deletions

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ AC_ARG_WITH(gtk-server,
4747
[GTK_SERVER="yes"],
4848
[GTK_SERVER="no"])
4949

50+
AC_ARG_WITH(ioio,
51+
[AS_HELP_STRING([--with-ioio], [Build the ioio module])],
52+
[IOIO="yes"],
53+
[IOIO="no"])
54+
5055
case "${host_os}" in
5156
*mingw* | *msys*)
5257
AC_DEFINE(_WIN32, 1, [building for win32])
@@ -95,6 +100,10 @@ if test "${GTK_SERVER}" = "yes"
95100
then
96101
BUILD_SUBDIRS="${BUILD_SUBDIRS} gtk-server"
97102
fi
103+
if test "${IOIO}" = "yes"
104+
then
105+
BUILD_SUBDIRS="${BUILD_SUBDIRS} ioio"
106+
fi
98107

99108
AC_SUBST(BUILD_SUBDIRS)
100109
checkDebugMode
@@ -111,6 +120,7 @@ clipboard/Makefile
111120
websocket/Makefile
112121
raylib/Makefile
113122
mlpack/Makefile
123+
ioio/Makefile
114124
gtk-server/Makefile])
115125

116126
AC_OUTPUT

ioio/Makefile.am

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SmallBASIC
2+
# Copyright(C) 2001-2023 Chris Warren-Smith.
3+
#
4+
# This program is distributed under the terms of the GPL v2.0 or later
5+
# Download the GNU Public License (GPL) from www.gnu.org
6+
#
7+
# export LD_LIBRARY_PATH=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/server:$LD_LIBRARY_PATH
8+
# javap -s -p -cp target/ioio-1.0.jar 'net.sourceforge.smallbasic.ioio.AnalogInput'
9+
#
10+
11+
AM_CXXFLAGS=-fno-rtti -std=c++14
12+
AM_CPPFLAGS = -I../include -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux -Wall
13+
lib_LTLIBRARIES = libioio.la
14+
libioio_la_SOURCES = ../include/param.cpp ../include/hashmap.cpp ../include/apiexec.cpp main.cpp
15+
libioio_la_LDFLAGS = -module -rpath '$(libdir)' @PLATFORM_LDFLAGS@ -L/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/server -ljvm
16+
17+

ioio/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
https://github.com/ytai/ioio/wiki
3+
4+
5+
https://github.com/ytai/ioio/blob/master/applications/HelloIOIOService/src/main/java/ioio/examples/hello_service/HelloIOIOService.java
6+
https://github.com/ytai/ioio/wiki/IOIOLib-Core-API
7+
8+
/etc/udev/rules.d/50-ioio.rules
9+
10+
```
11+
ACTION=="add", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="0008", SYMLINK+="IOIO%n", MODE="666"
12+
ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="0008", ENV{ID_MM_DEVICE_IGNORE}="1"
13+
```
14+
15+
looper:
16+
17+
init
18+
AnalogInput in = ioio.openAnalogInput(pinNum);
19+
20+
loop:
21+
22+
23+
```
24+
SB-> openAnalogInput(pin) -> JNI -> JAVA -> (pin)
25+
service.methods.push(function (ioio) { ioio.openAnalogInput(pin) });
26+
service.initMethods.push(function (ioio) { ioio.openAnalogInput(pin) });
27+
returns handle
28+
29+
init:
30+
initmethods.pop().invoke();
31+
32+
loop
33+
methods.pop().invoke()
34+
35+
```
36+
37+
38+
When you plug an IOIO-OTG board into a USB port on your Linux machine, you can check which serial port has been assigned to the device by using various commands and tools. Here are a few methods:
39+
40+
Check dmesg Logs:
41+
42+
Open a terminal and run the following command to view the kernel logs:
43+
44+
bash
45+
Copy code
46+
dmesg | tail
47+
Look for lines related to the connected USB device. The assigned serial port might be mentioned in the logs.
48+
49+
Use lsusb and udevadm:
50+
51+
Use lsusb to list the connected USB devices and note the device ID.
52+
53+
bash
54+
Copy code
55+
lsusb
56+
Use udevadm to get detailed information about the device:
57+
58+
bash
59+
Copy code
60+
udevadm info -a -n /dev/ttyUSB0
61+
Replace /dev/ttyUSB0 with the appropriate device file.
62+
63+
Check /dev/ Directory:
64+
65+
After connecting the device, run the following command to list the /dev/ directory:
66+
67+
bash
68+
Copy code
69+
ls /dev/ttyUSB*
70+
This should show you the assigned serial port(s) for connected USB devices.
71+
72+
Use minicom or screen:
73+
74+
Install minicom if it's not already installed:
75+
76+
bash
77+
Copy code
78+
sudo apt-get install minicom
79+
Run minicom:
80+
81+
bash
82+
Copy code
83+
minicom -D /dev/ttyUSB0
84+
Replace /dev/ttyUSB0 with the actual serial port.
85+
86+
Alternatively, use screen:
87+
88+
bash
89+
Copy code
90+
screen /dev/ttyUSB0
91+
Replace /dev/ttyUSB0 with the actual serial port.

ioio/main.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// This program is distributed under the terms of the GPL v2.0 or later
4+
// Download the GNU Public License (GPL) from www.gnu.org
5+
//
6+
// Copyright(C) 2020 Chris Warren-Smith
7+
8+
#include "config.h"
9+
#include "include/var.h"
10+
#include "include/module.h"
11+
#include "include/param.h"
12+
13+
#include <cstring>
14+
#include <cstdio>
15+
#include <jni.h>
16+
#include <pthread.h>
17+
18+
JNIEnv *env;
19+
JavaVM *jvm;
20+
jclass analogInputClass = nullptr;
21+
jobject analogInput = nullptr;
22+
23+
// void callVoidMethod(jmethodID method, int n) {
24+
// env->CallVoidMethod(instance, method, n);
25+
// }
26+
27+
// jmethodID getMethodID(const char *name, const char *signature) {
28+
// return env->GetMethodID(clazz, name, signature);
29+
// }
30+
31+
// jmethodID getStaticMethodId(const char *name, const char *signature) {
32+
// return env->GetStaticMethodID(clazz, name, signature);
33+
// }
34+
35+
jobject createInstance(jclass clazz) {
36+
jobject result = nullptr;
37+
if (clazz == nullptr) {
38+
env->ExceptionDescribe();
39+
} else {
40+
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
41+
if (constructor == nullptr) {
42+
env->ExceptionDescribe();
43+
} else {
44+
result = env->NewObject(clazz, constructor);
45+
}
46+
}
47+
return result;
48+
}
49+
50+
int sblib_init(const char *sourceFile) {
51+
JavaVMInitArgs vm_args;
52+
JavaVMOption options[2];
53+
options[0].optionString = (char *)"-Djava.class.path=./target/ioio-1.0-jar-with-dependencies.jar";
54+
options[1].optionString = (char *)"-Dioio.SerialPorts=ACM0";
55+
vm_args.version = JNI_VERSION_1_8;
56+
vm_args.nOptions = 2;
57+
vm_args.options = options;
58+
vm_args.ignoreUnrecognized = 0;
59+
int result = (JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args) == JNI_OK);
60+
if (!result) {
61+
fprintf(stderr, "Unable to create JVM\n");
62+
}
63+
return result;
64+
}
65+
66+
void sblib_close(void) {
67+
jvm->DestroyJavaVM();
68+
analogInputClass = nullptr;
69+
analogInput = nullptr;
70+
env = nullptr;
71+
jvm = nullptr;
72+
}
73+
74+
static int cmd_openanaloginput(int argc, slib_par_t *params, var_t *retval) {
75+
int pin = get_param_int(argc, params, 0, 0);
76+
int result = 0;
77+
if (analogInput == nullptr && jvm->AttachCurrentThread((void**)&env, nullptr) == JNI_OK) {
78+
analogInputClass = env->FindClass("net/sourceforge/smallbasic/ioio/AnalogInput");
79+
analogInput = createInstance(analogInputClass);
80+
if (analogInput != nullptr) {
81+
jmethodID method = env->GetMethodID(analogInputClass, "openInput", "(I)V");
82+
if (method != nullptr) {
83+
env->CallVoidMethod(analogInput, method, pin);
84+
result = 1;
85+
} else {
86+
env->ExceptionDescribe();
87+
}
88+
}
89+
jvm->DetachCurrentThread();
90+
}
91+
if (!result) {
92+
error(retval, "openAnalogInput() failed");
93+
}
94+
return result;
95+
}
96+
97+
FUNC_SIG lib_func[] = {
98+
{1, 1, "OPENANALOGINPUT", cmd_openanaloginput},
99+
};
100+
101+
FUNC_SIG lib_proc[] = {
102+
};
103+
104+
SBLIB_API int sblib_proc_count() {
105+
return (sizeof(lib_proc) / sizeof(lib_proc[0]));
106+
}
107+
108+
SBLIB_API int sblib_func_count() {
109+
return (sizeof(lib_func) / sizeof(lib_func[0]));
110+
}
111+
112+

ioio/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>io.smallbasic</groupId>
5+
<artifactId>ioio</artifactId>
6+
<version>1.0</version>
7+
<name>ioio</name>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
14+
<!--
15+
<repositories>
16+
<repository>
17+
<id>sparetimelabs</id>
18+
<url>https://www.sparetimelabs.com/maven2</url>
19+
</repository>
20+
</repositories>
21+
-->
22+
<dependencies>
23+
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
24+
<dependency>
25+
<groupId>com.google.guava</groupId>
26+
<artifactId>guava</artifactId>
27+
<version>33.0.0-jre</version>
28+
</dependency>
29+
<!-- https://mvnrepository.com/artifact/com.github.ytai.ioio/IOIOLibPC -->
30+
31+
<dependency>
32+
<groupId>com.github.ytai.ioio</groupId>
33+
<artifactId>IOIOLibCore</artifactId>
34+
<version>5.07</version>
35+
</dependency>
36+
<!-- https://mvnrepository.com/artifact/com.github.purejavacomm/purejavacomm -->
37+
<dependency>
38+
<groupId>com.github.purejavacomm</groupId>
39+
<artifactId>purejavacomm</artifactId>
40+
<version>1.0.2.RELEASE</version>
41+
</dependency>
42+
43+
<!--
44+
<dependency>
45+
<groupId>com.sparetimelabs</groupId>
46+
<artifactId>purejavacomm</artifactId>
47+
<version>1.0.1</version>
48+
</dependency>
49+
-->
50+
</dependencies>
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<artifactId>maven-assembly-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<phase>package</phase>
58+
<goals>
59+
<goal>single</goal>
60+
</goals>
61+
</execution>
62+
</executions>
63+
<configuration>
64+
<descriptorRefs>
65+
<descriptorRef>jar-with-dependencies</descriptorRef>
66+
</descriptorRefs>
67+
</configuration>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
</project>

ioio/samples/led.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ioio
2+
3+
n = ioio.openAnalogInput(1)
4+
delay 5000
5+

ioio/sbasic.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
export LD_LIBRARY_PATH=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/server:$LD_LIBRARY_PATH
4+
5+
#valgrind --tool=callgrind
6+
# type "backtrace" to see stack trace
7+
# gdb -ex run --args \
8+
# valgrind --leak-check=full --track-origins=yes \
9+
#gdb -ex='set confirm on' -ex=run -ex=quit --args \
10+
11+
~/src/SmallBASIC/src/platform/console/sbasic --module-path="/home/chrisws/src/smallbasic.plugins/ioio/.libs:/home/chrisws/src/smallbasic.plugins/debug/.libs" $1

0 commit comments

Comments
 (0)