/**************************************************************************************************
*
*  uDrive
*
*   Version:          1.0.0 - Mai 2009
*   Author:           Etienne Ribeiro    / tutorial assistant caad      /  eribeiro[at]ethz.ch
*   Supervisor:       Christoph Wartmann / chair for caad - ETH Zürich  /  wartmann[at].arch.ethz.ch
*
*   Desc:             Library to write string-, int- and long-values to an SD-card using uDrive and a
*                     FAT16 formated SD-Card.
*
***************************************************************************************************/

// const

int onboardLED = 13; // Wiring-Board: Pin 48, Arduino: Pin 13


// var

boolean uDriveInitialized = true;




// setup

void setup() {

        // LED (2 * blink)
        pinMode(onboardLED, OUTPUT);
        digitalWrite(onboardLED, HIGH);
        delay(200);
        digitalWrite(onboardLED, LOW);
        delay(200);
        digitalWrite(onboardLED, HIGH);


        // Serial
        Serial.begin(9600);
        Serial.println ("Setup begin");


        // Initialize uDrive
        if (!uDrive_Initialize (38400, 12)) { // 38400, 28800, 14400, 9600, 1200 or 300

                Serial.println ("Device not initialized");
                uDriveInitialized = false;

        }
        // Check if Disk is inserted
        if (!uDrive_LoadDisk()) {

                Serial.println ("Disk not loaded");
                uDriveInitialized = false;

        }


        // done
        Serial.println ("Setup done");






        // Write to SD-Card
        if (uDriveInitialized) {

                // Big strings
                char data [] = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffggggggggggaaaaaaaaaabbbbbbbbbb";
                if (!uDrive_writeFile ("test01.txt", data)) // return false if an error occured while writing.
                Serial.println ("Data not written.");
                char data2 [] = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij";
                uDrive_writeFile ("test01.txt", data2);
                if (uDrive_HasErrors ()) // or call this to find out if an error occured while writing.
                Serial.println ("Data2 not written.");


                // Numbers and strings
                uDrive_writeFile ("test02.txt", (long) 3813273);
                uDrive_writeFile ("test02.txt", " - ");
                uDrive_writeFile ("test02.txt", (int) 2838);
                if (uDrive_HasErrors ())
                Serial.println ("Errors while writing.");
                else
                Serial.println ("All data written.");

        }

}


void loop() {

}