Compare commits

...

4 commits

Author SHA1 Message Date
Carl Philipp Klemm
4efb15d098 cli: fix get allways returning 8 channels 2025-11-11 11:18:02 +01:00
Carl Philipp Klemm
1f40693c19 Compile dyamic version with static libgcc on windows 2025-10-23 14:47:17 +02:00
Carl Philipp Klemm
a75774ca9f remove unneded header 2025-10-23 13:11:16 +02:00
Carl Philipp Klemm
5dc53f4485 add Wait command to cli to allow wating for trigger 2025-10-23 13:07:37 +02:00
4 changed files with 47 additions and 6 deletions

View file

@ -57,8 +57,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARIES})
if(WIN32)
target_link_libraries(${PROJECT_NAME} libpthread.a)
endif(WIN32)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -O2 -static-libgcc -fno-strict-aliasing)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -O2 -fno-strict-aliasing)
endif(WIN32)
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(FILES ./eismultiplexer.h DESTINATION include)

View file

@ -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

View file

@ -28,7 +28,7 @@
#pragma once
#include <stdint.h>
#include <semaphore.h>
#include <stddef.h>
#include <stdbool.h>
/**

45
main.c
View file

@ -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");
}
@ -155,8 +156,15 @@ static int process_commands(char** commands, size_t command_count, struct eismul
}
else if(strcmp(commands[0], "get") == 0)
{
uint16_t count;
int ret = eismultiplexer_get_channel_count(multiplexer, &count);
if(ret < 0)
{
printf("could not get the number of channels\n");
return 3;
}
channel_t channels = eismultiplexer_get_connected(multiplexer);
for(size_t i = 0; i < 7; ++i)
for(size_t i = 0; i < count; ++i)
{
bool connected = channels & (1 << i);
printf("Channel %c: %s\n", (char)('A'+i), connected ? "on" : "off");
@ -223,6 +231,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 +417,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);