@@ -73,7 +73,7 @@ struct IOTask {
7373 jstring jstr = (jstring) env->CallObjectMethod (exc, methodId);
7474 const char *message = env->GetStringUTFChars (jstr, JNI_FALSE);
7575 error (retval, message);
76- env->ReleaseStringUTFChars (jstr, message);
76+ env->ReleaseStringUTFChars (jstr, message);
7777 } else {
7878 env->ExceptionDescribe ();
7979 env->ExceptionClear ();
@@ -178,6 +178,34 @@ struct IOTask {
178178 return result;
179179 }
180180
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+
181209 // void foo(void)
182210 int invokeVoidVoid (const char *name, var_s *retval) {
183211 int result = 0 ;
@@ -197,6 +225,14 @@ struct IOTask {
197225 return invokeVoidInt (" open" , pin, retval);
198226 }
199227
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+
200236 private:
201237 jclass _clazz;
202238 jobject _instance;
@@ -221,7 +257,7 @@ static int get_io_class_id(var_s *map, var_s *retval) {
221257static int cmd_twimaster_writeread (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
222258 int result = 0 ;
223259 if (argc != 0 ) {
224- error (retval, " writeRead" , 0 );
260+ error (retval, " TwiMaster. writeRead" , 0 );
225261 } else {
226262 // TODO
227263 // 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
232268static int cmd_spimaster_write (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
233269 int result = 0 ;
234270 if (argc != 2 ) {
235- error (retval, " writeRead " , 0 );
271+ error (retval, " SpiMaster.write " , 0 );
236272 } 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+ }
239279 }
240280 return result;
241281}
@@ -251,13 +291,14 @@ static void create_spimaster(var_t *map) {
251291#include " api.h"
252292
253293FUNC_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},
261302};
262303
263304FUNC_SIG lib_proc[] = {
0 commit comments