newest

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_08012018_newest by Calvin Kalintra

Committer:
ckalintra
Date:
Tue Jan 09 15:45:56 2018 +0000
Revision:
5:8aa72ee456fc
Parent:
4:5dbb5145d0a9
s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ckalintra 0:7023c3f98f36 1 #include "mbed.h"
ckalintra 0:7023c3f98f36 2 #include "TextLCD.h"
ckalintra 1:dc21a6fce3af 3 #include "BME280.h"
ckalintra 5:8aa72ee456fc 4 #include "sd.h"
ckalintra 3:f5fe5071416a 5 #define watchdog_time 15
ckalintra 0:7023c3f98f36 6 //DigitalOut myled(LED1);
ckalintra 3:f5fe5071416a 7 int dislcd = 0, wdcounter = 0, watchdog = 0;
ckalintra 0:7023c3f98f36 8 float T = 15;
ckalintra 5:8aa72ee456fc 9 char ch = 0;
ckalintra 0:7023c3f98f36 10 Ticker display;
ckalintra 0:7023c3f98f36 11 Ticker second_pass;
ckalintra 0:7023c3f98f36 12 InterruptIn button(USER_BUTTON);
ckalintra 5:8aa72ee456fc 13
ckalintra 0:7023c3f98f36 14 //NVIC_SetPriority(display, 0);
ckalintra 0:7023c3f98f36 15 //NVIC_SetPriority(second_pass, 1);
ckalintra 0:7023c3f98f36 16 //NVIC_SetPriority(button, 1);
ckalintra 2:c696dfd53eeb 17
ckalintra 2:c696dfd53eeb 18
ckalintra 0:7023c3f98f36 19 void second_tick()
ckalintra 0:7023c3f98f36 20 {
ckalintra 0:7023c3f98f36 21 ss++;
ckalintra 3:f5fe5071416a 22 if(watchdog == 1)
ckalintra 3:f5fe5071416a 23 {
ckalintra 3:f5fe5071416a 24 wdcounter++;
ckalintra 3:f5fe5071416a 25 }
ckalintra 0:7023c3f98f36 26 time_rule();
ckalintra 0:7023c3f98f36 27 day_check();
ckalintra 0:7023c3f98f36 28 lcd.cls();
ckalintra 0:7023c3f98f36 29 if (dislcd == 1)
ckalintra 0:7023c3f98f36 30 {
ckalintra 0:7023c3f98f36 31 lcd.locate(10,0);
ckalintra 0:7023c3f98f36 32 lcd.printf("l:%1.2f", lvl);
ckalintra 0:7023c3f98f36 33 lcd.locate(0,0);
ckalintra 2:c696dfd53eeb 34 lcd.printf("p:%5.1f", pressuref);
ckalintra 5:8aa72ee456fc 35 lcd.locate(10,1);
ckalintra 5:8aa72ee456fc 36 lcd.printf("t:%3.1f", tempf);
ckalintra 2:c696dfd53eeb 37 display_time();
ckalintra 0:7023c3f98f36 38 }
ckalintra 0:7023c3f98f36 39 else if (dislcd == 0)
ckalintra 0:7023c3f98f36 40 {
ckalintra 0:7023c3f98f36 41 display_dates();
ckalintra 0:7023c3f98f36 42 display_time();
ckalintra 0:7023c3f98f36 43 }
ckalintra 3:f5fe5071416a 44 if (wdcounter >= watchdog_time)
ckalintra 3:f5fe5071416a 45 {
ckalintra 5:8aa72ee456fc 46 pc.printf("system stuck, reset\n\r");
ckalintra 3:f5fe5071416a 47 NVIC_SystemReset();
ckalintra 3:f5fe5071416a 48 }
ckalintra 0:7023c3f98f36 49 }
ckalintra 5:8aa72ee456fc 50 void watchdog()
ckalintra 5:8aa72ee456fc 51 {
ckalintra 5:8aa72ee456fc 52 wdcounter = 0;
ckalintra 5:8aa72ee456fc 53 watchdog = 1;
ckalintra 5:8aa72ee456fc 54 }
ckalintra 0:7023c3f98f36 55 void lcddisp()
ckalintra 0:7023c3f98f36 56 {
ckalintra 5:8aa72ee456fc 57
ckalintra 1:dc21a6fce3af 58 if (gather_data == 1)
ckalintra 1:dc21a6fce3af 59 {
ckalintra 5:8aa72ee456fc 60 redLED = 1;
ckalintra 1:dc21a6fce3af 61 display_time();
ckalintra 1:dc21a6fce3af 62 getdata();
ckalintra 1:dc21a6fce3af 63 store();
ckalintra 5:8aa72ee456fc 64 redLED = 0;
ckalintra 1:dc21a6fce3af 65 }
ckalintra 1:dc21a6fce3af 66 if (gather_data ==0)
ckalintra 1:dc21a6fce3af 67 {
ckalintra 5:8aa72ee456fc 68 redLED = 1;
ckalintra 2:c696dfd53eeb 69 wait(0.2);
ckalintra 1:dc21a6fce3af 70 }
ckalintra 5:8aa72ee456fc 71
ckalintra 0:7023c3f98f36 72 }
ckalintra 0:7023c3f98f36 73
ckalintra 0:7023c3f98f36 74 void check_display()
ckalintra 0:7023c3f98f36 75 {
ckalintra 0:7023c3f98f36 76 if(dislcd == 0)
ckalintra 0:7023c3f98f36 77 {dislcd = 1;}
ckalintra 0:7023c3f98f36 78 else
ckalintra 0:7023c3f98f36 79 {dislcd = 0;}
ckalintra 0:7023c3f98f36 80 }
ckalintra 0:7023c3f98f36 81
ckalintra 0:7023c3f98f36 82
ckalintra 0:7023c3f98f36 83 int main()
ckalintra 0:7023c3f98f36 84 {
ckalintra 0:7023c3f98f36 85 lcd.cls();
ckalintra 2:c696dfd53eeb 86
ckalintra 0:7023c3f98f36 87 //display_date_time();
ckalintra 0:7023c3f98f36 88 // while (pointer != 14)
ckalintra 0:7023c3f98f36 89 // {
ckalintra 0:7023c3f98f36 90 // select_date();
ckalintra 0:7023c3f98f36 91 // }
ckalintra 4:5dbb5145d0a9 92 //bmp.initialize();
ckalintra 2:c696dfd53eeb 93 pc.printf("\n\rputty ready\n\r");
ckalintra 0:7023c3f98f36 94 display.attach(&lcddisp, T);
ckalintra 0:7023c3f98f36 95 second_pass.attach(&second_tick, 1.0);
ckalintra 0:7023c3f98f36 96 button.rise(&check_display);
ckalintra 0:7023c3f98f36 97 while(1)
ckalintra 0:7023c3f98f36 98 {
ckalintra 2:c696dfd53eeb 99 check_display();
ckalintra 5:8aa72ee456fc 100 if (putty_enabled == 1)
ckalintra 5:8aa72ee456fc 101 {
ckalintra 5:8aa72ee456fc 102 //watchdog();
ckalintra 5:8aa72ee456fc 103 putty_write();
ckalintra 5:8aa72ee456fc 104 watchdog = 0;
ckalintra 5:8aa72ee456fc 105 }
ckalintra 5:8aa72ee456fc 106
ckalintra 5:8aa72ee456fc 107 if (putty_enabled == 0)
ckalintra 5:8aa72ee456fc 108 {
ckalintra 5:8aa72ee456fc 109 while(ch != 'p')
ckalintra 5:8aa72ee456fc 110 {
ckalintra 5:8aa72ee456fc 111 ch = 0;
ckalintra 5:8aa72ee456fc 112 yellowLED = 1;
ckalintra 5:8aa72ee456fc 113 ch = pc.getc();
ckalintra 5:8aa72ee456fc 114 }
ckalintra 5:8aa72ee456fc 115 putty_enabled = 1;
ckalintra 5:8aa72ee456fc 116 }
ckalintra 5:8aa72ee456fc 117 yellowLED = 0;
ckalintra 2:c696dfd53eeb 118 check_display();
ckalintra 2:c696dfd53eeb 119 if (interrupt == 1)
ckalintra 2:c696dfd53eeb 120 {
ckalintra 2:c696dfd53eeb 121 T = t;
ckalintra 2:c696dfd53eeb 122 display.attach(&lcddisp, T);
ckalintra 2:c696dfd53eeb 123 interrupt = 0;
ckalintra 2:c696dfd53eeb 124 }
ckalintra 5:8aa72ee456fc 125 //if(sw1 == 1 && sw2 == 1)
ckalintra 5:8aa72ee456fc 126 // {
ckalintra 5:8aa72ee456fc 127 // sd();
ckalintra 5:8aa72ee456fc 128 // }
ckalintra 0:7023c3f98f36 129 }
ckalintra 0:7023c3f98f36 130 }
ckalintra 0:7023c3f98f36 131
ckalintra 0:7023c3f98f36 132
ckalintra 0:7023c3f98f36 133