StarBoard Orange - Example application No.4 (Version 0.0.1)
Dependencies: mbed SDFileSystem
main.cpp@0:34080147c1da, 2010-09-20 (annotated)
- Committer:
- shintamainjp
- Date:
- Mon Sep 20 06:20:27 2010 +0000
- Revision:
- 0:34080147c1da
- Child:
- 1:cda1048cb9c9
Who changed what in which revision?
User | Revision | Line number | New 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 bool sd_disabled = false; |
shintamainjp | 0:34080147c1da | 43 | static FILE *fp = NULL; |
shintamainjp | 0:34080147c1da | 44 | static int display_mode = 0; |
shintamainjp | 0:34080147c1da | 45 | |
shintamainjp | 0:34080147c1da | 46 | /* |
shintamainjp | 0:34080147c1da | 47 | * Functions. |
shintamainjp | 0:34080147c1da | 48 | */ |
shintamainjp | 0:34080147c1da | 49 | |
shintamainjp | 0:34080147c1da | 50 | /** |
shintamainjp | 0:34080147c1da | 51 | * A ticker function. |
shintamainjp | 0:34080147c1da | 52 | */ |
shintamainjp | 0:34080147c1da | 53 | void func_ticker(void) { |
shintamainjp | 0:34080147c1da | 54 | led = led + 1; |
shintamainjp | 0:34080147c1da | 55 | } |
shintamainjp | 0:34080147c1da | 56 | |
shintamainjp | 0:34080147c1da | 57 | /** |
shintamainjp | 0:34080147c1da | 58 | * A callback function for logging data. |
shintamainjp | 0:34080147c1da | 59 | */ |
shintamainjp | 0:34080147c1da | 60 | void cbfunc_log(char *s) { |
shintamainjp | 0:34080147c1da | 61 | if (!sd_disabled) { |
shintamainjp | 0:34080147c1da | 62 | fprintf(fp, "%s\n", s); |
shintamainjp | 0:34080147c1da | 63 | fflush(fp); |
shintamainjp | 0:34080147c1da | 64 | } else { |
shintamainjp | 0:34080147c1da | 65 | // printf("%s\n", s); |
shintamainjp | 0:34080147c1da | 66 | } |
shintamainjp | 0:34080147c1da | 67 | } |
shintamainjp | 0:34080147c1da | 68 | |
shintamainjp | 0:34080147c1da | 69 | /** |
shintamainjp | 0:34080147c1da | 70 | * A callback function for GGA. |
shintamainjp | 0:34080147c1da | 71 | * |
shintamainjp | 0:34080147c1da | 72 | * GGA - Global Positioning System Fixed Data. |
shintamainjp | 0:34080147c1da | 73 | */ |
shintamainjp | 0:34080147c1da | 74 | void cbfunc_gga(SerialGPS::gps_gga_t *p) { |
shintamainjp | 0:34080147c1da | 75 | if (display_mode == 0) { |
shintamainjp | 0:34080147c1da | 76 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 77 | lcd.printf("%02d:%02d:%02d(P%d,S%d)", p->hour, p->min, p->sec, p->position_fix, p->satellites_used); |
shintamainjp | 0:34080147c1da | 78 | } |
shintamainjp | 0:34080147c1da | 79 | |
shintamainjp | 0:34080147c1da | 80 | if (display_mode == 1) { |
shintamainjp | 0:34080147c1da | 81 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 82 | lcd.printf("%c=%10.4f", p->ns, p->latitude); |
shintamainjp | 0:34080147c1da | 83 | } |
shintamainjp | 0:34080147c1da | 84 | if (display_mode == 2) { |
shintamainjp | 0:34080147c1da | 85 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 86 | lcd.printf("%c=%10.4f", p->ew, p->longitude); |
shintamainjp | 0:34080147c1da | 87 | } |
shintamainjp | 0:34080147c1da | 88 | } |
shintamainjp | 0:34080147c1da | 89 | |
shintamainjp | 0:34080147c1da | 90 | /** |
shintamainjp | 0:34080147c1da | 91 | * A callback function for GSA. |
shintamainjp | 0:34080147c1da | 92 | * |
shintamainjp | 0:34080147c1da | 93 | * GSA - GNSS DOP and Active Satellites. |
shintamainjp | 0:34080147c1da | 94 | */ |
shintamainjp | 0:34080147c1da | 95 | void cbfunc_gsa(SerialGPS::gps_gsa_t *p) { |
shintamainjp | 0:34080147c1da | 96 | if (display_mode == 3) { |
shintamainjp | 0:34080147c1da | 97 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 98 | lcd.printf("SEL:%c FIX:%d", p->selmode, p->fix); |
shintamainjp | 0:34080147c1da | 99 | } |
shintamainjp | 0:34080147c1da | 100 | } |
shintamainjp | 0:34080147c1da | 101 | |
shintamainjp | 0:34080147c1da | 102 | /** |
shintamainjp | 0:34080147c1da | 103 | * A callback function for GSV. |
shintamainjp | 0:34080147c1da | 104 | * |
shintamainjp | 0:34080147c1da | 105 | * GSV - GNSS Satellites in View. |
shintamainjp | 0:34080147c1da | 106 | */ |
shintamainjp | 0:34080147c1da | 107 | void cbfunc_gsv(SerialGPS::gps_gsv_t *p) { |
shintamainjp | 0:34080147c1da | 108 | if (display_mode == 4) { |
shintamainjp | 0:34080147c1da | 109 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 110 | lcd.printf("Satellites:%2d", p->satcnt); |
shintamainjp | 0:34080147c1da | 111 | } |
shintamainjp | 0:34080147c1da | 112 | } |
shintamainjp | 0:34080147c1da | 113 | |
shintamainjp | 0:34080147c1da | 114 | /** |
shintamainjp | 0:34080147c1da | 115 | * A callback function for RMC. |
shintamainjp | 0:34080147c1da | 116 | * |
shintamainjp | 0:34080147c1da | 117 | * RMC - Recommended Minimum Specific GNSS Data. |
shintamainjp | 0:34080147c1da | 118 | */ |
shintamainjp | 0:34080147c1da | 119 | void cbfunc_rmc(SerialGPS::gps_rmc_t *p) { |
shintamainjp | 0:34080147c1da | 120 | if (display_mode == 5) { |
shintamainjp | 0:34080147c1da | 121 | lcd.locate(0, 1); |
shintamainjp | 0:34080147c1da | 122 | lcd.printf("%02d:%02d:%02d(%c)", p->hour, p->min, p->sec, p->status); |
shintamainjp | 0:34080147c1da | 123 | } |
shintamainjp | 0:34080147c1da | 124 | } |
shintamainjp | 0:34080147c1da | 125 | |
shintamainjp | 0:34080147c1da | 126 | /** |
shintamainjp | 0:34080147c1da | 127 | * Entry point. |
shintamainjp | 0:34080147c1da | 128 | */ |
shintamainjp | 0:34080147c1da | 129 | int main() { |
shintamainjp | 0:34080147c1da | 130 | /* |
shintamainjp | 0:34080147c1da | 131 | * Attach callback functions. |
shintamainjp | 0:34080147c1da | 132 | */ |
shintamainjp | 0:34080147c1da | 133 | SerialGPS::gps_callback_t cb; |
shintamainjp | 0:34080147c1da | 134 | cb.cbfunc_log = cbfunc_log; |
shintamainjp | 0:34080147c1da | 135 | cb.cbfunc_gga = cbfunc_gga; |
shintamainjp | 0:34080147c1da | 136 | cb.cbfunc_gsa = cbfunc_gsa; |
shintamainjp | 0:34080147c1da | 137 | cb.cbfunc_gsv = cbfunc_gsv; |
shintamainjp | 0:34080147c1da | 138 | cb.cbfunc_rmc = cbfunc_rmc; |
shintamainjp | 0:34080147c1da | 139 | gps.attach(&cb); |
shintamainjp | 0:34080147c1da | 140 | |
shintamainjp | 0:34080147c1da | 141 | /* |
shintamainjp | 0:34080147c1da | 142 | * Test a SD card. |
shintamainjp | 0:34080147c1da | 143 | */ |
shintamainjp | 0:34080147c1da | 144 | fp = fopen("/sd/gpslog.txt", "w"); |
shintamainjp | 0:34080147c1da | 145 | if (fp == NULL) { |
shintamainjp | 0:34080147c1da | 146 | sd_disabled = true; |
shintamainjp | 0:34080147c1da | 147 | } else { |
shintamainjp | 0:34080147c1da | 148 | sd_disabled = false; |
shintamainjp | 0:34080147c1da | 149 | fprintf(fp, "Hello World!\n"); |
shintamainjp | 0:34080147c1da | 150 | } |
shintamainjp | 0:34080147c1da | 151 | |
shintamainjp | 0:34080147c1da | 152 | /* |
shintamainjp | 0:34080147c1da | 153 | * Attach a ticker for interrupt test. |
shintamainjp | 0:34080147c1da | 154 | */ |
shintamainjp | 0:34080147c1da | 155 | ticker.attach_us(&func_ticker, 250 * 1000); |
shintamainjp | 0:34080147c1da | 156 | |
shintamainjp | 0:34080147c1da | 157 | /* |
shintamainjp | 0:34080147c1da | 158 | * Initial display. |
shintamainjp | 0:34080147c1da | 159 | */ |
shintamainjp | 0:34080147c1da | 160 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 161 | lcd.printf("GGA (Time)"); |
shintamainjp | 0:34080147c1da | 162 | |
shintamainjp | 0:34080147c1da | 163 | /* |
shintamainjp | 0:34080147c1da | 164 | * Loop. |
shintamainjp | 0:34080147c1da | 165 | */ |
shintamainjp | 0:34080147c1da | 166 | int irlen; |
shintamainjp | 0:34080147c1da | 167 | uint8_t irbuf[32]; |
shintamainjp | 0:34080147c1da | 168 | RemoteIR::Format irfmt; |
shintamainjp | 0:34080147c1da | 169 | while (1) { |
shintamainjp | 0:34080147c1da | 170 | irlen = ir_rx.getData(&irfmt, irbuf, sizeof(irbuf) * 8); |
shintamainjp | 0:34080147c1da | 171 | if (0 < irlen) { |
shintamainjp | 0:34080147c1da | 172 | uint64_t n = 0; |
shintamainjp | 0:34080147c1da | 173 | for (int i = 0; i < irlen; i++) { |
shintamainjp | 0:34080147c1da | 174 | if (irbuf[i / 8] & (1 << (i % 8))) { |
shintamainjp | 0:34080147c1da | 175 | n = n | (1 << i); |
shintamainjp | 0:34080147c1da | 176 | } |
shintamainjp | 0:34080147c1da | 177 | } |
shintamainjp | 0:34080147c1da | 178 | // printf("%d:0x%llx\n", irlen, n); |
shintamainjp | 0:34080147c1da | 179 | if ((irlen == 12) && (irfmt == RemoteIR::SONY)) { |
shintamainjp | 0:34080147c1da | 180 | switch (n) { |
shintamainjp | 0:34080147c1da | 181 | case 0x80: |
shintamainjp | 0:34080147c1da | 182 | display_mode = 0; |
shintamainjp | 0:34080147c1da | 183 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 184 | lcd.printf("GGA (Time)"); |
shintamainjp | 0:34080147c1da | 185 | break; |
shintamainjp | 0:34080147c1da | 186 | case 0x81: |
shintamainjp | 0:34080147c1da | 187 | display_mode = 1; |
shintamainjp | 0:34080147c1da | 188 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 189 | lcd.printf("GGA (Latitude)"); |
shintamainjp | 0:34080147c1da | 190 | break; |
shintamainjp | 0:34080147c1da | 191 | case 0x82: |
shintamainjp | 0:34080147c1da | 192 | display_mode = 2; |
shintamainjp | 0:34080147c1da | 193 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 194 | lcd.printf("GGA (Longitude)"); |
shintamainjp | 0:34080147c1da | 195 | break; |
shintamainjp | 0:34080147c1da | 196 | case 0x83: |
shintamainjp | 0:34080147c1da | 197 | display_mode = 3; |
shintamainjp | 0:34080147c1da | 198 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 199 | lcd.printf("GSA (Statuses)"); |
shintamainjp | 0:34080147c1da | 200 | break; |
shintamainjp | 0:34080147c1da | 201 | case 0x84: |
shintamainjp | 0:34080147c1da | 202 | display_mode = 4; |
shintamainjp | 0:34080147c1da | 203 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 204 | lcd.printf("GSV (Satellites)"); |
shintamainjp | 0:34080147c1da | 205 | break; |
shintamainjp | 0:34080147c1da | 206 | case 0x85: |
shintamainjp | 0:34080147c1da | 207 | display_mode = 5; |
shintamainjp | 0:34080147c1da | 208 | lcd.cls(); |
shintamainjp | 0:34080147c1da | 209 | lcd.printf("RMC (Time)"); |
shintamainjp | 0:34080147c1da | 210 | break; |
shintamainjp | 0:34080147c1da | 211 | default: |
shintamainjp | 0:34080147c1da | 212 | break; |
shintamainjp | 0:34080147c1da | 213 | } |
shintamainjp | 0:34080147c1da | 214 | } |
shintamainjp | 0:34080147c1da | 215 | } |
shintamainjp | 0:34080147c1da | 216 | gps.processing(); |
shintamainjp | 0:34080147c1da | 217 | } |
shintamainjp | 0:34080147c1da | 218 | } |