void PlayFile_3_0(Fat16 &file, LightWall &LW, void (*error_code)(int)) {
 /*Message Type 0 header: 4 bytes
  * 1 Byte:  Lights per string
  * 1 Byte:  Lights per Row
  * 2 Bytes: Inter-frame pause
  */ 
 if (file.read(header_3_0, 2) <2)
  {
    error_code(4); //Unexpected EOF
    return;
  }

  if (header_3_0[0] != LW.lightsPerString())
  {
    error_code(13); //Mismatched light count
    return;
  }
 
   if (header_3_0[1] != LW.lightsPerRow())
  {
    error_code(14); //Mismatched Row Size
    return;
  }
  if (file.read(&ifg, 2) <2) // Bytes 4 & 5 are Inter-frame pause
  {
    error_code(4); //Unexpected EOF
    return;
  }
  if (ifg == 0)
  { 
    ifg=1; 
  }

  readsize = file.read(LW.Buffer, 12);
  if (readsize <12)//File should never be empty here
    error_code(4); // Unexpected EOF

  int i = 0;
  while (readsize==12)
  {
    for (i = 0; i < LW.lightsPerString(); i++)
    {
      LW.send_frame(i);
      _delay_us(30);
      readsize = file.read(LW.Buffer, 12);
    }
    delay(ifg);
  }
  
  LW.fadeout(5000);

  LW.blank_screen();
  //reset intensity from fadeout
  LW.set_intensity(0xFF); //intensity=DEFAULT_INTENSITY;
  LW.send_frame(63);
  _delay_us(50);

  delay(1000);
}
Esempio n. 2
0
boolean newSD::findIndex(char *fileName,unsigned int &songindex)
{
  unsigned char dname[11];   // name formated for dir entry
  dir_t* p;            // pointer to cached dir entry
  // error if invalid name
  unsigned int _rootDirEntryCount = file.rootDirEntryCount();
  if (!make83Name(fileName, dname)) return false;//false

  for (uint16_t index = 0; index < _rootDirEntryCount; index++) {
    if (!(p = file.dbgCacheDir(index))) return false;//false
    if (p->name[0] == DIR_NAME_FREE || p->name[0] == DIR_NAME_DELETED) {
      // done if no entries follow
      if (p->name[0] == DIR_NAME_FREE) break;
    } else if (!memcmp(dname, p->name, 11)) {
      songindex = index;
      return true;
    }
  }
}
Esempio n. 3
0
void logInit() {
    // initialize the SD card
    if (!card.init()) { 
        Serial.print("Error initializing card - ");
        Serial.println(card.errorCode, HEX);
        return;
    }
    
    // initialize a FAT16 volume
    if (!Fat16::init(&card)) {
        Serial.println("Can't initialize volume.");
        return;
    }
    
    // create a new file
    char name[] = "LOGGER00.TXT";
    for (uint8_t i = 0; i < 100; i++) {
        name[6] = i/10 + '0';
        name[7] = i%10 + '0';
        // O_CREAT - create the file if it does not exist
        // O_EXCL - fail if the file exists
        // O_WRITE - open for write only
        if (file.open(name, O_CREAT | O_EXCL | O_WRITE)) break;
    }

    if (!file.isOpen()) {
        Serial.println("Error creating log file.");
        return;
    }
    
    Serial.print("Logging to: ");
    Serial.println(name);

    // write data header
    
    // clear write error
    file.writeError = false;
    file.println("Started log.");
    file.sync();
    
    fileReady = 1;
}
Esempio n. 4
0
unsigned char newSD::openFile(unsigned int index)
{
  if (file.open(index, O_READ)) {
   // Serial.print(index);
  //  Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 5
0
unsigned char newSD::openFile(char *fileName)
{
  if (file.open(fileName, O_READ)) {
    Serial.write(fileName);
    Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 6
0
int openFile(uint16_t index)
{

  if (file.open(index, O_READ)) {
    Serial.print(index);
    Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 7
0
boolean newSD::traverseRootSong(unsigned int songIndex[], unsigned char &totalNum)
{
  dir_t* p;            // pointer to  directory entry
  unsigned int _rootDirEntryCount = file.rootDirEntryCount();
  Serial.println("All songs in the root directory:");
  for (unsigned int index = 0; index < _rootDirEntryCount; index++) 
  {
    if (!(p = file.dbgCacheDir(index))) return false;
    if (p->name[0] == DIR_NAME_FREE) return true;
    else if(p->name[0] == DIR_NAME_DELETED)continue;
    else if((p->name[8] == 'M')&&(p->name[9] == 'P')&&(p->name[10] == '3')){
      songIndex[totalNum] = index;
      totalNum ++;
      ucharArray2String(p->name);
    }
    else if((p->name[8] == 'W')&&(p->name[9] == 'A')&&(p->name[10] == 'V')){
      songIndex[totalNum] = index;
      totalNum ++;
      ucharArray2String(p->name);
    }
    else if((p->name[8] == 'W')&&(p->name[9] == 'M')&&(p->name[10] == 'A')){
      songIndex[totalNum] = index;
      totalNum ++;
      ucharArray2String(p->name);
    }
    else if((p->name[8] == 'M')&&(p->name[9] == 'I')&&(p->name[10] == 'D')){
      songIndex[totalNum] = index;
      totalNum ++;
      ucharArray2String(p->name);
    }
    else if((p->name[8] == 'O')&&(p->name[9] == 'G')&&(p->name[10] == 'G')){
      songIndex[totalNum] = index;
      totalNum ++;
      ucharArray2String(p->name);
    }
    if(totalNum == 100)return true;
  }
}
Esempio n. 8
0
void log(char *fmt, ... ) {
    char buf[128]; // resulting string limited to 128 chars
    va_list args;
    va_start (args, fmt );
    vsnprintf(buf, 128, fmt, args);
    va_end (args);

    if (serial_logging) {
      Serial.print(gps_time);
      Serial.print(':');
      Serial.print(millis());
      Serial.print(' ');
      Serial.print(buf);
    }
    
    if (fileReady) {
        file.print(gps_time);
        file.print(':');
        file.print(millis());
        file.print(' ');
        file.print(buf);
        file.sync();
    }
}
Esempio n. 9
0
 uint8_t read() { return f.read(); }
Esempio n. 10
0
 void seek(size_t offset) { f.seekSet(offset); }
Esempio n. 11
0
File: lcd.cpp Progetto: 0724/Arduino
uint32_t read32(Fat16& f) {
  uint32_t result;
  f.read(&result,sizeof(result));
  return result;
}
Esempio n. 12
0
File: lcd.cpp Progetto: 0724/Arduino
uint16_t read16(Fat16& f) {
  uint16_t result;
  f.read(&result,sizeof(result));
  return result;
}
Esempio n. 13
0
int readFile(byte *buffer, int len)
{
  int readLen = 0;
  readLen = file.read(buffer,len);
  return readLen;
}
Esempio n. 14
0
int newSD::readFile(byte *buffer,unsigned int len)
{
  int readLen = 0;
  readLen = file.read(buffer,len);
  return readLen;
}