Skip to content

Commit 8c24e81

Browse files
committed
IOIO: implement jni methods
1 parent 16ce829 commit 8c24e81

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

ioio/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ This interface represents AnalogInput functionality, providing methods to obtain
1515
|float getReference(void)|Gets the maximum value against which read() values are scaled.|
1616
|float read(void)|Gets the analog input reading, as a scaled real value between 0 and 1.|
1717
|float readSync(void)|This is very similar to read(), but will wait for a new sample to arrive before returning.|
18-
|void setBuffer(int)|Initializes or destroys an internal buffer, used for queuing sampled data.|
1918
|int getOverflowCount(void)|Gets the number of samples that have been dropped as a result of overflow.|
2019
|int available(void)|Gets the number of samples currently in the buffer. Reading that many samples is guaranteed not to block.|
2120
|float readBuffered(void)|Read a sample from the internal buffer. This method will block until at least one sample is available.|
@@ -33,7 +32,6 @@ This interface represents PulseInput functionality, providing methods for pulse
3332
|float getDuration(void)|Gets the pulse duration in case of pulse measurement mode, or the period in case of frequency mode.|
3433
|float getDurationSync(void)|This is very similar to getDuration(), but will wait for a new sample to arrive before returning.|
3534
|float getDurationBuffered(void)|Reads a single measurement from the queue. If the queue is empty, will block until more data arrives.|
36-
|float waitPulseGetDuration(void)|@deprecated Please use getDurationBuffered() instead.|
3735
|float getFrequency(void)|Gets the momentary frequency of the measured signal. When scaling is used, this is compensated for here.|
3836
|float getFrequencySync(void)|This is very similar to getFrequency(), but will wait for a new sample to arrive before returning.|
3937

ioio/main.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,40 @@ struct IOClass {
6767
return exc;
6868
}
6969

70+
// boolean foo(void)
71+
int invokeBoolVoid(const char *name, var_s *retval) {
72+
int result = 0;
73+
if (_instance != nullptr) {
74+
jmethodID method = env->GetMethodID(_clazz, name, "()Z");
75+
int value = 0;
76+
if (method != nullptr) {
77+
value = env->CallBooleanMethod(_instance, method);
78+
}
79+
if (!checkException()) {
80+
v_setint(retval, value);
81+
result = 1;
82+
}
83+
}
84+
return result;
85+
}
86+
7087
// float foo(void)
7188
int invokeFloatVoid(const char *name, var_s *retval) {
7289
int result = 0;
90+
if (_instance != nullptr) {
91+
jmethodID method = env->GetMethodID(_clazz, name, "()F");
92+
var_num_t value = 0;
93+
if (method != nullptr) {
94+
value = env->CallFloatMethod(_instance, method);
95+
}
96+
if (!checkException()) {
97+
v_setreal(retval, value);
98+
result = 1;
99+
}
100+
}
73101
return result;
74102
}
75-
103+
76104
// int foo(void)
77105
int invokeIntVoid(const char *name, var_s *retval) {
78106
int result = 0;
@@ -90,12 +118,36 @@ struct IOClass {
90118
return result;
91119
}
92120

121+
// void foo(boolean)
122+
int invokeVoidBool(const char *name, int value, var_s *retval) {
123+
int result = 0;
124+
if (_instance != nullptr) {
125+
jmethodID method = env->GetMethodID(_clazz, name, "(Z)V");
126+
if (method != nullptr) {
127+
env->CallVoidMethod(_instance, method, value);
128+
}
129+
if (!checkException()) {
130+
result = 1;
131+
}
132+
}
133+
return result;
134+
}
135+
93136
// void foo(float)
94137
int invokeVoidFloat(const char *name, var_num_t value, var_s *retval) {
95138
int result = 0;
139+
if (_instance != nullptr) {
140+
jmethodID method = env->GetMethodID(_clazz, name, "()F");
141+
if (method != nullptr) {
142+
env->CallVoidMethod(_instance, method, value);
143+
}
144+
if (!checkException()) {
145+
result = 1;
146+
}
147+
}
96148
return result;
97149
}
98-
150+
99151
// void foo(int)
100152
int invokeVoidInt(const char *name, int value, var_s *retval) {
101153
int result = 0;

ioio/mkapi.bas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ func get_method_name(method)
1212

1313
if (method.rtn == "void") then
1414
result = "invokeVoid"
15-
else if (method.rtn == "boolean" || method.rtn == "int") then
15+
else if (method.rtn == "int") then
1616
result = "invokeInt"
17+
else if (method.rtn == "boolean") then
18+
result = "invokeBool"
1719
else if (method.rtn == "float") then
1820
result = "invokeFloat"
1921
endif
2022

2123
if (method.arg == "void") then
2224
result += "Void"
23-
else if (method.arg == "boolean" || method.arg == "int") then
25+
else if (method.arg == method.arg == "int") then
2426
result += "Int"
27+
else if (method.arg == "boolean") then
28+
result += "Bool"
2529
else if (method.arg == "float") then
2630
result += "Float"
2731
endif

0 commit comments

Comments
 (0)