当前位置: 首页>>代码示例>>C++>>正文


C++ SdFile::read方法代码示例

本文整理汇总了C++中SdFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::read方法的具体用法?C++ SdFile::read怎么用?C++ SdFile::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SdFile的用法示例。


在下文中一共展示了SdFile::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

boolean MP3Player::mp3PlayCallback()
{
   if(filesize==0 &&PLAY==true)
   { 
     return false;
   }
   
   else if(filesize>0 &&PLAY==true)
   {
	if(k>=BUF_SIZE)
    {     //if buffer emptied refill buffer
        //word res=
		myFile.read(AudioBuf, BUF_SIZE);
              //reset counter
        k=0; 
    }
 
    if(STA013_DATREQ())       // if STA013 request data
    {
        
        STA013_CSH();   //enable STA013
        SPI.transfer(AudioBuf[k]); //send data  
        STA013_CSL();   //disable STA013      
        k++;
        filesize--;        //counting down
    }
	
	return true;
	
   }
   else
	 return false;
   
}
开发者ID:CytronTechnologies,项目名称:Cytron_MP3Shield,代码行数:34,代码来源:MP3Player.cpp

示例2: readSettings

void readSettings() {
	int n,cc;
	char ch, buff[24];
	char  buff2[80];
	unsigned int ndx=0;
	int read=0;
    if (!settingsFile.open(&root, settingsFileName, O_READ)) {
        console.printf("DBG: Creating New Settings File\r\n"); console.flush();
        writeSettings();
        return;
	}
    console.printf("DBG: Opened Settings File: %s\r\n",settingsFileName);
	settingsFile.seekSet(0);
	while ((read=settingsFile.read(buff, sizeof(buff))) > 0) {
        //console.printf("DBG: READ %d\r\n",read); console.flush();
        for (cc=0; cc < read ; cc++) {
            
            ch=buff[cc];
            //console.putChar(ch); console.flush();
            buff2[ndx]=ch;
            if (ndx<MAX_INPUT_LINE) {ndx++;}
            if (ch=='\n'){//console.putChar('\r');
                if(ndx) {
                    ndx--; // eat the newline.
                }
                buff2[ndx]='\0';
                //console.puts(buff2);
                if ((ndx>4) && buff2[3]=='!') {//fix this when the files are better
                    buff2[3]='\0';
                    n=lookupIndex(buff2);
                    switch (n) {
                        case _NPW_:
                            networkSetPassword(buff2+4);
                            break;
                        case _NJN_:
                            Watchdog_Reset();
                            networkJoin(buff2 +4);
                            break;
                        case _PKY_:
                            strncpy(pachubeKey, buff2+4, MAX_PATCHUBE_KEY_LENGHT-1);
                            break;
                        case _PFD_:
                            strncpy(pachubeFeed, buff2+4, MAX_PATCHUBE_FEED_LENGHT-1);
                            break;
                        default:
                            break;
                    }
                    
                }
            
                ndx=0; 

            }
        }
    }
    
    console.printf("DBG: Finished with Settings File: %s\r\n",settingsFileName);
    
	settingsFile.close();
}
开发者ID:suspect-devices,项目名称:cache-and-carry,代码行数:60,代码来源:main.cpp

示例3: WiFiSendPicture

int WiFiCmdRobot::WiFiSendPicture (int16_t n)
{
  int ret=SUCCESS;
  int16_t nbytes; 
  uint8_t buf[PAYLOAD_SIZE];
  char filename[12+1];
 
  Serial.print("n: ");
  Serial.println(n);
  
  // Open the file
  sprintf(filename, "PICT%02d.jpg", n);
  if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR;  

  Serial.print("Open file: ");
  Serial.println(filename);

  // read from the file until there's nothing else in it:
  while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
       for (unsigned int idx = 0; idx<nbytes;idx++)
       {
           tcpClient.print(buf[idx]);
       }
 
  }// while
  
  //Close file
  if (!FilePicture.close()) return FILE_CLOSE_ERROR;  
  
  return SUCCESS;
}
开发者ID:saildrones,项目名称:RobotChipKit,代码行数:31,代码来源:WiFiCmdRobot.cpp

示例4:

// grafix has to be stored at /gfx/
int speedo_disp::sd2ssd(char filename[10],int frame){
	send_command(0x15);
	send_command(0x00);
	send_command(0x7F);
	send_command(0x75);
	send_command(0x00);
	send_command(0x3F);

	SdFile root;
	SdFile file;
	SdFile subdir;
	root.openRoot(&pSD->volume);

	if(!subdir.open(&root, "gfx", O_READ))    {  return 1; };
	if(!file.open(&subdir, filename, O_READ)) {  return 2; };
	unsigned long frame_seeker=(unsigned long)frame*64*64;
	if(!file.seekSet(frame_seeker))			  {  return 3; }; // ein bild ist 64*64 Byte groß, da wir 64 lines zu je 64*2*4 Bit Breite haben

	uint8_t buf[65];
	//int n;
	//while ((n = file.read(buf, sizeof(byte)*64)) > 0) {
	for (int zeile=0;	(file.read(buf, sizeof(byte)*64)>0)	&& zeile<64;	zeile++ ) {
		for(int j=0;j<64;j++){
			send_char(buf[j]);
		};
	};
	file.close();
	subdir.close();
	root.close();
	return 0;
};
开发者ID:KoljaWindeler,项目名称:speedoino,代码行数:32,代码来源:display.cpp

示例5: send_file

void AtMegaWebServer::send_file(SdFile& file) {
  size_t size;
  while ((size = file.read(buffer, sizeof(buffer))) > 0) {
    if (!client_.connected()) {
      break;
    }
    client_.write((uint8_t*)buffer, size);
  }
}
开发者ID:gonboy,项目名称:AtMegaWebServer,代码行数:9,代码来源:AtMegaWebServer.cpp

示例6: send_file

void TinyWebServer::send_file(SdFile& file) {
  char _buf[512];
  size_t size;
  while ((size = file.read(_buf, sizeof(_buf))) > 0) {
    if (!client_.connected()) {
      break;
    }
    write((uint8_t*)_buf, size);
  }
}
开发者ID:d0ughb0y,项目名称:Chauvet16,代码行数:10,代码来源:TinyWebServer.cpp

示例7: loop

void loop() { 
  uint32_t t;
  double r;

  Serial.println("Type any character to start");
  while (!Serial.available()) SPARK_WLAN_Loop();
  while (Serial.available()) Serial.read();

  // open or create file - truncate existing file.
  if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
    error("open failed");
  }
  // fill buf with known data
  for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
    buf[i] = 'A' + (i % 26);
  }
  buf[BUF_SIZE-2] = '\r';
  buf[BUF_SIZE-1] = '\n';
  Serial.print("File size ");
  Serial.print(FILE_SIZE_MB);
  Serial.println(" MB");
  uint32_t n = FILE_SIZE/sizeof(buf);
  Serial.println("Starting write test.  Please wait up to a minute");
  // do write test
  t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
      error("write failed");
    }
  }
  t = millis() - t;
  file.sync();
  r = (double)file.fileSize()/t;
  Serial.print("Write ");
  Serial.print(r);
  Serial.println(" kB/sec");
  Serial.println();
  Serial.println("Starting read test.  Please wait up to a minute");
  // do read test
  file.rewind();
  t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
      error("read failed");
    }
  }
  t = millis() - t;
  r = (double)file.fileSize()/t;
  Serial.print("Read ");
  Serial.print(r);
  Serial.println(" kB/sec");
  Serial.println("Done");
  file.close();
}
开发者ID:TomEngr44,项目名称:SparkCore-SD,代码行数:54,代码来源:Spark-SpeedTest.cpp

示例8: importEEPROM

void HAL::importEEPROM() {
    if (eepromFile.isOpen())
			eepromFile.close();
		if (!eepromFile.open("eeprom.bin", O_RDWR | O_CREAT | O_SYNC) ||
			eepromFile.read(virtualEeprom, EEPROM_BYTES) != EEPROM_BYTES)
		{
			Com::printFLN(Com::tOpenFailedFile, "eeprom.bin");
		} else {
      Com::printFLN("EEPROM read from sd card.");
    }
    EEPROM::readDataFromEEPROM(true);
}
开发者ID:luc-github,项目名称:Repetier-Firmware-0.92,代码行数:12,代码来源:HAL.cpp

示例9: setup

void setup(void) {
  Serial.begin(BPS_115200);
  Serial.println();
  PgmPrintln("Type any character to start");
  while (!Serial.available());
  
  //PgmPrint("FreeRam: ");
  //Serial.println(FreeRam());
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!card.init(SPI_HALF_SPEED)) error("card.init failed");

  // initialize a FAT volume
  if (!volume.init(&card)) error("volume.init failed");

  // open the root directory
  if (!root.openRoot(&volume)) error("openRoot failed");
  
  strcpy_P(buf, PSTR("APPEND.TXT"));
  // open for read
  if (!from.open(&root, buf, O_READ)) {
    PgmPrint("Can't open "); 
    Serial.println(buf);
    PgmPrintln("Run the append example to create the file.");
    error("from.open failed");
  }
  strcpy_P(buf, PSTR("ACOPY.TXT"));
  // create if needed, truncate to zero length, open for write
  if (!copy.open(&root, buf, O_CREAT | O_TRUNC | O_WRITE)) {
    error("copy.open failed");
  }
  // count for printing periods
  uint16_t p = 0;
  int16_t n;  
  while ((n = from.read(buf, sizeof(buf))) > 0) {
    if (copy.write(buf, n) != n) error("write failed");
    // print progress periods
    if (!(p++ % 25)) Serial.print('.');
    if (!(p % 500)) Serial.println();
  }
  Serial.println();
  if (n != 0) error ("read");
  // force write of directory entry and last data
  if (!copy.close()) error("copy.close failed");
  PgmPrintln("Copy done.");
}
开发者ID:cohabo,项目名称:my_src,代码行数:47,代码来源:main.cpp

示例10: ServeFile

static void ServeFile(FILE * stream_file, const char * fname, SdFile & theFile, EthernetClient & client)
{
	freeMemory();
	const char * ext;
	for (ext=fname + strlen(fname); ext>fname; ext--)
		if (*ext == '.')
		{
			ext++;
			break;
		}
	if (ext > fname)
	{
		if (strcmp(ext, "jpg") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/jpeg");
		else if (strcmp(ext, "gif") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/gif");
		else if (strcmp(ext, "css") == 0)
			ServeHeader(stream_file, 200, "OK", true, "text/css");
		else if (strcmp(ext, "js") == 0)
			ServeHeader(stream_file, 200, "OK", true, "application/javascript");
		else if (strcmp(ext, "ico") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/x-icon");
		else
			ServeHeader(stream_file, 200, "OK", true);
	}
	else
		ServeHeader(stream_file, 200, "OK", true);


#ifdef ARDUINO
	flush_sendbuf(client);
#else
	fflush(stream_file);
#endif
	while (theFile.available())
	{
		int bytes = theFile.read(sendbuf, 512);
		if (bytes <= 0)
			break;
		client.write((uint8_t*) sendbuf, bytes);
	}
}
开发者ID:egisz,项目名称:sprinklers_pi,代码行数:42,代码来源:web.cpp

示例11: setup

void setup(void) {
    Serial.begin(9600);
    Serial.println();
    Serial.println("type any character to start");
    while (!Serial.available());
    Serial.println();

    // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
    // breadboards.  use SPI_FULL_SPEED for better performance.
    if (!card.init(SPI_HALF_SPEED)) error("card.init failed");

    // initialize a FAT volume
    if (!volume.init(&card)) error("volume.init failed");

    // open the root directory
    if (!root.openRoot(&volume)) error("openRoot failed");

    // open a file
    if (file.open(&root, "PRINT00.TXT", O_READ)) {
        Serial.println("Opened PRINT00.TXT");
    }
    else if (file.open(&root, "WRITE00.TXT", O_READ)) {
        Serial.println("Opened WRITE00.TXT");
    }
    else {
        error("file.open failed");
    }
    Serial.println();

    // copy file to serial port
    int16_t n;
    uint8_t buf[7];// nothing special about 7, just a lucky number.
    while ((n = file.read(buf, sizeof(buf))) > 0) {
        for (uint8_t i = 0; i < n; i++) Serial.print(buf[i]);
    }
    /* easier way
    int16_t c;
    while ((c = file.read()) > 0) Serial.print((char)c);
    */
    Serial.println("\nDone");
}
开发者ID:aerospace6666,项目名称:AeroQuad,代码行数:41,代码来源:SdFatRead.c

示例12: app_process_file_read

idigi_callback_status_t iDigiFileSystem::app_process_file_read(idigi_file_request_t * const request_data,
                                                     idigi_file_data_response_t * const response_data)
{
    idigi_callback_status_t status = idigi_callback_continue;
    SdFile *file = (SdFile *) request_data->handle;

    int const result = file->read(response_data->data_ptr, response_data->size_in_bytes);

    if (result < 0)
    {
        APP_DEBUG("read %p req %d, returned err %d\n", (void *) file, response_data->size_in_bytes, result);
        response_data->error->error_status = idigi_file_unspec_error;
        goto done;
    }

    APP_DEBUG("read %p req %d, returned %d\n", (void *) file, response_data->size_in_bytes, result);
    response_data->size_in_bytes = result;

done:
    return status;
}
开发者ID:jordanh,项目名称:idigi-arduino-connector,代码行数:21,代码来源:iDigiFileSystem.cpp

示例13: while

boolean MP3Player::Setup_STA013(void)
{ 
  byte buf[2];
  
  if (!myFile.open("sta013.cfg", O_READ)) 
  {
    #if DEBUG
	sd.errorHalt("cfg file error");
	#endif 
	return false;
  }
  
  #if DEBUG
  Serial.println("setting STA013 from cfgfile");  
  #endif 
  
  
  while (myFile.available()) 
  {
    buf[0]=byte (myFile.read());
    buf[1]=byte (myFile.read()); 
    I2C_Write(buf[0], buf[1]);
    // Serial.write(buf[0]);
    // Serial.write(buf[1]);
  }  
  
  while(!myFile.close())
  {
	  #if DEBUG
	  Serial.println("close cfg file..");
	  #endif
  }
  
    
  #if DEBUG
  Serial.println("Setup STA013 Register Done..");     
  #endif 
  
  return true;
}
开发者ID:CytronTechnologies,项目名称:Cytron_MP3Shield,代码行数:40,代码来源:MP3Player.cpp

示例14: SD_ReadFile

boolean SD_ReadFile(const char *filename)
{
    uint32_t t_arrival = millis();
    boolean retVal = false;
    sdf.chdir();
    if (!file.open(filename, O_READ)) {
        sdf.errorHalt("opening FILE for read failed");
    }
    else
    {
        uint32_t len = file.fileSize();
        uint8_t index = 0;
        for(uint32_t i=0; i< len; i++)
        {
            int intData = file.read();
            char byteData;
            int base = 10u;
            //itoa(intData,&byteData,base);	// Convert to ASCII
            buffer[index] = (uint8_t)intData;//byteData;
            if(index < 63u) {
                index++;
            }
            else {
                usb_rawhid_send(buffer, 100u);
                index = 0;
            }

        }
        file.close();
        uint32_t t_exit = millis() - t_arrival;
        buffer[62] = (uint8_t)((t_exit & 0x000000FF)>>8);
        buffer[63] = (uint8_t)t_exit;
        usb_rawhid_send(buffer,100u);

    }
}
开发者ID:ro0lz,项目名称:_CANcrusher_ARM,代码行数:36,代码来源:sdfi.cpp

示例15: pan

int UTFT_SdRaw::pan(int dispx, int dispy, int sx, int sy, unsigned long offsetx, unsigned long offsety, unsigned long sizex, unsigned long sizey, char *filename, bool iswap)
{
	char buffer[2*sx];
	int cx, cy, cp;
	word temp, result;
	unsigned long temp1,temp2;
	temp1=sizex*2;
	temp2=offsetx*2;
	if (dataFile.open(filename))
	{
		cbi(_UTFT->P_CS, _UTFT->B_CS);
		cx=0;
		cy=0;
		result=sx;
		if (_UTFT->orient==PORTRAIT)
		{
			_UTFT->setXY(dispx, dispy, dispx+sx-1, dispy+sy-1);
		}
		for(int n=0;n<sy;n++)
		{
			dataFile.seekSet(((n+offsety)*temp1)+temp2);
			result=dataFile.read(&buffer,2*sx);
			if (_UTFT->orient==PORTRAIT)
			{
				for (int i=0; i<result; i+=2)
				{
					if(iswap==1)
					{
						_UTFT->LCD_Write_DATA(buffer[i+1],buffer[i]);
					}
					else
					{
					_UTFT->LCD_Write_DATA(buffer[i],buffer[i+1]);
					}						
				}
			}
			else
			{
				cp=0;
				while (cp<result)
				{
					if (((result-cp)/2)<(sx-cx))
					{
						_UTFT->setXY(dispx+cx, dispy+cy, dispx+cx+((result-cp)/2)-1, dispy+cy);
						for (int i=(result-cp)-2; i>=0; i-=2)
						{
							if(iswap==1)
							{
								_UTFT->LCD_Write_DATA(buffer[cp+i+1],buffer[cp+i]);
							}
							else
							{
								_UTFT->LCD_Write_DATA(buffer[cp+i],buffer[cp+i+1]);
							}						
						}
						cx+=((result-cp)/2);
						cp=result;
					}
					else
					{
						_UTFT->setXY(dispx+cx, dispy+cy, dispx+sx-1, dispy+cy);
						for (int i=sx-cx-1; i>=0; i--)
						{
							if(iswap==1)
							{
								_UTFT->LCD_Write_DATA(buffer[cp+(i*2)+1],buffer[cp+(i*2)]);
							}
							else
							{
								_UTFT->LCD_Write_DATA(buffer[cp+(i*2)],buffer[cp+(i*2)+1]);
							}
						}
						cp+=(sx-cx)*2;
						cx=0;
						cy++;
					}
				}
			}              
		}
		dataFile.close();
		_UTFT->setXY(0,0,_UTFT->getDisplayXSize()-1,_UTFT->getDisplayYSize()-1);
		sbi(_UTFT->P_CS, _UTFT->B_CS);
		return 0;
	}
	else
	{
		return 99;
	}
}
开发者ID:RitterRBC,项目名称:Arduino,代码行数:89,代码来源:UTFT_SdRaw.cpp


注:本文中的SdFile::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。