00001 #include <stdio.h> 00002 #include <unistd.h> 00003 #include <sys/ioctl.h> 00004 #include <sys/types.h> 00005 #include <sys/stat.h> 00006 #include <fcntl.h> 00007 #include <stdlib.h> 00008 #include <string.h> 00009 00010 #include <sys/mman.h> 00011 00012 #include <asm/elphel/hist.h> 00013 #include <asm/elphel/autoexp.h> 00014 #include <asm/elphel/c313a.h> 00015 00016 #define ARG_ENABLE "-e" 00017 #define ARG_DISABLE "-d" 00018 #define ARG_OVEREXP_MAX "-o" 00019 #define ARG_EXP_MAX "-m" 00020 #define ARG_WIDTH "-w" 00021 #define ARG_HEIGHT "-h" 00022 #define ARG_LEFT "-l" 00023 #define ARG_TOP "-t" 00024 #define ARG_STATE "-s" 00025 00026 struct autoexp_t autoexp = { 00027 .on = HIST_NOT_CHANGE, 00028 .width = HIST_NOT_CHANGE, 00029 .height = HIST_NOT_CHANGE, 00030 .left = HIST_NOT_CHANGE, 00031 .top = HIST_NOT_CHANGE, 00032 .exp_max = HIST_NOT_CHANGE, 00033 .overexp_max = HIST_NOT_CHANGE, 00034 .exp = HIST_NOT_CHANGE, 00035 .skip_pmin = HIST_NOT_CHANGE, 00036 .skip_pmax = HIST_NOT_CHANGE, 00037 .skip_t = HIST_NOT_CHANGE, 00038 }; 00039 00040 int main(int argc, char *argv[]) { 00041 int z; 00042 int flag = 0; 00043 int fd; 00044 int state = 0; 00045 00046 printf("ctrl\r\n"); 00047 for(z = 1; z < argc; z++) { 00048 if(strcmp(argv[z], ARG_OVEREXP_MAX) == 0 && z + 1 < argc) { 00049 autoexp.overexp_max = (unsigned long)atol(argv[z + 1]); 00050 flag = 1; 00051 } 00052 if(strcmp(argv[z], ARG_EXP_MAX) == 0 && z + 1 < argc) { 00053 autoexp.exp_max = (unsigned long)atol(argv[z + 1]); 00054 flag = 1; 00055 } 00056 if(strcmp(argv[z], ARG_WIDTH) == 0 && z + 1 < argc) { 00057 autoexp.width = (unsigned long)atol(argv[z + 1]); 00058 flag = 1; 00059 } 00060 if(strcmp(argv[z], ARG_HEIGHT) == 0 && z + 1 < argc) { 00061 autoexp.height = (unsigned long)atol(argv[z + 1]); 00062 flag = 1; 00063 } 00064 if(strcmp(argv[z], ARG_LEFT) == 0 && z + 1 < argc) { 00065 autoexp.left = (unsigned long)atol(argv[z + 1]); 00066 flag = 1; 00067 } 00068 if(strcmp(argv[z], ARG_TOP) == 0 && z + 1 < argc) { 00069 autoexp.top = (unsigned long)atol(argv[z + 1]); 00070 flag = 1; 00071 } 00072 if(strcmp(argv[z], ARG_STATE) == 0) { 00073 state = 1; 00074 } 00075 if(strcmp(argv[z], ARG_ENABLE) == 0) { 00076 autoexp.on = 1; 00077 flag = 1; 00078 } 00079 if(strcmp(argv[z], ARG_DISABLE) == 0) { 00080 autoexp.on = 0; 00081 flag = 1; 00082 } 00083 } 00084 if(flag == 0 && state == 0) { 00085 printf("usage: autoexpctrl OPTIONS\r\n"); 00086 printf("\t%s - enable autoexposition algorithm\r\n", ARG_ENABLE); 00087 printf("\t%s - disable autoexposition algorithm\r\n", ARG_DISABLE); 00088 printf("\t%s - set window width, in percents: 5%% == 5; 20%% == 20 etc...\r\n", ARG_WIDTH); 00089 printf("\t%s - set window height, in percents: 5%% == 5; 20%% == 20 etc...\r\n", ARG_HEIGHT); 00090 printf("\t%s - set window horizontal (left) offset alignment, in percents: 0%% - left, 50%% - center, 100%% - right edge\r\n", ARG_LEFT); 00091 printf("\t%s - set window vertical (top) offset alignment, in percents: 0%% - left, 50%% - center, 100%% - right edge\r\n", ARG_TOP); 00092 printf("\t%s - set exposition limit, in 100 usec: 0.1 msec == 1; 1 ms == 10; 0.02 sec == 200 etc...\r\n", ARG_EXP_MAX); 00093 printf("\t%s - set overexposure limit, in percents: 1%% == 100; 0.02%% == 2 etc...\r\n", ARG_OVEREXP_MAX); 00094 printf("\t%s - show current state\r\n", ARG_STATE); 00095 return 0; 00096 } 00097 fd = open(AUTOEXP_DEV_NAME, O_RDWR); 00098 if(fd < 0) { 00099 printf("open %s failed - may be busy, or not started\r\n", AUTOEXP_DEV_NAME); 00100 return -1; 00101 } 00102 if(flag) { 00103 z = ioctl(fd, _IO(IOC_AUTOEXP_SET, 0x00), &autoexp); 00104 if(z >= 0) 00105 printf("apply settings ok\r\n"); 00106 else { 00107 printf("apply settings failed\r\n"); 00108 return -1; 00109 } 00110 } 00111 if(state) { 00112 z = ioctl(fd, _IO(IOC_AUTOEXP_GET, 0x00), &autoexp); 00113 if(z >= 0) { 00114 printf("get state ok:\r\n"); 00115 printf("autoexposure enable: "); 00116 if(autoexp.on) 00117 printf("on\r\n"); 00118 else 00119 printf("off\r\n"); 00120 printf("window width: %lu%%\r\n", autoexp.width); 00121 printf("window height: %lu%%\r\n", autoexp.height); 00122 printf("window left: %lu%%\r\n", autoexp.left); 00123 printf("window top: %lu%%\r\n", autoexp.top); 00124 printf("exp time max: %5.1fms\r\n", ((float)autoexp.exp_max) / 10.0); 00125 printf("overexp max: %3.2f%%\r\n", ((float)autoexp.overexp_max) / 100.0); 00126 printf("exp of last frame: %5.1fms\r\n", ((float)autoexp.exp) / 10.0); 00127 } 00128 else { 00129 printf("get state failed\r\n"); 00130 return -1; 00131 } 00132 } 00133 close(fd); 00134 00135 return 0; 00136 }