SCP1000 Logger example

Dependencies:   SCP1000 mbed

Committer:
yamaguch
Date:
Fri Nov 18 02:16:46 2011 +0000
Revision:
0:08e60fccbe4a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 0:08e60fccbe4a 1 #include "mbed.h"
yamaguch 0:08e60fccbe4a 2 #include "SCP1000.h"
yamaguch 0:08e60fccbe4a 3
yamaguch 0:08e60fccbe4a 4 DigitalIn sw(p9);
yamaguch 0:08e60fccbe4a 5 DigitalOut leds[4] = {LED1, LED2, LED3, LED4};
yamaguch 0:08e60fccbe4a 6 SCP1000 scp1000(p5, p6, p7, p8);
yamaguch 0:08e60fccbe4a 7 LocalFileSystem local("local");
yamaguch 0:08e60fccbe4a 8 void printMeasurements(char *title, int n);
yamaguch 0:08e60fccbe4a 9
yamaguch 0:08e60fccbe4a 10 int main() {
yamaguch 0:08e60fccbe4a 11 char buf[32];
yamaguch 0:08e60fccbe4a 12
yamaguch 0:08e60fccbe4a 13 for (int i = 0; !sw; i = (i + 1) % 8) {
yamaguch 0:08e60fccbe4a 14 leds[i < 4 ? i : 7 - i] = 1;
yamaguch 0:08e60fccbe4a 15 wait(0.05);
yamaguch 0:08e60fccbe4a 16 leds[i < 4 ? i : 7 - i] = 0;
yamaguch 0:08e60fccbe4a 17 }
yamaguch 0:08e60fccbe4a 18
yamaguch 0:08e60fccbe4a 19 FILE *fp = fopen("/local/scp1000.txt", "a");
yamaguch 0:08e60fccbe4a 20 if (fp == NULL) exit(-1);
yamaguch 0:08e60fccbe4a 21
yamaguch 0:08e60fccbe4a 22 time_t seconds = time(NULL);
yamaguch 0:08e60fccbe4a 23 strftime(buf, sizeof(buf), "%x %X", localtime(&seconds));
yamaguch 0:08e60fccbe4a 24 fprintf(fp, "Time: %s\n", buf);
yamaguch 0:08e60fccbe4a 25 fprintf(fp, "SCP1000 ASIC revision number = %d\n", scp1000.revision());
yamaguch 0:08e60fccbe4a 26 bool result = scp1000.performSelfTest();
yamaguch 0:08e60fccbe4a 27 fprintf(fp, "SCP1000 self test: %s\n", result ? "PASSED" : "FAILED");
yamaguch 0:08e60fccbe4a 28 fprintf(fp, "SCP1000 reset\n");
yamaguch 0:08e60fccbe4a 29 scp1000.reset();
yamaguch 0:08e60fccbe4a 30 fclose(fp);
yamaguch 0:08e60fccbe4a 31
yamaguch 0:08e60fccbe4a 32 scp1000.setOperationMode(SCP1000::HIGH_SPEED_MODE);
yamaguch 0:08e60fccbe4a 33 printMeasurements("SCP1000 High Speed Mode - 9Hz", 3600 * 9);
yamaguch 0:08e60fccbe4a 34
yamaguch 0:08e60fccbe4a 35 scp1000.setOperationMode(SCP1000::HIGH_RESOLUTION_MODE);
yamaguch 0:08e60fccbe4a 36 printMeasurements("SCP1000 High Resolution Mode - 1.8Hz", 3600 * 9 / 5);
yamaguch 0:08e60fccbe4a 37
yamaguch 0:08e60fccbe4a 38 scp1000.setOperationMode(SCP1000::ULTRA_LOW_POWER_MODE);
yamaguch 0:08e60fccbe4a 39 printMeasurements("SCP1000 Ultra Low Power Mode - 1Hz", 3600 * 10);
yamaguch 0:08e60fccbe4a 40 }
yamaguch 0:08e60fccbe4a 41
yamaguch 0:08e60fccbe4a 42 void printMeasurements(char *title, int n) {
yamaguch 0:08e60fccbe4a 43 FILE *fp = fopen("/local/scp1000.txt", "a");
yamaguch 0:08e60fccbe4a 44 fprintf(fp, "%s\n", title);
yamaguch 0:08e60fccbe4a 45
yamaguch 0:08e60fccbe4a 46 for (int i = 0; !sw && i < n; i++) {
yamaguch 0:08e60fccbe4a 47 while (!scp1000.isReady())
yamaguch 0:08e60fccbe4a 48 ;
yamaguch 0:08e60fccbe4a 49 time_t seconds = time(NULL);
yamaguch 0:08e60fccbe4a 50 char buf[16];
yamaguch 0:08e60fccbe4a 51 strftime(buf, sizeof(buf), "%X", localtime(&seconds));
yamaguch 0:08e60fccbe4a 52 fprintf(fp, "%s %3.2f, %3.3f\n", buf, scp1000.readTemperature(), scp1000.readPressure());
yamaguch 0:08e60fccbe4a 53 leds[i % 4] = (i % 8) < 4;
yamaguch 0:08e60fccbe4a 54 if (i % 100 == 99) {
yamaguch 0:08e60fccbe4a 55 fclose(fp);
yamaguch 0:08e60fccbe4a 56 fp = fopen("/local/scp1000.txt", "a");
yamaguch 0:08e60fccbe4a 57 }
yamaguch 0:08e60fccbe4a 58 }
yamaguch 0:08e60fccbe4a 59
yamaguch 0:08e60fccbe4a 60 fclose(fp);
yamaguch 0:08e60fccbe4a 61 wait(1.0);
yamaguch 0:08e60fccbe4a 62 }