Skip to content

Commit 301a242

Browse files
committed
IOIO: android integration
1 parent 846082d commit 301a242

File tree

9 files changed

+88
-11
lines changed

9 files changed

+88
-11
lines changed

ioio/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ $(generated): api.json mkapi.bas mkdoc.bas
2929
$(sbasic) mkapi.bas > $@
3030
$(sbasic) mkdoc.bas > README.md
3131
@touch main.cpp
32+
33+
34+
android:
35+
./gradlew clean :ioio:assemble && ls -l ioio/build/outputs/aar/ && cp ioio/build/outputs/aar/ioio-* ~/src/SmallBASIC/src/platform/android/app/libs/

ioio/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ buildscript {
33
repositories {
44
google()
55
mavenCentral()
6-
maven { url 'https://jitpack.io' }
76
}
87
dependencies {
98
classpath 'com.android.tools.build:gradle:8.3.0'
@@ -22,4 +21,3 @@ apply plugin: 'idea'
2221
tasks.register('clean', Delete) {
2322
delete rootProject.buildDir
2423
}
25-

ioio/ioio/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LOCAL_PATH := $(JNI_PATH)
1010

1111
include $(CLEAR_VARS)
1212
LOCAL_MODULE := ioio
13-
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 -Wno-unknown-pragmas -I../ -I../../ -I../include
13+
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 -DANDROID_MODULE -Wno-unknown-pragmas -I../ -I../../ -I../include
1414
LOCAL_SRC_FILES := ../../include/param.cpp \
1515
../../include/hashmap.cpp \
1616
../../include/apiexec.cpp \

ioio/ioio/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ android {
1111
}
1212
}
1313

14+
1415
namespace 'net.sourceforge.smallbasic.ioio'
1516
compileSdk 34
1617

@@ -37,3 +38,21 @@ android {
3738
dependencies {
3839
implementation 'com.github.ytai.ioio:IOIOLibCore:5.07'
3940
}
41+
42+
configurations.implementation.setCanBeResolved(true)
43+
44+
tasks.register('jarWithDependencies', Jar) {
45+
def libDir = file("${project.buildDir}/../lib")
46+
configurations.implementation.files.each { dependencyJar ->
47+
zipTree(dependencyJar).visit { details ->
48+
if (!details.directory) {
49+
copy {
50+
from details.file
51+
into "${libDir}/${details.path}"
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
assemble.dependsOn jarWithDependencies

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public void beginBatch() {
1919
lock.invoke(IOIO::beginBatch);
2020
}
2121

22+
public void close() {
23+
super.close();
24+
IOService.getInstance().stop();
25+
}
26+
2227
public void disconnect() {
2328
lock.invoke(IOIO::disconnect);
2429
}
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
package net.sourceforge.smallbasic.ioio;
22

3+
import ioio.lib.spi.Log;
4+
35
public class IOIOLoader {
4-
public static native void init();
5-
static {
6-
init();
6+
private static final String TAG = "IOIOLoader";
7+
public static native void init(Class<?> clazz);
8+
9+
public IOIOLoader() {
10+
super();
11+
init(getClass());
12+
}
13+
14+
public static Class<?> findClass(String className) {
15+
try {
16+
Log.i(TAG, "findClass " + className);
17+
return Class.forName("net.sourceforge.smallbasic.ioio." + className);
18+
}
19+
catch (ClassNotFoundException e) {
20+
throw new RuntimeException(e);
21+
}
722
}
823
}

ioio/ioio/src/main/java/net/sourceforge/smallbasic/ioio/IOService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public void start() {
5555
connectionController.start();
5656
}
5757

58+
public void stop() {
59+
looper.ioio.disconnect();
60+
connectionController.stop();
61+
}
62+
5863
private void registerPin(int pin) throws IOException {
5964
if (pin != -1) {
6065
if (pin < 0 || pin > MAX_PINS) {

ioio/log.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// Copyright(C) 2024 Chris Warren-Smith.
4+
//
5+
// This program is distributed under the terms of the GPL v2.0 or later
6+
// Download the GNU Public License (GPL) from www.gnu.org
7+
//
8+
9+
#pragma once
10+
11+
#include "config.h"
12+
13+
#if defined(ANDROID_MODULE)
14+
#include <android/log.h>
15+
#if defined(_DEBUG)
16+
#define deviceLog(...) __android_log_print(ANDROID_LOG_ERROR, "smallbasic", __VA_ARGS__)
17+
#else
18+
#define deviceLog(...) __android_log_print(ANDROID_LOG_INFO, "smallbasic", __VA_ARGS__)
19+
#endif
20+
#else
21+
#define deviceLog(...) printf(__VA_ARGS__)
22+
#endif
23+
24+
#if defined(_DEBUG)
25+
#define trace(...) deviceLog(__VA_ARGS__)
26+
#else
27+
#define trace(...)
28+
#endif
29+
30+
#define logEntered() trace("%s entered (%s %d)", __FUNCTION__, __FILE__, __LINE__);
31+
#define logLeaving() trace("%s leaving (%s %d)", __FUNCTION__, __FILE__, __LINE__);

ioio/mkapi.bas

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ sub generate_command(objName, method)
5757

5858
local getter, indent
5959
if (objName == "IOIO") then
60-
getter = "ioioTask->"
60+
getter = "g_ioioTask->"
6161
indent = " "
6262
else
63-
getter = "_ioTaskMap.at(id)."
63+
getter = "g_ioTaskMap.at(id)."
6464
indent = " "
6565
print " int id = get_io_class_id(self, retval);"
6666
print " if (id != -1) {"
@@ -114,15 +114,15 @@ sub generate_open_function(byref obj)
114114
print " int pin" + pin + " = get_param_int(argc, params, " + (pin - 1) + ", -1);"
115115
next
116116
endif
117-
print " int id = ++nextId;"
118-
print " IOTask &instance = _ioTaskMap[id];"
117+
print " int id = ++g_nextId;"
118+
print " IOTask &instance = g_ioTaskMap[id];"
119119
print " if (instance.create(CLASS_" + upper(obj.name) + ", retval) &&"
120120
print " instance." + openFunc + "retval)) {"
121121
print " map_init_id(retval, id, CLASS_IOTASK_ID);"
122122
print " create_" + lower(obj.name) + "(retval);"
123123
print " result = 1;"
124124
print " } else {"
125-
print " _ioTaskMap.erase(id);"
125+
print " g_ioTaskMap.erase(id);"
126126
print " result = 0;"
127127
print " }"
128128
print " return result;"

0 commit comments

Comments
 (0)