void write_header_SD(void)
{
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_LOW); //accendo led esterno
	if(open_append(&log_file_object, (char const *)file_name))
		terminate("Error opening logfile!");
	//scrivo intestazione file di log a seconda del modello scelto
	switch(model)
	{	
		case log:
			f_printf(&log_file_object, "Model:%s Interval:%ds  Vout:%dmV\r\n", modelStrings[model], interval, log_vout);
			break;
		case bat:
			f_printf(&log_file_object, "Model:%s Interval:%ds Vmax:%dmV Vexp:%dmV Qexp:%dmAh Vnom:%dmV Qnom:%dmAh Qtot:%dmAh Rint:%dmOhm Isam:%dmAh\r\n", 
					modelStrings[model], interval, bat_vmax, bat_vexp, bat_qexp, bat_vnom, bat_qnom, bat_qtot, bat_rint, bat_isam);
			sprintf(str, "Calculated values:E0:%lf K:%lf A:%lf B:%lf\r\n", bat_param[0], bat_param[1], bat_param[2], bat_param[3]);
			f_printf(&log_file_object, "%s", str);
			break;
	/*	case phv:
			//impl
			break;
		case tec:
			//impl
			break;
	*/
	}
	f_printf(&log_file_object, "Data Ora Tensione(mV) Corrente(uA)\r\n");
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_HIGH); //spengo led esterno
}
Exemple #2
0
FRESULT ff_test(void)
{
    printf("test fatfs begin\n\r");
    SD_NVIC_Configuration();

    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);
    
    res = f_open(&file, "test.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    res = f_open(&file2, "var.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    if(res != FR_OK) printf("open failed: %d\n\r", res);
    
    res = f_write(&file, buff, 12 * sizeof(char), &bw);
    res = f_printf(&file, "test-");
    res = f_printf(&file, "speed:%d,%d\n\r",speed[0],speed[1]--);
    res = f_puts("end of file\n\r", &file);

    speed[0] = 65;
    speed[1] = 1;
    res = f_write(&file2, speed, sizeof(speed), &bw);
    if(res != FR_OK) printf("fwrite failed: %d\n\r", res);
    
    res = f_close(&file);
    res = f_close(&file2);
    if(res != FR_OK) printf("fclose failled: %d\n\r", res);

    res = f_mount(NULL,"", 0);
    if(res != FR_OK) printf("umonut failed: %d\n\r", res);
    
    if(res == FR_OK) printf("test fatfs success\n\r");
}
/***************************************************************************
Desc:	Prints a string to stdout
****************************************************************************/
void printMessage(
	const char *		pszMessage,
	FLMUINT				uiLevel)
{
	unsigned int		uiLoop;

	for (uiLoop = 0; uiLoop < uiLevel; uiLoop++)
	{
		f_printf( " ");
	}
	
	f_printf( "%s\n", pszMessage);
}
 void MTD_FLASHMEM HTTPGPIOConfigurationResponse::flush()
 {
     if (getRequest().method == HTTPHandler::Post)
     {
         char const* gpio = getRequest().form[FSTR("GPIO")];
         if (getRequest().form[FSTR("configured")])
         {		
             // gpio enabled
             char const* mode     = getRequest().form[STR_mode];
             char const* pullUp   = getRequest().form[STR_pullup];
             ConfigurationManager::setGPIOParams(strtol(gpio, NULL, 10), true, f_strcmp(mode, STR_out) == 0, pullUp != NULL, false);
             ConfigurationManager::applyGPIO();
         }
         else if (gpio)
         {
             // gpio disabled (not configured)
             ConfigurationManager::setGPIOParams(strtol(gpio, NULL, 10), false, false, false, false);
         }
     }
     
     HTTPHelperConfiguration::GPIOSetValue(this);
     
     LinkedCharChunks* linkedChunks = addParamCharChunks(FSTR("GPIOS"));
     for (uint32_t i = 0; i != 16; ++i)
     {
         if (i != 1 && i != 3 && (i < 6 || i > 11))
         {
             bool configured, isOutput, pullUp, value;
             ConfigurationManager::getGPIOParams(i, &configured, &isOutput, &pullUp, &value);
             
             linkedChunks->addChunk(f_printf(FSTR("<tr> <td>%d</td> <td><form method='POST'>"), i), true);
             linkedChunks->addChunk(f_printf(FSTR("Enabled <input type='checkbox' name='configured' value='1' onclick=\"document.getElementById('GPIO%d').disabled=!this.checked\" %s>"), i, configured? STR_checked:STR_), true);
             linkedChunks->addChunk(f_printf(FSTR("<fieldset class='inline' id='GPIO%d' %s>"), i, configured? STR_:STR_disabled), true);
             linkedChunks->addChunk(f_printf(FSTR("<select name='mode'><option value='in' %s>IN</option><option value='out' %s>OUT</option></select>"), 
                                            isOutput? STR_:STR_selected, 
                                            isOutput? STR_selected:STR_), 
                                   true);
             linkedChunks->addChunk(f_printf(FSTR("     PullUp <input type='checkbox' name='pullup' value='1' %s> </fieldset>"), pullUp? STR_checked:STR_), true);
             linkedChunks->addChunk(f_printf(FSTR("<input type='hidden' name='GPIO' value='%d'>"), i), true);
             linkedChunks->addChunk(FSTR("<input type='submit' value='Save'></form></td>"));
             if (configured)
             {
                 if (isOutput)
                 {
                     linkedChunks->addChunk(f_printf(FSTR("<td><a href='confgpio?gpio=%d&val=%d&store=1' class='link_button2'>%s</a></td> </tr>"), i, !value, value? STR_HI:STR_LO), true);
                 }
                 else
                 {
                     linkedChunks->addChunk(f_printf(FSTR("<td>%s</td> </tr>"), GPIO(i).read()? STR_HI:STR_LO), true);
                 }
             }
             else
             {
                 linkedChunks->addChunk(FSTR("<td></td></tr>"));
             }
         }
     }			
         
     HTTPTemplateResponse::flush();
 }
Exemple #5
0
int main ( void ) {
	initADC();
	init_stdusart0( BAUD, DB8 | P_N | SB1 );
	init_timer0_ctc( T0_PRESCALER_1024, PIN_DISCONNECT, PIN_DISCONNECT );// initalize timer 0 in ctc mode with a 1024 prescale
	DDRD |= (1 << PORTD4) | (1 << PORTD5);                              //set status LED pins to outputs
	set_ocr0a( 108 );                                                    // compare match every 156 ticks, producing 10ms interrupts
	enable_interrupt_t0a();                                             //enable interrupt on timer0 channel A          
	static FATFS FATFS_Obj;                                             //file system descriptor
	disk_timerproc();                                                   //produce a base timer clock
	FIL logfile;       													//file descriptor for datalogging file
	FILINFO info;                                                       //file info structure
	DSTATUS status = disk_initialize(0);                                //initalize the SD card
	if( status & STA_NOINIT ) {                                         //check for an error
		printf( "Disk Error\n\r" );
		PORTD |= (1 << PORTD4);                                         //Set LED to Error
		PORTD &= ~(1 << PORTD5);
		while (1);
	}
	PORTD |= (1 << PORTD5);                                             //set LED to Success
	PORTD &= ~(1 << PORTD4);
	f_mount(0, &FATFS_Obj);                                             //mount the filesystem
	double vout = 0.0;
	unsigned photo = 0, therm = 0, in = 0;
	while(1) {
		_delay_ms(5000);             //delay 5 seconds
		PORTD |= (1 << PORTD4);      //turn on the writing status
		int res = f_stat( "/avr/datalog.txt", &info );    //find the length of the datalog file
		if(f_open(&logfile, "/avr/datalog.txt", FA_OPEN_ALWAYS | FA_WRITE) != FR_OK) { //open the datalog and create anew ifnot present
			printf("System Error"); 
			PORTD |= (1 << PORTD4);                        //Set LED to Error
			PORTD &= ~(1 << PORTD5);	
			while(1);
        }		
		if(res == FR_OK) f_lseek( &logfile, info.fsize ); //If the file existed seek to the end
		in = getADC(0);                                   //Log the values
		vout = 3.3 * (in/1023.0);
		photo = (vout*10000.0)/(3.3-vout);
		printf( "Photo: %u ohms(%u raw) ", photo, in );
		f_printf( &logfile, "Photo: %u ohms(%u raw) ", photo, in );
		in = getADC(1);
		vout = 3.3 * (in/1023.0);
		therm = (vout*10000.0)/(3.3-vout);
		printf( "Therm: %u ohms(%u raw) \r\n", therm, in );
		f_printf( &logfile, "Therm: %u ohms(%u raw)\n", therm, in );
		f_close( &logfile );       //close the file
		PORTD &= ~(1 << PORTD4);   //off with the writing status
	}
	return 0;
}
bool TestExtString::test_printf() {
  g_context->obStart();
  f_printf(2, "A%sB%dC", CREATE_VECTOR2("test", 10));
  String output = g_context->obCopyContents();
  g_context->obEnd();
  VS(output, "AtestB10C");

  g_context->obStart();
  f_printf(2, "test %2$d %d", CREATE_VECTOR2(1, 10));
  output = g_context->obCopyContents();
  g_context->obEnd();
  VS(output, "test 10 1");

  return Count(true);
}
Exemple #7
0
void recControlData(uint32_t pwm_L, uint32_t pwm_R, int enc_L, int enc_R){
    if(&file){
        res = f_printf(&file, "%d %d %d %d\r\n", pwm_L, pwm_R, enc_L, enc_R);
    }
    //res = f_sync(&file);
    /* f_sync would spend some much time, making timer delayed and data error */
}
	char const* MTD_FLASHMEM ParameterReplacer::replaceTag(char const* curc)
	{
		char const* tagEnd;
		char const* tagStart = extractTagStr(curc, &tagEnd);
		if (getChar(tagStart) == '#')
		{
			// replace multiple parameters ('0param', '1param', ...)
			++tagStart;			
			uint32_t tagLen = tagEnd - tagStart;
			char tag[tagLen];
			f_memcpy(tag, tagStart, tagLen);
			tag[tagLen] = 0;
			for (uint32_t index = 0; ; ++index)
			{
				char const* fulltagname = f_printf(FSTR("%d%s"), index, tag);
				Params::Item* item = m_params->getItem(fulltagname);
				if (item)
					m_result.addChunks(&item->value); // push parameter content
				else
					break;
			}
		}
		else
		{
			// replace one parameter
			Params::Item* item = m_params->getItem(tagStart, tagEnd);
			if (item)				
				m_result.addChunks(&item->value); // push parameter content
		}
		return tagEnd + 2;	// bypass "}}"
	}
Exemple #9
0
FRESULT writeResult(char test[], int result){
	char timeString[20];
	getSQL(timeString); // Load time at which the test occurred
	f_mount(0, &FileSystemObject);
	if (f_open(&logFile, "/tictoc.csv", FA_WRITE | FA_OPEN_EXISTING)){
		// File does not exist yet, try to create it and write the header
		FRESULT res = f_open(&logFile, "/tictoc.csv", FA_WRITE | FA_CREATE_NEW);
		if(res)	return res; // File opening failed!
		f_printf(&logFile, "time,device,test,result\n"); // Write header
	}
	f_lseek(&logFile, f_size(&logFile)); // Make sure we are at the end of the file
	f_printf(&logFile, "%s,watch,%s,%d\n",timeString,test,result); // Write line of data
	f_sync(&logFile); // Make sure file is synched
	f_close(&logFile);
	return f_mount(0,0);
}
static void data_logging_add_header_name(data_logging_t* data_logging)
{
	bool init = false;
	
	uint16_t i;
	data_logging_set_t* data_set = data_logging->data_logging_set;
	
	for (i = 0; i < data_set->data_logging_count; i++)
	{
		data_logging_entry_t* param = &data_set->data_log[i];
		
		int32_t res = f_printf(&data_logging->fil,param->param_name);
		if (res == EOF)
		{
			if (data_logging->debug)
			{
				print_util_dbg_print("Error appending header!\r\n");
			}
			init = false;
		}
		else
		{
			init = true;
			data_logging_put_r_or_n(data_logging, i);
		}
	}
	data_logging->file_init = init;
}
static int32_t data_logging_put_uint64_t(FIL* fp, uint64_t c)
{
	int32_t res = EOF;

	char storage[MAX_DIGITS_LONG];
	int32_t i = MAX_DIGITS_LONG;
	
	do
	{
		i--;
		storage[i] = c % 10;
		c = c / 10;
	} while((i >= 0) && (c > 0) );

	for( ; i<MAX_DIGITS_LONG; i++)
	{
		res = f_printf(fp,"%d",storage[i]);
		if (res == EOF)
		{
			return res;
		}
	}
	
	return res;
}
void close_logfile_SD()
{
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_LOW); //accendo led esterno
	strncpy(buffer, buffer, buffer_p-buffer);
	f_printf(&log_file_object, buffer);
	f_close(&log_file_object); //chiudo file
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_HIGH); //spengo led esterno
}
 void MTD_FLASHMEM HTTPHelperConfiguration::getAPWiFiParams(HTTPTemplateResponse* response, APtr<char>& APCHStr, APtr<char>& APSECStr)
 {
     uint8_t channel;
     WiFi::SecurityProtocol securityProtocol;
     bool hiddenSSID;
     char const* SSID;
     char const* securityKey;
     ConfigurationManager::getAccessPointParams(&SSID, &securityKey, &channel, &securityProtocol, &hiddenSSID);
     response->addParamStr(FSTR("APSSID"), SSID);
     response->addParamStr(FSTR("APPSW"), securityKey);
     APCHStr.reset(f_printf(FSTR("APCH%d"), channel));
     response->addParamStr(APCHStr.get(), STR_selected);
     APSECStr.reset(f_printf(FSTR("APSEC%d"), (int32_t)securityProtocol));
     response->addParamStr(APSECStr.get(), STR_selected);
     if (hiddenSSID)
         response->addParamStr(FSTR("APHSSID"), STR_checked);
 }
static int32_t data_logging_put_float(FIL* fp, float c, int32_t after_digits)
{
	int32_t i;
	int32_t res = 0;
	float num = c;
	
	if (c<0)
	{
		res = f_puts("-",fp);
		if (res == EOF)
		{
			return res;
		}
		num=-c;
	}

	int32_t whole=abs((int32_t)num);
	float after=(num-(float)whole);

	res = f_printf(fp,"%d", whole);
	if (res == EOF)
	{
		return res;
	}
	
	res = f_puts(".",fp);
	if (res == EOF)
	{
		return res;
	}
	
	for (i=0; i<after_digits; i++)
	{
		after*=10;
		res = f_printf(fp, "%d",(int32_t)after);
		if (res == EOF)
		{
			return res;
		}
		after=after-(int32_t)after;
	}
	
	return res;
}
Exemple #15
0
void record()
{
		f_open(&file, record_file_name, FA_OPEN_EXISTING | FA_READ | FA_WRITE);  //  以读方式打开,如果文件不存在则打开失败
		f_lseek(&file,file.fsize);
		sprintf(write_Buff,"%f %d\r\n",velocity,ggz);
// 		f_puts (write_Buff,&file);
		f_printf(&file,write_Buff);
		f_close(&file);  
	
}
int main(void)
{
    WdtGo(T3CON_ENABLE_DIS);//stop watch-dog

    uart_init();
    led_init();

    Radio_init();//inicializuje radio prenos
    SD_init();//nacita kartu a vytvori subor prijaty cez radio prenos


    for(i=0; i<29; i++) {

        Radio_recieve();//pocka na prijatie jedneho paketu

        if (RIE_Response == RIE_Success)
        {
            printf("\n\r-> %s \n@ RSSI %d ",Buffer,(int)RSSI);
            fr = f_printf(&fil,"\n\r-> %s \n@ RSSI %d \n",Buffer,(int)RSSI);
        }
        else
        {
            printf("\n\r-> ERROR");
            fr = f_printf(&fil,"\n\r-> ERROR");
        }
    }

    RIE_Response = RadioTerminateRadioOp();

    fr=f_close(&fil);//koiec zapisu na kartu
    printf("\nzatvaram\n");
    if(fr)printf("chyba pri zatvarani suboru %d\n",fr);

    while (1)//ukonceny zapis
    {
        DioTgl(pADI_GP4,BIT2);
        Delay();
    }



}
void write_record_syslog(char *string)
{
	
	if(open_append(&syslog_file_object, (char const *)SYSLOG_FILE))//apro il file
		terminate("Errore di apertura syslog file !\r\n");	
	//scrivo su file syslog
	f_printf(&syslog_file_object, "%02d/%02d/%04d %02d:%02d:%02d %s\r\n", day, month, year, hour, minute, second, string);
	//scrivo su seriale
	printf("%02d/%02d/%04d %02d:%02d:%02d %s\r\n", day, month, year, hour, minute, second, string);
	f_close(&syslog_file_object); //chiudo file
}
Exemple #18
0
void write_double(double data)
{
	
//	f_lseek(&fil,fil.fsize);
	if(data<0&&data>-1)
	{

	f_printf(&fil, "%s", "   -0");
	}	else
	{		
  f_printf(&fil, "%5d", (int)data);
	}
	
	  f_printf(&fil, "%c", '.');
		if(data<0)
		data=-data;
		data=data-(int)data;
		data=data*10;
		f_printf(&fil, "%d", (int)data);
		data=data-(int)data;
  	data=data*10;
		f_printf(&fil, "%d", (int)data);
}
void datalog(void)
{
		float nick, roll, yaw;
	uint32_t system_time;
	 		//update_IMU();	 //Ersetzen durch Interrupt Handler!!!!!!
			nick = getEuler_nick();
			roll = getEuler_roll();
			yaw = getEuler_yaw();
		
		if(Datalogger_ready() && !datalog_main_opened)
		{
				//rc_main = f_mkfs(0,0,0);
				rc_main = f_open(&Fil_Main, "QuadMain.TXT", FA_WRITE | FA_CREATE_ALWAYS);
				if(rc_main != FR_OK)
				{
					chprintf((BaseChannel *) &SD2, "SD QuadMain.TXT: f_open() failed %d\r\n", rc_main);
					return;
				}	
				//rc_main = f_printf(&Fil, "moin\r\n");	 
				rc_main = f_sync(&Fil_Main);
				if(rc_main != FR_OK)
				{
					chprintf((BaseChannel *) &SD2, "SD QuadMain.TXT: f_sync() failed %d\r\n", rc_main);
					return;
				}	
				chprintf((BaseChannel *) &SD2, "SD QuadMain.TXT: opened successfull\r\n");
				f_printf(&Fil_Main, "Time_Main; Nick_Main; Roll_Main; Yaw_Main\r\n");
				f_sync(&Fil_Main);
				datalog_main_opened = TRUE;
		}
		if(Datalogger_ready() && datalog_main_opened)
		{
			system_time = chTimeNow();
			f_printf(&Fil_Main, "%d;%d;%d;%d\r\n",system_time,(int)(nick*100),(int)(roll*100),(int)(yaw*100));
			rc_main = f_sync(&Fil_Main);
		}
}
Exemple #20
0
/***************************************************
 *	Save _smParam to config file
 */
void saveSmParam(void)
{
#if (USE_SDCARD == 1)
	FIL fid;
	int i;

	f_unlink(CONF_FILE_NAME);

	FRESULT fres = f_open(&fid, CONF_FILE_NAME, FA_CREATE_ALWAYS | FA_WRITE);
	if (fres != FR_OK)
	{
		win_showErrorWin();
		scr_printf("Error save file:'%s'\n Status:%d [%d/%d]", CONF_FILE_NAME, fres, SD_errno, SD_step);
		scr_puts("\n\n\t PRESS C-KEY");
		WAIT_KEY_C();
		return;
	}

	scr_printf("\nSave into %s", CONF_FILE_NAME);
	for (i = 0; i < 3; i++)
	{
		f_printf(&fid, "Crd%d (F:steps*%d/sec): 'smoothStartF_from0,smoothStopF_to0,smoothAF,maxFeedRate\n", i, K_FRQ);
		f_printf(&fid, "%d,%d,%d,%d,%d\n",
			_smParam.smoothStartF_from0[i],
			_smParam.smoothStopF_to0[i],
			_smParam.smoothAF[i],
			_smParam.maxFeedRate[i]
		);
		scr_puts(".");
	}
	f_printf(&fid, "Spindle switch-off temperature (C.degree)\n");
	f_printf(&fid, "%d\n", _smParam.maxSpindleTemperature);
	scr_puts("*");
	f_close(&fid);
	scr_puts(" - OK");
#endif
}
Exemple #21
0
void __fatal_error(const char *msg) {
    FIL fp;
    if (f_open(&fp, "ERROR.LOG",
               FA_WRITE|FA_CREATE_ALWAYS) == FR_OK) {
        f_printf(&fp, "\nFATAL ERROR:\n%s\n", msg);
    }
    f_close(&fp);
    storage_flush();

    for (uint i = 0;;) {
        led_toggle(((i++) & 3));
        for (volatile uint delay = 0; delay < 500000; delay++) {
        }
    }
}
/*
* inicializovanie karty vytvorenie textoveho suboru signal.txt
* s nalogovanymi hodnotamy urovni signalu meranych pri prime
*/
void SD_init(void) {
    char str[30];
    fr=f_mount(&FatFs, "", 0);//inicializacia SD karty
    printf("inicializujem kartu");
    if(fr)printf("chyba pri inicializacii karty (alebo SPI) %d \n",fr);

    //vytvorenie textoveho suboru
    get_txt_name(str);//pocka na prijatie paketu s nazvom suboru
    fr = f_open(&fil, str , FA_WRITE|FA_CREATE_ALWAYS);
    printf("vytvaram subor %s",str);
    if(fr)printf("chyba pri vytvarani suboru %d \n",fr);

    Radio_recieve();//cakanie na prijatie hlavicky suboru
    fr = f_printf(&fil,"%s",Buffer);//hlavicka v txt subore

}
void write_record_SD(int volt, int current)
{
	static int n;
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_LOW); //accendo led esterno
	if(buffer+BUF_SIZE-buffer_p<45)//se non c'è spazio nel buffer
	{
		strncpy(buffer, buffer, buffer_p-buffer);
		f_printf(&log_file_object, buffer);
		buffer_p=buffer;
	}
	if(dac_out_overflow)
		n=sprintf(buffer_p, "%04d/%02d/%02d %02d:%02d:%02d %d %d V>3300\r\n", year, month, day, hour, minute, second, volt, current);
	else
		n=sprintf(buffer_p, "%04d/%02d/%02d %02d:%02d:%02d %d %d\r\n", year, month, day, hour, minute, second, volt, current);
	buffer_p+=n;	
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_HIGH); //spengo led esterno
}
void datalog_lage(void)
{
	uint32_t system_time;
	
		if(Datalogger_ready() && datalog_lage_opened && datalog_lage_syncing == 0)
		{
			//int worst, last, best;
			system_time = chTimeNow();
			f_printf(&Fil_Lage, "%d;%d;%d;%d\r\n",system_time,(int)(euler[1]*100),(int)(euler[2]*100),(int)(euler[0]*100));
			//tmStartMeasurement(&lagedatalogsync_tmup);
			//rc_lage = f_sync(&Fil_Lage);
			//tmStopMeasurement(&lagedatalogsync_tmup);
			//best = RTT2MS(lagedatalogsync_tmup.best);
			//last = RTT2MS(lagedatalogsync_tmup.last);
			//worst = RTT2MS(lagedatalogsync_tmup.worst);
			//chprintf((BaseChannel *) &SD2, "Lage SD Sync Best:%d Worst:%d Last:%d \r\n",best ,worst , last);
		}
}
void STC_FLASHMEM
    ConfigurationManager::getGPIOParams(uint32_t gpioNum, bool *configured, bool *isOutput, bool *pullUp, bool *value) {
  APtr<char> key(f_printf(FSTR("GPIO%d"), gpioNum));
  uint8_t const *infoPtr = FlashDictionary::getValue(key.get());
  if (infoPtr) {
    uint32_t infoInt = getDWord(infoPtr);
    GPIOInfo *info = (GPIOInfo *)&infoInt;
    *configured = info->configured;
    *isOutput = info->isOutput;
    *pullUp = info->pullUp;
    *value = info->value;
  } else {
    // defaults
    *configured = false;
    *isOutput = false;
    *pullUp = false;
    *value = false;
  }
}
Exemple #26
0
static int g_write (lua_State *L, FILE *f, int arg) {
  int nargs = lua_gettop(L) - arg;
  int status = 1;
  for (; nargs--; arg++) {
    if (lua_type(L, arg) == LUA_TNUMBER) {
      /* optimization: could be done exactly as for strings */
      status = status &&
          f_printf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
    }
    else {
      size_t l;
      UINT count;
      const char *s = luaL_checklstring(L, arg, &l);
      status = status && (f_write(f, s, l, &count) == FR_OK && count == l);
    }
  }
  if (status) return 1;  /* file handle already on stack top */
  else return luaL_fileresult(L, status, NULL);
}
/*
 * LageSync
 */
static msg_t LageSyncthread(void *arg) {
 
  systime_t time = chTimeNow();     // Tnow
  while (TRUE) 
	{
		if(Datalogger_ready() && !datalog_lage_opened)
		{
				//rc_lage = f_mkfs(0,0,0);
				rc_lage = f_open(&Fil_Lage, ("QuadLage.TXT"), FA_WRITE | FA_CREATE_ALWAYS);
				if(rc_lage != FR_OK)
				{
					chprintf((BaseChannel *) &SD2, "SD QuadLage.TXT: f_open() failed %d\r\n", rc_lage);
				}	
				//rc = f_printf(&Fil, "moin\r\n");	 
				rc_lage = f_sync(&Fil_Lage);
				if(rc_lage != FR_OK)
				{
					chprintf((BaseChannel *) &SD2, "SD QuadLage.TXT: f_sync() failed %d\r\n", rc_lage);
				}	
				f_printf(&Fil_Lage, "Time_Lage; Nick_Lage; Roll_Lage; Yaw_Lage\r\n");
				rc_lage = f_sync(&Fil_Lage);
				if(rc_lage != FR_OK)
				{
					chprintf((BaseChannel *) &SD2, "SD QuadLage.TXT: f_sync() failed %d\r\n", rc_lage);
				}	
				else
				{
				datalog_lage_opened = TRUE;
				chprintf((BaseChannel *) &SD2, "SD QuadLage.TXT: opened successfull\r\n");
				}
				chThdSleepMilliseconds(10);

		}
		else if(Datalogger_ready() && datalog_lage_opened)
		{
		datalog_lage_syncing = 1;
		rc_lage = f_sync(&Fil_Lage);
		datalog_lage_syncing = 0;
		chThdSleepMilliseconds(700);
		}
  }
}
Exemple #28
0
int main (void)
{
    FRESULT fr;
    FIL fil;


    f_mount(0, &Fatfs);

    /* Open or create a log file and ready to append */
    fr = open_append(&fil, "logfile.txt");
    if (fr != FR_OK) return 1;

    /* Append a line */
    f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);

    /* Close the file */
    f_close(&fil);

    return 0;
}
static int32_t data_logging_put_double(FIL* fp, double c, int32_t after_digits)
{
	int32_t i;
	int32_t res = 0;
	double num = c;
	
	if (c<0)
	{
		res = f_puts("-",fp);
		if (res == EOF)
		{
			return res;
		}
		num=-c;
	}

	int64_t whole=(int64_t)floor(num);
	double after=(num-(double)whole);

	data_logging_put_uint64_t(fp,(uint64_t)whole);
	
	res = f_puts(".",fp);
	if (res == EOF)
	{
		return res;
	}
	
	for (i=0; i<after_digits; i++)
	{
		after*=10;
		res = f_printf(fp, "%ld",(int32_t)after);
		if (res == EOF)
		{
			return res;
		}
		after=after-(int64_t)after;
	}
	
	return res;
}
Exemple #30
0
void  writetable0(table*  tab, FILE * fi)
{ int i;

  linelist ll=tab->strings;
  if(!(fi)) return;
  f_printf(fi,"%s\n",tab->mdlName);
  f_printf(fi,"%s\n",tab->headln);
  f_printf(fi,"%s\n",tab->format);
  while (ll) 
  { i=strlen(ll->line)-1; 
    while(i>=0 && ll->line[i]==' ')i--;      
    f_printf(fi,"%*.*s\n",i+1,i+1,ll->line); 
    ll=ll->next;
  }
  for(i=0;i<strlen(tab->format);i++) f_printf(fi,"=");
  f_printf(fi,"\n");
}