Skip to content

Commit b24b3a8

Browse files
committed
Implement base methods
1 parent 982fc18 commit b24b3a8

2 files changed

Lines changed: 116 additions & 13 deletions

File tree

ioio/main.cpp

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,62 @@ static int get_io_class_id(var_s *map, var_s *retval) {
175175
return result;
176176
}
177177

178+
static int cmd_begin_batch(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
179+
int result = 0;
180+
if (param_count != 0) {
181+
error(retval, METHOD_BEGIN_BATCH, 0);
182+
} else {
183+
int id = get_io_class_id(self, retval);
184+
if (id != -1) {
185+
_classMap.at(id).beginBatch();
186+
result = 1;
187+
}
188+
}
189+
return result;
190+
}
191+
192+
static int cmd_disconnect(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_DISCONNECT, 0);
196+
} else {
197+
int id = get_io_class_id(self, retval);
198+
if (id != -1) {
199+
_classMap.at(id).disconnect();
200+
result = 1;
201+
}
202+
}
203+
return result;
204+
}
205+
206+
static int cmd_end_batch(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
207+
int result = 0;
208+
if (param_count != 0) {
209+
error(retval, METHOD_END_BATCH, 0);
210+
} else {
211+
int id = get_io_class_id(self, retval);
212+
if (id != -1) {
213+
_classMap.at(id).endBatch();
214+
result = 1;
215+
}
216+
}
217+
return result;
218+
}
219+
220+
static int cmd_hard_reset(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
221+
int result = 0;
222+
if (param_count != 0) {
223+
error(retval, METHOD_HARD_RESET, 0);
224+
} else {
225+
int id = get_io_class_id(self, retval);
226+
if (id != -1) {
227+
_classMap.at(id).hardReset();
228+
result = 1;
229+
}
230+
}
231+
return result;
232+
}
233+
178234
static int cmd_is_ready(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
179235
int result = 0;
180236
if (param_count != 0) {
@@ -189,6 +245,34 @@ static int cmd_is_ready(var_s *self, int param_count, slib_par_t *params, var_s
189245
return result;
190246
}
191247

248+
static int cmd_soft_reset(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
249+
int result = 0;
250+
if (param_count != 0) {
251+
error(retval, METHOD_SOFT_RESET, 0);
252+
} else {
253+
int id = get_io_class_id(self, retval);
254+
if (id != -1) {
255+
_classMap.at(id).softReset();
256+
result = 1;
257+
}
258+
}
259+
return result;
260+
}
261+
262+
static int cmd_sync(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
263+
int result = 0;
264+
if (param_count != 0) {
265+
error(retval, METHOD_SYNC, 0);
266+
} else {
267+
int id = get_io_class_id(self, retval);
268+
if (id != -1) {
269+
_classMap.at(id).sync();
270+
result = 1;
271+
}
272+
}
273+
return result;
274+
}
275+
192276
static int cmd_wait_for_connect(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
193277
int result = 0;
194278
if (param_count != 0) {
@@ -203,6 +287,19 @@ static int cmd_wait_for_connect(var_s *self, int param_count, slib_par_t *params
203287
return result;
204288
}
205289

290+
static int cmd_wait_for_disconnect(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
291+
int result = 0;
292+
if (param_count != 0) {
293+
error(retval, METHOD_WAIT_FOR_DISCONNECT, 0);
294+
} else {
295+
int id = get_io_class_id(self, retval);
296+
if (id != -1) {
297+
_classMap.at(id).waitForDisconnect();
298+
result = 1;
299+
}
300+
}
301+
return result;
302+
}
206303

207304
static int cmd_digital_output_write(var_s *self, int param_count, slib_par_t *params, var_s *retval) {
208305
int result = 0;
@@ -221,8 +318,15 @@ static int cmd_digital_output_write(var_s *self, int param_count, slib_par_t *pa
221318

222319
static void create_io_class(var_t *map, int id) {
223320
map_init_id(map, id, CLASS_IOCLASS);
224-
v_create_callback(map, METHOD_WRITE, cmd_digital_output_write);
321+
v_create_callback(map, METHOD_BEGIN_BATCH, cmd_begin_batch);
322+
v_create_callback(map, METHOD_DISCONNECT, cmd_disconnect);
323+
v_create_callback(map, METHOD_END_BATCH, cmd_end_batch);
324+
v_create_callback(map, METHOD_HARD_RESET, cmd_hard_reset);
225325
v_create_callback(map, METHOD_READY, cmd_is_ready);
326+
v_create_callback(map, METHOD_SOFT_RESET, cmd_soft_reset);
327+
v_create_callback(map, METHOD_SYNC, cmd_sync);
328+
v_create_callback(map, METHOD_WAIT_FOR_CONNECT, cmd_wait_for_connect);
329+
v_create_callback(map, METHOD_WAIT_FOR_DISCONNECT, cmd_wait_for_disconnect);
226330
}
227331

228332
static int cmd_openanaloginput(int argc, slib_par_t *params, var_t *retval) {
@@ -251,7 +355,7 @@ static int cmd_opendigitaloutput(int argc, slib_par_t *params, var_t *retval) {
251355
if (output.create(CLASS_DIGITAL_INPUT) &&
252356
output.open(pin)) {
253357
create_io_class(retval, id);
254-
v_create_callback(retval, METHOD_WAIT_FOR_CONNECT, cmd_wait_for_connect);
358+
v_create_callback(retval, METHOD_WRITE, cmd_digital_output_write);
255359
result = 1;
256360
} else {
257361
_classMap.erase(id);
@@ -266,8 +370,7 @@ FUNC_SIG lib_func[] = {
266370
{1, 1, "OPENDIGITALOUTPUT", cmd_opendigitaloutput},
267371
};
268372

269-
FUNC_SIG lib_proc[] = {
270-
};
373+
FUNC_SIG lib_proc[] = {};
271374

272375
SBLIB_API int sblib_proc_count() {
273376
return (sizeof(lib_proc) / sizeof(lib_proc[0]));

ioio/src/main/java/net/sourceforge/smallbasic/ioio/AbstractLooperProvider.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ protected AbstractLooperProvider() {
2020
}
2121

2222
public void beginBatch() {
23-
putMethod(IOIO::beginBatch);
23+
invoke(IOIO::beginBatch);
2424
}
2525

2626
public void disconnect() {
27-
putMethod(IOIO::disconnect);
27+
invoke(IOIO::disconnect);
2828
}
2929

3030
public void endBatch() {
31-
putMethod(IOIO::endBatch);
31+
invoke(IOIO::endBatch);
3232
}
3333

3434
public void hardReset() {
35-
putMethod(IOIO::hardReset);
35+
invoke(IOIO::hardReset);
3636
}
3737

3838
public void softReset() {
39-
putMethod(IOIO::softReset);
39+
invoke(IOIO::softReset);
4040
}
4141

4242
public void stop() {
@@ -45,23 +45,23 @@ public void stop() {
4545
}
4646

4747
public void sync() {
48-
putMethod(IOIO::sync);
48+
invoke(IOIO::sync);
4949
}
5050

5151
public void waitForConnect() {
52-
putMethod(IOIO::waitForConnect);
52+
invoke(IOIO::waitForConnect);
5353
}
5454

5555
public void waitForDisconnect() {
56-
putMethod(IOIO::waitForDisconnect);
56+
invoke(IOIO::waitForDisconnect);
5757
}
5858

5959
protected void start() {
6060
this.controller.start();
6161
this.ready = true;
6262
}
6363

64-
private void putMethod(Consumer<IOIO> consumer) {
64+
private void invoke(Consumer<IOIO> consumer) {
6565
final CountDownLatch latch = new CountDownLatch(1);
6666
try {
6767
if (this.ready) {

0 commit comments

Comments
 (0)