Generation 3 of the Harp project
Dependencies: Servo TMP36 GZ buffered-serial1 chan_fatfs_sd nmea_parser watchdog mbed-rtos mbed
Fork of HARP2 by
main.cpp
- Committer:
- tylerjw
- Date:
- 2012-12-11
- Revision:
- 11:890a721158a5
- Parent:
- 10:b13416bbb4cd
- Child:
- 12:0d943d69d3ec
File content as of revision 11:890a721158a5:
#include "mbed.h" #include "rtos.h" #include "buffered_serial.h" #include "SDFileSystem.h" SDFileSystem sd(p5, p6, p7, p8, "sd"); #define CELLS 3.0 #define LIPO_EMPTY 3.4 #define LIPO_FULL 4.2 const float BAT_MUL = 4.7; const float BAT_FULL = (CELLS * LIPO_FULL); const float BAT_EMPTY = (CELLS * LIPO_EMPTY); const float BAT_RANGE = BAT_FULL - BAT_EMPTY; Serial pc(USBTX, USBRX); BufferedSerial gps(NC, p14); AnalogIn gps_battery(p20); void gps_thread(void const *args) { char buffer[80]; DigitalOut gps_led(LED4); gps.baud(4800); mkdir("/sd/hab", 0777); FILE *fp = fopen("/sd/hab/gps.txt", "a"); fputs("--- new log --- \r\n", fp); fclose(fp); while(true) { fp = fopen("/sd/hab/gps.txt", "a"); gps.read_line(buffer); gps_led = !gps_led; //pc.puts(buffer); fputs(buffer, fp); fclose(fp); } } int main() { pc.baud(9600); Thread thread(gps_thread, NULL, osPriorityHigh); while(true) { float sample = gps_battery.read(); pc.printf("Sample: %f Volts\r\n", sample*3.3); float voltage = sample*BAT_MUL*3.3; pc.printf("Battery Voltage: %f Volts\r\n", voltage); float level = (voltage-BAT_EMPTY) / (BAT_RANGE); pc.printf("Battery Level: %f \r\n", level); Thread::wait(1000); } }