@@ -23,8 +23,16 @@ int nextId = 1;
2323#define CLASS_DIGITAL_INPUT " net/sourceforge/smallbasic/ioio/DigitalOutput"
2424#define CLASS_ANALOG_INPUT " net/sourceforge/smallbasic/ioio/AnalogInput"
2525#define CLASS_IOCLASS 1
26+ #define METHOD_BEGIN_BATCH " beginBatch"
27+ #define METHOD_DISCONNECT " disconnect"
28+ #define METHOD_END_BATCH " endBatch"
29+ #define METHOD_HARD_RESET " hardReset"
2630#define METHOD_OPEN " open"
2731#define METHOD_READY " isReady"
32+ #define METHOD_SOFT_RESET " softReset"
33+ #define METHOD_SYNC " sync"
34+ #define METHOD_WAIT_FOR_CONNECT " waitForConnect"
35+ #define METHOD_WAIT_FOR_DISCONNECT " waitForDisconnect"
2836#define METHOD_WRITE " write"
2937
3038struct IOClass {
@@ -92,14 +100,56 @@ struct IOClass {
92100 return result;
93101 }
94102
95- bool open (int pin) {
96- return invokeIV (METHOD_OPEN, pin);
103+ void invokeV (const char *name) {
104+ if (_instance != nullptr ) {
105+ jmethodID method = env->GetMethodID (_clazz, name, " ()V" );
106+ if (method != nullptr ) {
107+ env->CallVoidMethod (_instance, method);
108+ }
109+ checkException ();
110+ }
97111 }
98112
99113 int isReady () {
100114 return invokeI (METHOD_READY);
101115 }
102116
117+ bool open (int pin) {
118+ return invokeIV (METHOD_OPEN, pin);
119+ }
120+
121+ void beginBatch () {
122+ invokeV (METHOD_BEGIN_BATCH);
123+ }
124+
125+ void endBatch () {
126+ invokeV (METHOD_END_BATCH);
127+ }
128+
129+ void disconnect () {
130+ invokeV (METHOD_DISCONNECT);
131+ }
132+
133+ void hardReset () {
134+ invokeV (METHOD_HARD_RESET);
135+ }
136+
137+ void softReset () {
138+ invokeV (METHOD_SOFT_RESET);
139+ }
140+
141+ void sync () {
142+ invokeV (METHOD_SYNC);
143+ }
144+
145+ void waitForConnect () {
146+ invokeV (METHOD_WAIT_FOR_CONNECT);
147+ }
148+
149+ void waitForDisconnect () {
150+ invokeV (METHOD_WAIT_FOR_DISCONNECT);
151+ }
152+
103153 bool write (int value) {
104154 return invokeIV (METHOD_WRITE, value);
105155 }
@@ -125,7 +175,7 @@ static int get_io_class_id(var_s *map, var_s *retval) {
125175 return result;
126176}
127177
128- static int cmd_digital_output_is_ready (var_s *self, int param_count, slib_par_t *params, var_s *retval) {
178+ static int cmd_is_ready (var_s *self, int param_count, slib_par_t *params, var_s *retval) {
129179 int result = 0 ;
130180 if (param_count != 0 ) {
131181 error (retval, METHOD_READY, 0 );
@@ -139,6 +189,21 @@ static int cmd_digital_output_is_ready(var_s *self, int param_count, slib_par_t
139189 return result;
140190}
141191
192+ static int cmd_wait_for_connect (var_s *self, int param_count, slib_par_t *params, var_s *retval) {
193+ int result = 0 ;
194+ if (param_count != 0 ) {
195+ error (retval, METHOD_WAIT_FOR_CONNECT, 0 );
196+ } else {
197+ int id = get_io_class_id (self, retval);
198+ if (id != -1 ) {
199+ _classMap.at (id).waitForConnect ();
200+ result = 1 ;
201+ }
202+ }
203+ return result;
204+ }
205+
206+
142207static int cmd_digital_output_write (var_s *self, int param_count, slib_par_t *params, var_s *retval) {
143208 int result = 0 ;
144209 if (param_count != 1 ) {
@@ -154,14 +219,20 @@ static int cmd_digital_output_write(var_s *self, int param_count, slib_par_t *pa
154219 return result;
155220}
156221
222+ static void create_io_class (var_t *map, int id) {
223+ map_init_id (map, id, CLASS_IOCLASS);
224+ v_create_callback (map, METHOD_WRITE, cmd_digital_output_write);
225+ v_create_callback (map, METHOD_READY, cmd_is_ready);
226+ }
227+
157228static int cmd_openanaloginput (int argc, slib_par_t *params, var_t *retval) {
158229 int result;
159230 int pin = get_param_int (argc, params, 0 , 0 );
160231 int id = ++nextId;
161232 IOClass &input = _classMap[id];
162233 if (input.create (CLASS_ANALOG_INPUT) &&
163234 input.open (pin)) {
164- map_init_id (retval, id, CLASS_IOCLASS );
235+ create_io_class (retval, id);
165236 // v_create_func(retval, "write", cmd_digital_output_write);
166237 result = 1 ;
167238 } else {
@@ -179,9 +250,8 @@ static int cmd_opendigitaloutput(int argc, slib_par_t *params, var_t *retval) {
179250 IOClass &output = _classMap[id];
180251 if (output.create (CLASS_DIGITAL_INPUT) &&
181252 output.open (pin)) {
182- map_init_id (retval, id, CLASS_IOCLASS);
183- v_create_callback (retval, METHOD_READY, cmd_digital_output_is_ready);
184- v_create_callback (retval, METHOD_WRITE, cmd_digital_output_write);
253+ create_io_class (retval, id);
254+ v_create_callback (retval, METHOD_WAIT_FOR_CONNECT, cmd_wait_for_connect);
185255 result = 1 ;
186256 } else {
187257 _classMap.erase (id);
0 commit comments