예제 #1
0
파일: main.c 프로젝트: YuliaKON/amistom1
//----------------------------------------------------------------------------------------------------
int main(void)
{
	Initialization_All();
	uint8_t pat_count, counter1, meandre_ok = 0;
	SysTick_Config(SystemCoreClock / 1000);//200000

	if (Button_test() == false) 					   state_err[4] = 0x04;		//button on test
	if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0) == 0) state_err[6] = 0x06;		//LV1 error
	if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0) state_err[8] = 0x08;		//LV2 error
	if (meandr_test(GPIOB, GPIO_Pin_0) == true)		   state_err[7] = 0x07;		//short-circuit K1
	if (meandr_test(GPIOB, GPIO_Pin_1) == true)		   {state_err[9] = 0x09;	//emission in process \/ monoblok isn't connected
	Emission(true); Beeper(true);}												//вкл индикатор излучение, вкл бипер

	Display(&display, struct_sample.voltage_correction*struct_sample.man_exposition*20);//длительность экспозиции мс


	//main loop
	while(1)
	{
		wait_label:

// while B_SAFE and B_FILM is ON, do get voltage and output to display
			if (Button_OnClick(B_SAFE) && Button_OnClick(B_FILM)) {
				DI_Display(&display, readADC1(), 0);
			}

		meandr_auto();

// Выбор пациента
			if(Button_OnClick(B_PAT) == 1)	++pat_count;

		    if (pat_count > 3)  pat_count = 1;
		    switch(pat_count) {
		    		    	case 1: {GPIO_SetBits(GPIOB, GPIO_Pin_3);	GPIO_ResetBits(GPIOD, GPIO_Pin_6);	GPIO_ResetBits(GPIOD, GPIO_Pin_4); \
		    		    	DI_Display(&display, 3, 0);\
		    		    	struct_sample.patient_type = PAT1;} break;
		    		    	case 2: {GPIO_ResetBits(GPIOB, GPIO_Pin_3);	GPIO_SetBits(GPIOD, GPIO_Pin_6);	GPIO_ResetBits(GPIOD, GPIO_Pin_4);\
		    		    	DI_Display(&display, 33, 0);\
		    		    	struct_sample.patient_type = PAT2;} break;
		    		    	case 3: {GPIO_ResetBits(GPIOB, GPIO_Pin_3);	GPIO_ResetBits(GPIOD, GPIO_Pin_6);	GPIO_SetBits(GPIOD, GPIO_Pin_4);\
		    		    	DI_Display(&display, 111, 0);\
		    		    	struct_sample.patient_type = PAT3;} break;
		    		    	default:{GPIO_ResetBits(GPIOB, GPIO_Pin_3);	GPIO_ResetBits(GPIOD, GPIO_Pin_6);	GPIO_ResetBits(GPIOD, GPIO_Pin_4);}	break;
		   }

//Выбор пленки
		    if(Button_OnClick(B_FILM) == 1)	++film_count;

		    if (film_count > 3)  film_count = 1;
		    switch(pat_count) {
		    		    		case 1: {GPIO_SetBits(GPIOA, GPIO_Pin_15);	GPIO_ResetBits(GPIOA, GPIO_Pin_13);	GPIO_ResetBits(GPIOA, GPIO_Pin_9);\
		    		    		struct_sample.film = FILM_1;} break;
		    		    		case 2: {GPIO_ResetBits(GPIOA, GPIO_Pin_15);GPIO_SetBits(GPIOA, GPIO_Pin_13);	GPIO_ResetBits(GPIOA, GPIO_Pin_9);\
		    		    		struct_sample.film = FILM_2;} break;
		    		    		case 3: {GPIO_ResetBits(GPIOA, GPIO_Pin_15);GPIO_ResetBits(GPIOA, GPIO_Pin_13);	GPIO_SetBits(GPIOA, GPIO_Pin_9);\
		    		    		struct_sample.film = FILM_3;} break;
		    		    		default:{GPIO_ResetBits(GPIOA, GPIO_Pin_15);GPIO_ResetBits(GPIOA, GPIO_Pin_13);	GPIO_ResetBits(GPIOA, GPIO_Pin_9);}	break;
		    }

// Кнопка безопасности
		    if(Button_OnClick(B_SAFE) == 1) {
		    		if (!b_Safe) {
		    			GPIO_SetBits(GPIOC, GPIO_Pin_9);
		    			b_Safe = 1;// safe
		    		}
		    		else if(b_Safe) {
		    		   GPIO_ResetBits(GPIOC, GPIO_Pin_9);
		    		   b_Safe = 0;// safe
		    		}
		   	}


//buttons released
		    Button_OnClick(B_EXP)?  (b_Exp = 1):(b_Exp = 0);
		    Button_OnClick(B_PLUS)? (b_Plus = 1):(b_Plus = 0);
		    Button_OnClick(B_MINUS)?(b_Minus = 1):(b_Minus = 0);
		    Button_OnClick(B_FILM)? (b_Film = 1):(b_Film = 0);
		    Button_OnClick(B_UIN)? 	(b_Uin = 1):(b_Uin = 0);

		/*if (Button_OnClick(B_EXP) == 1)
			b_Exp = 1;
		if (Button_OnClick(B_PLUS) == 1)
			b_Plus = 1;
		if (Button_OnClick(B_MINUS) == 1)
			b_Minus = 1;
		if (Button_OnClick(B_FILM) == 1)
			b_Film = 1;
		if (Button_OnClick(B_UIN) == 1)
			b_Uin = 1;
*/
//Выбор зуба
		if (Button_OnClick(B_UPM) == 1){
			TOOTH_IND_ON('upm') ;
			struct_sample.tooth = UPM;
		}
		if (Button_OnClick( B_UMO) == 1){
			TOOTH_IND_ON('umo') ;
			struct_sample.tooth = UMO;
		}
		if (Button_OnClick(B_DIN) == 1){
			TOOTH_IND_ON('din') ;
			struct_sample.tooth = DIN;
		}
		if (Button_OnClick(B_DPM) == 1){
			TOOTH_IND_ON('dpm') ;
			struct_sample.tooth = DPM;
		}
		if (Button_OnClick(B_UIN) == 1){
			TOOTH_IND_ON('uin') ;
			struct_sample.tooth = UIN;
		}
		if (Button_OnClick(B_DMO) == 1){
			TOOTH_IND_ON('dmo') ;
			struct_sample.tooth = DMO;
		}

//====================================================================================
//		starting mode
//====================================================================================

		if (mode_emit == starting)
		{
            //ошибка при преждевременном отпускании кнопки экспозиции
			if (Button_OnClick(B_EXP) == 1){

				uint8_t i = 0;

				for(i = 0; i <= 5; i++){
					voltage += readADC1();
					delay_ms(20);
				}

				if ((voltage = voltage/i) < 2)//volt < 192V
				{state_err[1] = 0x01; mode_emit = idle; goto wait_label;}
				if ((voltage = voltage/i) > 3)//volt > 247V
				{state_err[2] = 0x02; mode_emit = idle; goto wait_label;}

				delay_ms(100);

				if (meandr_test(GPIOB, GPIO_Pin_0) == false)
				{state_err[1] = 0x01; mode_emit = idle; goto wait_label;}
				if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0)
				{state_err[6] = 0x06; mode_emit = idle; goto wait_label;}
				if (meandr_test(GPIOB, GPIO_Pin_1) == 1)
				{state_err[9] = 0x09; mode_emit = idle;
				Emission(true); Beeper(true);}//light ON, beeper ON

				if ((GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 1)&(meandr_test(GPIOB, GPIO_Pin_0) == true))
				{mode_emit = emit;}

				}
			}




		//			starting mode

		if (mode_emit == emit)
		{
			Display(&display, struct_sample.voltage_correction);

				if (cntr_imp >= imp_len)
				{
				//	stopEmission();
					mode_emit = idle;
					goto wait_label;
				}


		}
	}//while(1)
}//main()
예제 #2
0
파일: p_edition.c 프로젝트: armnlib/xrec
/** ARGSUSED **/
XtCallbackProc PeEditerValeurs(Widget w, caddr_t clientData, caddr_t  callData)
{
   int lng;
   static char *pasAvecDesChampsVectoriels[] = {"\nCette fonction ne s'applique pas\naux champs vectoriels\n", 
						   "\nThis function does not work\nwith vector fields\n"};
   
   int bouton, event;
   int x0, y0, xsize, ysize, x1, y1, x2, y2;
   int nbMenus;
   char TitreMenu[3][80];
   int temp;
   int i,j,k,n;
   float newX1, newY1, newX2, newY2;
   float ancienneValeur, valeurPloguee, val;
   PointEditionStruct *anciennesValeurs;
   char  *txtValeurPloguee;
   int mode;
   Arg args[1];
   int oldIndCourantPile;
   _Champ *champ;

   FldMgrGetChamp(&champ, 0);
   mode = (int)clientData;
   anciennesValeurs = NULL;
   ancienneValeur = 0.0;

   if (xc.statuts[EN_TRAIN_DE_DESSINER])
      {
      Beeper();
      return 0;
      }
   
   if (champ->natureTensorielle == VECTEUR)
      {
      lng = c_getulng();
      DesactiverTousPeWidgets();
      MessageAvertissementAux(pasAvecDesChampsVectoriels[lng], AVERTISSEMENT, peWarning, peTopLevel);
      ActiverTousPeWidgets();
      return 0;
      }

   oldIndCourantPile = indCourantPile;
   DesactiverTousPeWidgets();

   i = 0;
   XtSetArg(args[i], XmNvalue, &txtValeurPloguee); i++;
   XtGetValues(peTextValRemplacement, args, i);

   sscanf(txtValeurPloguee, "%e", &valeurPloguee);

   InvertWidget(w);

   xc.statuts[EN_TRAIN_DE_DESSINER] = TRUE;
   nbMenus = 0;
   
   event = 0;
   while (event != RESET)
      {
      f77name(souris)(&bouton, &event, 
	      &x0, &y0, &xsize, &ysize, 
	      &x1, &y1, &x2, &y2, TitreMenu, &nbMenus, (F2Cl) 80);
      
      if (x2 < x1)
	 {
	 temp = x1;
	 x1 = x2;
	 x2 = temp;
	 }
      
      if (y2 < y1)
	 {
	 temp = y1;
	 y1 = y2;
	 y2 = temp;
	 }
      
      x1 -= x0; x2 -= x0;
      y1 -= y0; y2 -= y0;
      
      c_wgliax(&newX1, &newY1, x1, y1);
      c_wgliax(&newX2, &newY2, x2, y2);
      c_fxfy2xy(&newX1, &newY1, newX1, newY1);
      c_fxfy2xy(&newX2, &newY2, newX2, newY2);
      
      switch(event)
	 {
	 case DRAG:
	 champ->champModifie = True;
	 newX1 = (float)ROUND(newX1+0.5);
	 newY1 = (float)ROUND(newY1+0.5);
	 newX2 = (float)ROUND(newX2-0.5);
	 newY2 = (float)ROUND(newY2-0.5);


	 if (newX1 < 1.0 || newX2 > (float)mapInfo.ni || newY1 < 1.0 || newY2 > (float)mapInfo.nj)
	    {
	    Beeper();
	    }
	 else
	    {
	    anciennesValeurs = (PointEditionStruct *) calloc(((int)(newY2 - newY1)+1)*((int)(newX2 - newX1)+1), 
							     sizeof(PointEditionStruct));
	    n = 0;
	    for (i=(int)newX1; i <= (int)newX2; i++)
	       {
	       for (j=(int)newY1; j <= (int)newY2; j++)
		  {
		  k=C2FTN(i-1,j-1,mapInfo.ni);
		  anciennesValeurs[n].ind = k;
		  anciennesValeurs[n].val = champ->fld[k];
		  if (mode == MODIFIER)
		     val = valeurPloguee;
		  else
		     val = champOriginal.fld[k];
		  
		  champ->fld[k] = val;
		  n++;
		  }
	       }
	    
	    AfficherPixelBarre(newX1, newY1, newX2, newY2);
	    AjouterItemDansLaPile(DRAG, valeurPloguee, ancienneValeur,anciennesValeurs,(int)newX1,(int)newY1,(int)newX2,(int)newY2); 
	    }
	 break;
	 
	 case CLIC:
	 if (newX1 < 1.0 || newX2 > (float)mapInfo.ni || newY1 < 1.0 || newY2 > (float)mapInfo.nj)
	    {
	    Beeper();
	    }
	 else
	    {
	    champ->champModifie = True;
	    newX1 = (float)ROUND(newX1);
	    newY1 = (float)ROUND(newY1);
	    newX2 = (float)ROUND(newX2);
	    newY2 = (float)ROUND(newY2);
	    
	    k=C2FTN(ROUND(newX1)-1,ROUND(newY1)-1,mapInfo.ni);
	    ancienneValeur = champ->fld[k];
	    anciennesValeurs = NULL;
	    newX2 = newX1;
	    newY2 = newY1;
	    if (mode == MODIFIER)
	       val = valeurPloguee;
	    else
	       val = champOriginal.fld[k];
	    champ->fld[k] = val;
	    AfficherPixelBarre(newX1, newY1, newX2, newY2);
	    AjouterItemDansLaPile(CLIC, val, ancienneValeur, anciennesValeurs, (int)newX1, (int)newY1, (int)newX2, (int)newY2);
	    }
	 break;

	 case BACK_CLIC:
	 PeAfficher( NULL, NULL, NULL);

	 break;

	 case NIL:
	 event = RESET;
	 break;

	 default:
	 break;
	 }

      }

   if (champ->champModifie)
      {
      ActiverWidget(peRemettreValeurs);
      ActiverAuxPeWidgets();
      }

   ActiverWidget(peEditerValeurs);
   ActiverTextFields();
   PeActiverBoutons();

   if (champ->champModifie && indCourantPile > oldIndCourantPile)
      {
      PeAfficher(NULL, NULL, NULL);
      }
   xc.statuts[EN_TRAIN_DE_DESSINER] = FALSE;
   InvertWidget(w);
   return 0;

   }