本文整理汇总了C++中SdFile::available方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::available方法的具体用法?C++ SdFile::available怎么用?C++ SdFile::available使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::available方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: writeGPSLog
void writeGPSLog(uint32_t gpstime, int32_t latitude, int32_t longitude, int32_t altitude) {
#else
void writeGPSLog(int32_t latitude, int32_t longitude, int32_t altitude) {
#endif
if (f.SDCARD == 0) return;
if (gps_data.open(GPS_LOG_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
#ifdef UBLOX
gps_data.print(gpstime); gps_data.write(',');
#endif
gps_data.print(latitude); gps_data.write(',');
gps_data.print(longitude); gps_data.write(',');
gps_data.print(altitude); gps_data.println();
gps_data.close();
} else {
return;
}
}
void writePLogToSD() {
if (f.SDCARD == 0) return;
plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
if (permanent.open(PERMANENT_LOG_FILENAME, O_WRITE | O_CREAT | O_TRUNC)) {
permanent.print(F("arm=")); permanent.println(plog.arm);
permanent.print(F("disarm=")); permanent.println(plog.disarm);
permanent.print(F("start=")); permanent.println(plog.start);
permanent.print(F("armed_time=")); permanent.println(plog.armed_time);
permanent.print(F("lifetime=")); permanent.println(plog.lifetime, DEC);
permanent.print(F("failsafe=")); permanent.println(plog.failsafe);
permanent.print(F("i2c=")); permanent.println(plog.i2c);
permanent.print(F("running=")); permanent.println(plog.running, DEC);
permanent.print(F("checksum=")); permanent.println(plog.checksum, DEC);
permanent.print(F("debug=")); permanent.print(debug[0]);
permanent.print(F(",")); permanent.print(debug[1]);
permanent.print(F(",")); permanent.print(debug[2]);
permanent.print(F(",")); permanent.println(debug[3]);
permanent.println();
permanent.close();
} else {
return;
}
}
void fillPlogStruct(char* key, char* value) {
if (strcmp(key, "arm") == 0) sscanf(value, "%u", &plog.arm);
if (strcmp(key, "disarm") == 0) sscanf(value, "%u", &plog.disarm);
if (strcmp(key, "start") == 0) sscanf(value, "%u", &plog.start);
if (strcmp(key, "armed_time") == 0) sscanf(value, "%lu", &plog.armed_time);
if (strcmp(key, "lifetime") == 0) sscanf(value, "%lu", &plog.lifetime);
if (strcmp(key, "failsafe") == 0) sscanf(value, "%u", &plog.failsafe);
if (strcmp(key, "i2c") == 0) sscanf(value, "%u", &plog.i2c);
if (strcmp(key, "running") == 0) sscanf(value, "%hhu", &plog.running);
if (strcmp(key, "checksum") == 0) sscanf(value, "%hhu", &plog.checksum);
}
void readPLogFromSD() {
if (f.SDCARD == 0) return;
SdFile myfile;
char key[12];
char value[32];
char* tabPtr = key;
int c;
uint8_t i = 0;
if (myfile.open(PERMANENT_LOG_FILENAME, O_READ)) {
while (myfile.available()) {
c = myfile.read();
switch ((char)c) {
case ' ':
break;
case '=':
*tabPtr = '\0';
tabPtr = value;
break;
case '\n':
*tabPtr = '\0';
tabPtr = key;
i = 0;
fillPlogStruct(key, value);
memset(key, '\0', sizeof(key));
memset(value, '\0', sizeof(value));
break;
default:
i++;
if (i <= 12) {
*tabPtr = (char)c;
tabPtr++;
}
break;
}
}
} else return;
if (calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
#if defined(BUZZER)
alarmArray[7] = 3;
blinkLED(9, 100, 3);
#endif
// force load defaults
plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 11;
plog.running = 1;
plog.lifetime = plog.armed_time = 3;
//.........这里部分代码省略.........