예제 #1
0
파일: TM.C 프로젝트: luonango/vs_tiny
int getNum(void)
{
	int sign;
	int term;
	int temp = FALSE;
	num = 0;
	do
	{
		sign = 1;
		while (nonBlank() && ((ch == '+') || (ch == '-')))
		{
			temp = FALSE;
			if (ch == '-')  sign = -sign;
			getCh();
		}
		term = 0;
		nonBlank();
		while (isdigit(ch))
		{
			temp = TRUE;
			term = term * 10 + (ch - '0');
			getCh();
		}
		num = num + (term * sign);
	} while ((nonBlank()) && ((ch == '+') || (ch == '-')));
	return temp;
} /* getNum */
예제 #2
0
파일: main.c 프로젝트: Buridan/burned_cream
int mainEventLoop()
{
	int end = 0;
	Character* tgr = getCh(0);
	byte_t dirMask=0;
	SDL_Event evenement;
	printf("Starts main loop\n");
	while(!end)
	{
		SDL_PollEvent(&evenement);
		character_setDirection(getCh(0),dirMask);
		if(tgr->bhv == moving)
		{
			refreshAnimation(ANIM_FPS);
			refreshMove(MOVE_FPS);
		}
		switch(evenement.type)
		{
			case SDL_KEYDOWN:
				switch(evenement.key.keysym.sym)
				{
					case SDLK_q:
						end=1;
					break;
					case SDLK_k: case SDLK_UP: dirMask 	 |= 8; break;
					case SDLK_j: case SDLK_DOWN: dirMask  |= 4; break;
					case SDLK_h: case SDLK_LEFT: dirMask  |= 2; break;
					case SDLK_l: case SDLK_RIGHT: dirMask |= 1; break;

				}
			break;
			case SDL_KEYUP:
				switch(evenement.key.keysym.sym)
				{
					case SDLK_r:
						printf("r released\n");
					break;
					case SDLK_k: case SDLK_UP: dirMask 	 &= 7 ; break;
					case SDLK_j: case SDLK_DOWN: dirMask  &= 11; break;
					case SDLK_h: case SDLK_LEFT: dirMask  &= 13; break;
					case SDLK_l: case SDLK_RIGHT: dirMask &= 14; break;
				}
			break;
			default:
			break;
		}
	}
return 0;
}
예제 #3
0
파일: tm.c 프로젝트: JiongWang/salad
int skipCh ( char c  )
{ int temp = FALSE;
  if ( nonBlank() && (ch == c) )
  { getCh();
    temp = TRUE;
  }
  return temp;
} /* skipCh */
예제 #4
0
void waitFor( FT_HANDLE ftHandle, const char ch ) {
	char buf = 0;

	while(1) {
		buf = getCh( ftHandle );
		if (ch == buf) {
			break;
		}
	}
}
예제 #5
0
/********************************************/
int getNum (void)
{ int sign;
  int term;
  int temp = FALSE;
  num = 0 ;
  do
  { sign = 1;
    while ( nonBlank() && ((ch == '+') || (ch == '-')) )
    { temp = FALSE ;
      if (ch == '-')  sign = - sign ;
      getCh();
    }
    term = 0 ;
    nonBlank();
    while (isdigit(ch) )
    { temp = TRUE ;             
            term = term * 10 + ( ch - '0' ) ;
      getCh();
    }
    num = num + (term * sign) ;
  } while ( (nonBlank()) && ((ch == '+') || (ch == '-')) ) ;
  return temp;
} /* getNum */
int getNumF (void)
{ int sign;
  float term;
  int termf;
  int temp = FALSE;
  num = 0 ;
  do
  { sign = 1;
    while ( nonBlank() && ((ch == '+') || (ch == '-')) )
    { temp = FALSE ;
      if (ch == '-')  sign = - sign ;
      getCh();
    }
    term = 0 ;
    termf = 0;
    nonBlank();
    int dot = false;
    while (isdigit(ch) || ch == '.')
    { temp = true ;   
           if(dot == true)
           {
                  termf = termf +1;
                  }        
        if(ch == '.')
        {
              dot = true;
              
        }
        else
                term = term * 10 + ( ch - '0' ) ;
                
      getCh();
    }
    dot = false;
    num = num + (term * sign);
    
    for(int i=0 ; i<termf; i++)
    {
        num = num / 10;
    }
  } while ( (nonBlank()) && ((ch == '+') || (ch == '-')) ) ;
  return temp;
} /* getNum */
예제 #6
0
char BBSCharReady()
{
char KBReady();

return ( (ra.haveCarrier  &&  /**interpret(pMIReady)*/mIready() )
   || (ra.whichIO==CONSOLE  &&   KBReady() )
   || (KBReady() && getCh() == SPECIAL)
   );

}
예제 #7
0
파일: getop.c 프로젝트: ddakhane/c
/* getop: get next character or numeric operand */
int getop(char s[])
{
	int c, i;

	while ((s[0] = c = getCh()) == ' ' || c == '\t')
		;	/* 由判断条件可知,当跳出while循环时,s[0]中的字符不是空白字符 */
	s[1] = '\0';
	if (!isDigit(c) && c != '.')
		return c;	/* not a number */
	i = 0;
	if (isDigit(c))	/* collect integer part */
		while (isDigit(s[++i] = c = getCh()))
				;
	if (c == '.')	/* collect fraction part */
		while (isDigit(s[++i] = c = getCh()))
			;
	s[i] = '\0';
	if (c != EOF)
		ungetCh(c);
	return '0';
}
예제 #8
0
파일: tm.c 프로젝트: JiongWang/salad
int getWord (void)
{ int temp = FALSE;
  int length = 0;
  if (nonBlank ())
  { while (isalnum(ch))
    { if (length < WORDSIZE-1) word [length++] =  ch ;
      getCh() ;
    }
    word[length] = '\0';
    temp = (length != 0);
  }
  return temp;
} /* getWord */
예제 #9
0
bool LogFileWatcher::changed() 
{
  if( timer.expired() && filePos != fileSize() ) {

    bool feof;
    while( !(feof = file.eof()) && peekCh() != '\n' && bufpos < WATCHER_BUF_SIZE-3 ) {
      buffer[ bufpos++ ] = getCh();
      // ++filePos;
    }

    if( !feof ) {
      if( peekCh() == '\n' ) 
	getCh();
      buffer[bufpos++] = '\n';
      buffer[bufpos++] = '\0';
      return (completeLine = true);
    }
    // wait another interval for completed line.
    timer.reset(interval);
  }
  return false;
}
예제 #10
0
파일: main.c 프로젝트: Buridan/burned_cream
void refreshAnimation(const byte_t fps)
{
	static unsigned int cTime, lTime;
	cTime = SDL_GetTicks();
	//printf("last time : %d\n current time : %d\n",lTime,cTime);
	if(cTime > (lTime + (1000/fps)))
	{
		background_copyAllToRender();
		character_nextImage(getCh(0));
		character_copyAllToRender();
		SDL_RenderPresent(getRenderer());
		lTime = cTime;
	}
}
예제 #11
0
파일: main.c 프로젝트: Buridan/burned_cream
void refreshMove(const byte_t fps) //pourquoi recopier l'intégralité des sprites si certains n'ont pas bougé?
{
	static unsigned int cTime, lTime;
	cTime = SDL_GetTicks();
	//printf("last time : %d\n current time : %d\n",lTime,cTime);
	if(cTime > (lTime + (1000/fps)))
	{
		Character* pTgr = getCh(0);
		character_move(pTgr);
		background_copyAllToRender();
		character_copyAllToRender();
		SDL_RenderPresent(getRenderer());
		lTime = cTime;
	}
}
예제 #12
0
void _servosCenter(SERVO_LIST* const servos, uint8_t numServos, UART* uart){
	rprintfInit(uart->writer);

	list(servos,numServos);
	help();
	prompt();
	while(1){
		char c = getCh(uart);
		switch(c){
		case 'L':
			list(servos,numServos);
			prompt();
			break;
		case '+':
			update(servos,1);
			break;
		case '*':
			update(servos,10);
			break;
		case '-':
			update(servos,-1);
			break;
		case '/':
			update(servos,-10);
			break;
		case 'N':
			current = (current+1) % numServos;
			prompt();
			break;
		case 'P':
			current = (current==0) ? numServos-1 : current-1;
			prompt();
			break;
		case 'C':
			setRanging(FALSE, servos,numServos);
			prompt();
			break;
		case 'R':
			setRanging(TRUE, servos,numServos);
			prompt();
			break;
		default:
			help();
			prompt();
			break;
		}
	}
}
예제 #13
0
void uploadHex( FT_HANDLE ftHandle, const std::string &data ) {
	int bytesLeft = 0, i = 0;
	char byte;
	
	while (i < data.length()) {
		byte = getCh(ftHandle);
		if (byte == 'b') {
			bytesLeft = data.length() - i;
			if (bytesLeft > 0xFF) {
				bytesLeft = 0xFF;
			}
			send(ftHandle, bytesLeft);
		} else if (byte == 'd') {
			send(ftHandle, data[i]);
			--bytesLeft;
			++i;
			printf("\r%d%%", (int)((float)i/data.length()*100.0));
			fflush(stdout);
		}
	}
	printf("\n100%%\n");
}
예제 #14
0
void TellStick::enterBootloader() {
	FT_Purge(d->ftHandle, FT_PURGE_RX | FT_PURGE_TX);

	FT_STATUS ftStatus = FT_SetBitMode(d->ftHandle, 0xff, 0x20);
	for (int i = 0; i < 100; ++i) {
		msleep(1);
		QApplication::processEvents();
	}
	ftStatus = FT_SetBitMode(d->ftHandle, 0xf0, 0x20);

	char buf = 0;
	while(1) { //TODO: Make it possible to bail!
		QApplication::processEvents();
		buf = getCh();
		if (buf == 'g') {
			break;
		}
	}
	send('r');
	setUpgradeStep(3);
	QTimer::singleShot(1000, this, SLOT(downloadFirmware()));
}
예제 #15
0
void TellStick::downloadFirmware() {
	QString filename = "TellStick";
	int bootloaderStart = 0x3A00;
	if (type() == 2) {
		filename = "TellStickDuo";
		bootloaderStart = 0x7A00;
	}
	QString path;
	//if (QApplication::arguments().count() > 1) {
	//	path = QApplication::arguments().at(1);
	//} else {
		path = QString(":/firmware/%1.hex").arg(filename);
	//}

	QByteArray data = readHex(path, bootloaderStart);
	int bytesLeft = 0, i = 0;
	char byte;

	while (i < data.length()) {
		QApplication::processEvents();
		byte = getCh();
		QApplication::processEvents();
		if (byte == 'b') {
			bytesLeft = data.length() - i;
			if (bytesLeft > 0xFF) {
				bytesLeft = 0xFF;
			}
			send(bytesLeft);
		} else if (byte == 'd') {
			send(data[i]);
			--bytesLeft;
			++i;
			this->setUpgradeProgress( (qreal)i/(qreal)data.length()*100.0 );
		}
	}
	setUpgradeStep(4);
	QTimer::singleShot(0, this, SLOT(rebootTellStick()));
}
예제 #16
0
TGraphErrors *run(int dec_time_ns = 67, bool outside_call = false)
{
	char filename[16];
	snprintf(filename, sizeof(filename), "rate_%d.dat", dec_time_ns);

	cout << "\n////////////////////////////////////////////////////////////////////////////////\n\n";
	cout << "Opening filtering files!\n";
	cout << "\n////////////////////////////////////////////////////////////////////////////////\n\n\n";
	TH2F *hist_2d = createScan("/home/l_mayilyan/Documents/PhD/workspace/Mythen/filter/filter_scan_12400eV_%d.raw",0,40,1,1280*4);

	int last_item = 41;
	double av_x[41] = {0.,};
	double av_x_err[41] = {0.,};
	for (int channel = 1; channel <= last_item; channel++)
	{
		for (int Xrow = 20; Xrow < 120; Xrow++)
		{
			double cell_content = hist_2d->GetBinContent(Xrow,channel);
			av_x[channel-1] += cell_content;
			av_x_err[channel-1] += cell_content*cell_content;
		}

		av_x[channel-1] /= 100; // 120-20
		av_x_err[channel-1] = sqrt(av_x[channel-1]) / 100;

		// cout << hist_2d->GetBinContent(20,channel) << "\t" << hist_2d->GetBinContent(599,channel) << endl;
		// cout << hist_2d->GetBinContent(20,channel) << "\t" << hist_2d->GetBinContent(598,channel) << "\t" << av_x[channel-1] << endl;

	}

	cout << "\n\n";

	gr1 = new TGraph();
	gr2 = new TGraphErrors();
	gr3 = new TGraphErrors();

	double x[500] = {0,};
	double y[500] = {0,};
	double x_err[500] = {0,};
	double y_err[500] = {0,};

	double x_eval[500] = {0,};
	double y_eval[500] = {0,};
	// double x_eval_err[500] = {0,};
	double y_eval_err[500] = {0,};

	double x_ratio[500] = {0,};
	double y_ratio[500] = {0,};
	// double x_ratio_err[500] = {0,};
	double y_ratio_err[500] = {0,};

	int shift = 0;
	int fit_lev = 0;
	bool thresh_found = false;
	double max_ratio = 0.;
	for (int chan = 498-1; chan <= 598-1; chan++)
	{
		gr = new TGraphErrors();
		TH1F *hist_ch = getCh(hist_2d, chan);
		for (int i = 1+shift; i <= last_item+shift; i++)
		{
			// cout << (i-1)%42 << endl;
			x[(i-1)%41] = av_x[(i-1)%41];
			y[(i-1)%41] = hist_ch->GetBinContent((i-1)%41 + 1);
			x_err[(i-1)%41] = av_x_err[(i-1)%41];
			y_err[(i-1)%41] = sqrt(y[(i-1)%41]);

			// cout << (i-1)%41 << "\t" << x[(i-1)%41] << "\t" << y[(i-1)%41] << endl;

			gr->SetPoint(i-1,x[(i-1)%41],y[(i-1)%41]);
			gr->SetPointError(i-1,x_err[(i-1)%41],y_err[(i-1)%41]);

			// finding level for linear fit
			if ((y[(i-1)%41]<=50000) && (thresh_found == false))
			{
				fit_lev = (i-1)%41;
				// cout << "fit_lev " << fit_lev << endl;
				thresh_found = true;
			}

			if ((i-1)%41==40)
			{
				// checking if the call is from outside
				if (outside_call == false)
				{
					gr->Draw("A*");
					c1->SetGridx();
					c1->SetGridy();					
				}

				// cout << x[last_item] << " x[last_item]" << endl;

				TF1 *f1 = new TF1("f1","pol1",x[fit_lev],x[last_item-1]);
				f1->FixParameter(0,0);
				// f1->SetParLimits(0,-0.1,0.1);
				gr->Fit("f1", "RCQN");
	
				f1->SetRange(x[40],x[0]);
				// checking if the call is from outside
				if (outside_call == false)
				{
					f1->SetLineColor(kRed);
					f1->Draw("SAME R");
				}
					
				for (int j = 0; j < last_item; j++)
				{
					x_eval[j] = f1->Eval(x[j]);
					y_eval[j] = y[j];
					y_eval_err[j] = y_err[j];


					// cout << y[(i-1)%41] << " y[(i-1)%41]\n";

					gr2->SetPoint(j+shift,x_eval[j],y_eval[j]);
					gr2->SetPointError(j+shift,0,y_eval_err[j]);
					// cout << x_eval[j] << "\t" << y_eval[j] << endl;

					x_ratio[j] = x_eval[j];
					y_ratio[j] = y_eval[j]/x_eval[j];
					y_ratio_err[j] = y_eval_err[j]/x_eval[j];
					gr3->SetPoint(j+shift, x_ratio[j], y_ratio[j]);
					gr3->SetPointError(j+shift, 0, y_ratio_err[j]);

					if (x_ratio[j]>=max_ratio)
						max_ratio = x_ratio[j];
				}
	
			// c1->SaveAs("qwe.png");
			// int q;
			// cin >> q;
				
			}

		}
		thresh_found = false;
		shift += last_item;
	}

	cout << max_ratio << " max_ratio\n";

	// plotting rate ratio
	// checking if the call is from outside
	if (outside_call == false)
	{
		TCanvas *c3 = new TCanvas("Ratio");
		gr3->Draw("A*");
	}

	TF1 *exp_fit = new TF1("exp_fit","exp(-[0]*x)",x_ratio[0],x_ratio[40]);
	if (outside_call == false)
	{
		exp_fit->SetLineColor(kRed);
		gr3->Fit("exp_fit", "R");
	}
	else
		gr3->Fit("exp_fit", "RN");

	double exp_par0 = exp_fit->GetParameter(0);
	double exp_par0_err = exp_fit->GetParError(0);


	// TCanvas *c2 = new TCanvas("decay");
	// gr1->Draw("A*");
	// TF1 *exp_expo = new TF1("f2","pol1",x_ratio[0],x_ratio[40]);

	// return 0;


	//////////////////////////////////////////////////////////////////////////////////////////
	// analysing theoretical data

	// reading theoretical data


	double x2[500] = {0,};
	double y2[500] = {0,};
	double x2_err[500] = {0,};
	double y2_err[500] = {0,};

	double x_sim_ratio[500] = {0,};
	double y_sim_ratio[500] = {0,};
	double x_sim_ratio_err[500] = {0,};
	double y_sim_ratio_err[500] = {0,};
	
	// checking if the call is from outside
	if (outside_call == false)
		TCanvas *c3 = new TCanvas("Simulation data");

	gr4 = new TGraphErrors();
	gr5 = new TGraphErrors();

	char line[1024] = {0};
	ifstream f;

	// ifstream f("rate_" + std::to_string(dec_time_ns) + ".dat");

	f.open(filename, ios::in);
	if (!f.is_open())
		cout << "\nCouldn't open the file!\n\n";

	int dc = 0;
	int max_r = 0;

	// finding maximum rate
	// Processing the file
	f.getline(line,1024);
	while(!f.eof() && strlen(line) > 0)
	{
		double r, tc, c;
		sscanf(line, "%lf\t%lf\t%lf", &r, &tc, &c);
		// printf("a = %lf, \tb = %lf, \tc = %lf\n", r, tc, c);

		x2[dc] = r;
		if (dc != 0)
			if (x2[dc] > x2[dc-1])
				max_r = x2[dc];

		dc++;

		f.getline(line, 1024);
	}

	f.clear();
	f.seekg(0, ios::beg);

	double charge_sh[3] = {24.08,23.55,23.71};
	double coll_corr = 50./(50.+charge_sh[0]);

	dc = 0;
	f.getline(line,1024);
	while(!f.eof() && strlen(line) > 0)
	{
		double r, tc, c;
		sscanf(line, "%lf\t%lf\t%lf", &r, &tc, &c);


		// cout << r << "\t" << tc << "\t" << c << " QWE\n";
		tc = tc*coll_corr;

		x2[dc] = r*coll_corr*1000;
		y2[dc] = c/tc;
		x2_err[dc] = sqrt(r)*coll_corr;
		y2_err[dc] = sqrt(1/c+1/tc);

		gr4->SetPoint(dc,x2[dc],y2[dc]);
		gr4->SetPointError(dc,x2_err[dc],y2_err[dc]);

		dc++;

		f.getline(line, 1024);
	}

	f.close();

	int fit_lev = 0;
	for (int i = 0; i <= dc; i++)
	{
		if (x2[i]>=max_ratio)
		{
			fit_lev = i;
			cout << "fit_lev " << fit_lev << endl;
			break;
		}

	}

	// TCanvas *c3 = new TCanvas("Ratio sim");
	// checking if the call is from outside
	if (outside_call == false)
		gr4->Draw("A*");

	TF1 *sim_fit = new TF1("sim_fit","exp(-[0]*x)",x2[0],x2[fit_lev]);
	sim_fit->SetParameter(0,1.55e-7);
	if (outside_call == false)
	{
		sim_fit->SetLineColor(kRed);
		gr4->Fit("sim_fit", "R");
	}
	else
		gr4->Fit("sim_fit", "RN");

	double sim_par0 = sim_fit->GetParameter(0);
	double sim_par0_err = sim_fit->GetParError(0);
	gr4->GetXaxis()->SetRangeUser(0,x2[fit_lev]);


	printf("\n////////////////////////////////////////////////////////////////////////////////\n\n");
	printf("exp_0\texp_0_err\tsim_0\tsim_0_err\n");
	printf("%e\t%e\t%e\t%e\n", exp_par0,exp_par0_err,sim_par0,sim_par0_err);
	printf("\n////////////////////////////////////////////////////////////////////////////////\n\n");


	return gr3;

}