Example #1
0
/** ISR to handle the 500ms ticks for sampling and data logging */
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
{
	uint8_t LEDMask = LEDs_GetLEDs();

	/* Check to see if the logging interval has expired */
	if (CurrentLoggingTicks++ < LoggingInterval500MS_SRAM)
	  return;
	    
	LEDs_SetAllLEDs(LEDMASK_USB_BUSY);

	/* Reset log tick counter to prepare for next logging interval */
	CurrentLoggingTicks = 0;
	
	/* Only log when not connected to a USB host */
	if (USB_DeviceState == DEVICE_STATE_Unattached)
	{
		uint8_t Day,  Month,  Year;
		uint8_t Hour, Minute, Second;

		DS1307_GetDate(&Day,  &Month,  &Year);
		DS1307_GetTime(&Hour, &Minute, &Second);

		char     LineBuffer[100];
		uint16_t BytesWritten;

		BytesWritten = sprintf(LineBuffer, "%02d/%02d/20%04d, %02d:%02d:%02d, %d Degrees\r\n",
							   Day, Month, Year, Hour, Minute, Second, Temperature_GetTemperature());

		f_write(&TempLogFile, LineBuffer, BytesWritten, &BytesWritten);
		f_sync(&TempLogFile);
	}
	
	LEDs_SetAllLEDs(LEDMask);
}
Example #2
0
/** HID class driver callback function for the creation of HID reports to the host.
 *
 *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
 *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID
 *  \param[in] ReportType  Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature
 *  \param[out] ReportData  Pointer to a buffer where the created report should be stored
 *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent
 *
 *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent
 */
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,
                                         const uint8_t ReportType, void* ReportData, uint16_t* ReportSize)
{
	Device_Report_t* ReportParams = (Device_Report_t*)ReportData;

	DS1307_GetDate(&ReportParams->Day,  &ReportParams->Month,  &ReportParams->Year);
	DS1307_GetTime(&ReportParams->Hour, &ReportParams->Minute, &ReportParams->Second);
	
	ReportParams->LogInterval500MS = LoggingInterval500MS_SRAM;

	*ReportSize = sizeof(Device_Report_t);
	return true;
}
Example #3
0
void ShowDateTime() {
	uint8_t tmp[3];
	char imprime[20];
	//LCD_Clear();

	DS1307_GetDate(tmp);
	sprintf(imprime, "%02d/%02d/%02d", tmp[0], tmp[1], tmp[2]);
	LCD_WriteCol(imprime, 0, 0);

	DS1307_GetTime(tmp);
	sprintf(imprime, "%02d:%02d", tmp[0], tmp[1]);
	LCD_WriteCol(imprime, 0, 12);
}
Example #4
0
/** Opens the log file on the Dataflash's FAT formatted partition according to the current date */
void OpenLogFile(void)
{
	char LogFileName[12];

	/* Get the current date for the filename as "DDMMYY.csv" */
	uint8_t Day, Month, Year;
	DS1307_GetDate(&Day, &Month, &Year);
	sprintf(LogFileName, "%02d%02d%02d.csv", Day, Month, Year);

	/* Mount the storage device, open the file */
	f_mount(0, &DiskFATState);
	f_open(&TempLogFile, LogFileName, FA_OPEN_ALWAYS | FA_WRITE);
	f_lseek(&TempLogFile, TempLogFile.fsize);
}
Example #5
0
void readClock()
{
    unsigned char a,b,c,n ;
    
    DS1307_GetTime(&a,&b,&c);
    
    // clock data is BCD
    hour = (a % 16) + ((a / 16 ) * 10) ;
    minute = (b % 16) + ((b / 16 ) * 10) ;
    seconds = (c % 16) + ((c / 16 ) * 10) ;
    
    if (hour != last_hour)
    {
        last_hour = hour ;
        
        DS1307_GetDate(&n,&a,&b,&c) ;
        
        day = (n % 16) ; // 1-7
        date = (a % 16) + ((a / 16 ) * 10) ;
        month = (b % 16) + ((b / 16 ) * 10) ;
        year = (c % 16) + ((c / 16 ) * 10) ;
    }
    
    if (minute != runningMinute)
    {
        runningMinute = minute ;
        runningMinutes++ ;
        
        if (runningMinutes >= 60)
        {
            runningHours++;
            DS1307_writeRam(&runningHours,2,2) ;
            runningMinutes = 0 ;
        }
        
        // write our running total to clock memory
        DS1307_writeRam(&runningMinutes,0,2) ;
    }
}
Example #6
0
void CheckToSave(uint16_t* leitura_acumulada, REFTEMPO* atual) {
	DADOMEDIDA leitura_hora;
	DADOANUAL leitura_media;
	uint8_t time[3]; //0) HORA - MINUTO - SEGUNDO
	uint8_t data[3]; //0) DIA - MES - ANO
	
	DS1307_GetTime(time);	
	if(time[2] > atual->hora && time[1] >= atual->minu){
		DS1307_GetDate(data);
		//PREENCHER LEITURA DA HORA NO MES ATUAL
		if(atual->mes != data[1]) {	
            if(atual->end_proxmes.word + 4467 < ANO1) { //limite da área
				atual->mes = data[1];
				atual->end_diaria.word = atual->end_proxmes.word + 3;				
				atual->end_proxmes.word = atual->end_proxmes.word + 4467;
			} else {				
				EEPROM_MudaSemestre(data[1], data[2]);
				atual->mes = data[1];
				atual->end_diaria.word = MES1 + 3;				
				atual->end_proxmes.word = MES2;				
			}		
						
			leitura_hora.end.word = atual->end_diaria.word;
			if(atual->ano == data[2]) {	
                //ATUALIZA ESTRUTURA COM VALORES SALVOS			
				leitura_media = EEPROM_PegaMedia(atual->end_media.word);				
				if(leitura_media.acu_lo.word + *leitura_acumulada > 0xFFFF)								
					leitura_media.acu_hi.word++;				
				leitura_media.acu_lo.word = leitura_media.acu_lo.word + *leitura_acumulada;
				leitura_media.cnt_ms.word++;
				EEPROM_SalvaMedia(leitura_media);
			} else {
				//PREPARA ESTRUTURA COM VALOR INICIAL
				leitura_media.end.word = atual->end_proxano.word;
				leitura_media.acu_hi.word = 0x0000;
				leitura_media.acu_lo.word = *leitura_acumulada;
				leitura_media.cnt_ms.word = 0x0001;
				leitura_media.cnt_ag.word = 0x0000;				
				EEPROM_SalvaMedia(leitura_media);
				
				atual->ano = data[2];
				if(atual->end_media.word + 9 <= ANOA) { //limite da area
					atual->end_media.word = atual->end_media.word + 10;
					atual->end_proxano.word = atual->end_proxano.word + 18;	
				} else {
					atual->end_media.word = ANO1 + 1;
					atual->end_proxano.word = ANO2;
				}								
			}
		}
		
		leitura_hora.end.word = atual->end_diaria.word;				
		leitura_hora.datetime[0] = data[0]; //DIA
		leitura_hora.datetime[1] = time[0]; //HOR
		leitura_hora.datetime[2] = time[1]; //MIN
		leitura_hora.datetime[3] = time[2]; //SEG
		leitura_hora.med.word = *leitura_acumulada;
		atual->end_diaria.word = atual->end_diaria.word + 6;
		atual->hora = time[2];
		atual->minu = time[1];	
		*leitura_acumulada = 0;		
		EEPROM_SalvaLeitura(leitura_hora);									
	}    
}