StarBoard Orange - Example application No.4 (Version 0.0.1)

Dependencies:   mbed SDFileSystem

Committer:
shintamainjp
Date:
Mon Sep 20 06:32:27 2010 +0000
Revision:
1:cda1048cb9c9
Parent:
0:34080147c1da
Child:
2:3885fc2eefd8

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:34080147c1da 1 /**
shintamainjp 0:34080147c1da 2 * StarBoard Orange - Example application No.4 (Version 0.0.1)
shintamainjp 0:34080147c1da 3 * Make a GPS logger!
shintamainjp 0:34080147c1da 4 *
shintamainjp 0:34080147c1da 5 * See also ... http://mbed.org/users/shintamainjp/notebook/starboard_example4_ja/
shintamainjp 0:34080147c1da 6 * See also ... http://mbed.org/users/shintamainjp/notebook/starboard_example4_en/
shintamainjp 0:34080147c1da 7 *
shintamainjp 0:34080147c1da 8 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
shintamainjp 0:34080147c1da 9 * http://shinta.main.jp/
shintamainjp 0:34080147c1da 10 */
shintamainjp 0:34080147c1da 11
shintamainjp 0:34080147c1da 12 /*
shintamainjp 0:34080147c1da 13 * Connection map.
shintamainjp 0:34080147c1da 14 *
shintamainjp 0:34080147c1da 15 * +---+----------------+---------+
shintamainjp 0:34080147c1da 16 * |Pin|Target |Direction|
shintamainjp 0:34080147c1da 17 * +---+----------------+---------+
shintamainjp 0:34080147c1da 18 * |
shintamainjp 0:34080147c1da 19 * +---+----------------+---------+
shintamainjp 0:34080147c1da 20 */
shintamainjp 0:34080147c1da 21
shintamainjp 0:34080147c1da 22 #include "mbed.h"
shintamainjp 0:34080147c1da 23 #include "TextLCD.h"
shintamainjp 0:34080147c1da 24 #include "SerialGPS.h"
shintamainjp 0:34080147c1da 25 #include "SDFileSystem.h"
shintamainjp 0:34080147c1da 26 #include "ReceiverIR.h"
shintamainjp 0:34080147c1da 27 #include "RemoteIR.h"
shintamainjp 0:34080147c1da 28
shintamainjp 0:34080147c1da 29 /*
shintamainjp 0:34080147c1da 30 * Objects.
shintamainjp 0:34080147c1da 31 */
shintamainjp 0:34080147c1da 32 TextLCD lcd(p24, p26, p27, p28, p29, p30);
shintamainjp 0:34080147c1da 33 BusOut led(LED4, LED3, LED2, LED1);
shintamainjp 0:34080147c1da 34 SerialGPS gps(p9, p10);
shintamainjp 0:34080147c1da 35 SDFileSystem sd(p5, p6, p7, p8, "sd");
shintamainjp 0:34080147c1da 36 Ticker ticker;
shintamainjp 0:34080147c1da 37 ReceiverIR ir_rx(p15);
shintamainjp 0:34080147c1da 38
shintamainjp 0:34080147c1da 39 /*
shintamainjp 0:34080147c1da 40 * Variables.
shintamainjp 0:34080147c1da 41 */
shintamainjp 0:34080147c1da 42 static int display_mode = 0;
shintamainjp 0:34080147c1da 43
shintamainjp 0:34080147c1da 44 /*
shintamainjp 0:34080147c1da 45 * Functions.
shintamainjp 0:34080147c1da 46 */
shintamainjp 0:34080147c1da 47
shintamainjp 0:34080147c1da 48 /**
shintamainjp 0:34080147c1da 49 * A ticker function.
shintamainjp 0:34080147c1da 50 */
shintamainjp 0:34080147c1da 51 void func_ticker(void) {
shintamainjp 0:34080147c1da 52 led = led + 1;
shintamainjp 0:34080147c1da 53 }
shintamainjp 0:34080147c1da 54
shintamainjp 0:34080147c1da 55 /**
shintamainjp 0:34080147c1da 56 * A callback function for logging data.
shintamainjp 0:34080147c1da 57 */
shintamainjp 0:34080147c1da 58 void cbfunc_log(char *s) {
shintamainjp 1:cda1048cb9c9 59 // printf("%s\n", s);
shintamainjp 0:34080147c1da 60 }
shintamainjp 0:34080147c1da 61
shintamainjp 0:34080147c1da 62 /**
shintamainjp 0:34080147c1da 63 * A callback function for GGA.
shintamainjp 0:34080147c1da 64 *
shintamainjp 0:34080147c1da 65 * GGA - Global Positioning System Fixed Data.
shintamainjp 0:34080147c1da 66 */
shintamainjp 0:34080147c1da 67 void cbfunc_gga(SerialGPS::gps_gga_t *p) {
shintamainjp 0:34080147c1da 68 if (display_mode == 0) {
shintamainjp 0:34080147c1da 69 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 70 lcd.printf("%02d:%02d:%02d(P%d,S%d)", p->hour, p->min, p->sec, p->position_fix, p->satellites_used);
shintamainjp 0:34080147c1da 71 }
shintamainjp 0:34080147c1da 72
shintamainjp 0:34080147c1da 73 if (display_mode == 1) {
shintamainjp 0:34080147c1da 74 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 75 lcd.printf("%c=%10.4f", p->ns, p->latitude);
shintamainjp 0:34080147c1da 76 }
shintamainjp 0:34080147c1da 77 if (display_mode == 2) {
shintamainjp 0:34080147c1da 78 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 79 lcd.printf("%c=%10.4f", p->ew, p->longitude);
shintamainjp 0:34080147c1da 80 }
shintamainjp 0:34080147c1da 81 }
shintamainjp 0:34080147c1da 82
shintamainjp 0:34080147c1da 83 /**
shintamainjp 0:34080147c1da 84 * A callback function for GSA.
shintamainjp 0:34080147c1da 85 *
shintamainjp 0:34080147c1da 86 * GSA - GNSS DOP and Active Satellites.
shintamainjp 0:34080147c1da 87 */
shintamainjp 0:34080147c1da 88 void cbfunc_gsa(SerialGPS::gps_gsa_t *p) {
shintamainjp 0:34080147c1da 89 if (display_mode == 3) {
shintamainjp 0:34080147c1da 90 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 91 lcd.printf("SEL:%c FIX:%d", p->selmode, p->fix);
shintamainjp 0:34080147c1da 92 }
shintamainjp 0:34080147c1da 93 }
shintamainjp 0:34080147c1da 94
shintamainjp 0:34080147c1da 95 /**
shintamainjp 0:34080147c1da 96 * A callback function for GSV.
shintamainjp 0:34080147c1da 97 *
shintamainjp 0:34080147c1da 98 * GSV - GNSS Satellites in View.
shintamainjp 0:34080147c1da 99 */
shintamainjp 0:34080147c1da 100 void cbfunc_gsv(SerialGPS::gps_gsv_t *p) {
shintamainjp 0:34080147c1da 101 if (display_mode == 4) {
shintamainjp 0:34080147c1da 102 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 103 lcd.printf("Satellites:%2d", p->satcnt);
shintamainjp 0:34080147c1da 104 }
shintamainjp 0:34080147c1da 105 }
shintamainjp 0:34080147c1da 106
shintamainjp 0:34080147c1da 107 /**
shintamainjp 0:34080147c1da 108 * A callback function for RMC.
shintamainjp 0:34080147c1da 109 *
shintamainjp 0:34080147c1da 110 * RMC - Recommended Minimum Specific GNSS Data.
shintamainjp 0:34080147c1da 111 */
shintamainjp 0:34080147c1da 112 void cbfunc_rmc(SerialGPS::gps_rmc_t *p) {
shintamainjp 0:34080147c1da 113 if (display_mode == 5) {
shintamainjp 0:34080147c1da 114 lcd.locate(0, 1);
shintamainjp 0:34080147c1da 115 lcd.printf("%02d:%02d:%02d(%c)", p->hour, p->min, p->sec, p->status);
shintamainjp 0:34080147c1da 116 }
shintamainjp 0:34080147c1da 117 }
shintamainjp 0:34080147c1da 118
shintamainjp 0:34080147c1da 119 /**
shintamainjp 0:34080147c1da 120 * Entry point.
shintamainjp 0:34080147c1da 121 */
shintamainjp 0:34080147c1da 122 int main() {
shintamainjp 0:34080147c1da 123 /*
shintamainjp 0:34080147c1da 124 * Attach callback functions.
shintamainjp 0:34080147c1da 125 */
shintamainjp 0:34080147c1da 126 SerialGPS::gps_callback_t cb;
shintamainjp 0:34080147c1da 127 cb.cbfunc_log = cbfunc_log;
shintamainjp 0:34080147c1da 128 cb.cbfunc_gga = cbfunc_gga;
shintamainjp 0:34080147c1da 129 cb.cbfunc_gsa = cbfunc_gsa;
shintamainjp 0:34080147c1da 130 cb.cbfunc_gsv = cbfunc_gsv;
shintamainjp 0:34080147c1da 131 cb.cbfunc_rmc = cbfunc_rmc;
shintamainjp 0:34080147c1da 132 gps.attach(&cb);
shintamainjp 0:34080147c1da 133
shintamainjp 0:34080147c1da 134 /*
shintamainjp 0:34080147c1da 135 * Attach a ticker for interrupt test.
shintamainjp 0:34080147c1da 136 */
shintamainjp 0:34080147c1da 137 ticker.attach_us(&func_ticker, 250 * 1000);
shintamainjp 0:34080147c1da 138
shintamainjp 0:34080147c1da 139 /*
shintamainjp 0:34080147c1da 140 * Initial display.
shintamainjp 0:34080147c1da 141 */
shintamainjp 0:34080147c1da 142 lcd.cls();
shintamainjp 0:34080147c1da 143 lcd.printf("GGA (Time)");
shintamainjp 0:34080147c1da 144
shintamainjp 0:34080147c1da 145 /*
shintamainjp 0:34080147c1da 146 * Loop.
shintamainjp 0:34080147c1da 147 */
shintamainjp 0:34080147c1da 148 int irlen;
shintamainjp 0:34080147c1da 149 uint8_t irbuf[32];
shintamainjp 0:34080147c1da 150 RemoteIR::Format irfmt;
shintamainjp 0:34080147c1da 151 while (1) {
shintamainjp 0:34080147c1da 152 irlen = ir_rx.getData(&irfmt, irbuf, sizeof(irbuf) * 8);
shintamainjp 0:34080147c1da 153 if (0 < irlen) {
shintamainjp 0:34080147c1da 154 uint64_t n = 0;
shintamainjp 0:34080147c1da 155 for (int i = 0; i < irlen; i++) {
shintamainjp 0:34080147c1da 156 if (irbuf[i / 8] & (1 << (i % 8))) {
shintamainjp 0:34080147c1da 157 n = n | (1 << i);
shintamainjp 0:34080147c1da 158 }
shintamainjp 0:34080147c1da 159 }
shintamainjp 0:34080147c1da 160 // printf("%d:0x%llx\n", irlen, n);
shintamainjp 0:34080147c1da 161 if ((irlen == 12) && (irfmt == RemoteIR::SONY)) {
shintamainjp 0:34080147c1da 162 switch (n) {
shintamainjp 0:34080147c1da 163 case 0x80:
shintamainjp 0:34080147c1da 164 display_mode = 0;
shintamainjp 0:34080147c1da 165 lcd.cls();
shintamainjp 0:34080147c1da 166 lcd.printf("GGA (Time)");
shintamainjp 0:34080147c1da 167 break;
shintamainjp 0:34080147c1da 168 case 0x81:
shintamainjp 0:34080147c1da 169 display_mode = 1;
shintamainjp 0:34080147c1da 170 lcd.cls();
shintamainjp 0:34080147c1da 171 lcd.printf("GGA (Latitude)");
shintamainjp 0:34080147c1da 172 break;
shintamainjp 0:34080147c1da 173 case 0x82:
shintamainjp 0:34080147c1da 174 display_mode = 2;
shintamainjp 0:34080147c1da 175 lcd.cls();
shintamainjp 0:34080147c1da 176 lcd.printf("GGA (Longitude)");
shintamainjp 0:34080147c1da 177 break;
shintamainjp 0:34080147c1da 178 case 0x83:
shintamainjp 0:34080147c1da 179 display_mode = 3;
shintamainjp 0:34080147c1da 180 lcd.cls();
shintamainjp 0:34080147c1da 181 lcd.printf("GSA (Statuses)");
shintamainjp 0:34080147c1da 182 break;
shintamainjp 0:34080147c1da 183 case 0x84:
shintamainjp 0:34080147c1da 184 display_mode = 4;
shintamainjp 0:34080147c1da 185 lcd.cls();
shintamainjp 0:34080147c1da 186 lcd.printf("GSV (Satellites)");
shintamainjp 0:34080147c1da 187 break;
shintamainjp 0:34080147c1da 188 case 0x85:
shintamainjp 0:34080147c1da 189 display_mode = 5;
shintamainjp 0:34080147c1da 190 lcd.cls();
shintamainjp 0:34080147c1da 191 lcd.printf("RMC (Time)");
shintamainjp 0:34080147c1da 192 break;
shintamainjp 0:34080147c1da 193 default:
shintamainjp 0:34080147c1da 194 break;
shintamainjp 0:34080147c1da 195 }
shintamainjp 0:34080147c1da 196 }
shintamainjp 0:34080147c1da 197 }
shintamainjp 0:34080147c1da 198 gps.processing();
shintamainjp 0:34080147c1da 199 }
shintamainjp 0:34080147c1da 200 }