mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Committer:
okini3939
Date:
Mon Jul 04 15:16:45 2011 +0000
Revision:
0:bdb53686c194
Child:
1:6c7141895545

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:bdb53686c194 1 #include "mbed.h"
okini3939 0:bdb53686c194 2 #include "weather.h"
okini3939 0:bdb53686c194 3
okini3939 0:bdb53686c194 4 const char VERSION[] = "mbed Weather Platform 0.4.0 (C) 2011 Suga koubou";
okini3939 0:bdb53686c194 5 Serial pc(USBTX, USBRX);
okini3939 0:bdb53686c194 6 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
okini3939 0:bdb53686c194 7 static volatile int interval = 60;
okini3939 0:bdb53686c194 8 char csv[120];
okini3939 0:bdb53686c194 9 static char csv_mesg[120] = "%y-%m-%d %h:%i:%s,%.2P,%.2T,%.2H,%.2A,%.2V,%.2R,%.2L,%.2U,%.2M,%.2p\r\n";
okini3939 0:bdb53686c194 10
okini3939 0:bdb53686c194 11
okini3939 0:bdb53686c194 12 // Interrupt 10Hz
okini3939 0:bdb53686c194 13 void isr_timer () {
okini3939 0:bdb53686c194 14
okini3939 0:bdb53686c194 15 // uptime
okini3939 0:bdb53686c194 16 locUpTime = locUpTime + 10;
okini3939 0:bdb53686c194 17
okini3939 0:bdb53686c194 18 pool_ilip();
okini3939 0:bdb53686c194 19 pool_display();
okini3939 0:bdb53686c194 20
okini3939 0:bdb53686c194 21 LED_NET_OFF;
okini3939 0:bdb53686c194 22 }
okini3939 0:bdb53686c194 23
okini3939 0:bdb53686c194 24 void init () {
okini3939 0:bdb53686c194 25 char buf[128];
okini3939 0:bdb53686c194 26
okini3939 0:bdb53686c194 27 init_conf();
okini3939 0:bdb53686c194 28
okini3939 0:bdb53686c194 29 if (cfg.getValue("DIR", buf, sizeof(buf))) {
okini3939 0:bdb53686c194 30 init_ilip(buf);
okini3939 0:bdb53686c194 31 }
okini3939 0:bdb53686c194 32
okini3939 0:bdb53686c194 33 if (cfg.getValue("BAUD", buf, sizeof(buf))) {
okini3939 0:bdb53686c194 34 pc.baud(atoi(buf));
okini3939 0:bdb53686c194 35 }
okini3939 0:bdb53686c194 36
okini3939 0:bdb53686c194 37 if (cfg.getValue("CSV_MESG", csv_mesg, sizeof(csv_mesg))) {
okini3939 0:bdb53686c194 38 chop(csv_mesg);
okini3939 0:bdb53686c194 39 }
okini3939 0:bdb53686c194 40
okini3939 0:bdb53686c194 41 if (cfg.getValue("INTERVAL", buf, sizeof(buf))) {
okini3939 0:bdb53686c194 42 interval = atoi(buf);
okini3939 0:bdb53686c194 43 pc.printf("Interval: %d sec.\r\n", interval);
okini3939 0:bdb53686c194 44 }
okini3939 0:bdb53686c194 45
okini3939 0:bdb53686c194 46 init_file();
okini3939 0:bdb53686c194 47 init_display();
okini3939 0:bdb53686c194 48 init_net();
okini3939 0:bdb53686c194 49 }
okini3939 0:bdb53686c194 50
okini3939 0:bdb53686c194 51 int main() {
okini3939 0:bdb53686c194 52 Timer timer;
okini3939 0:bdb53686c194 53 Ticker ticker;
okini3939 0:bdb53686c194 54
okini3939 0:bdb53686c194 55 LED_BUSY_ON;
okini3939 0:bdb53686c194 56 init();
okini3939 0:bdb53686c194 57 LED_BUSY_OFF;
okini3939 0:bdb53686c194 58
okini3939 0:bdb53686c194 59 ticker.attach(&isr_timer, 0.1); // Interrupt 10Hz
okini3939 0:bdb53686c194 60 timer.start();
okini3939 0:bdb53686c194 61 while(1) {
okini3939 0:bdb53686c194 62 // main loop
okini3939 0:bdb53686c194 63 LED_BUSY_ON;
okini3939 0:bdb53686c194 64 pool_net();
okini3939 0:bdb53686c194 65
okini3939 0:bdb53686c194 66 __disable_irq();
okini3939 0:bdb53686c194 67 update_sensor();
okini3939 0:bdb53686c194 68 __enable_irq();
okini3939 0:bdb53686c194 69
okini3939 0:bdb53686c194 70 // create CSV
okini3939 0:bdb53686c194 71 format_str(csv_mesg, csv, sizeof(csv));
okini3939 0:bdb53686c194 72 pc.printf(csv);
okini3939 0:bdb53686c194 73 write_log(csv);
okini3939 0:bdb53686c194 74
okini3939 0:bdb53686c194 75 // in/out
okini3939 0:bdb53686c194 76 exec_ilip(1);
okini3939 0:bdb53686c194 77
okini3939 0:bdb53686c194 78 LED_BUSY_OFF;
okini3939 0:bdb53686c194 79
okini3939 0:bdb53686c194 80 while (locUpTime % 100 != 0) {
okini3939 0:bdb53686c194 81 pool_net();
okini3939 0:bdb53686c194 82 wait_ms(100);
okini3939 0:bdb53686c194 83 }
okini3939 0:bdb53686c194 84
okini3939 0:bdb53686c194 85 // interval (wait)
okini3939 0:bdb53686c194 86 while (timer.read() < interval) {
okini3939 0:bdb53686c194 87 pool_net();
okini3939 0:bdb53686c194 88 wait_ms(100);
okini3939 0:bdb53686c194 89
okini3939 0:bdb53686c194 90 // in/out (timer) 1s
okini3939 0:bdb53686c194 91 if (locUpTime % 100 == 0) {
okini3939 0:bdb53686c194 92 exec_ilip(0);
okini3939 0:bdb53686c194 93 }
okini3939 0:bdb53686c194 94
okini3939 0:bdb53686c194 95 // for debug
okini3939 0:bdb53686c194 96 if (pc.readable()) {
okini3939 0:bdb53686c194 97 int i;
okini3939 0:bdb53686c194 98 i = pc.getc();
okini3939 0:bdb53686c194 99 if (i == ' ') {
okini3939 0:bdb53686c194 100 break;
okini3939 0:bdb53686c194 101 } else {
okini3939 0:bdb53686c194 102 pc.printf("( %d )\r\n", (int)timer.read());
okini3939 0:bdb53686c194 103 }
okini3939 0:bdb53686c194 104 }
okini3939 0:bdb53686c194 105 }
okini3939 0:bdb53686c194 106 timer.reset();
okini3939 0:bdb53686c194 107 }
okini3939 0:bdb53686c194 108 }