diff --git a/eismultiplexer.c b/eismultiplexer.c index 08477fa..b960541 100644 --- a/eismultiplexer.c +++ b/eismultiplexer.c @@ -230,7 +230,7 @@ int eismultiplexer_wait_trigger(struct eismultiplexer* muliplexer, uint16_t inde int eismultiplexer_get_trigger_count(struct eismultiplexer* muliplexer) { uint8_t buffer[1] = {}; - int ret = usbshm_read_control_transfer(muliplexer->priv, COMMAND_GET_TRIG, 0, 0, buffer, 1); + int ret = usbshm_read_control_transfer(muliplexer->priv, COMMAND_GET_TRIG_COUNT, 0, 0, buffer, 1); if(ret >= 0) return buffer[0]; else diff --git a/main.c b/main.c index 62fc29f..d1c482b 100644 --- a/main.c +++ b/main.c @@ -81,6 +81,7 @@ void print_commands(void) puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address"); puts("write [ADDRESS] [LENGTH] | write to the device eeprom at address"); puts("trigger [INDEX] [STATE]\t | set the trigger state input (0), output and low (1) or output and high(2)"); + puts("wait [INDEX] [TYPE]\t | wait for an input trigger event"); puts("list\t\t\t | list the serial nummbers of the connected devices"); puts("channels\t\t | get the number of channels the device has"); } @@ -223,6 +224,39 @@ static int process_commands(char** commands, size_t command_count, struct eismul return 3; } } + else if(strcmp(commands[0], "wait") == 0) + { + if(command_count < 2) + { + printf("Usage %s %s [INDEX] [TYPE]\n", name, commands[0]); + puts("Type is one of:"); + puts("0: Waits until the trigger falls from high to low"); + puts("1: Waits until the trigger rises from low to high"); + puts("2: Waits until the trigger changes from low to high or high to low"); + puts("3: Waits until the trigger is low"); + puts("4: Waits until the trigger is high"); + return 2; + } + int trigger_count = eismultiplexer_get_trigger_count(multiplexer); + long index = strtol(commands[1], NULL, 10); + long type = strtol(commands[2], NULL, 10); + if(type >= 5) + { + printf("%li is an invalid type\n", type); + return 2; + } + if(index >= trigger_count) + { + printf("%li is out of range as the device has only %i triggers\n", index, trigger_count); + return 2; + } + int ret = eismultiplexer_wait_trigger(multiplexer, index, type, 1000000000); + if(ret < 0) + { + puts("Unable to wait for trigger"); + return 3; + } + } else { if(command_count != 2) @@ -376,9 +410,7 @@ int main(int argc, char* argv[]) } else { - eismultiplexer_set_led(&multiplexer, true); ret = process_commands(config.commands, config.command_count, &multiplexer, argv[0]); - eismultiplexer_set_led(&multiplexer, false); } eismultiplexer_disconnect(&multiplexer);