expand the test program
This commit is contained in:
		
							parent
							
								
									dd4ba45a2b
								
							
						
					
					
						commit
						f76f56a471
					
				
					 2 changed files with 76 additions and 12 deletions
				
			
		
							
								
								
									
										80
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										80
									
								
								main.c
									
										
									
									
									
								
							|  | @ -1,32 +1,90 @@ | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
|  | #include <math.h> | ||||||
|  | #include <stdlib.h> | ||||||
|  | #include <string.h> | ||||||
| #include "uvosled.h" | #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[]) | int main(int argc, char* argv[]) | ||||||
| { | { | ||||||
|  | 	if(argc < 2 || strcmp (argv[1], "help") == 0) | ||||||
|  | 	{ | ||||||
|  | 		print_help(argv[0]); | ||||||
|  | 		return 0; | ||||||
|  | 	}  | ||||||
|  | 	 | ||||||
| 	struct uvosled led; | 	struct uvosled led; | ||||||
| 	 | 	 | ||||||
| 	if(uvosled_connect(&led)) | 	if(uvosled_connect(&led)) | ||||||
| 	{ | 	{ | ||||||
| 		printf("cant connect \n"); | 		printf("Can not connect to UVOS usbled device\n"); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 	if(uvosled_poweron(&led)) | 	 | ||||||
|  | 	if(strcmp(argv[1], "on") == 0) | ||||||
| 	{ | 	{ | ||||||
| 		printf("cant power on \n"); | 		if(uvosled_poweron(&led)) | ||||||
| 		return -2; | 			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"); | 		uvosled_set_current(&led, 0xff , 0); | ||||||
| 		return -3; | 		uvosled_poweroff(&led); | ||||||
| 	} | 	} | ||||||
| 	sleep(30); | 	else if(strcmp(argv[1], "set") == 0) | ||||||
| 	if(uvosled_set_current(&led, CHANNEL_A | CHANNEL_B , 0)) |  | ||||||
| 	{ | 	{ | ||||||
| 		printf("cant set current \n"); | 		if(argc != 4) | ||||||
| 		return -3; | 		{ | ||||||
|  | 			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_poweroff(&led); | ||||||
| 	uvosled_disconnect(&led); | 	uvosled_disconnect(&led); | ||||||
| 	return 0; | 	return 0; | ||||||
|  |  | ||||||
|  | @ -15,23 +15,29 @@ struct uvosled { | ||||||
| 	struct usbshm* priv; | 	struct usbshm* priv; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // returns 0 on sucess and < 0 on failure
 | ||||||
| int uvosled_connect(struct uvosled* led); | int uvosled_connect(struct uvosled* led); | ||||||
| 
 | 
 | ||||||
| // power on cameras
 | // power on cameras
 | ||||||
|  | // returns 0 on sucess and < 0 on failure
 | ||||||
| int uvosled_poweron(struct uvosled* led); | int uvosled_poweron(struct uvosled* led); | ||||||
| 
 | 
 | ||||||
| // power off cameras
 | // power off cameras
 | ||||||
|  | // returns 0 on sucess and < 0 on failure
 | ||||||
| int uvosled_poweroff(struct uvosled* led); | 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
 | // 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); | int uvosled_set_current(struct uvosled* led, uint8_t channels, float current); | ||||||
| 
 | 
 | ||||||
| // causes the cameras to take an image
 | // causes the cameras to take an image
 | ||||||
|  | // returns 0 on sucess and < 0 on failure
 | ||||||
| int uvosled_trigger(struct uvosled* led); | int uvosled_trigger(struct uvosled* led); | ||||||
| 
 | 
 | ||||||
| // leds are lit for time seconds and the camera is activated cameraOffset seconds after they are lit
 | // leds are lit for time seconds and the camera is activated cameraOffset seconds after they are lit
 | ||||||
| // real time guarenteed by microcontroller
 | // 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); | int uvosled_capture(struct uvosled* led, int channels, float current, double time, double cameraOffset); | ||||||
| 
 | 
 | ||||||
| void uvosled_disconnect(struct uvosled* led); | void uvosled_disconnect(struct uvosled* led); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue