bool FDirectInputJoystick::IsChangedKeyState()const
{
//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("x %d %d"), InitialJoyBuf_.lX, joyBuf_[nCurIndex_].lX);
//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("y %d %d"), joyBuf_[nCurIndex_].lY, InitialJoyBuf_.lY);
//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("z %d %d"), joyBuf_[nCurIndex_].lZ, InitialJoyBuf_.lZ);

//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("Rx %d %d"), joyBuf_[nCurIndex_].lRx, InitialJoyBuf_.lRx);
//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("Ry %d %d"), joyBuf_[nCurIndex_].lRy, InitialJoyBuf_.lRy);
//	UE_LOG(LogDirectInputPadPlugin, Log, TEXT("Rz %d %d"), joyBuf_[nCurIndex_].lRz, InitialJoyBuf_.lRz);

	// 軸からチェック。初期値と比較
	if(InitX()!=X()
	|| InitY()!=Y()
	|| InitZ()!=Z()
	|| InitRotX()!=RotX()
	|| InitRotY()!=RotY()
	|| InitRotZ()!=RotZ())
		return true;

	// ボタンは、PushもReleaseもされてない
	for(uint32 i = 0; i<32; ++i)
	{
		if(((joyBuf_[nCurIndex_].rgbButtons[i]&0x80)>0)||((joyBuf_[1^nCurIndex_].rgbButtons[i]&0x80)>0))
			return true;
	}

	// POVも押されていない
	if(LOWORD(joyBuf_[nCurIndex_].rgdwPOV[0])!=0xFFFF) return true;

	//UE_LOG(LogDirectInputPadPlugin, Log, TEXT("IsChangedState: false"));
	return false;
}
/*  Main Method
 *  Author: Hasan Almawi
 *  Date of Creation: 13th September, 2014
 *  Purpose: Calls upon the other functions to draw the lines with the specified point of origin and point of termination
 *  Input Parameters: None
 *  Output Parameters: A 512x512 white window with lines drawn on it.
*/
int main() {
  Display *d;
  Window w;
  XEvent e;
  int s, i, j;
  unsigned int r, g, b;
  KeySym key;
  char text[255];
  d = InitX(d, &w, &s);
  while (1) {
    XNextEvent(d, &e);
    if (e.type == Expose) {
      SetCurrentColorX(d, &(DefaultGC(d, s)), 0, 0, 0);
      DrawLineX(d, w, s, 256, 256, 500, 300); //Eighth Octant
      DrawLineX(d, w, s, 256, 256, 300, 500); //Seventh Octant
      DrawLineX(d, w, s, 256, 256, 200, 500); //Sixth Octant
      DrawLineX(d, w, s, 256, 256, 50, 300); //Fifth Octant
      DrawLineX(d, w, s, 256, 256, 50, 200); //Fourth Octant
      DrawLineX(d, w, s, 256, 256, 200, 50); //Third Octant
      DrawLineX(d, w, s, 256, 256, 300, 50); //Second Octant
      DrawLineX(d, w, s, 256, 256, 500, 200); //First Octant
      DrawLineX(d, w, s, 511, 511, 256, 256); //First Quadrant
      DrawLineX(d, w, s, 256, 256, 0, 511); //Second Quadrant
      DrawLineX(d, w, s, 1, 1, 256, 256); //Third Quadrant
      DrawLineX(d, w, s, 256, 256, 511, 0); //Fourth Quadrant
      DrawLineX(d, w, s, 0, 256, 512, 256); //Horizontal Line
      DrawLineX(d, w, s, 256, 0, 256, 512); //Vertical Line
    }
    if(e.type == KeyPress && XLookupString(&e.xkey,text,255,&key,0)==1){ //If q key is pressed, then quit
      if(text[0]=='q') break;
    }
    if(e.type == ClientMessage) break;
  }
  QuitX(d,w);
}
Esempio n. 3
0
void	main(void)
{
	InitX();
	InitColor();
	InitScratch();
	MainLoop();
	EndX();
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  long i; 
  long c;
  extern char *optarg;
  long m1;
  long factor;
  long pages;
  unsigned long start;

  CLOCK(start);

  while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) {
    switch(c) {
      case 'p': P = atoi(optarg); 
                if (P < 1) {
                  printerr("P must be >= 1\n");
                  exit(-1);
                }
                if (log_2(P) == -1) {
                  printerr("P must be a power of 2\n");
                  exit(-1);
                }
	        break;  
      case 'm': M = atoi(optarg); 
                m1 = M/2;
                if (2*m1 != M) {
                  printerr("M must be even\n");
                  exit(-1);
                }
	        break;  
      case 'n': num_cache_lines = atoi(optarg); 
                orig_num_lines = num_cache_lines;
                if (num_cache_lines < 1) {
                  printerr("Number of cache lines must be >= 1\n");
                  exit(-1);
                }
	        break;  
      case 'l': log2_line_size = atoi(optarg); 
                if (log2_line_size < 0) {
                  printerr("Log base 2 of cache line length in bytes must be >= 0\n");
                  exit(-1);
                }
	        break;  
      case 's': dostats = !dostats; 
	        break;
      case 't': test_result = !test_result; 
	        break;
      case 'o': doprint = !doprint; 
	        break;
      case 'h': printf("Usage: FFT <options>\n\n");
                printf("options:\n");
                printf("  -mM : M = even integer; 2**M total complex data points transformed.\n");
                printf("  -pP : P = number of processors; Must be a power of 2.\n");
                printf("  -nN : N = number of cache lines.\n");
                printf("  -lL : L = Log base 2 of cache line length in bytes.\n");
                printf("  -s  : Print individual processor timing statistics.\n");
                printf("  -t  : Perform FFT and inverse FFT.  Test output by comparing the\n");
                printf("        integral of the original data to the integral of the data that\n");
                printf("        results from performing the FFT and inverse FFT.\n");
                printf("  -o  : Print out complex data points.\n");
                printf("  -h  : Print out command line options.\n\n");
                printf("Default: FFT -m%1d -p%1d -n%1d -l%1d\n",
                       DEFAULT_M,DEFAULT_P,NUM_CACHE_LINES,LOG2_LINE_SIZE);
		exit(0);
	        break;
    }
  }

  MAIN_INITENV(,80000000);

  N = 1<<M;
  rootN = 1<<(M/2);
  rowsperproc = rootN/P;
  if (rowsperproc == 0) {
    printerr("Matrix not large enough. 2**(M/2) must be >= P\n");
    exit(-1);
  }

  line_size = 1 << log2_line_size;
  if (line_size < 2*sizeof(double)) {
    printf("WARNING: Each element is a complex double (%ld bytes)\n",2*sizeof(double));
    printf("  => Less than one element per cache line\n");
    printf("     Computing transpose blocking factor\n");
    factor = (2*sizeof(double)) / line_size;
    num_cache_lines = orig_num_lines / factor;
  }  
  if (line_size <= 2*sizeof(double)) {
    pad_length = 1;
  } else {
    pad_length = line_size / (2*sizeof(double));
  }

  if (rowsperproc * rootN * 2 * sizeof(double) >= PAGE_SIZE) {
    pages = (2 * pad_length * sizeof(double) * rowsperproc) / PAGE_SIZE;
    if (pages * PAGE_SIZE != 2 * pad_length * sizeof(double) * rowsperproc) {
      pages ++;
    }
    pad_length = (pages * PAGE_SIZE) / (2 * sizeof(double) * rowsperproc);
  } else {
    pad_length = (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double))) /

                 (2 * sizeof(double) * rowsperproc);
    if (pad_length * (2 * sizeof(double) * rowsperproc) !=
        (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double)))) {
      printerr("Padding algorithm unsuccessful\n");
      exit(-1);
    }
  }

  Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));
  x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  umain = (double *) G_MALLOC(2*rootN*sizeof(double));  
  umain2 = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);

  Global->transtimes = (long *) G_MALLOC(P*sizeof(long));  
  Global->totaltimes = (long *) G_MALLOC(P*sizeof(long));  
  if (Global == NULL) {
    printerr("Could not malloc memory for Global\n");
    exit(-1);
  } else if (x == NULL) {
    printerr("Could not malloc memory for x\n");
    exit(-1);
  } else if (trans == NULL) {
    printerr("Could not malloc memory for trans\n");
    exit(-1);
  } else if (umain == NULL) {
    printerr("Could not malloc memory for umain\n");
    exit(-1);
  } else if (umain2 == NULL) {
    printerr("Could not malloc memory for umain2\n");
    exit(-1);
  }

  x = (double *) (((unsigned long) x) + PAGE_SIZE - ((unsigned long) x) % PAGE_SIZE);
  trans = (double *) (((unsigned long) trans) + PAGE_SIZE - ((unsigned long) trans) % PAGE_SIZE);
  umain2 = (double *) (((unsigned long) umain2) + PAGE_SIZE - ((unsigned long) umain2) % PAGE_SIZE);

/* In order to optimize data distribution, the data structures x, trans, 
   and umain2 have been aligned so that each begins on a page boundary. 
   This ensures that the amount of padding calculated by the program is 
   such that each processor's partition ends on a page boundary, thus 
   ensuring that all data from these structures that are needed by a 
   processor can be allocated to its local memory */

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the x,
   trans, and umain2 data structures across physically distributed 
   memories as desired.
   
   One way to place data is as follows:

   double *base;
   long i;

   i = ((N/P)+(rootN/P)*pad_length)*2;
   base = &(x[0]);
   for (j=0;j<P;j++) {
    Place all addresses x such that (base <= x < base+i) on node j
    base += i;
   }

   The trans and umain2 data structures can be placed in a similar manner.

   */

  printf("\n");
  printf("FFT with Blocking Transpose\n");
  printf("   %ld Complex Doubles\n",N);
  printf("   %ld Processors\n",P);
  if (num_cache_lines != orig_num_lines) {
    printf("   %ld Cache lines\n",orig_num_lines);
    printf("   %ld Cache lines for blocking transpose\n",num_cache_lines);
  } else {
    printf("   %ld Cache lines\n",num_cache_lines);
  }
  printf("   %d Byte line size\n",(1 << log2_line_size));
  printf("   %d Bytes per page\n",PAGE_SIZE);
  printf("\n");

  BARINIT(Global->start, P);
  LOCKINIT(Global->idlock);
  Global->id = 0;
  InitX(x);                  /* place random values in x */

  if (test_result) {
    ck1 = CheckSum(x);
  }
  if (doprint) {
    printf("Original data values:\n");
    PrintArray(N, x);
  }

  InitU(N,umain);               /* initialize u arrays*/
  InitU2(N,umain2,rootN);

  /* fire off P processes */

  CREATE(SlaveStart, P);
  WAIT_FOR_END(P);

  if (doprint) {
    if (test_result) {
      printf("Data values after inverse FFT:\n");
    } else {
      printf("Data values after FFT:\n");
    }
    PrintArray(N, x);
  }

  transtime = Global->transtimes[0];
  printf("\n");
  printf("                 PROCESS STATISTICS\n");
  printf("            Computation      Transpose     Transpose\n");
  printf(" Proc          Time            Time        Fraction\n");
  printf("    0        %10ld     %10ld      %8.5f\n",
         Global->totaltimes[0],Global->transtimes[0],
         ((double)Global->transtimes[0])/Global->totaltimes[0]);
  if (dostats) {
    transtime2 = Global->transtimes[0];
    avgtranstime = Global->transtimes[0];
    avgcomptime = Global->totaltimes[0];
    maxtotal = Global->totaltimes[0];
    mintotal = Global->totaltimes[0];
    maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0];
    for (i=1;i<P;i++) {
      if (Global->transtimes[i] > transtime) {
        transtime = Global->transtimes[i];
      }
      if (Global->transtimes[i] < transtime2) {
        transtime2 = Global->transtimes[i];
      }
      if (Global->totaltimes[i] > maxtotal) {
        maxtotal = Global->totaltimes[i];
      }
      if (Global->totaltimes[i] < mintotal) {
        mintotal = Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) {
        maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) {
        minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      printf("  %3ld        %10ld     %10ld      %8.5f\n",
             i,Global->totaltimes[i],Global->transtimes[i],
             ((double)Global->transtimes[i])/Global->totaltimes[i]);
      avgtranstime += Global->transtimes[i];
      avgcomptime += Global->totaltimes[i];
      avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i];
    }
    printf("  Avg        %10.0f     %10.0f      %8.5f\n",
           ((double) avgcomptime)/P,((double) avgtranstime)/P,avgfractime/P);
    printf("  Max        %10ld     %10ld      %8.5f\n",
	   maxtotal,transtime,maxfrac);
    printf("  Min        %10ld     %10ld      %8.5f\n",
	   mintotal,transtime2,minfrac);
  }
  Global->starttime = start;
  printf("\n");
  printf("                 TIMING INFORMATION\n");
  printf("Start time                        : %16lu\n",
	  Global->starttime);
  printf("Initialization finish time        : %16lu\n",
	  Global->initdonetime);
  printf("Overall finish time               : %16lu\n",
	  Global->finishtime);
  printf("Total time with initialization    : %16lu\n",
	  Global->finishtime-Global->starttime);
  printf("Total time without initialization : %16lu\n",
	  Global->finishtime-Global->initdonetime);
  printf("Overall transpose time            : %16ld\n",
         transtime);
  printf("Overall transpose fraction        : %16.5f\n",
         ((double) transtime)/(Global->finishtime-Global->initdonetime));
  printf("\n");

  if (test_result) {
    ck3 = CheckSum(x);
    printf("              INVERSE FFT TEST RESULTS\n");
    printf("Checksum difference is %.3f (%.3f, %.3f)\n",
	   ck1-ck3, ck1, ck3);
    if (fabs(ck1-ck3) < 0.001) {
      printf("TEST PASSED\n");
    } else {
      printf("TEST FAILED\n");
    }
  }

  MAIN_END;
}
Esempio n. 5
0
int main_PY()
{
//    int             c;     //用于保存用户输入的参数
//   Bool            bBackground = True;
//   char        *imname=(char *)NULL;
    extern  Bool            bPYBaseDictLoaded;
    extern Bool            bPYOtherDictLoaded;
    initConfig();  //szj
    initConfig2();  //szj

    if (!InitX ()){};
    //exit (1);

    /*加载用户配置文件,通常是“~/.fcitx/config”,如果该文件不存在就从安装目录中拷贝
     * “/data/config”到“~/.fcitx/config”
     */

    LoadConfig (True);

    /*创建字体。实际上,就是根据用户的设置,使用xft读取字体的相关信息。
     * xft是x11提供的处理字体的相关函数集
     */
    CreateFont ();

    //根据字体计算输入窗口的高度
    CalculateInputWindowHeight ();

    /*加载配置文件,这个配置文件不是用户配置的,而是用于记录fctix的运行状态的,
     * 比如是全角还是半角等等。通常是“~/.fcitx/profile”,如果该文件不存在就从安装
     * 目录中拷贝“/data/profile”到“~/.fcitx/profile”
     */
    LoadProfile ();

    //加载标点字典文件
    LoadPuncDict ();
    //加载成语
    LoadQuickPhrase ();
    /*从 ~/.fcitx/AutoEng.dat (如果不存在,
     * 则从 /usr/local/share/fcitx/data/AutoEng.dat)
     * 读取需要自动转换到英文输入状态的情况的数据
     */
    LoadAutoEng ();

    //以下是界面的处理

    CreateMainWindow ();    //创建主窗口,即输入法状态窗口
    CreateVKWindow ();        //创建候选词窗口
    CreateInputWindow ();    //创建输入窗口
//szj    CreateAboutWindow ();    //创建关于窗口

    //处理颜色,即候选词窗口的颜色,也就是我们在“~/.fcitx/config”定义的那些颜色信息
    InitGC (inputWindow);

    //将本程序加入到输入法组,告诉系统,使用我输入字符
    SetIM ();

    //处理主窗口的显示
    if (hideMainWindow != HM_HIDE) {
    DisplayMainWindow ();
    DrawMainWindow ();
    }
    if (!bPYBaseDictLoaded)
    LoadPYBaseDict ();
    if (!bPYOtherDictLoaded)
    LoadPYOtherDict ();

    //以后台方式运行

#ifdef _ENABLE_TRAY
    CreateTrayWindow ();        //创建系统托盘窗口
    DrawTrayWindow (INACTIVE_ICON);    //显示托盘图标
#endif

    return 0;
}
Esempio n. 6
0
int main(int argc, char **argv) {
  pthread_t   tidUpdate;
  int         nFlag, nQuit=0, c;
  KeySym      key;
  char        str[kSTRMAX];

  opterr = 0;
     
  while ((c = getopt (argc, argv, "hl:w:r:")) != -1) {
    switch (c) {

    case 'h':
      Usage();
      return 0;

    case 'l':
      fTempLimit = atof(optarg);
      break;
	
    case 'w':
      fTempWarn = atof(optarg);
      break;

    case 'r':
      nSleepSecs = atoi(optarg);
      break;

    case '?':
      if (optopt == 'l' || optopt == 'w' || optopt == 'r')
	fprintf (stderr, "Option -%c requires an argument.\n", optopt);
      else if (isprint (optopt))
	fprintf (stderr, "Unknown option `-%c'.\n", optopt);
      else
	fprintf (stderr,
		 "Unknown option character `\\x%x'.\n",
		 optopt);
      return 1;

    default:
      abort ();
    }
  }
  
  XInitThreads();

  if(InitX()) {
    return 1;
  } if(GetConstants()) {
    return 2;
  } if(pthread_create(&tidUpdate, NULL, &UpdateThread, NULL)) {
    fprintf(stderr, "ERROR: Can't create update thread.\n");
    return 3;
  }

  float fTemp;
  GetTemp(&fTemp);
  printf("Current Temp = %.1f\n", fTemp);

  while(1) {
    XEvent e;
    XNextEvent(dpy, &e);

    nFlag = 0;
    switch(e.type) {

    case Expose:
      nFlag = 1;
      break;

    case ClientMessage:
      
      if(e.xclient.data.l[0] == 42) {
	nFlag = 1;
      } else if(e.xclient.data.l[0] == wmDeleteMessage) {
	XDestroyWindow(dpy, e.xclient.window);
	nQuit = 1;
      }
      break;

    case KeyPress:
      if(XLookupString(&e.xkey, str, kSTRMAX-1, &key, 0)==1) {
	if(str[0] == 'q' || str[0] == 'Q') {
	  XDestroyWindow(dpy, win);
	  nQuit = 1;
	}
      }
      break;

    case ConfigureNotify:
      break;
    
    }

    if(nQuit)
      break;

    if(nFlag) {

      int rc = Redraw();
      if(rc) {
	fprintf(stderr, "ERROR: Redraw() returned %d\n", rc);
	break;
      }
    }
  }

  XCloseDisplay(dpy);
  pthread_kill(tidUpdate, 1);
  pthread_exit(NULL);
}