?? process.h~
字號:
/*****************author : DONG Shengdong********************/ /****************** process the points********************/ #ifndef _PROCESS_H #define _PROCESS_H /*--------------------initialize the struction---------------*/ #include "math.h" #include "string.h" #include "loadbmp.h" #include "blind_ime_more.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////全局變量以及宏定義////////////////////////////////// /*--------------------initialize the struction---------------*/ #define DEVICE_NAME_TOUCH "/dev/touchscreen/0raw" #define MY_PICTURE_DISPLAY "./res/girl.bmp" #define MY_PICTURE_POINT "./res/point.bmp" #define TIME 1 #define DEFAULTLINEDISTANCE 500 #define DEFAULTROWDISTANCE 600 #define SYLLABLE_MAX 43 #define ERROR 200 #define POINTRADIUS 200 #define PROPERTY_CLICK_X 600 #define PROPERTY_CLICK_Y 600 #define STOP_POINT_R_X 3000 #define STOP_POINT_R_Y 500 #define POINTS_TO_POINTS 2000 #define MAX_PROPERTY_VALUE 800 #define DEFAULTMINDIS 160 #define TANX_ERROR 0.1 #define BENCHMARK_POINT_X 2000 #define BENCHMARK_POINT_Y 3000 #define DISTANCE_CHANGE_CONSTANT 20 #define DISTANCE_CHANGE 5 #define ANGLE_CHANGE_CONSTANT 5 #define EXTEND_TO 800 #define EXTEND_TO_MIN 200/*************signal of control the time**********/ struct counttime { pthread_mutex_t lock; pthread_cond_t timer; pthread_cond_t exe; int times; int sem; int point_rd; };/*************the struct of proverty*************/ struct PRO{ unsigned short pointx; unsigned short pointy; };/*********the information of blind points***********/ typedef struct{ unsigned short x; unsigned short y; }POINT;/**************six points matrix******************/ typedef struct { POINT matrix_point[6]; unsigned short distance_change; double radian_change; }MATRIX; /*****read the X and Y of value from touchscreen*****/ typedef struct { unsigned short pressure; unsigned short x; unsigned short y; unsigned short pad; }TS_RET; struct counttime buffer; //instancing the signal struct PRO property; //instancing the property POINT poi1[12],poi2[12],point[6]; MATRIX matrix; int count; int p1count; //the number of first group int p2count; //the number of second group int exec; //control the overtime int afresh; //control the property circle int count_pro; //the number of points of perperty int quit_s; //send signal to quit int color; //顏色刷新 int colorchange=1; char blind_character[20];
/*************the list of syllable***************/ typedef struct { char number[6]; unsigned short point_num; //the number of the first group of blind character unsigned short line; //the number of line unsigned short row; //the number of row unsigned short longslash; //the number of long slash unsigned short shortslash; //the number of short slash unsigned short longslash_minus; //the number of minus long slash unsigned short shortslash_minus; //the number of minus short slash unsigned short head_line_num; unsigned short head_row_num; unsigned short head_exist; }SYL_RET; SYL_RET List[SYLLABLE_MAX]={ {"12", 2, 0, 1, 0, 0, 0, 0, 1, 2, 1}, {"13", 2, 0, 0, 0, 0, 0, 0, 1, 2, 1}, {"14", 2, 1, 0, 0, 0, 0, 0, 2, 1, 1}, {"15", 2, 0, 0, 0, 1, 0, 0, 1, 1, 1}, {"16", 2, 0, 1, 0, 0, 0, 0, 1, 1, 1}, {"24", 2, 0, 0, 0, 0, 0, 1, 1, 1, 0}, {"34", 2, 0, 0, 0, 0, 1, 0, 1, 1, 0}, {"123", 3, 0, 2, 0, 0, 0, 0, 1, 3, 1}, {"124", 3, 1, 1, 0, 0, 0, 1, 2, 2, 1}, {"125", 3, 1, 1, 0, 1, 0, 0, 1, 2, 1}, {"126", 3, 0, 1, 1, 1, 0, 0, 1, 2, 1}, {"134", 3, 1, 0, 0, 0, 1, 0, 2, 2, 1}, {"135", 3, 0, 0, 0, 1, 0, 1, 1, 2, 1}, {"136", 3, 1, 0, 1, 0, 0, 0, 1, 2, 1}, {"145", 3, 1, 1, 0, 1, 0, 0, 2, 1, 1}, {"146", 3, 1, 0, 1, 0, 0, 0, 2, 1, 1}, {"156", 3, 0, 1, 1, 1, 0, 0, 1, 1, 1}, {"234", 3, 0, 1, 0, 0, 1, 1, 1, 2, 0}, {"245", 3, 1, 1, 0, 0, 0, 1, 2, 1, 0}, {"246", 3, 0, 0, 0, 1, 0, 1, 1, 1, 0}, {"345", 3, 0, 1, 0, 0, 1, 1, 1, 1, 0}, {"346", 3, 1, 0, 0, 0, 1, 0, 2, 1, 0}, {"1234", 4, 1, 2, 0, 0, 1, 1, 2, 3, 1}, {"1235", 4, 1, 2, 0, 1, 0, 1, 1, 3, 1}, {"1236", 4, 1, 2, 1, 1, 0, 0, 1, 3, 1}, {"1245", 4, 2, 2, 0, 1, 0, 1, 2, 2, 1}, {"1246", 4, 1, 1, 1, 1, 0, 1, 2, 2, 1}, {"1345", 4, 1, 1, 0, 1, 1, 1, 2, 2, 1}, {"1346", 4, 2, 0, 1, 0, 1, 0, 2, 2, 1}, {"1356", 4, 1, 1, 1, 1, 0, 1, 1, 2, 1}, {"1456", 4, 1, 2, 1, 1, 0, 0, 2, 1, 1}, {"2345", 4, 1, 2, 0, 0, 1, 2, 2, 2, 0}, {"2346", 4, 1, 1, 0, 1, 1, 1, 1, 2, 0}, {"2456", 4, 1, 2, 0, 1, 0, 1, 2, 1, 0}, {"3456", 4, 1, 2, 0, 0, 1, 1, 2, 1, 0}, {"12345", 5, 2, 3, 0, 1, 1, 2, 2, 3, 1}, {"12346", 5, 2, 2, 1, 1, 1, 1, 2, 3, 1}, {"12356", 5, 2, 3, 1, 2, 0, 1, 1, 3, 1}, {"12456", 5, 2, 3, 1, 2, 0, 1, 2, 2, 1}, {"13456", 5, 2, 2, 1, 1, 1, 1, 2, 2, 1}, {"23456", 5, 2, 3, 0, 1, 1, 2, 2, 2, 0}, {"123456",6, 3, 4, 1, 2, 1, 2, 2, 3, 1} };
/////////////////////////////////////////////////////////////////////////////////////////////////
/*-------------the head of the function---------*/ void init(); void initpro(); void initpoint(); //initialize the value of points groups is 0 void initmatrix(); void varinit(); int activation(POINT poival[],int pointcount,int aim,int binary[]); void getnumber(int binarynumber[],char number[]); void matrix_set(); char to_char(int NO); void * point_receive(void * data); void * process(void * data ); void * property_set( void * data); void * overtime( void * data ); void * check_pro( void * data ); int pro_process(POINT point_temp[]); void * time_count(void * data); ////////////////////////////////////////////////////////////////////////////////////////////// /*-----------the function to initialize the struct value---------*/ void init() { pthread_mutex_init(&buffer.lock,NULL); /* mutex ensuring exclusive access to change the value of times */ pthread_cond_init(&buffer.timer,NULL); /* signaled when times is 0 */ pthread_cond_init(&buffer.exe,NULL); buffer.times = 0; /* the initial value */ buffer.sem = 1; buffer.point_rd =1; } /*-----------the function to initialize value of property--------------*/ void initpro() { property.pointx = DEFAULTLINEDISTANCE; property.pointy = DEFAULTROWDISTANCE; } /*---------the function to initialize value of matrix points---------*/ void initmatrix() { matrix.matrix_point[0].x=BENCHMARK_POINT_X; matrix.matrix_point[0].y=BENCHMARK_POINT_Y; } /*------------the function to initialize the value of points----*/ void initpoint() { int i; /*---------------------initialize the POINT---------------------------*/ for(i=0;i<12;i++) { poi1[i].x=0; poi1[i].y=0; poi2[i].x=0; poi2[i].y=0; if(i<6) { point[i].x=0; point[i].y=0; } } } void varinit() { count=0; p1count=0; //the number of first group p2count=0; //the number of second group exec=0; //control the overtime afresh = 1; //control the property circle count_pro = 0; //the number of points of perperty quit_s = 1; //send signal to quit //color=0; //顏色刷新 strcpy(blind_character,"\0"); }
////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////功能函數(shù)定義/////////////////////////////// /*--------------以首點為基點將盲文點整體平移至正規(guī)6點規(guī)陣------------*/ /*------matrix為盲文點移動到正規(guī)矩陣相應(yīng)的第n個點 --------*/
/*----以正規(guī)矩陣的首點延長或縮短所打盲文點(除首點)判斷是否經(jīng)過 正規(guī)矩陣的其它的點,并確定是哪個點------------------------*/ int activation(POINT poival[],int pointcount,int aim,int binary[]) { ////////////////////////////////////////////////////////////////////////// ///////////////////////////////變量聲明集合///////////////////////////////// int i,val; ////////////////////循環(huán)次數(shù) int pointnum; //直線延長過程所經(jīng)過的點數(shù) int pointnumanother; //第2點和第6點的判斷 int poiline; //判斷盲文是否存在兩個點和標(biāo)準(zhǔn)點在同一條直線上 int sign; //經(jīng)過第二點的標(biāo)志 int two; //兩次經(jīng)過第二點的標(biāo)志 int three; //三次經(jīng)過第二點的標(biāo)志 int four; //四次經(jīng)過第二點的標(biāo)志 unsigned short x_temp; //臨時變量 unsigned short y_temp; //臨時變量
unsigned short x_move; //盲文點X軸移動的距離
unsigned short y_move; //盲文點Y軸移動的距離 unsigned short x_standard; //正規(guī)矩陣的首點的X軸值 unsigned short y_standard; //正規(guī)矩陣的首點的Y軸值 unsigned short x_change; //延長或縮小所得到的新坐標(biāo)X值 unsigned short y_change; //延長或縮小所得到的新坐標(biāo)Y值 unsigned short max_extend; //X軸坐標(biāo)值最大可擴展的數(shù)值 unsigned short step_extend; //X軸坐值一次可擴展的數(shù)值 unsigned short divide_1_x; //盲點中,經(jīng)過第二點一次時的X值 unsigned short divide_1_y; //盲點中,經(jīng)過第二點一次時的Y值 unsigned short divide_2_x; //盲點中,經(jīng)過第二點兩次時的X值 unsigned short divide_2_y; //盲點中,經(jīng)過第二點兩次時的Y值 unsigned short divide_3_x; //盲點中,經(jīng)過第二點三次時的X值 unsigned short divide_3_y; //盲點中,經(jīng)過第二點三次時的Y值 double dis1; //當(dāng)直線延長得到兩個點時就比較dis離哪個點最近就激活相應(yīng)點 double dis2; //當(dāng)直線延長得到兩個點時就比較dis離哪個點最近就激活相應(yīng)點 double A; //直線系數(shù) 例:Ax+y=B double B; //直線系數(shù) 例:Ax+y=B double distance; //測試到個點的距離 int binarynumber[6]; //盲文 例:101000,哪位為1表示盲文所打的點有效 POINT poi[6]; /////////////////////////變量初始化 pointnumanother=0; poiline =0; two =0; three =0; four =0; for(i=0;i<pointcount;i++) { poi[i].x=poival[i].x; poi[i].y=poival[i].y; }
x_move = poi[0].x - matrix.matrix_point[aim].x;
y_move = poi[0].y - matrix.matrix_point[aim].y;
for(i=0;i<pointcount;i++) //盲文整體平移
{
poi[i].x=poi[i].x-x_move;
poi[i].y=poi[i].y-y_move;
} /*for(i=0;i<6;i++) printf("m x:%d,m y:%d\n", matrix.matrix_point[i].x,matrix.matrix_point[i].y);*/ for(i=0;i<pointcount;i++) printf("poi[i].x%d--poi[i].y%d-\n",poi[i].x,poi[i].y); for(val=1;val<pointcount;val++) { ///////////////變量在循環(huán)之前賦值 dis1 = 0; dis2 = 0; pointnum = 0; x_standard = matrix.matrix_point[aim].x; y_standard = matrix.matrix_point[aim].y; x_change = x_standard; y_change = y_standard; x_temp = poi[val].x; y_temp = poi[val].y; sign=0; for(i=0;i<6;i++)
binarynumber[i] = 0 ; /*-------------------計算直線的系數(shù)---------------*/ if(x_standard-x_temp!=0) { A = (double)(y_temp-y_standard)/(x_standard-x_temp); B = A*x_standard+y_standard; } /*-----直線以DISTANCE_CHANGE_CONSTANT為單位延長----*/ /*-----DISTANCE_REDUCE------*/ // printf("A:%f--B:%f\n",A,B); if(A>15) { max_extend=100; step_extend=1; } else if(A>10) { max_extend=200; step_extend=2; } else if(A>5) { max_extend=400; step_extend=5; } else if(A>3) { max_extend=600; step_extend=10; } else if(A>1) { max_extend=700; step_extend=15; } else if(A>=0) { max_extend=EXTEND_TO; step_extend=DISTANCE_CHANGE_CONSTANT; } else if(A>-1) { max_extend=EXTEND_TO; step_extend=DISTANCE_CHANGE_CONSTANT; } else if(A>-3) { max_extend=700; step_extend=15; } else if(A>-5) { max_extend=600; step_extend=10; } else if(A>-10) { max_extend=400; step_extend=5; } else if(A>=-15) { max_extend=200; step_extend=2; } else { max_extend=100; step_extend=1; } //printf("begin-%d\n",val); while(x_change-x_standard<=max_extend&&x_standard-x_change<=max_extend) { if(x_standard<x_temp) //向X軸正方向延長 { x_change = x_change+step_extend; y_change = B-A*x_change; // printf("x_change:%d---y_change:%d\n",x_change,y_change); } else if(x_standard>x_temp) //向X軸負(fù)方向延長 { x_change = x_change-step_extend; y_change = B-A*x_change; // printf("x_change:%d---y_change:%d\n",x_change,y_change); } else //向Y軸負(fù)方向延長 { x_change = x_standard; y_change = y_change-DISTANCE_CHANGE_CONSTANT; if(y_change<1000) break; } /* for(i=0;i<6;i++) { distance=sqrt((double)(x_change-matrix.matrix_point[i].x)* (x_change-matrix.matrix_point[i].x)+ (y_change-matrix.matrix_point[i].y)* (y_change-matrix.matrix_point[i].y)); printf("distance:%f\n",distance); } printf("end\n"); */ /*--------正規(guī)矩陣第1個點的區(qū)域范圍-------------*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -