Example #1
0
int main()
{
	init();
	//Test();
	wdt_start(wdt_60ms);
	while(1)
	{
		wdt_feed();
		DoMenu();
		if (isPedal1Pressed() == TRUE && (getCurMenuId() == idPrograms)) // если нажата педаль и активное меню - "Программы"
		{
			StartTaskWelding();
			while(isPedal1Pressed())
			{
				u8 res = DoWelding();
				if (res == WELD_HAS_BROKEN)
					break;
				wdt_feed();
			}
			StopTaskWelding();
			SetMenu(&mPrograms);
		}
	}
	return 0;
}
Example #2
0
/*****************************************************************************
Envia o mesmo IR repetidamente
*****************************************************************************/
void repeat_IR(char *str_IdIr, char qtd_interval_100ms, char time_start_100ms)
{
	char i, cont=0, start=0;

	memset(buf_rx,0,sizeof(buf_rx));
	NVIC_EnableIRQ(UART2_IRQn);		/*Habilita a interrupção serial para receber a tecla despressionada (TOU 000)*/
	while(1)
	{
		/*Sai do laço caso a tecla deixe de ser pressionada ou aconteça algum erro ao enviar o IR*/	
		if(strstr(buf_rx,"TOU 000") || buf_tx[0] == 'E')
			break;
		else
			cmd_ir_send(str_IdIr);  /*Envia o IR localizado no endereço recebido pela função*/	

		wdt_feed();
		if(!start)	/*Apenas na inicialização*/
		{
			if(time_start_100ms)	/*Existe tempo de start para o IR*/
			{
				while(1)	/*Loop para da um tempo minimo para o primeiro IR enviado*/
				{
					/*Contagem de tempo para comparação com o tempo de Start*/
					timer_poll();
					if(tick)
						if(++cont >= time_start_100ms)break;
				}
			}
			start = 1;	
		}
		/*Continua no laço caso não tenha intervalo de repetição*/
		if(!qtd_interval_100ms)	
			continue;
		/*Contagem de tempo para comparação com o intervalo de repetição*/
		cont=0;
		while(1)
		{
			wdt_feed();
			timer_poll();
			if(tick)
				if(++cont >= qtd_interval_100ms)	/*No primeiro IR demora um pouco mais*/
					break;
		}	
	}
	NVIC_DisableIRQ(UART2_IRQn);		/*Desabilita novamente a interrupção serial*/
	memset(buf_rx,0,sizeof(buf_rx));	
	for(i=TOUCH_0;i<=TOUCH_15;i++)		/*Loop para desligar todos os leds 4x4*/
		out_leds &= ~(1<<i);
	touch_led_press = TOUCH_NONE;

	if(buf_tx[0] == 'E')    /*Houve algum erro ao enviar o IR?*/
	{
		beep(BEEP_ERROR);
		strcat(buf_tx,"\r\r\0");
		uart_putString(0,buf_tx);	/*String de erro*/
	}
}
Example #3
0
LOCAL void ICACHE_FLASH_ATTR
read_cb(void)
{
	uint8_t ack, low, high;
	wdt_feed();
	os_printf("Time=%ld\n", system_get_time());
	i2c_master_start();
	i2c_master_writeByte(BH1750_ADDR);
	ack = i2c_master_getAck();
	if (ack)
	{
		os_printf("I2C:No ack after sending address\n");
		i2c_master_stop();
		return;
	}
	i2c_master_stop();
    i2c_master_wait(40000); // why?

    i2c_master_start();
    i2c_master_writeByte(BH1750_ADDR + 1);
    ack = i2c_master_getAck();
	if (ack)
	{
		os_printf("I2C:No ack after write command\n");
		i2c_master_stop();
		return;
	}
	low = i2c_master_readByte();
	high = i2c_master_readByte();
	i2c_master_setAck(1);
    i2c_master_stop();
	os_printf("I2C:read(L/H)=(0x%02x/0x%02x)\n", low, high);
}
Example #4
0
void g35_cfill(char br,g35_color c){
	int i;
	if(br<0)br=0;
	if(br>0x3F)br=0x3F;
	for(i=0;i<g35_len;i++){
		wdt_feed();
		g35_csendframe((char)i,br,c);
	}
	//g35_csendframe(0b111111,br,c);
}
Example #5
0
File: main.c Project: dpmjoshi/ARM7
void main()
{   
  PINSEL0 |= 0X00050005;	 // selecting UART0 and UART1
  PINSEL1 |= 0X00080000;
  IO1DIR  |= 0X0FFF0000;	 //pins 1.16 to 1.23 output pins
  IO0DIR  |= 0X003E0C00;	 //port 0 rs and en as output
  IO0CLR   = 0X00FF0000;	
  
  IO0SET   = 0X0FF00400;
  IO0CLR   = BUZZER;

  //*************************************//
  //         Initialisations             //
  //*************************************//
  lcd_init();
  irq_init();
  uart_init();
  adc_init();
  //wdt_init();
  pwm5_init();
  timer1_init_interrupt();
  rtc_init_interrupt();

  U1IER = 0;
  
  //*************************************//
  //          Welcome Note               //
  //*************************************//
 
  //*************************************//
  //  Displaying Static Messages		 //
  //*************************************//
  clrscr();
  default_page();
  U0IER = 0;
  wdt_init();
  while(1)
  {	
  	wdt_feed(0x03ffffff);

	Uc_key_temp = get_key(0);

	if(Uc_key_temp == '1')
	{
		Uc_key_temp = 0;
		clrscr();
		ms_delay(8000);

		ZIGB_setting();
		
		default_page();
		
   	}
  }
}
Example #6
0
void WatchdogTask (void * Parameters)
{
    wdt_start();
    for ( ;; ) {
        if (xSemaphoreTake(watchdog_smphr, 0)) {
            NVIC_SystemReset();
        }
        wdt_feed();
        //printf(" Watchdog fed (again) \n ");
        vTaskDelay(WATCHDOG_FEED_DELAY);
    }
}
Example #7
0
LOCAL void ICACHE_FLASH_ATTR
info_cb(void *arg)
{
	wdt_feed();
	uart0_sendStr("System Info\r\n");
	os_printf("Time=%ld\r\n", system_get_time());
	os_printf("Chip id=%ld\r\n", system_get_chip_id());
	os_printf("Free heap size=%ld\r\n", system_get_free_heap_size());
	uart0_sendStr("Mem info:\r\n");
	system_print_meminfo();
	uart0_sendStr("\r\n");
}
Example #8
0
void user_init(void)
{
	uint8_t state=0;
	ets_wdt_enable();
	ets_wdt_disable();
	// Configure pin as a GPIO
	PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC);
	for(;;)
	{
		GPIO_OUTPUT_SET(LED_GPIO, state);
		os_delay_us(DELAY);
		state ^=1;
		wdt_feed();
	}
}
Example #9
0
void g35_tick(void){
	wdt_feed();
	ets_wdt_disable();
	tick_count++;
	if(tick_count > pattern_rotate_ticks && rotate_patterns){
		tick_count = 0;
		int old_pattern = cur_pattern;
		
		cur_pattern++;
		while(!(g35_patterns[cur_pattern].enabled)&&(cur_pattern!=old_pattern)){
			cur_pattern++;
			if(g35_patterns[cur_pattern].g35_pattern_ticker==NULL)
				cur_pattern=0;
		}
	}
	g35_patterns[cur_pattern].g35_pattern_ticker(tick_count);
	ets_wdt_enable();
}
Example #10
0
void LcdSendByte(uint8_t data) {
    
    //74HC595
	wdt_feed();
    
    GPIO_OUTPUT_SET(SIPO_LATCH, 0);
    GPIO_OUTPUT_SET(SIPO_SDO, 0);
    GPIO_OUTPUT_SET(SIPO_SCK, 0);
    int i;
    for (i = 7; i >= 0; i--) {
    
        if((data >> i) & 0x01) {
            GPIO_OUTPUT_SET(SIPO_SDO, 1);
            //print("1")
        } else {
            GPIO_OUTPUT_SET(SIPO_SDO, 0);
            //print("0")
        }
        GPIO_OUTPUT_SET(SIPO_SCK, 1);
        Pause();
        GPIO_OUTPUT_SET(SIPO_SCK, 0);
    }
Example #11
0
void LcdReset(void) {
    //LCD_RST
    //LCD_WR_n 

    //LCD_CS_n 
    //LCD_RS
    //SIPO_LATCH 
    //SIPO_SDO  
    //SIPO_SCK    
    
    GPIO_OUTPUT_SET(LCD_RST, 1);
    Pause();
    GPIO_OUTPUT_SET(LCD_RST, 0);
    Pause();
    GPIO_OUTPUT_SET(LCD_RST, 1);
    
    GPIO_OUTPUT_SET(LCD_CS_n, 1);
    GPIO_OUTPUT_SET(LCD_WR_n, 1);

	GPIO_OUTPUT_SET(LED_GPIO, stateled);
	stateled ^=1;
	wdt_feed();
}
Example #12
0
void ZIGB_write()
{
 ZIGB_read();

 ZIGB_wr_page();
 
 Uc_key_temp = get_key(0);
 while(Uc_key_temp != 'D')
 {
  Uc_key_temp = get_key(0);
  wdt_feed(0x03ffffff);
  lcd_line1_disp(&Uc_zigb_pan[0],10);
  lcd_line2_disp(&Uc_zigb_ch[0],10);
  lcd_line3_disp(&Uc_zigb_my[0],10);
  lcd_line4_disp(&Uc_zigb_dl[0],10);
  

  if(Uc_key_temp == '1')
  { 
 	clrscr();
	lcd_line1_disp("PAN",0);
 	key_usr_ip(4,&Uc_zigb_pan[0],1,10);
	ZIGB_wr_page();
  }
  else if(Uc_key_temp == '2')
   {
	clrscr();
	lcd_line1_disp("CH",0);
    key_usr_ip(2,&Uc_zigb_ch[0],1,10);
	ZIGB_wr_page();
   }
  else if(Uc_key_temp == '3')
   {
 	clrscr();
	lcd_line1_disp("MY",0);
 	key_usr_ip(4,&Uc_zigb_my[0],1,10);
	ZIGB_wr_page();
   }
  else if(Uc_key_temp == '4')
   {
 	clrscr();
	lcd_line1_disp("DL",0);
 	key_usr_ip(4,&Uc_zigb_dl[0],1,10);
	ZIGB_wr_page();
   }
 }

 ms_delay(500);

 // Writing to ZigBee //
 
 ZIGB_cmd_mode();
 
 ZIGB_dl_wrt(&Uc_zigb_dl[0]);
 ZIGB_pan_wrt(&Uc_zigb_pan[0]);
 ZIGB_my_wrt(&Uc_zigb_my[0]);
 ZIGB_ch_wrt(&Uc_zigb_ch[0]);

 ZIGB_wr_cmd();

 ZIGB_exit_cmd();

}
Example #13
0
/*****************************************************************************
Reinicia placa
exemplo: RST!
******************************************************************************/
void cmd_reset_board (char *par) 
{
	LPC_WDT->WDTC = 0x003FFFF;	/*0.5s*/
	wdt_feed();
	while(1);
} 
Example #14
0
void cmd_task(void)
{
	static char rst = 0;
	char *sp,*cp,*next; //,str[4];
	long i=0;

	if(rcv_cmd)
	{
		rcv = 0;
		wdt_feed();
  		sp = get_entry (&buf_rx[0], &next);
  		if(*sp == 0)
		{
			if(rst++ >= 10)
			{
				printf ("[FAIL CMD..restart now]\r");
				fflush(stdout);
				LPC_WDT->WDTC = 0x003FFFF;	/*0.5s*/
				wdt_feed();
				while(1);			
			}
			sprintf(buf_tx,"ERROR %u",ERROR_COMMAND);
    	}else
		{
    		for (cp = sp; *cp && *cp != ' '; cp++)
				*cp = toupper (*cp);
		
    		for (i = 0; i < CMD_COUNT; i++)
			{
      			if (strcmp (sp, (const char *)&cmd[i].val))
        			continue;
      			cmd[i].func (next);		
				rst = 0;
				break;
    		}
		}

		if(i == CMD_COUNT)
			sprintf(buf_tx,"ERROR %u",ERROR_COMMAND);
			  

		if(i!=6 && rcv_cmd == RCV_CMD_UART_0)	/*i=6 (Rcv Touch lpc1113)*/
		{
			if(buf_tx[0] == 'E')
				beep(BEEP_ERROR);
			else
				beep(BEEP_CFG);
		}else
			/*Função IR learn, IR learn Scene, Detect Swing e IR learn app via TCP?*/
		if((i == 0 || i == 12 || i == 13 || i == 17) && (rcv_cmd == RCV_CMD_TCP_SERVER || rcv_cmd == RCV_CMD_TCP_CLIENT)) 
		{
			if(buf_tx[0] == 'E')
				beep(BEEP_ERROR);
			else
				beep(BEEP_CFG);
		}
		
		strcat(buf_tx,"\r\n\0");

		if(rcv_cmd == RCV_CMD_UART_2)	
		{
//			uart_putString(2,buf_tx);
		}else
		if(rcv_cmd == RCV_CMD_UART_0)
			uart_putString(0,buf_tx);
			
#if USE_TCP_CLIENT	/*Comunicação TCP CLIENT será usada?*/
		else
		if((rcv_cmd == RCV_CMD_TCP_CLIENT))
		{
			tcpSend (buf_tx, strlen(buf_tx), last_soc_client,CMD_SEND_TO_CLIENT);
			uart_putString(0,buf_tx);
		}
#endif

#if USE_TCP_SERVER	/*Comunicação TCP SERVER será usada?*/
		else
		if((rcv_cmd == RCV_CMD_TCP_SERVER))
		{
			tcpSend (buf_tx, strlen(buf_tx), tcp_server_soc,CMD_SEND_TO_SERVER);
			uart_putString(0,buf_tx);
		}
#endif			
	
		memset(buf_rx,0,sizeof(buf_rx));
		memset(buf_tx,0,sizeof(buf_tx));
		if(!rcv)
			rcv_cmd = __FALSE;
		cntUART2 = 0;
		cntUART0 = 0;
		NVIC_EnableIRQ(UART2_IRQn);
		NVIC_EnableIRQ(UART0_IRQn);
	}
}
Example #15
0
File: main.c Project: dpmjoshi/ARM7
void main()
{   
  PINSEL0 |= 0X00050005;	 // selecting UART0 and UART1
  PINSEL1 |= 0X00080000;
  IO1DIR  |= 0X0FFF0000;	 //pins 1.16 to 1.23 output pins
  IO0DIR  |= 0X003E0C00;	 //port 0 rs and en as output
  IO0CLR   = 0X00FF0000;	
  
  IO0SET   = 0X0FF00400;
  IO0CLR   = BUZZER;

  //*************************************//
  //         Initialisations             //
  //*************************************//
  lcd_init();
  irq_init();
  uart_init();
  adc_init();
  //wdt_init();
  pwm5_init();
  timer1_init_interrupt();
  rtc_init_interrupt();
  
  //*************************************//
  //          Welcome Note               //
  //*************************************//
  lcd_line2_disp(&welcome_note1[0],0);
  lcd_line3_disp(&welcome_note2[0],6);
  ms_delay(50000);
  clrscr();
  lcd_line1_disp(&lcd_data_sys_chk[0],0);
  display_dots();
  display_dots();
  //*************************************//
  //  Displaying Static Messages		 //
  //*************************************//
  clrscr();
  default_page();
  U0IER = 0;

  rtc_get_time();
  lcd_line4_disp(&Uc_real_time[0],12);
  lcd_line4_disp(&Uc_set_user_time[0],0);

  wdt_init();
  while(1)
  {	
  
  	wdt_feed(0x03ffffff);
	rtc_get_time();
	lcd_line4_disp(&Uc_real_time[0],12);
	if(wdt_timeout == 1)
	{
		wdt_timeout = 0;
		lcd_line3_disp("WDEnable",12);
	}
	//*********************************************//
	//		ADC input value						   //
	//*********************************************//
	if(Uc_adc_time_out_flag == 1)
	{			
		Uc_adc_time_out_flag = 0;
		Ui_sample1 = adc1_getval();
		ms_delay(800);
		Ui_sample2 = adc1_getval();
		ms_delay(800);
		Ui_sample3 = adc1_getval();
		ms_delay(800);
		Ui_sample4 = adc1_getval();
		ms_delay(800);
		Ui_sample5 = adc1_getval();
		adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5, 1);
		temp_ctrl();
		lcd_line1_disp(&Uc_dec_arr[1],5);
		
		
					
		//*********Sending DATA to User desk*************//
		//uart0_send_string("\n\r ");
		uart0_send_byte((Ui_sample1 & 0xff));
		uart1_send_byte(0x7E);
		uart1_send_string(&Uc_dec_arr[1]);
		uart1_send_byte('\0');
		//**********************************************//
		
		Ui_sample1 = adc3_getval();
		ms_delay(900);
		Ui_sample2 = adc3_getval();
		ms_delay(900);
		Ui_sample3 = adc3_getval();
		ms_delay(900);
		Ui_sample4 = adc3_getval();
		ms_delay(900);
		Ui_sample5 = adc3_getval();
		ms_delay(750);
		Ui_sample6 = adc3_getval();
		ms_delay(750);
		Ui_sample7 = adc3_getval();
		ms_delay(750);
		Ui_sample8 = adc3_getval();
		ms_delay(750);
		Ui_sample9 = adc3_getval();
		Ui_sample6 = ((Ui_sample6 + Ui_sample7 + Ui_sample8 + Ui_sample9) / 4);
		Ui_sample5 = ((Ui_sample6 + Ui_sample5)/2);
		adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5 , 0);
		lcd_line3_disp(&Uc_dec_arr[1],5);
		
		//*********Sending DATA to User desk*************//
		uart1_send_string(&Uc_dec_arr[1]);
		//**********************************************//

	}


	//*********************************************//
	//   displaying Real Time & user Set Time      //
	//*********************************************//
	
	if(Uc_alrm == 1)
	{
		Uc_alrm = 2;
		pwm5_pulse_width(5000, 100);
	}
	/*
	else if(Uc_alrm == 3)
	{
		if(Uc_user_dwn_sec == 0)
		{
		   Uc_user_dwn_sec  = 59;

		   if( (Uc_user_dwn_min +  Uc_user_dwn_hr) != 0)
	   	 	{	
				Uc_user_dwn_min -= 1;
	   	   	}
		   Uc_set_user_time[3] = ((Uc_user_dwn_min / 10) + 0x30);
	   	   Uc_set_user_time[4] = ((Uc_user_dwn_min % 10) + 0x30);
		}
		if(Uc_user_dwn_min == 0)
		{
		   Uc_user_dwn_min  = 59;
	       if(Uc_user_dwn_hr != 0)
		   {
		   		Uc_user_dwn_hr -= 1;
		   }
	   	   Uc_set_user_time[0] = ((Uc_user_dwn_hr / 10) + 0x30);
	   	   Uc_set_user_time[1] = ((Uc_user_dwn_hr % 10) + 0x30);
		}
		Uc_set_user_time[6] = ((Uc_user_dwn_sec / 10) + 0x30);
		Uc_set_user_time[7] = ((Uc_user_dwn_sec % 10) + 0x30);
	 }

	 */
	//*********************************************//
	rtc_get_time();
	lcd_line4_disp(&Uc_real_time[0],12);
	lcd_line4_disp(&Uc_set_user_time[0],0);

	//*********************************************//
	//			key press on background  		   //
	//*********************************************//
	Uc_key_temp = get_key(0);
	if(Uc_key_temp == 'E')
	{
		Uc_key_temp = 0;
		get_user_time();
	}
	else if((Uc_key_temp == '.')&(Uc_alrm == 2))
	{
		Uc_key_temp = 0;
		Uc_alrm = 0;
		pwm_disable();
	}
	else if(Uc_key_temp == 'A')
	{
		clrscr();
		ms_delay(1000);
		lcd_line2_disp("Emergency Stop!",3);
		lcd_line4_disp("Cooling ON",5);
		IO0CLR = SSR_ON;
		IO0CLR = HEATER_ON;
		IO0SET = COOLER_ON;
		while(1);
	}
	else if(Uc_key_temp == 'D')
	{
		Uc_key_temp = 0;
		rtc_change_time();
	}

  }
}
Example #16
0
void EspClass::wdtFeed(void)
{
	wdt_feed();
}
Example #17
0
/*****************************************************************************
** Function name:		U16 udp_callback (U8 socket, U8 *remip, U16 port, U8 *buf, U16 len)
**
** Descriptions:		verificamos os eventos do UDP
*****************************************************************************/
U16 udp_callback (U8 socket, U8 *remip, U16 port, U8 *buf, U16 len)
{
	U16 sz;
	U8 *sndbuf;
	char str[50],aux[8][20];
	int i,z,j;

  	/* This function is called when UDP data has been received. */
	if(len >= LEN_UDP_BUF)	/*Erro do tamanho do pacote recebido?*/
	{
		printf("[Overflow error in the UDP packet size]\r");
		printf("\r[buf:%s]\r",buf);
		fflush(stdout);
		return 0;
	}
	memset(udp_buf,0,sizeof(udp_buf));
	strncpy((char*)udp_buf,(const char*)buf,len);
	
	/*Informações do pacote*/
	printf("\r***[IP: %u.%u.%u.%u] Receiver Packet UDP:%s\r",remip[0],remip[1],remip[2],remip[3],udp_buf);
//	printf("\r*** Receiver Packet UDP: %s\r",udp_buf);
//	printf("*** IP: %u.%u.%u.%u\r",remip[0],remip[1],remip[2],remip[3]);	  		
	fflush(stdout);	

	/*Se receber a mensagem 'motel' via udp retorna para o IP do remetente as informações locais, como host name, IP e MAC*/
	if(strstr((const char *)udp_buf,"motel_all") != NULL)
	{
		sprintf(str,"%s : %u.%u.%u.%u : %02X.%02X.%02X.%02X.%02X.%02X\r\n\0",lhost_name,MY_IP[0],MY_IP[1],MY_IP[2],MY_IP[3],
		                                  own_hw_adr[0],own_hw_adr[1],own_hw_adr[2],own_hw_adr[3],own_hw_adr[4],own_hw_adr[5]);
		sz = strlen(str);
		sndbuf = udp_get_buf (sz);
		str_copy(sndbuf, (U8 *)str);
		udp_send (udp_soc, remip, port, sndbuf, sz);

	}else
	if((strstr((const char *)udp_buf,"SET") != NULL))
	{
		if(strlen((const char*)udp_buf) > 20)
		{
			memset(aux,0,sizeof(aux));
			for(i=0,j=0,z=0;i<strlen((const char*)udp_buf);i++)
			{
			    /*Exemplo: 6SET 040045047101:6SET 040045047101:6SET 040045047101*/ 
				if(udp_buf[i] == ':' || udp_buf[i] == '\r')
				{
					z++;
					j=0;
				}else		  
				{
					aux[z][j] = udp_buf[i];	/*Armazena scene z*/
					j++;
				}
			}
			for(i=0;i<NUM_SCENE;i++)
			{
				if((strstr(aux[i], scene[i]) != NULL))
				{ 
					printf("%s já existente na cena %u\r",aux[i],i); 
				}
				else
				{
					cmd_scene(aux[i]); 
					printf("%s...%s\r\n",buf_tx,aux[i]);
				}
				fflush(stdout);
			}
		}else
		{
			if((strstr((const char *)udp_buf,scene[udp_buf[0]]) != NULL))
			{  
				printf("%s já existente na cena %c\r",udp_buf,udp_buf[0]); 
			}
			else
			{
				cmd_scene((char*)udp_buf); 
				printf("%s\r\n",buf_tx);
			}
			fflush(stdout);
			memset(buf_tx,0,sizeof(buf_tx));
		}
	}else
	if(strstr((const char *)udp_buf,"PORT") != NULL)
	{
		for(i=0;i<8;i++)
			memset(aux[i],0,sizeof(aux[i]));
		
		for(i=0,j=0,z=0;i<strlen((const char*)udp_buf);i++)
		{
			/*Exemplo:PORT:5000:7000:6000:192.168.0.15:192.168.0.1<CR>*/
			if(udp_buf[i] == ':' || udp_buf[i] == '\r')
			{
				if(strstr(aux[0],"PORT") != NULL) //Tem "PORT" escrito?
					z=0;
				else
					z++;
				j=0;
				if(udp_buf[i] == '\r')
					break;
			}else		  
			{
				aux[z][j] = udp_buf[i];
				j++;
			}
		}

		j=0;
		if(atoi(cfg.tcp.port_udp) != atoi(aux[0]) && atoi(aux[0]) >= 5000 && atoi(aux[0]) <= 5050)
		{
			j = j + fwrite_line(aux[0], FILE_TCP_CFG, LINE_PORT_UDP);	/*Reinicia*/
			printf("Update Port Udp: %s\r",aux[0]);
			fflush(stdout);	  
		}	 
		
		if(atoi(cfg.tcp.port_serv_loc) != atoi(aux[1]) && atoi(aux[1]) >= 5000 && atoi(aux[1]) <= 5050)
		{
			j = j + fwrite_line(aux[1], FILE_TCP_CFG, LINE_PORT_SERV_LOC);	/*Reinicia*/
			printf("Update Port Tcp Local: %s\r",aux[1]);
			fflush(stdout);
		}
		
		if(atoi(cfg.tcp.port_serv_rem) != atoi(aux[2]) && atoi(aux[2]) >= 5000 && atoi(aux[2]) <= 5050)
		{
			/*j = j +*/  fwrite_line(aux[2], FILE_TCP_CFG, LINE_PORT_SERV_REM);	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.port_serv_rem,aux[2]);
			printf("Update Port Server Remoto: %s\r",cfg.tcp.port_serv_rem);
			fflush(stdout);
		}

		if(strcmp(cfg.tcp.ip_serv_rem,aux[3]) && strlen(aux[3]) > 8)
		{
			/*j = j +*/  fwrite_line(aux[3], FILE_TCP_CFG, LINE_IP_SERV_REM);	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.ip_serv_rem,aux[3]);
			printf("Update IP Server Remoto: %s\r",cfg.tcp.ip_serv_rem);
			fflush(stdout);
		}
		
		if(strcmp(cfg.tcp.ip_app,aux[4]) && strlen(aux[4]) > 8)
		{
			/*j = j +*/  fwrite_line(aux[4], FILE_TCP_CFG, LINE_IP_APP); 	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.ip_app,aux[4]);
			printf("Update IP App: %s\r",cfg.tcp.ip_app);
			fflush(stdout);
		}

		if(j)
		{
			printf ("[TCP Config via UDP..Reiniciando]\r\r");
			fflush(stdout);
			#if USE_TCP_CLIENT	
			for(i=0;i<MAX_NUM_SOC;i++)
				tcp_close (tcp_client_soc[i]);
			#endif
			#if USE_TCP_SERVER	
				tcp_close (tcp_server_soc);
			#endif
			wdt_feed();
			for(i=0;i<5000000;i++)
				for(j=0;j<5000000;j++);
			LPC_WDT->WDTC = 0x3FFFF;	/*0.5s*/
			wdt_feed();
		}

	}else
	if(strstr((const char *)udp_buf,"RST") != NULL)
	{
		printf ("[Reset Solicitado..Reiniciando]\r\r");
		fflush(stdout);
		#if USE_TCP_CLIENT	
		for(i=0;i<MAX_NUM_SOC;i++)
			tcp_close (tcp_client_soc[i]);
		#endif
		#if USE_TCP_SERVER	
			tcp_close (tcp_server_soc);
		#endif
		LPC_WDT->WDTC = 0x003FFFF;	/*0.5s*/
		wdt_feed();
		while(1);
	}

  	return 0;
}
Example #18
0
File: app.c Project: dpmjoshi/ARM7
//***************************************************
// function to get time duration from user
//***************************************************
void get_user_time(void)
{
  U8 uc_lcd_data_user_time[30] = {"Enter Time: "};
  U8 uc_lcd_data_user_temp[30] = {"Enter Temp: "};
  U8 sc_set_time_count = 0;
  U8 uc_set_temp_count = 0;

  clrscr();
  lcd_line1_disp(&uc_lcd_data_user_time[0],0);
  lcd_line1_disp(&Uc_set_user_time[0],12);
 
  while(sc_set_time_count < 8)					 //uc_set_time_count < 9
  {
  	wdt_feed(0x03ffffff);
	Uc_key_temp = get_key(1);
	pwm5_pulse_width(5000, 100);
	//pwm_enable();

	if((Uc_key_temp <= '9')&(Uc_key_temp >= '0'))
	{
		if(sc_set_time_count == 0)
		{
			
			if(Uc_key_temp < '3')
			{
				Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 1;
			}
		}
		else if(sc_set_time_count == 1)
		{
		   if((Uc_set_user_time[0] - 0x30) == 2)
		   {
			if(Uc_key_temp < '4')
			{
				Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 2;
			}
		   }
		   else
		   {
		   		Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 2;
		   }
		}
		else if(sc_set_time_count == 3)
		{
			
		  	if(Uc_key_temp < '6')
			{
				Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 1;
			}
		}
		else if(sc_set_time_count == 4)
		{
		 	
			Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
			sc_set_time_count += 2;
			
		}
		else if(sc_set_time_count == 6)
		{
		  	
			if(Uc_key_temp < '6')
			{
				Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 1;
			}
		}
		else if(sc_set_time_count == 7)
		{
		  	
			if(Uc_key_temp < 'A')
			{
				Uc_set_user_time[sc_set_time_count] = Uc_key_temp;
				sc_set_time_count += 1;
			}
		}

	}

	if(Uc_key_temp == 'A')
	{	  	
		  lcd_line2_disp(&uc_lcd_data_user_temp[0],0);
		  lcd_line2_disp(&Uc_set_temp[0],12);
		  sc_set_time_count = 8;
		  uc_set_temp_count	= 3;
	}
	//*********************************************//
  
  	if(sc_set_time_count == 0)
	{
		lcd_line4_disp("Range 0-2",11);
	}
	if(sc_set_time_count == 1)
	{
		lcd_line4_disp("Range 0-3",11);
	}
	if(sc_set_time_count == 3)
	{
		lcd_line4_disp("Range 0-5",11);
	}
	if(sc_set_time_count == 4)
	{
		lcd_line4_disp("Range 0-9",11);
	}
	if(sc_set_time_count == 6)
	{
		lcd_line4_disp("Range 0-5",11);
	}
	if(sc_set_time_count == 7)
	{
		lcd_line4_disp("Range 0-9",11);
	}
	//*********************************************//
	lcd_line1_ch_disp(' ',((sc_set_time_count+12)-1));
	//Uc_set_user_time[sc_set_time_count + 1] = '\0';
	key_delay(250);		// do not remove it
	lcd_line1_disp(&Uc_set_user_time[0],12);
	pwm_disable();
  }
  

//---------------------------------------------------------------------------------
//------------------------------get temp from User---------------------------------
//---------------------------------------------------------------------------------
  lcd_line2_disp(&uc_lcd_data_user_temp[0],0);
  while(uc_set_temp_count < 3)
  {
  	wdt_feed(0x03ffffff);
	Uc_key_temp = get_key(1);
	
	pwm5_pulse_width(5000, 100);

	if((Uc_key_temp <= '9')&(Uc_key_temp >= '0'))
	{
		 if(uc_set_temp_count == 0)
		 {
		 	if(Uc_key_temp <= '3')
			{
				Uc_set_temp[uc_set_temp_count] =  Uc_key_temp;
		 		uc_set_temp_count++; 

			}
		 }
		 else 
		 {
		 		Uc_set_temp[uc_set_temp_count] =  Uc_key_temp;
		 		uc_set_temp_count++; 

		 }

	}
	if(Uc_key_temp == 'A')
	{
		 uc_set_temp_count = 3;
	}
	lcd_line2_disp(&Uc_set_temp[0],12);
	key_delay(250);		// do not remove it
	//*************range of no*****************//
	if(uc_set_temp_count == 0)
	{
		lcd_line4_disp("Range 0-3",11);
	}
	if(uc_set_temp_count == 1)
	{
		lcd_line4_disp("Range 0-9",11);
	}
	if(uc_set_temp_count == 2)
	{
		lcd_line4_disp("Range 0-9",11);
	}
	//****************************************//
	pwm_disable();
  }	
  
  lcd_line4_disp("Press Start",9);															 
  while((Uc_key_temp = get_key(1)) != 'D');
  Uc_alrm = 3;
  user_time_conv();	  // to convert the time entered by USER
  user_temp_conv();	  // to convert the temp entered by USER

  clrscr();
  default_page();    // Displaying default PAGE while leaving from USER MODE.
}
Example #19
0
/** 
Originally from: http://harizanov.com/2014/11/esp8266-powered-web-server-led-control-dht22-temperaturehumidity-sensor-reading/
Adapted from: https://github.com/adafruit/Adafruit_Python_DHT/blob/master/source/Raspberry_Pi/pi_dht_read.c
LICENSE:
// Copyright (c) 2014 Adafruit Industries
// Author: Tony DiCola

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
*/
static  void ICACHE_FLASH_ATTR pollDHTCb(void * arg){
  int counter = 0;
  int laststate = 1;
  int i = 0;
  int bits_in = 0;
  // int bitidx = 0;
  // int bits[250];

  int data[100];

  data[0] = data[1] = data[2] = data[3] = data[4] = 0;

  //disable interrupts, start of critical section
  os_intr_lock();
  wdt_feed();
  // Wake up device, 250ms of high
  GPIO_OUTPUT_SET(DHT_PIN, 1);
  delay_ms(20);

  // Hold low for 20ms
  GPIO_OUTPUT_SET(DHT_PIN, 0);
  delay_ms(20);

  // High for 40ms
  // GPIO_OUTPUT_SET(2, 1);

  GPIO_DIS_OUTPUT(DHT_PIN);
  os_delay_us(40);

  // Set pin to input with pullup
  // PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);

  // os_printf("Waiting for gpio2 to drop \n");

  // wait for pin to drop?
  while (GPIO_INPUT_GET(DHT_PIN) == 1 && i < DHT_MAXCOUNT) {
    if (i >= DHT_MAXCOUNT) {
      goto fail;
    }
    i++;
  }

//  os_printf("Reading DHT\n");

  // read data!
  for (i = 0; i < MAXTIMINGS; i++) {
    // Count high time (in approx us)
    counter = 0;
    while (GPIO_INPUT_GET(DHT_PIN) == laststate) {
      counter++;
      os_delay_us(1);
      if (counter == 1000)
        break;
    }
    laststate = GPIO_INPUT_GET(DHT_PIN);

    if (counter == 1000)
      break;

    // store data after 3 reads
    if ((i > 3) && (i % 2 == 0)) {
      // shove each bit into the storage bytes
      data[bits_in / 8] <<= 1;
      if (counter > BREAKTIME) {
        //os_printf("1");
        data[bits_in / 8] |= 1;
      } else {
        //os_printf("0");
      }
      bits_in++;
    }
  }

  //Re-enable interrupts, end of critical section
  os_intr_unlock();

  if (bits_in < 40) {
    os_printf("Got too few bits: %d should be at least 40", bits_in);
    goto fail;
  }
  

  int checksum = (data[0] + data[1] + data[2] + data[3]) & 0xFF;
  
  os_printf("DHT: %02x %02x %02x %02x [%02x] CS: %02x", data[0], data[1],data[2],data[3],data[4],checksum);
  
  if (data[4] != checksum) {
    os_printf("Checksum was incorrect after %d bits. Expected %d but got %d",
              bits_in, data[4], checksum);
    goto fail;
  }

  reading.temperature = scale_temperature(data);
  reading.humidity = scale_humidity(data);
  os_printf("Temp =  %d *C, Hum = %d %%\n", (int)(reading.temperature * 100),
            (int)(reading.humidity * 100));

  reading.success = 1;
  return;
fail:
  
  os_printf("Failed to get reading, dying\n");
  reading.success = 0;
}
Example #20
0
/*****************************************************************************
** Function name:		U16 tcp_task (void)
**
** Descriptions:		envia dados para o servidor TCP
*****************************************************************************/
void tcp_task(void)
{
	static U32 tcp_timer 	= 0u;
	U8 buf_udp[100],i;
			
	/****************** instantâneo ********************************/

#if USE_TCP_SERVER 	/*Comunicação TCP SERVER será usada?*/

	U8 ip[4];

	#if USE_PCK_SERV 
	static U32 cnt_tcp_serv = 0u;

	if(tcp_state.bit.dataToSend)
 	{						
		tcp_state.bit.dataToSend = __FALSE;
		cnt_tcp_serv = 0;

		//if(tcp_buf[0] == 0)		
	 		//sprintf((char*)tcp_buf,"%02X.%02X.%02X.%02X.%02X.%02X\r\n\0",own_hw_adr[0],own_hw_adr[1],own_hw_adr[2],own_hw_adr[3],own_hw_adr[4],own_hw_adr[5]);
		
		//tcpSend((char*)tcp_buf, strlen((const char*)tcp_buf), tcp_server_soc, CMD_SEND_TO_SERVER);
		//memset(tcp_buf,0,sizeof(tcp_buf));
	}
	#endif

#endif

	/****************** a cada 100ms *******************************/

	if(!tick)
		return;
	++tcp_timer;
	dhcp_check();

	/****************** a cada 1s **********************************/

	if((tcp_timer%TASK_1S))
		return;

#if USE_TCP_CLIENT
	
	if(!(tcp_timer%TASK_5S)) 
	{
		/*Pacote UDP de identificação*/
		sprintf((char*)buf_udp,"%s %u.%u.%u.%u %02X.%02X.%02X.%02X.%02X.%02X %s %s %u.%u.%u.%u %u.%u.%u.%u\r\n\0",lhost_name,MY_IP[0],MY_IP[1],MY_IP[2],MY_IP[3],
		own_hw_adr[0],own_hw_adr[1],own_hw_adr[2],own_hw_adr[3],own_hw_adr[4],own_hw_adr[5], cfg.tcp.port_serv_rem, cfg.tcp.ip_serv_rem,
		MY_MASK[0], MY_MASK[1], MY_MASK[2], MY_MASK[3],  MY_GATEWAY[0], MY_GATEWAY[1], MY_GATEWAY[2], MY_GATEWAY[3]);	
										   

		if(!ftp_state.bit.UpdateTcp)
			udpSendBroadcast(buf_udp);
			//udpSendUnicast(buf_udp,cfg.tcp.ip_app);
	}

	if(!(tcp_timer%TASK_30S))	/*A cada 30s*/
	{ 
		/*Mantém o link ativo*/
		//if(tcp_get_state (tcp_client_soc[0]) == TCP_STATE_CONNECT)
		//{
			sprintf(buf_tx,"LOK OK\r\n\0");
			for(i=0;i<MAX_NUM_SOC;i++)
				tcpSend (buf_tx, strlen(buf_tx), tcp_client_soc[i], CMD_SEND_TO_CLIENT);
			//tcpSend (buf_tx, strlen(buf_tx), tcp_client_soc[0], CMD_SEND_TO_CLIENT);
		//}
	}

#endif


#if USE_TCP_SERVER && USE_PCK_SERV 	/*Comunicação TCP SERVER será usada?*/
		
	if(!(++cnt_tcp_serv % atoi(cfg.tcp.interval_packet_serv)))
		tcp_state.bit.dataToSend = __TRUE;

#endif

#if USE_TCP_SERVER	/*Comunicação TCP SERVER será usada?*/

	/*Analisa estado de comunicação com o servidor externo*/
	if(tcp_get_state (tcp_server_soc) != TCP_STATE_CONNECT)
	{
		tcp_state.bit.serverConnected = __FALSE; 
		inet_aton((U8*)cfg.tcp.ip_serv_rem,ip);
		tcp_connect(tcp_server_soc,ip,atoi(cfg.tcp.port_serv_rem),atoi(cfg.tcp.port_serv_loc));
		
	}else
		tcp_state.bit.serverConnected = __TRUE; 
	
#endif	

	/*Houve alteração das cenas via FTP?*/
	if(ftp_state.bit.UpdateScene)	
	{
		printf ("[Scene config via FTP]\r\r");
		fflush(stdout);
		ftp_state.bit.UpdateScene = __FALSE;
		init_scene(0xFF);
	}

	if(ftp_state.bit.UpdateFileCfg)
	{
		printf ("[CFG.CFG configurado via FTP]\r\r");
		fflush(stdout);
		ftp_state.bit.UpdateFileCfg = __FALSE;
		read_file_cfg();
	}
	
	/*Houve alteração das configurações TCP via FTP?*/
	if(ftp_state.bit.UpdateTcp)
	{
		printf ("[TCP Config via FTP..Reiniciando]\r\r");
		fflush(stdout);
				
#if USE_TCP_CLIENT	
		for(i=0;i<MAX_NUM_SOC;i++)
			tcp_close (tcp_client_soc[i]);
#endif
#if USE_TCP_SERVER	
		tcp_close (tcp_server_soc);
#endif
		LPC_WDT->WDTC = 0x003FFFF;	/*0.5s*/
		wdt_feed();
		while(1);
	}			
}