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 Tyler Weaver

main.cpp

Committer:
tylerjw
Date:
2012-12-11
Revision:
12:0d943d69d3ec
Parent:
11:890a721158a5
Child:
13:db6af0620264

File content as of revision 12:0d943d69d3ec:

#include "mbed.h"
#include "rtos.h"
#include "buffered_serial.h"
#include "ff.h"

#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);

#define FSS_DBG

void gps_thread(void const *args)
{
    char buffer[80];
    FATFS fs;
    FIL fp;

    DigitalOut gps_led(LED4);

    gps.baud(4800);
    
    f_mount(0, &fs);
    f_open(&fp, "0:gps.txt", FA_CREATE_ALWAYS | FA_WRITE);

    while(true) {
        gps.read_line(buffer);
        gps_led = !gps_led;
        pc.puts(buffer);
        f_puts(buffer, &fp);
        f_sync(&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);
    }
}