Add trigger functionality
Some checks failed
Build eismuliplexer for windows / Build (push) Has been cancelled
Build eismuliplexer for linux / Build (push) Has been cancelled
Some checks failed
Build eismuliplexer for windows / Build (push) Has been cancelled
Build eismuliplexer for linux / Build (push) Has been cancelled
This commit is contained in:
parent
5c42094b06
commit
ba13899644
3 changed files with 197 additions and 2 deletions
40
main.c
40
main.c
|
|
@ -80,8 +80,9 @@ void print_commands(void)
|
|||
puts("get\t\t\t | get the state of all channels");
|
||||
puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address");
|
||||
puts("write [ADDRESS] [LENGTH] | write to the device eeprom at address");
|
||||
puts("list | list the serial nummbers of the connected devices");
|
||||
puts("channels | get the channel of the device");
|
||||
puts("trigger [INDEX] [STATE]\t | set the trigger state input (0), output and low (1) or output and high(2)");
|
||||
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");
|
||||
}
|
||||
|
||||
static int process_commands(char** commands, size_t command_count, struct eismultiplexer* multiplexer, char* name)
|
||||
|
|
@ -160,6 +161,14 @@ static int process_commands(char** commands, size_t command_count, struct eismul
|
|||
bool connected = channels & (1 << i);
|
||||
printf("Channel %c: %s\n", (char)('A'+i), connected ? "on" : "off");
|
||||
}
|
||||
int trigger_count = eismultiplexer_get_trigger_count(multiplexer);
|
||||
for(int i = 0; i < trigger_count; ++i)
|
||||
{
|
||||
trigger_state_t state;
|
||||
bool level;
|
||||
eismultiplexer_get_trigger_state(multiplexer, i, &state, &level);
|
||||
printf("Trigger %i: state: %i level: %i\n", i, state, level);
|
||||
}
|
||||
}
|
||||
else if(strcmp(commands[0], "channels") == 0)
|
||||
{
|
||||
|
|
@ -187,6 +196,33 @@ static int process_commands(char** commands, size_t command_count, struct eismul
|
|||
|
||||
free(serials);
|
||||
}
|
||||
else if(strcmp(commands[0], "trigger") == 0)
|
||||
{
|
||||
if(command_count < 2)
|
||||
{
|
||||
printf("Usage %s %s [INDEX] [STATE]\n", name, commands[0]);
|
||||
return 2;
|
||||
}
|
||||
int trigger_count = eismultiplexer_get_trigger_count(multiplexer);
|
||||
long index = strtol(commands[1], NULL, 10);
|
||||
long state = strtol(commands[2], NULL, 10);
|
||||
if(state >= TRIGGER_STATE_COUNT)
|
||||
{
|
||||
printf("%li is an invalid state\n", state);
|
||||
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_set_trigger_state(multiplexer, index, state);
|
||||
if(ret < 0)
|
||||
{
|
||||
puts("Unable to set trigger state");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(command_count != 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue