diff --git a/examples/example.py b/examples/example.py new file mode 100755 index 0000000000000000000000000000000000000000..07fb0ac7aa7368610d84d724a28ec93896d0ef19 --- /dev/null +++ b/examples/example.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +import moberg + +def scan(): + result = [[], [], [], [], []] + m = moberg.Moberg() + for i, f in enumerate([m.analog_in, m.analog_out, + m.digital_in, m.digital_out, + m.encoder_in]): + for j in range(0, 100): + try: + result[i].append((j, f(j))) + pass + except: + pass + pass + pass + return result + +def main(): + channels = scan() + for c in channels: + print(len(c)) + pass + pass + +if __name__ == '__main__': + main() diff --git a/moberg_device.c b/moberg_device.c index 038974b237a964ae56425353383ac7c82b5ab9ad..015591f7626543c9d5ed397dc7b2448140effb04 100644 --- a/moberg_device.c +++ b/moberg_device.c @@ -151,16 +151,22 @@ static struct moberg_status map( struct moberg_channel *channel) { struct moberg_status result = MOBERG_ERRNO(EINVAL); - + if (device->range->kind != channel->kind) { + fprintf(stderr, "Mapping wrong kind of channel %d != %d\n", + device->range->kind, channel->kind); return MOBERG_ERRNO(EINVAL); } if (device->range->min > device->range->max) { + fprintf(stderr, "Mapping outside range %d > %d\n", + device->range->min, device->range->max); return MOBERG_ERRNO(ENOSPC); } result = add_channel(device, device->range->kind, device->range->min, (union channel) { .channel=channel }); if (! OK(result)) { + fprintf(stderr, "Failed to add channel kind=%d, index=%d\n", + device->range->kind, device->range->min); return result; } device->range->min++;