Ejemplo n.º 1
0
void AjustaHora(){
	LCD_Clear();

	LCD_Write("  RECEBENDO DADOS", 0);

	//recebe data
	char imprime[15];
	char auxData[6] = "999999";
	Delay(1000);
	while(auxData[0] == '9'){
		Delay(200);
		recebeDadosBluetooth = Bluetooth_RecebeDados();
		for(index = 0; index < 6; index++){
			auxData[index] = recebeDadosBluetooth[index];
		}
	}
	date[3] = ((auxData[0] - 0x30 ) * 10) + (auxData[1] - 0x30);
	date[4] = ((auxData[2] - 0x30 ) * 10) + (auxData[3] - 0x30);
	date[5] = ((auxData[4] - 0x30 ) * 10) + (auxData[5] - 0x30);

	sprintf(imprime, "DATA %02d/%02d/%02d", date[3], date[4], date[5]);
	LCD_Write(imprime, 1);

	//recebe hora
	char auxTime[6] = "999999";
	Delay(1000);
	while(auxTime[0] == '9'){
		Delay(200);
		recebeDadosBluetooth = Bluetooth_RecebeDados();
		for(index = 0; index < 6; index++){
			auxTime[index] = recebeDadosBluetooth[index];
		}
	}
	date[2] = ((auxTime[0] - 0x30 ) * 10) + (auxTime[1] - 0x30);
	date[1] = ((auxTime[2] - 0x30 ) * 10) + (auxTime[3] - 0x30);
	date[0] = ((auxTime[4] - 0x30 ) * 10) + (auxTime[5] - 0x30);

	sprintf(imprime, "HORA %02d:%02d:%02d", date[2], date[1], date[0]);
	LCD_Write(imprime, 2);

	Delay(1000);

	//HORA - MINUTO - SEGUNDO
	DS1307_SetTime(date[2],date[1],date[0]);
	//DIA - MES - ANO
	DS1307_SetDate(date[3],date[4],date[5]);

	LCD_Clear();
}
Ejemplo n.º 2
0
/** HID class driver callback function for the processing of HID reports from the host.
 *
 *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
 *  \param[in] ReportID  Report ID of the received report from the host
 *  \param[in] ReportType  The type of report that the host has sent, either REPORT_ITEM_TYPE_Out or REPORT_ITEM_TYPE_Feature
 *  \param[in] ReportData  Pointer to a buffer where the created report has been stored
 *  \param[in] ReportSize  Size in bytes of the received HID report
 */
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID,
                                          const uint8_t ReportType, const void* ReportData, const uint16_t ReportSize)
{
	Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
	
	DS1307_SetDate(ReportParams->Day,  ReportParams->Month,  ReportParams->Year);
	DS1307_SetTime(ReportParams->Hour, ReportParams->Minute, ReportParams->Second);
	
	/* If the logging interval has changed from its current value, write it to EEPROM */
	if (LoggingInterval500MS_SRAM != ReportParams->LogInterval500MS)
	{
		LoggingInterval500MS_SRAM = ReportParams->LogInterval500MS;
		eeprom_write_byte(&LoggingInterval500MS_EEPROM, LoggingInterval500MS_SRAM);
	}
}
Ejemplo n.º 3
0
void doMenu()
{   
    while(bButton)
        readInputs();
    
    // set the new time
    if (menuFunction == MENU_NONE | menuFunction == MENU_TIME)
    {
        int h,m,s ;
        
        h = hour ;
        m = minute ;
        s = seconds ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Hours");
        
        LCDGotoXY(0,1) ;
        showTime();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                hour++;
                if (hour > 23)
                    hour = 0 ;
            }
            else if (state & DIR_CCW)
            {
                hour--;
                if (hour < 0)
                    hour = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Minutes");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                minute++;
                if (minute > 59)
                    minute = 0 ;
            }
            else if (state & DIR_CCW)
            {
                minute--;
                if (minute < 0)
                    minute = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Seconds");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                seconds++;
                if (seconds > 59)
                    seconds = 0 ;
            }
            else if (state & DIR_CCW)
            {
                seconds--;
                if (seconds < 0)
                    seconds = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        // save changes
        if (h != hour || m != minute || s != seconds)
        { // we only update the RTC if changes have been made
            h = ((hour / 10) << 4) + hour % 10 ;
            m = ((minute / 10) << 4) + minute % 10 ;
            s = ((seconds / 10) << 4) + seconds % 10 ;

            DS1307_SetTime(h,m,s) ;
            
            runningMinute = minute ;
        }
        
        while(bButton)
            readInputs();
    }
    
    // set the new date
    if (menuFunction == MENU_NONE | menuFunction == MENU_DATE)
    {
        int n,d,m,y ;
        
        n = day ;
        d = date ;
        m = month ;
        y = year ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Year");
        
        LCDGotoXY(0,1) ;
        showDate();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                year++;
                if (year > 99)
                    year = 0 ;
            }
            else if (state & DIR_CCW)
            {
                year--;
                if (year < 0)
                    date = 99 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Month");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                month++;
                if (month > 12)
                    month = 1 ;
            }
            else if (state & DIR_CCW)
            {
                month--;
                if (!month)
                    month = 12 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Date ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                date++;
                if (date > monthDays[month-1])
                    date = 1 ;
            }
            else if (state & DIR_CCW)
            {
                date--;
                if (date < 0)
                    date = monthDays[month-1] ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Day  ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                day++;
                if (day > 7)
                    day = 1 ;
            }
            else if (state & DIR_CCW)
            {
                day--;
                if (day < 0)
                    day = 7 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }

        if (n != day || d != date || m != month || y != year)
        { // again, we only update the RTC if changes have been made
            n = ((day / 10) << 4) + day % 10 ;
            d = ((date / 10) << 4) + date % 10 ;
            m = ((month / 10) << 4) + month % 10 ;
            y = ((year / 10) << 4) + year % 10 ;

            DS1307_SetDate(n,d,m,y) ;
        }

        
        while(bButton)
            readInputs();
    }
}
Ejemplo n.º 4
0
 void main(void) {
	Inicia_Tiva();

	REFTEMPO referencia;
	uint8_t date[6] = {0x00,0x00,0x0C,0x1B,0x08,0x10};
	uint8_t modo_atual = START, aberta = 0x00;
	uint16_t leituras_salvas= 0;


	LCD_BlackLight_Enable();
	LCD_Clear();
	LCD_Write("    BEM VINDO!!!", 1);
	LCD_Write("  MEDIDOR DE AGUA!", 2);

	InitSensores();

	Delay(2000);
	LCD_Clear();
	StartMonit(date, &referencia);

	while(1) {
		Delay(250);
		LeSensores();

//		OpenValve();
//		Delay(5000);
//		CloseValve();
//		Delay(5000);

		recebeDadosBluetooth = Bluetooth_RecebeDados();
		char comando;
//		char temp[5];
//		for(i = 0; i < 5; i++){
//			temp[i] = recebeDadosBluetooth[i];
//		}
		comando = recebeDadosBluetooth[5];
		if(comando == '1'){
	//	if( strcmp(temp, "atual") == 0 ){
			LCD_Clear();
			LCD_Write("       ENVIA", 0);
			LCD_Write("       ULTIMO", 1);
			LCD_Write("       VALOR", 2);

			DADOMEDIDA ultimo;
			uint16_t mes_atual = referencia.end_proxmes - 0x1173;
			if(referencia.end_diaria.word - 3 != mes_atual)
				ultimo = EEPROM_PegaLeitura(referencia.end_diaria.word - 6);
			else
				ultimo.med.word = 0;
			Bluetooth_EnviaMedicao(ultimo.med.word);

			Delay(1000);
		}
		if(comando == '2'){
	//	if( strcmp(temp, "anter") == 0 ){
			LCD_Clear();
			LCD_Write("       ENVIA", 0);
			LCD_Write("       MEDIA ", 1);
			LCD_Write("       ANUAL", 2);
            
			DADOANUAL media;
			media = EEPROM_PegaMedia(referencia.end_proxano.word - 9);
            uint32_t valor = ((media.acu_hi.word*65536) + media.acu_lo.word)/media.cnt_ms.word;			
			Bluetooth_EnviaMedicao(valor);

			Delay(1000);
		}
 		if(comando == '3'){
	//	if( strcmp(temp, "histo") == 0 ){
			LCD_Clear();
			LCD_Write("       ENVIA ", 1);
			LCD_Write("     HISTORICO", 2);
			
			B16 cal;
			uint16_t mem_mes = MES1;
			uint8_t day[3];
			uint8_t hour[3];
			DADOMEDIDA hist;
			for(int ind_mes = 0; ind_mes < 6; ind_mes++) {
				mem_mes = mem_mes + (ind_mes*0x1173);
				cal = GetMesAno(mem_mes);				
				for(int ler = 0; ler < 744; ler++) {
					hist = LeSequencia((ind_mes*0x1173), ler);
					day[0] = his.datetime[0];
					day[1] = cal.byte[1];
					day[2] = cal.byte[0];
					hour[0] = his.datetime[1];
					hour[1] = his.datetime[2];
					hour[2] = his.datetime[3];
					Bluetooth_EnviaDados(hist.med.word, day, hour);
				}
			}
			
			Delay(1000);
		}
		if(comando == '4'){
	//	if( strcmp(temp, "reset") == 0 ){
			LCD_Clear();
			LCD_Write("        RESET", 1);
			LCD_Write("       MEMORIA", 2);
			ResetMem();
		}
		if(comando == '5'){
	//	if( strcmp(temp, "ajust") == 0 ){
			LCD_Clear();
			LCD_Write("  RECEBENDO DADOS", 0);
			//recebe data
			char imprime[15];
			char auxData[6] = "999999";
			Delay(1000);
			while(auxData[0] == '9'){
				Delay(200);
				recebeDadosBluetooth = Bluetooth_RecebeDados();
				for(index = 0; index < 6; index++){
					auxData[index] = recebeDadosBluetooth[index];
				}
			}
			date[3] = ((auxData[0] - 0x30 ) * 10) + (auxData[1] - 0x30);
			date[4] = ((auxData[2] - 0x30 ) * 10) + (auxData[3] - 0x30);
			date[5] = ((auxData[4] - 0x30 ) * 10) + (auxData[5] - 0x30);
			sprintf(imprime, "DATA %02d/%02d/%02d", date[3], date[4], date[5]);
			LCD_Write(imprime, 1);
			//recebe hora
			char auxTime[6] = "999999";
			Delay(1000);
			while(auxTime[0] == '9'){
				Delay(200);
				recebeDadosBluetooth = Bluetooth_RecebeDados();
				for(index = 0; index < 6; index++){
					auxTime[index] = recebeDadosBluetooth[index];
				}
			}
			date[2] = ((auxTime[0] - 0x30 ) * 10) + (auxTime[1] - 0x30);
			date[1] = ((auxTime[2] - 0x30 ) * 10) + (auxTime[3] - 0x30);
			date[0] = ((auxTime[4] - 0x30 ) * 10) + (auxTime[5] - 0x30);
			sprintf(imprime, "HORA %02d:%02d:%02d", date[2], date[1], date[0]);
			LCD_Write(imprime, 2);

			Delay(1000);

			//HORA - MINUTO - SEGUNDO
			DS1307_SetTime(date[2],date[1],date[0]);
			//DIA - MES - ANO
			DS1307_SetDate(date[3],date[4],date[5]);
		}
		if(comando == '6'){
	//	if( strcmp(temp, "abrir") == 0 ){
			LCD_Clear();
			OpenValve();
			LCD_Write("    ABRE VALVULA", 0);
			LCD_Write("---------/ /--------", 2);
			Delay(1000);
		}
		if(comando == '7'){
	//	if( strcmp(temp, "fecha") == 0 ){
			LCD_Clear();
			CloseValve();
			LCD_Write("   FECHA VALVULA", 0);
			LCD_Write("--------------------", 2);
			Delay(1000);
		}
		if(comando == '8'){
	//	if( strcmp(temp, "volts") == 0 ){
			LCD_Clear();
			LCD_Write("FONTES DE ENERGIAS", 0);
			char imprime[10];
			float volt = bateria / 1.67;
			sprintf(imprime, "BATERIA = %.2f V", volt); // 9.0v -> 2.18V
			LCD_Write(imprime, 1);
			volt = rede / 2;
			sprintf(imprime, "REDE = %.2f V", volt); //12.4V -> 2.80V
			LCD_Write(imprime, 2);
			Delay(1000);
		}

		ShowDateTime();
		Scan(&referencia, &modo_atual, &tempo_passado, &pulsos_contados, &leituras_salvas);

		if(modo_atual == ENABLED)	{
			TimerEnable(TIMER0_BASE, TIMER_A);
		} else if(modo_atual == RESTART || modo_atual == DISABLED) {
			TimerDisable(TIMER0_BASE, TIMER_A);
			modo_atual = START;
			Delay(1);
		}

		if(modo_atual != DISABLED) {
			if(aberta == 0x00) {
				OpenValve();
				aberta = 0x01;
			}
		} else {
			if(aberta == 0x01) {
				CloseValve();
				aberta = 0x00;
			}
		}

		LCD_Process();
	}
}
Ejemplo n.º 5
0
void StartMonit(uint8_t datetime[6], REFTEMPO* atual) {
	B16 endereco;
	uint8_t aux = 0, ind = 0;
	uint8_t mesoff[6];
	uint8_t anooff[6];
	uint8_t decoff[10];
	
	//HORA - MINUTO - SEGUNDO
	DS1307_SetTime(datetime[2],datetime[1],datetime[0]);
	atual->hora = datetime[2];
	atual->minu = datetime[1];
	//DIA - MES - ANO
	DS1307_SetDate(datetime[3],datetime[4],datetime[5]);
	atual->mes = datetime[4];
	atual->ano = datetime[5];
	//LIMPA MEMORIA
	ResetMem();	
	//CALCULA OFFSET DE ESPACOS DA MEMORIA - AREA DE LEITURAS DIARIAS
	if(datetime[5] <= 6) {
		for(aux = 0; aux < 6; aux++) {
			mesoff[aux] = aux;
			anooff[aux] = 0;
		}
	} else {
		aux = datetime[5] - 7;
		for(ind = 0; ind < 6; ind++) {				
			if(ind + aux < 6) {
				mesoff[ind] = ind + aux;
				anooff[aux] = 0;					
			} else {
				mesoff[ind] = ind + aux + (251 - datetime[5]);
				if(datetime[6] < 99) 
					anooff[aux] = 1;
				else
					anooff[aux] = 157;
			}				
		}		
	}		
	//DEFINE OS VALORES DOS 6 MESES(ATUAL E PROXIMOS 5)
	endereco.word = MES1;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[0]);
	endereco.word = MES1+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[0]);
	endereco.word = MES1+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);
    atual->end_diaria.word = MES1+3;
	
	endereco.word = MES2;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[1]);
	endereco.word = MES2+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[1]);
	endereco.word = MES2+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);	
	atual->end_proxmes.word = MES2;
	
	endereco.word = MES3;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[2]);
	endereco.word = MES3+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[2]);
	endereco.word = MES3+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);
	
	endereco.word = MES4;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[3]);
	endereco.word = MES4+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[3]);
	endereco.word = MES4+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);	
	
	endereco.word = MES5;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[4]);
	endereco.word = MES5+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[4]);
	endereco.word = MES5+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);
	
	endereco.word = MES6;    //MES
	EEPROM_Define(endereco.word, datetime[5] + mesoff[5]);
	endereco.word = MES6+1;  //ANO
	EEPROM_Define(endereco.word, datetime[6] + anooff[5]);
	endereco.word = MES6+2;  //PRIMEIRA LEITURA
	EEPROM_Define(endereco.word, 0x01);				
	
	//DEFINE OS VALORES DOS 10 ANOS (ATUAL E PROXIMOS 9)
	//CALCULA OFFSET DE ESPACOS DA MEMORIA - AREA DE LEITURAS ANUAIS
	if(datetime[6] < 90) {
		for(aux = 0; aux < 10; aux++) {
			decoff[aux] = aux;
		}
	} else {
		aux = datetime[6] - 90;
		for(ind = 0; ind < 10; ind++) {				
			if(ind + aux < 10) {
				decoff[ind] = ind + aux;					
			} else {
				decoff[ind] = ind + aux + (246 - datetime[6]);				
			}				
		}		
	}
	endereco.word = ANO1;
	EEPROM_Define(endereco.word, datetime[5] + decoff[0]);	
	atual->end_media.word = ANO1 + 1;
	
	endereco.word = ANO2;
	EEPROM_Define(endereco.word, datetime[5] + decoff[1]);	
	atual->end_proxano.word = ANO2;
	
	endereco.word = ANO3;
	EEPROM_Define(endereco.word, datetime[5] + decoff[2]);	
	
	endereco.word = ANO4;
	EEPROM_Define(endereco.word, datetime[5] + decoff[3]);	
	
	endereco.word = ANO5;
	EEPROM_Define(endereco.word, datetime[5] + decoff[4]);	
	
	endereco.word = ANO6;
	EEPROM_Define(endereco.word, datetime[5] + decoff[5]);	
	
	endereco.word = ANO7;
	EEPROM_Define(endereco.word, datetime[5] + decoff[6]);
	
	endereco.word = ANO8;
	EEPROM_Define(endereco.word, datetime[5] + decoff[7]);	
	
	endereco.word = ANO9;
	EEPROM_Define(endereco.word, datetime[5] + decoff[8]);
	
	endereco.word = ANOA;
	EEPROM_Define(endereco.word, datetime[5] + decoff[9]);	
}