@@ -20,17 +20,8 @@ JavaVM *jvm;
2020jclass analogInputClass = nullptr ;
2121jobject analogInput = nullptr ;
2222
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- // }
23+ jclass digitalOutputClass = nullptr ;
24+ jobject digitalOutput = nullptr ;
3425
3526jobject createInstance (jclass clazz) {
3627 jobject result = nullptr ;
@@ -94,8 +85,37 @@ static int cmd_openanaloginput(int argc, slib_par_t *params, var_t *retval) {
9485 return result;
9586}
9687
88+ static int cmd_opendigitaloutput (int argc, slib_par_t *params, var_t *retval) {
89+ int pin = get_param_int (argc, params, 0 , 0 );
90+ int result = 0 ;
91+ if (digitalOutput == nullptr && jvm->AttachCurrentThread ((void **)&env, nullptr ) == JNI_OK) {
92+ digitalOutputClass = env->FindClass (" net/sourceforge/smallbasic/ioio/DigitalOutput" );
93+ digitalOutput = createInstance (digitalOutputClass);
94+ if (digitalOutput != nullptr ) {
95+ jmethodID method = env->GetMethodID (digitalOutputClass, " openOutput" , " (I)V" );
96+ if (method != nullptr ) {
97+ env->CallVoidMethod (digitalOutput, method, pin);
98+ map_init (retval);
99+
100+ // v_setint(map_add_var(var, "width", 0), width);
101+ // v_setint(map_add_var(var, "height", 0), height);
102+
103+ result = 1 ;
104+ } else {
105+ env->ExceptionDescribe ();
106+ }
107+ }
108+ jvm->DetachCurrentThread ();
109+ }
110+ if (!result) {
111+ error (retval, " openDigitalOutput() failed" );
112+ }
113+ return result;
114+ }
115+
97116FUNC_SIG lib_func[] = {
98117 {1 , 1 , " OPENANALOGINPUT" , cmd_openanaloginput},
118+ {1 , 1 , " OPENDIGITALOUTPUT" , cmd_opendigitaloutput},
99119};
100120
101121FUNC_SIG lib_proc[] = {
0 commit comments