4180 weather balloon logging and cutdown system

Dependencies:   GPS MPL3115A2 SDFileSystem mbed-rtos mbed

Fork of WeatherBalloon4180 by Chad Miller

main.cpp

Committer:
cmiller86
Date:
2015-11-17
Revision:
2:21e4b9092bb2
Parent:
1:2c4f640a8104
Child:
3:b490294520d5

File content as of revision 2:21e4b9092bb2:

#include "mbed.h"
#include "rtos.h"

#include "GPS.h"
#include "SDFileSystem.h"

Serial pc(USBTX, USBRX);
SDFileSystem sd(p5, p6, p7, p8, "sd");
GPS gps(p9, p10);

AnalogIn temp1(p18);
AnalogIn temp2(p19);
AnalogIn temp3(p20);

DigitalIn dtmf(p11);

DigitalOut led1(LED1);
DigitalOut relay(p8);

Timer t;

bool attempted = false;
bool cutdown = false;

FILE *sdout;

void init()
{
    t.start();
    relay = 0;
    
    mkdir("/sd/weather_balloon", 0777);
    sdout = fopen("/sd/weather_balloon/log.txt", "w");
}

int main()
{
    float tempC1, tempF1, tempC2, tempF2, tempC3, tempF3;
    
    while(1)
    {
        pc.printf("----- %f -----\n\r", t.read());
        fprintf(sdout, "----- %f -----\n\r", t.read());
        
        if(t.read() >= 20)
            cutdown = true;
                
        gps.sample();
        
        pc.printf("Long = %f\n\rLati = %f\n\r", gps.longitude, gps.latitude);
        fprintf(sdout, "Long = %f\n\rLati = %f\n\r", gps.longitude, gps.latitude);
        
        if(!gps.longitude)
            led1 = 1;
        
        tempC1 = ((temp1 * 3.3) - 0.600) * 100.0;
        tempC2 = ((temp2 * 3.3) - 0.600) * 100.0;
        tempC3 = ((temp3 * 3.3) - 0.600) * 100.0;
        tempF1 = (9.0 * tempC1) / 5.0 + 32;
        tempF2 = (9.0 * tempC2) / 5.0 + 32;
        tempF3 = (9.0 * tempC3) / 5.0 + 32;
        
        pc.printf("Temp1 = %f\n\rTemp2 = %f\n\rTemp3 = %f\n\r", tempF1, tempF2, tempF3);
        fprintf(sdout, "Temp1 = %f\n\rTemp2 = %f\n\rTemp3 = %f\n\r", tempF1, tempF2, tempF3);
        
        if(dtmf)
        {
            pc.printf("DTMF = True\n\r");
            fprintf(sdout, "DTMF = True\n\r");
            
            cutdown = true;
        }
        else
        {
            pc.printf("DTMF = False\n\r");
            fprintf(sdout, "DTMF = False\n\r");
        }

        if(cutdown && !attempted)
        {
            pc.printf("Cutdown Started = %f\n\r", t.read());
            fprintf(sdout, "Cutdown Started = %f\n\r", t.read());
            
            relay = 1;
            wait(20);
            relay = 0;
            
            pc.printf("Cutdown Ended = %f\n\r", t.read());
            fprintf(sdout, "Cutdown Ended = %f\n\r", t.read());
            
            attempted = true;
        }
    }
}