From f76f56a471dc587c40a712cd4282eae65555ee8e Mon Sep 17 00:00:00 2001 From: uvos Date: Mon, 28 Jun 2021 18:08:57 +0200 Subject: [PATCH] expand the test program --- main.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++-------- uvosled.h | 8 +++++- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 724fbec..74a92ac 100644 --- a/main.c +++ b/main.c @@ -1,32 +1,90 @@ #include #include +#include +#include +#include #include "uvosled.h" +void print_help(const char* progname) +{ + printf("UVOS usb led test application\n"); + printf("usage: %s [OPERATION] [CHANNEL] [VALUE]\n", progname); + printf("available operations: set on off help\n"); +} + int main(int argc, char* argv[]) { + if(argc < 2 || strcmp (argv[1], "help") == 0) + { + print_help(argv[0]); + return 0; + } + struct uvosled led; if(uvosled_connect(&led)) { - printf("cant connect \n"); + printf("Can not connect to UVOS usbled device\n"); return -1; } - if(uvosled_poweron(&led)) + + if(strcmp(argv[1], "on") == 0) { - printf("cant power on \n"); - return -2; + if(uvosled_poweron(&led)) + printf("cant power on \n"); } - if(uvosled_set_current(&led, CHANNEL_A | CHANNEL_B , 0.5)) + else if(strcmp(argv[1], "off") == 0) { - printf("cant set current \n"); - return -3; + uvosled_set_current(&led, 0xff , 0); + uvosled_poweroff(&led); } - sleep(30); - if(uvosled_set_current(&led, CHANNEL_A | CHANNEL_B , 0)) + else if(strcmp(argv[1], "set") == 0) { - printf("cant set current \n"); - return -3; + if(argc != 4) + { + print_help(argv[0]); + return 0; + } + + uint8_t mask = 0; + + switch(argv[2][0]) + { + case 'a': + case 'A': + case '1': + mask = CHANNEL_A; + break; + case 'b': + case 'B': + case '2': + mask = CHANNEL_B; + break; + case 'c': + case 'C': + case '3': + mask = CHANNEL_C; + break; + case 'd': + case 'D': + case '4': + mask = CHANNEL_D; + break; + default: + printf("A channel must be selected out of A, B, C or D\n"); + } + + if(mask) + { + char* end; + float value = strtof(argv[3], &end); + if(isnan(value) || value < 0 || value > 1.0f) + printf("A channel value between 0 and 1.0 must be supplied\n"); + else if(uvosled_set_current(&led, mask, value)) + printf("Failed to set current\n"); + } } + uvosled_poweroff(&led); uvosled_disconnect(&led); return 0; diff --git a/uvosled.h b/uvosled.h index d4bfe83..69e8454 100644 --- a/uvosled.h +++ b/uvosled.h @@ -15,23 +15,29 @@ struct uvosled { struct usbshm* priv; }; +// returns 0 on sucess and < 0 on failure int uvosled_connect(struct uvosled* led); // power on cameras +// returns 0 on sucess and < 0 on failure int uvosled_poweron(struct uvosled* led); // power off cameras +// returns 0 on sucess and < 0 on failure int uvosled_poweroff(struct uvosled* led); // channels is a mask of bits, you can set it like this: CHANNEL_A | CHANNEL_C to activate channels A and C -// current is in Ampere +// current is in percent of the values selected by the linear regulator resistors +// returns 0 on sucess and < 0 on failure int uvosled_set_current(struct uvosled* led, uint8_t channels, float current); // causes the cameras to take an image +// returns 0 on sucess and < 0 on failure int uvosled_trigger(struct uvosled* led); // leds are lit for time seconds and the camera is activated cameraOffset seconds after they are lit // real time guarenteed by microcontroller +// returns 0 on sucess and < 0 on failure int uvosled_capture(struct uvosled* led, int channels, float current, double time, double cameraOffset); void uvosled_disconnect(struct uvosled* led);