Version 3.0: Switching to newer LDC1614 which is placed on the same PCB.
Dependencies: Bob DS1825 LDC1614 LDC1101 SDFileSystem mbed
Fork of Inductive_Sensor by
Diff: main.cpp
- Revision:
- 13:2caedc56b863
- Parent:
- 12:cceece4f3afb
- Child:
- 15:5de8394fdb3c
--- a/main.cpp Tue Apr 12 14:42:52 2016 +0000 +++ b/main.cpp Tue Aug 23 08:26:14 2016 +0000 @@ -5,8 +5,8 @@ * - Led: processing communication with LDC1101 * * Log protocol: -* - 1 minute at 20 Hz -* - 29 minutes rest +* - 0:30 minutes at 20 Hz +* - 14:30 minutes rest * * @author Bob Giesberts * @@ -26,7 +26,7 @@ // SETTINGS bool DEBUG = false; float C = 120E-12; // Capacitor in F -uint16_t INTERVAL_FIRST = 600; // First sampling time in seconds. 60:00 minutes = 600 sec +uint16_t INTERVAL_FIRST = 3600; // First sampling time in seconds. 60:00 minutes = 3600 sec uint16_t INTERVAL_OFF = 870; // Waiting interval in seconds. 14:30 minutes = 870 sec (14*60+30) uint16_t INTERVAL_ON = 30; // Sampling interval in seconds. 0:30 minutes = 30 sec @@ -75,15 +75,78 @@ // function to write all data to the SD card void storeit( float T ) { + // TODO: writing to SD card more efficient! + // t 32-bit | 0.00 2000000.00 3-10x8-bit | FFFFFFFF 8x8 + // L 24-bit | 0 1677216 6- 7x8-bit | FFFFFF 6x8 + // V 8-bit | 3.10 4.20 4x8-bit | FF 2x8 + // T 16-bit | -20.0000 85.0000 7x8-bit | FFFF 4x8 + + + // construct data + /* + bob.ledon(); + // fp = fopen( fn, "a" ); // open file (append) + char buffer[16]; memset(buffer, 0, sizeof(buffer)); + char towrite[64]; memset(towrite, 0, sizeof(towrite)); + int n = 0, m = 0; + for( int i = 0; i < counter; i++ ) + { + for( int j = 0; j < 4; j++ ) + { + // build up next 'word' + switch(j) + { + case 0: n = sprintf(buffer, "%.2f;", (float) collected.t[i]/100.0); break; + case 1: n = sprintf(buffer, "%d;", collected.L[i]); break; + case 2: n = sprintf(buffer, "%.2f;", bob.battery()); break; + case 3: n = sprintf(buffer, "%.4f\r\n", T); break; + } + + // calculate if there is still room left for that word + if( strlen(towrite) + n > 64 ) + { + + // pc.printf( "%s", towrite); + fp = fopen( fn, "a" ); // open file (append) + fprintf( fp, "%s", towrite); + fclose( fp ); // close file + + memset(towrite, 0, sizeof(towrite)); + } + + // build up letter with the next word + m = sprintf(towrite, "%s%s", towrite, buffer); + } + } + if(m > 0) + { + fp = fopen( fn, "a" ); // open file (append) + fprintf( fp, "%s", towrite); + fclose( fp ); // close file + //pc.printf( "%s", towrite); + } + //fclose( fp ); // close file + bob.ledoff(); + */ + + + + + // write data to SD card bob.ledon(); fp = fopen( fn, "a" ); // open file (append) for( int i = 0; i < counter; i++ ) - fprintf( fp, "%.2f;%d;%.4f;%.4f\r\n", (float) collected.t[i]/100.0, collected.L[i], bob.battery(), T ); // write to file + fprintf( fp, "%.2f;%d;%.2f;%.4f\r\n", (float) collected.t[i]/100.0, collected.L[i], bob.battery(), T ); // write to file fclose( fp ); // close file + + // write to screen + //pc.printf( "%.2f;%d;%.2f;%.4f\r\n", (float) collected.t[counter-1]/100.0, collected.L[counter-1], bob.battery(), T ); // write to screen + bob.ledoff(); - - // pc.printf( "%d points: %.2f;%d;%.4f;%.4f\r\n", counter, (float) collected.t[0]/100.0, collected.L[0], bob.battery(), T ); + + + // Reset data memset(collected.t, 0, counter); @@ -93,6 +156,19 @@ int main(void) { + + // TODO: + // - implement this data conversion in writing to SD!! + // - use T as uint16_t, not float! + // - use V as uint16_t, not float! + // - write blocks of 512 bit (4x 32 + 32 + 16 + 16) + // + // float temp_a = 127.9375; + // pc.printf( "A: %.4f (%08x); \r\n", temp_a, * (uint32_t *) &temp_a); + + + + // Load SD File system // - the Raspberry Pie SD cards give a warning here that might just be ignored: // "Not in idle state after sending CMD8 (not an SD card?) @@ -238,7 +314,7 @@ t_lost += t_sleep; if( t_lost < lost_prev ) lost_high++; - + // Sleep now (ms), enter low power mode bob.sleep( t_sleep * 10 );