@@ -73,7 +73,7 @@ struct IOTask {
73
73
jstring jstr = (jstring) env->CallObjectMethod (exc, methodId);
74
74
const char *message = env->GetStringUTFChars (jstr, JNI_FALSE);
75
75
error (retval, message);
76
- env->ReleaseStringUTFChars (jstr, message);
76
+ env->ReleaseStringUTFChars (jstr, message);
77
77
} else {
78
78
env->ExceptionDescribe ();
79
79
env->ExceptionClear ();
@@ -178,6 +178,34 @@ struct IOTask {
178
178
return result;
179
179
}
180
180
181
+ int invokeVoidInt2 (const char *name, int value1, int value2, var_s *retval) {
182
+ int result = 0 ;
183
+ if (_instance != nullptr ) {
184
+ jmethodID method = env->GetMethodID (_clazz, name, " (II)V" );
185
+ if (method != nullptr ) {
186
+ env->CallVoidMethod (_instance, method, value1, value2);
187
+ }
188
+ if (!checkException (retval)) {
189
+ result = 1 ;
190
+ }
191
+ }
192
+ return result;
193
+ }
194
+
195
+ int invokeVoidInt4 (const char *name, int value1, int value2, int value3, int value4, var_s *retval) {
196
+ int result = 0 ;
197
+ if (_instance != nullptr ) {
198
+ jmethodID method = env->GetMethodID (_clazz, name, " (IIII)V" );
199
+ if (method != nullptr ) {
200
+ env->CallVoidMethod (_instance, method, value1, value2, value3, value4);
201
+ }
202
+ if (!checkException (retval)) {
203
+ result = 1 ;
204
+ }
205
+ }
206
+ return result;
207
+ }
208
+
181
209
// void foo(void)
182
210
int invokeVoidVoid (const char *name, var_s *retval) {
183
211
int result = 0 ;
@@ -197,6 +225,14 @@ struct IOTask {
197
225
return invokeVoidInt (" open" , pin, retval);
198
226
}
199
227
228
+ int open2 (int pin1, int pin2, var_s *retval) {
229
+ return invokeVoidInt2 (" open" , pin1, pin2, retval);
230
+ }
231
+
232
+ int open4 (int pin1, int pin2, int pin3, int pin4, var_s *retval) {
233
+ return invokeVoidInt4 (" open" , pin1, pin2, pin3, pin4, retval);
234
+ }
235
+
200
236
private:
201
237
jclass _clazz;
202
238
jobject _instance;
@@ -221,7 +257,7 @@ static int get_io_class_id(var_s *map, var_s *retval) {
221
257
static int cmd_twimaster_writeread (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
222
258
int result = 0 ;
223
259
if (argc != 0 ) {
224
- error (retval, " writeRead" , 0 );
260
+ error (retval, " TwiMaster. writeRead" , 0 );
225
261
} else {
226
262
// TODO
227
263
// result = ioioTask->invokeVoidVoid("waitForDisconnect", retval);
@@ -232,10 +268,14 @@ static int cmd_twimaster_writeread(var_s *self, int argc, slib_par_t *arg, var_s
232
268
static int cmd_spimaster_write (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
233
269
int result = 0 ;
234
270
if (argc != 2 ) {
235
- error (retval, " writeRead " , 0 );
271
+ error (retval, " SpiMaster.write " , 0 );
236
272
} else {
237
- // TODO
238
- // result = ioioTask->invokeVoidVoid("waitForDisconnect", retval);
273
+ int id = get_io_class_id (self, retval);
274
+ if (id != -1 ) {
275
+ auto address = get_param_int (argc, arg, 0 , 0 );
276
+ auto data = get_param_int (argc, arg, 1 , 0 );
277
+ result = _ioTaskMap.at (id).invokeVoidInt2 (" write" , address, data, retval);
278
+ }
239
279
}
240
280
return result;
241
281
}
@@ -251,13 +291,14 @@ static void create_spimaster(var_t *map) {
251
291
#include " api.h"
252
292
253
293
FUNC_SIG lib_func[] = {
254
- {1 , 2 , " OPENANALOGINPUT" , cmd_openanaloginput},
255
- {1 , 2 , " OPENCAPSENSE" , cmd_opencapsense},
256
- {1 , 2 , " OPENDIGITALINPUT" , cmd_opendigitalinput},
257
- {1 , 2 , " OPENDIGITALOUTPUT" , cmd_opendigitaloutput},
258
- {1 , 2 , " OPENPULSEINPUT" , cmd_openpulseinput},
259
- {1 , 2 , " OPENPWMOUTPUT" , cmd_openpwmoutput},
260
- {1 , 2 , " OPENTWIMASTER" , cmd_opentwimaster},
294
+ {1 , 1 , " OPENANALOGINPUT" , cmd_openanaloginput},
295
+ {1 , 1 , " OPENCAPSENSE" , cmd_opencapsense},
296
+ {1 , 1 , " OPENDIGITALINPUT" , cmd_opendigitalinput},
297
+ {1 , 1 , " OPENDIGITALOUTPUT" , cmd_opendigitaloutput},
298
+ {1 , 1 , " OPENPULSEINPUT" , cmd_openpulseinput},
299
+ {1 , 1 , " OPENPWMOUTPUT" , cmd_openpwmoutput},
300
+ {2 , 2 , " OPENTWIMASTER" , cmd_opentwimaster},
301
+ {4 , 4 , " OPENSPIMASTER" , cmd_openspimaster},
261
302
};
262
303
263
304
FUNC_SIG lib_proc[] = {
0 commit comments