add Wait command to cli to allow wating for trigger
This commit is contained in:
parent
ba13899644
commit
5dc53f4485
2 changed files with 35 additions and 3 deletions
|
|
@ -230,7 +230,7 @@ int eismultiplexer_wait_trigger(struct eismultiplexer* muliplexer, uint16_t inde
|
||||||
int eismultiplexer_get_trigger_count(struct eismultiplexer* muliplexer)
|
int eismultiplexer_get_trigger_count(struct eismultiplexer* muliplexer)
|
||||||
{
|
{
|
||||||
uint8_t buffer[1] = {};
|
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)
|
if(ret >= 0)
|
||||||
return buffer[0];
|
return buffer[0];
|
||||||
else
|
else
|
||||||
|
|
|
||||||
36
main.c
36
main.c
|
|
@ -81,6 +81,7 @@ void print_commands(void)
|
||||||
puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address");
|
puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address");
|
||||||
puts("write [ADDRESS] [LENGTH] | write to 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("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("list\t\t\t | list the serial nummbers of the connected devices");
|
||||||
puts("channels\t\t | get the number of channels the device has");
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
if(command_count != 2)
|
if(command_count != 2)
|
||||||
|
|
@ -376,9 +410,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
eismultiplexer_set_led(&multiplexer, true);
|
|
||||||
ret = process_commands(config.commands, config.command_count, &multiplexer, argv[0]);
|
ret = process_commands(config.commands, config.command_count, &multiplexer, argv[0]);
|
||||||
eismultiplexer_set_led(&multiplexer, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eismultiplexer_disconnect(&multiplexer);
|
eismultiplexer_disconnect(&multiplexer);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue