basic lightning detector with gps and sd card logging
Dependencies: AS3935 AdafruitGPS SDFileSystem TSI mbed ConfigFile
Revision 13:3d717008645c, committed 2015-07-15
- Comitter:
- cmkachur
- Date:
- Wed Jul 15 21:25:24 2015 +0000
- Parent:
- 12:7c58c7a6b25c
- Commit message:
- Eliminate 50 ms delay when changing LED in main loop. ; Add a configuration parameter for using the RTC. The default is to use the RTC time.; Update FW version to 5.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 7c58c7a6b25c -r 3d717008645c main.cpp --- a/main.cpp Wed Jul 01 19:39:05 2015 +0000 +++ b/main.cpp Wed Jul 15 21:25:24 2015 +0000 @@ -9,7 +9,7 @@ #include "time.h" #include <string> -#define FW_VER 4 +#define FW_VER 5 // frdm-kl25z as3935 connections for spi1 // ------------------------------------------------ @@ -61,6 +61,7 @@ unsigned int minNumLight; unsigned int spikeRej; unsigned int maskDisturber; +unsigned int bUseRtc; }sys_cfg_t; // default configuration values @@ -71,6 +72,7 @@ .minNumLight = 0, .spikeRej = 2, .maskDisturber = 0, + .bUseRtc = 1, }; @@ -217,6 +219,7 @@ {"minimum_num_light", &lSysCfg.minNumLight}, {"spike_reject", &lSysCfg.spikeRej}, {"mask_disturber", &lSysCfg.maskDisturber}, + {"use_rtc", &lSysCfg.bUseRtc}, }; ConfigFile *plCfgFile; string fileName; @@ -290,7 +293,6 @@ int main() { - unsigned char regBuff[MAX_CONFIG_REGS]; char c; Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? @@ -313,7 +315,7 @@ gpsd.minute=1; gpsd.seconds=1; red = 1; - green = 1; + pc.printf("Touch slider to start lightning detector application\r\n"); while(1) { green = 1; // turn led off @@ -404,7 +406,7 @@ // the ld detector generated an interrupt, log the event IntLightning.disable_irq(); writeLogFile(OriginInt,gDistance, energy); - //ld.clearStats(); + OriginInt = -1; gDistance = -1; energy = -1; @@ -421,67 +423,84 @@ } //check if we recieved a new message from GPS, if so, attempt to parse it, - if ( gpsd.newNMEAreceived() ) { - if ( !gpsd.parse(gpsd.lastNMEA()) ) { + if ( gpsd.newNMEAreceived() ) + { + if ( !gpsd.parse(gpsd.lastNMEA()) ) + { continue; } + else + { + // if the rtc is not running, update the rtc clock with the latest gps time stamp + if ( rtcRunning == false ) + { + IntLightning.disable_irq(); + // update system time with the lastest gps time stamp + SetDateTime(gpsd.year+2000, + gpsd.month-1, + gpsd.day, + gpsd.hour, + gpsd.minute, + gpsd.seconds); + IntLightning.enable_irq(); + } + } } - - // if the rtc is not running, update the rtc clock with the latest gps time stamp - if ( rtcRunning == false ) - { - // update rtc with the lastest gps time stamp - SetDateTime(gpsd.year+2000, - gpsd.month-1, - gpsd.day, - gpsd.hour, - gpsd.minute, - gpsd.seconds); - } //check if enough time has passed to warrant printing GPS info to screen //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing if (refresh_Timer.read_ms() >= refresh_Time) { + if (green) + green = 0; + else + green = 1; + if (gpsd.fix) { // got a gps fix if (gpsFix == false) { // first time fix obtained gpsFix = true; - // bug check - rtc may not be running. check if it is incrementing - time_t seconds_a = time(NULL); // get the current rtc second count - wait(2); // wait two seconds - time_t seconds_b = time(NULL); // get the current rtc second count - if (seconds_a != seconds_b) + + if (sysCfg.bUseRtc) { - // rtc must be running - rtcRunning = true; - pc.printf("RTC is running\r\n"); + // bug check - rtc may not be running. check if it is incrementing + time_t seconds_a = time(NULL); // get the current rtc second count + wait(2); // wait two seconds + time_t seconds_b = time(NULL); // get the current rtc second count + if (seconds_a != seconds_b) + { + // rtc must be running + rtcRunning = true; + pc.printf("RTC is running\r\n"); + } + else + { + // rtc is not running, we need to update the rtc every pass through the while loop + rtcRunning = false; // the gps time will update the system time + pc.printf("RTC is not running\r\n"); + } } - else + else { - // rtc is not running, we need to update the rtc every pass through the while loop - rtcRunning = false; // the gps time will update the rtc - pc.printf("RTC is not running\r\n"); + rtcRunning = false; // the gps time will update the system clock time } - // set the rtc with the latest gps time + IntLightning.disable_irq(); + // set the system with the latest gps time SetDateTime(gpsd.year+2000, - gpsd.month-1, - gpsd.day, - gpsd.hour, - gpsd.minute, - gpsd.seconds); + gpsd.month-1, + gpsd.day, + gpsd.hour, + gpsd.minute, + gpsd.seconds); + IntLightning.enable_irq(); + pc.printf("GPS fix obtained on %02d/%02d/20%02d_%02d:%02d:%02d (UTC)\r\n",gpsd.month,gpsd.day,gpsd.year,gpsd.hour,gpsd.minute,gpsd.seconds); - //pc.printf("Touch slider to suspend application\r\n"); + pc.printf("Waiting for lighting detection...\r\n"); } - - //red = 1; // turn led off - //pc.printf("turn green on\r\n"); - green = 0; // turn led on - wait_ms(50); } else { @@ -491,15 +510,7 @@ } // restart the timer for the gps print loop - // writeLogFile(-2); refresh_Timer.reset(); } - else - { - //red = 0; // turn led on - //pc.printf("turn green off\r\n"); - green = 1; // turn green led off - } // end else refresh timer } - }