void Actividad1(void){
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); //osc0 a 12Mhz
	   while (1)
	   {
		   
		  if (debounce2(QT1081_TOUCH_SENSOR_LEFT))
		   {
			   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
			  
			
			 
			 while(gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER)==0)
			 {
				
			 gpio_tgl_gpio_pin(LED3_GPIO);
			 
				delay_s(50);			 
				   
			   }
			   
			   display(0);
			   
		  }
		   
		   
		   if (debounce2(QT1081_TOUCH_SENSOR_RIGHT))
		   {
			   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
			   
			   while (gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER)==0)
			   {
				   
				   displayPrimo();
				   delay_s(50);
				   
			   }
			   
		   }
		   
		   if (debounce2(QT1081_TOUCH_SENSOR_UP))
		   {
			   pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
			   pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
			   
			   pm_pll_setup(&AVR32_PM,0,2,1,0,16); // lockcount in main clock for the PLL wait lock

			   //_______________________________________________________________________________
			   // Establece la frecuencia de salida del PLL
			   pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
			   //_______________________________________________________________________________
			   //Habilita el PLL 0
			   pm_pll_enable(&AVR32_PM,0);
			   //_______________________________________________________________________________
			   //Espera a que se establesca el PLL
			   pm_wait_for_pll0_locked(&AVR32_PM) ;
			   //_______________________________________________________________________________
			   // Set one wait-state (WS) for flash controller
			   flashc_set_wait_state(1);

			   //habilita la salida del PLL0 con 2 y el OSC0 con 1
			   pm_switch_to_clock(&AVR32_PM, 2);
			   
			   while (gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER)==0)
			   {
				   
				   displayA1();
					delay_s(50);
				   
			   }
			   display(0);
			   
		   }
		   
		   if (debounce2(QT1081_TOUCH_SENSOR_DOWN))
		   {
			   pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
			   pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
			   
			   pm_pll_setup(&AVR32_PM,0,6,1,0,16); // lockcount in main clock for the PLL wait lock

			   //_______________________________________________________________________________
			   // Establece la frecuencia de salida del PLL
			   pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
			   //_______________________________________________________________________________
			   //Habilita el PLL 0
			   pm_pll_enable(&AVR32_PM,0);
			   //_______________________________________________________________________________
			   //Espera a que se establesca el PLL
			   pm_wait_for_pll0_locked(&AVR32_PM) ;
			   //_______________________________________________________________________________
			   // Set one wait-state (WS) for flash controller
			   flashc_set_wait_state(1);

			   //habilita la salida del PLL0 con 2 y el OSC0 con 1
			   pm_switch_to_clock(&AVR32_PM, 2);
			   	
			   while (gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER)==0)
			   {
				   displayOnOff();
				   
			   }
			   display(0);
			   
		   }
	  
	   }
		
		
	}
示例#2
0
void TERMWINDOWMEMBER cron_commands(void)
	{
	int ich;

	SetDoWhat(SYSCRON);

	switch (toupper(ich = iCharNE()))
		{
		case 'A':
			{
			mPrintfCR(getsysmsg(68));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventListS *theEvent;
				for (int i = 1; (theEvent = Cron.GetEventNum(i)) != NULL; i++)
					{
					theEvent->Event.SetDone();
					}
				RELEASEm(CronMutex);

				CRmPrintfCR(getsysmsg(69));
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'D':
			{
			mPrintfCR(getsysmsg(70));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventC *theEvent = GetEventFromUser();

				if (theEvent)
					{
					theEvent->SetDone();
					}
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'E':
			{
			mPrintfCR(getsysmsg(71));

			if (WAITFORmTIMED(CronMutex))
				{
				Cron.ReadCronCit(WC_TWp);
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'F':
			{
			mPrintfCR(getsysmsg(72));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventC *theEvent = GetEventFromUser();

				if (theEvent)
					{
					theEvent->Do();
					}
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'L':
			{
			mPrintfCR(getsysmsg(73));

			if (WAITFORmTIMED(CronMutex))
				{
				ListAllEvents();
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'N':
			{
			mPrintfCR(getsysmsg(74));

			if (WAITFORmTIMED(CronMutex))
				{
				Cron.SetOnEvent(GetEventFromUser());
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'P':
			{
			Cron.TogglePause();
			displayOnOff(getsysmsg(75), Cron.IsPaused());
			doCR();
			break;
			}

		case 'R':
			{
			mPrintfCR(getsysmsg(76));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventC *theEvent = GetEventFromUser();

				if (theEvent)
					{
					theEvent->Reset();
					}
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'S':
			{
			mPrintfCR(getsysmsg(268));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventC *theEvent = GetEventFromUser();

				if (theEvent)
					{
					Bool First = TRUE;

					struct date dt;
					struct time tm;
					datestruct ds;
					timestruct ts;

					do
						{
						if (!HaveConnectionToUser())
							{
							RELEASEm(CronMutex);
							return;
							}

						if (!First)
							{
							mPrintfCR(getmsg(156));
							}

						First = FALSE;

						label usrIn;
						if (!GetStringWithBlurb(getmsg(266), usrIn, LABELSIZE, ns, B_DATESET))
							{
							RELEASEm(CronMutex);
							return;
							}

						gdate(usrIn, &ds);
						} while (!ds.Date);

					First = TRUE;

					do
						{
						if (!HaveConnectionToUser())
							{
							RELEASEm(CronMutex);
							return;
							}

						if (!First)
							{
							mPrintfCR(getmsg(121));
							}

						First = FALSE;

						label usrIn;
						if (!GetStringWithBlurb(getmsg(230), usrIn, LABELSIZE, ns, B_TIMESET))
							{
							RELEASEm(CronMutex);
							return;
							}

						gtime(usrIn, &ts);
						} while (ts.Hour < 0);

					tm.ti_min = (uchar) ts.Minute;
					tm.ti_hour = (uchar) ts.Hour;
					tm.ti_sec = (uchar) ts.Second;
					dt.da_year = ds.Year + 1900;		// i hate dostounix
					dt.da_day = (char) ds.Date;
					dt.da_mon = (char) (ds.Month + 1);	// i hate dostounix

					time_t tried = dostounix(&dt, &tm);

					theEvent->SetLastSuccess(tried);
					theEvent->SetLastTried(tried);

					label dtstr;

					strftime(dtstr, LABELSIZE, getmsg(435), tried);
					CRmPrintf(getmsg(598), dtstr);

					strftime(dtstr, LABELSIZE, getmsg(434), tried);
					CRmPrintfCR(getmsg(607), dtstr);
					}

				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case 'Z':
			{
			mPrintfCR(getsysmsg(77));

			if (WAITFORmTIMED(CronMutex))
				{
				CronEventC *theEvent = GetEventFromUser();

				if (theEvent)
					{
					theEvent->ToggleZap();
					}
				RELEASEm(CronMutex);
				}
			else
				{
				CRmPrintfCR(getsysmsg(264));
				}

			break;
			}

		case '?':
			{
			oChar('?');
			showMenu(M_CRON);
			break;
			}

		default:
			{
			BadMenuSelection(ich);
			break;
			}
		}
	}
__attribute__ ((__interrupt__)) void tecla_lrc_isr(void){//handler teclas left, right o center
	
	
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER);
	}
	

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_LEFT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_LEFT);
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
		
		while(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0){
			
			gpio_tgl_gpio_pin(LED3_GPIO);
			delay_s(50);
			
		}
		display(0);
	}

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_RIGHT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_RIGHT);
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
		while(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0){
			displayPrimo();
			delay_s(50);
			
		}
	}
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP))
	{
				gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP);
		       pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
			   pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
			   
			   pm_pll_setup(&AVR32_PM,0,2,1,0,16); // lockcount in main clock for the PLL wait lock

			   //_______________________________________________________________________________
			   // Establece la frecuencia de salida del PLL
			   pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
			   //_______________________________________________________________________________
			   //Habilita el PLL 0
			   pm_pll_enable(&AVR32_PM,0);
			   //_______________________________________________________________________________
			   //Espera a que se establesca el PLL
			   pm_wait_for_pll0_locked(&AVR32_PM) ;
			   //_______________________________________________________________________________
			   // Set one wait-state (WS) for flash controller
			   flashc_set_wait_state(1);

			   //habilita la salida del PLL0 con 2 y el OSC0 con 1
			   pm_switch_to_clock(&AVR32_PM, 2);
			   
			   while (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0)
			   {
				   
				   displayA1();
				    /*for (uint32_t j =0; j<18000; j++)//300ms 12Mhz
				    {
						delay_ms(10);
				    }*/
					delay_s(50);
				   
			   }
			   display(0);
			   
		
	}
	
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN);
		pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
		pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
		
		pm_pll_setup(&AVR32_PM,0,6,1,0,16); // lockcount in main clock for the PLL wait lock

		//_______________________________________________________________________________
		// Establece la frecuencia de salida del PLL
		pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
		//_______________________________________________________________________________
		//Habilita el PLL 0
		pm_pll_enable(&AVR32_PM,0);
		//_______________________________________________________________________________
		//Espera a que se establesca el PLL
		pm_wait_for_pll0_locked(&AVR32_PM) ;
		//_______________________________________________________________________________
		// Set one wait-state (WS) for flash controller
		flashc_set_wait_state(1);

		//habilita la salida del PLL0 con 2 y el OSC0 con 1
		pm_switch_to_clock(&AVR32_PM, 2);
		
		while (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0)
		{
			displayOnOff();
			
		}
		display(0);
		
		
	}
	
	
	
	

}