cli: fix get allways returning 8 channels

This commit is contained in:
Carl Philipp Klemm 2025-11-11 11:18:02 +01:00
parent 1f40693c19
commit 4efb15d098

9
main.c
View file

@ -156,8 +156,15 @@ static int process_commands(char** commands, size_t command_count, struct eismul
} }
else if(strcmp(commands[0], "get") == 0) 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); 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); bool connected = channels & (1 << i);
printf("Channel %c: %s\n", (char)('A'+i), connected ? "on" : "off"); printf("Channel %c: %s\n", (char)('A'+i), connected ? "on" : "off");