2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Committer:
shimniok
Date:
Thu Jan 03 19:07:20 2019 +0000
Revision:
43:9a285515f33a
Parent:
42:8d99f64f5898
Child:
44:0d72a8a1288a
implemented tinygps serial, parsing, and callback

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:7e98bbfd102a 1 /* mbed Microcontroller Library
shimniok 0:7e98bbfd102a 2 * Copyright (c) 2018 ARM Limited
shimniok 0:7e98bbfd102a 3 * SPDX-License-Identifier: Apache-2.0
shimniok 0:7e98bbfd102a 4 */
shimniok 0:7e98bbfd102a 5
shimniok 0:7e98bbfd102a 6 #include "mbed.h"
shimniok 0:7e98bbfd102a 7 #include <stdio.h>
shimniok 0:7e98bbfd102a 8 #include <errno.h>
shimniok 16:eb28d0f64a9b 9 #include "pinouts.h"
shimniok 0:7e98bbfd102a 10 #include "stats_report.h"
shimniok 0:7e98bbfd102a 11 #include "SDBlockDevice.h"
shimniok 0:7e98bbfd102a 12 #include "FATFileSystem.h"
shimniok 35:c42e7e29c3bd 13 #include "Servo.h"
shimniok 0:7e98bbfd102a 14 #include "SimpleShell.h"
shimniok 4:de7feb458652 15 #include "Config.h"
shimniok 11:8ec858b7c6d1 16 #include "Updater.h"
shimniok 43:9a285515f33a 17 //#include "Ublox6.h"
shimniok 43:9a285515f33a 18 #include "TinyGPS.h"
shimniok 24:a7f92dfc5310 19 #include "Logger.h"
shimniok 24:a7f92dfc5310 20 #include "SystemState.h"
shimniok 37:b8259500dbd3 21 #include "Display.h"
shimniok 0:7e98bbfd102a 22
shimniok 24:a7f92dfc5310 23 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 24 // Config
shimniok 24:a7f92dfc5310 25 Config config;
shimniok 24:a7f92dfc5310 26
shimniok 42:8d99f64f5898 27
shimniok 24:a7f92dfc5310 28 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 29 // Devices
shimniok 30:ed791f1f7f7d 30 DigitalOut led1(LED1);
shimniok 30:ed791f1f7f7d 31 DigitalOut led2(LED2);
shimniok 30:ed791f1f7f7d 32 DigitalOut led3(LED3);
shimniok 30:ed791f1f7f7d 33 DigitalOut led4(LED4);
shimniok 0:7e98bbfd102a 34 LocalFileSystem lfs("etc");
shimniok 24:a7f92dfc5310 35 SDBlockDevice bd(p5, p6, p7, p8); // MOSI, MISO, CLK, CS
shimniok 24:a7f92dfc5310 36 FATFileSystem ffs("log", &bd);
shimniok 24:a7f92dfc5310 37 Serial pc(USBTX, USBRX);
shimniok 43:9a285515f33a 38 //RawSerial s(UART1TX, UART1RX, 38400);
shimniok 43:9a285515f33a 39 RawSerial s(UART1TX, UART1RX, 19200);
shimniok 33:74c514aea0a1 40 InterruptIn lbutton(LBUTTON, PullUp); // button interrupts
shimniok 33:74c514aea0a1 41 InterruptIn cbutton(CBUTTON, PullUp);
shimniok 33:74c514aea0a1 42 InterruptIn rbutton(RBUTTON, PullUp);
shimniok 35:c42e7e29c3bd 43 Servo steer(STEERING);
shimniok 35:c42e7e29c3bd 44 Servo esc(THROTTLE);
shimniok 20:043987d06f8d 45
shimniok 19:0d1728091519 46
shimniok 24:a7f92dfc5310 47 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 48 // Logging
shimniok 29:cb2f55fbfe9c 49 EventQueue logQueue(16 * EVENTS_EVENT_SIZE);
shimniok 31:20a95043adb0 50 Logger logger;
shimniok 25:b8176ebb96c6 51
shimniok 42:8d99f64f5898 52
shimniok 42:8d99f64f5898 53 ///////////////////////////////////////////////////////////////////////////////
shimniok 42:8d99f64f5898 54 // Display
shimniok 42:8d99f64f5898 55 EventQueue lcdQueue(8 * EVENTS_EVENT_SIZE);
shimniok 42:8d99f64f5898 56 Display display(UART3TX, UART3RX);
shimniok 42:8d99f64f5898 57
shimniok 42:8d99f64f5898 58 const uint64_t sample_time_ms = 50;
shimniok 42:8d99f64f5898 59
shimniok 42:8d99f64f5898 60 void compute_cpu_stats()
shimniok 42:8d99f64f5898 61 {
shimniok 42:8d99f64f5898 62 static uint64_t prev_idle_time = 0;
shimniok 42:8d99f64f5898 63 mbed_stats_cpu_t cpu_stats;
shimniok 42:8d99f64f5898 64
shimniok 42:8d99f64f5898 65 // Collect and print cpu stats
shimniok 42:8d99f64f5898 66 mbed_stats_cpu_get(&cpu_stats);
shimniok 42:8d99f64f5898 67
shimniok 42:8d99f64f5898 68 uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
shimniok 42:8d99f64f5898 69 uint8_t idle = (diff * 100) / (sample_time_ms * 1000); // usec;
shimniok 42:8d99f64f5898 70 prev_idle_time = cpu_stats.idle_time;
shimniok 42:8d99f64f5898 71 display.cpu(idle);
shimniok 42:8d99f64f5898 72 }
shimniok 42:8d99f64f5898 73
shimniok 25:b8176ebb96c6 74 ///////////////////////////////////////////////////////////////////////////////
shimniok 25:b8176ebb96c6 75 // Updater
shimniok 25:b8176ebb96c6 76 Updater *u = Updater::instance();
shimniok 26:2dc31a801cc8 77 EventQueue updaterQueue(8 * EVENTS_EVENT_SIZE);
shimniok 25:b8176ebb96c6 78
shimniok 25:b8176ebb96c6 79 void updater_callback() {
shimniok 30:ed791f1f7f7d 80 SensorData d;
shimniok 30:ed791f1f7f7d 81 float dt;
shimniok 42:8d99f64f5898 82 static int count = 0;
shimniok 30:ed791f1f7f7d 83
shimniok 25:b8176ebb96c6 84 led1 = !led1;
shimniok 30:ed791f1f7f7d 85 d.timestamp = Kernel::get_ms_count();
shimniok 30:ed791f1f7f7d 86 d.encoder = u->encoder();
shimniok 32:eb673f6f5734 87 u->imu(d.gyro, d.accel, d.mag, dt);
shimniok 30:ed791f1f7f7d 88 logQueue.call(&logger, &Logger::log_sensors, d);
shimniok 42:8d99f64f5898 89 if (count++ > 10) {
shimniok 42:8d99f64f5898 90 lcdQueue.call(&display, &Display::imu, d);
shimniok 42:8d99f64f5898 91 count = 0;
shimniok 42:8d99f64f5898 92 }
shimniok 25:b8176ebb96c6 93 }
shimniok 25:b8176ebb96c6 94
shimniok 42:8d99f64f5898 95
shimniok 24:a7f92dfc5310 96 ///////////////////////////////////////////////////////////////////////////////
shimniok 30:ed791f1f7f7d 97 // Buttons
shimniok 30:ed791f1f7f7d 98 EventQueue buttonQueue(16 * EVENTS_EVENT_SIZE);
shimniok 33:74c514aea0a1 99 const int BUTTON_DEBOUNCE_SAMPLES = 20;
shimniok 33:74c514aea0a1 100 const int BUTTON_DEBOUNCE_THRESH = 8;
shimniok 33:74c514aea0a1 101 const int BUTTON_SAMPLE_MS = 0.005;
shimniok 30:ed791f1f7f7d 102
shimniok 30:ed791f1f7f7d 103 void button_event() {
shimniok 33:74c514aea0a1 104 int samples = 0;
shimniok 33:74c514aea0a1 105
shimniok 33:74c514aea0a1 106 // disable subsequent interrupts
shimniok 33:74c514aea0a1 107 lbutton.fall(NULL);
shimniok 33:74c514aea0a1 108
shimniok 33:74c514aea0a1 109 // sample repeatedly to debounce
shimniok 33:74c514aea0a1 110 for (int i=0; i < BUTTON_DEBOUNCE_SAMPLES; i++) {
shimniok 33:74c514aea0a1 111 if (lbutton == 0) samples++;
shimniok 33:74c514aea0a1 112 wait(BUTTON_SAMPLE_MS);
shimniok 33:74c514aea0a1 113 }
shimniok 33:74c514aea0a1 114
shimniok 33:74c514aea0a1 115 if (samples > BUTTON_DEBOUNCE_THRESH) {
shimniok 30:ed791f1f7f7d 116 if (logger.enabled()) {
shimniok 30:ed791f1f7f7d 117 logQueue.call(&logger, &Logger::stop);
shimniok 30:ed791f1f7f7d 118 led3 = 0;
shimniok 30:ed791f1f7f7d 119 } else {
shimniok 30:ed791f1f7f7d 120 logQueue.call(&logger, &Logger::start);
shimniok 30:ed791f1f7f7d 121 led3 = 1;
shimniok 30:ed791f1f7f7d 122 }
shimniok 30:ed791f1f7f7d 123 }
shimniok 33:74c514aea0a1 124
shimniok 33:74c514aea0a1 125 lbutton.fall(buttonQueue.event(button_event));
shimniok 30:ed791f1f7f7d 126 }
shimniok 30:ed791f1f7f7d 127
shimniok 30:ed791f1f7f7d 128
shimniok 30:ed791f1f7f7d 129 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 130 // GPS
shimniok 43:9a285515f33a 131 //Ublox6 ublox;
shimniok 43:9a285515f33a 132 TinyGPS gps;
shimniok 24:a7f92dfc5310 133 EventQueue gpsQueue(8 * EVENTS_EVENT_SIZE);
shimniok 23:5e61cf4a8c34 134
shimniok 23:5e61cf4a8c34 135 // Callback for gps parse data ready
shimniok 23:5e61cf4a8c34 136 void gps_callback() {
shimniok 24:a7f92dfc5310 137 GpsData d;
shimniok 24:a7f92dfc5310 138
shimniok 25:b8176ebb96c6 139 led2 = !led2;
shimniok 43:9a285515f33a 140 //ublox.read(d.latitude, d.longitude, d.course, d.speed, d.hdop, d.svcount);
shimniok 43:9a285515f33a 141 gps.read(d.latitude, d.longitude, d.course, d.speed, d.hdop, d.svcount);
shimniok 30:ed791f1f7f7d 142 d.timestamp = Kernel::get_ms_count();
shimniok 29:cb2f55fbfe9c 143 logQueue.call(&logger, &Logger::log_gps, d);
shimniok 39:465213249f71 144 lcdQueue.call(&display, &Display::gps, d);
shimniok 23:5e61cf4a8c34 145 }
shimniok 29:cb2f55fbfe9c 146
shimniok 22:4d62bd16f037 147 // ISR for GPS serial, passes off to thread
shimniok 20:043987d06f8d 148 void gps_handler() {
shimniok 22:4d62bd16f037 149 while (s.readable()) {
shimniok 43:9a285515f33a 150 char c = s.getc();
shimniok 43:9a285515f33a 151 //gpsQueue.call(&ublox, &Ublox6::parse, c);
shimniok 43:9a285515f33a 152 gpsQueue.call(&gps, &TinyGPS::parse, c);
shimniok 16:eb28d0f64a9b 153 }
shimniok 19:0d1728091519 154 }
shimniok 16:eb28d0f64a9b 155
shimniok 42:8d99f64f5898 156
shimniok 24:a7f92dfc5310 157 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 158 // Shell
shimniok 30:ed791f1f7f7d 159 SimpleShell sh("/log");
shimniok 9:fc3575d2cbbf 160
shimniok 24:a7f92dfc5310 161 void test(int argc, char **argv) {
shimniok 35:c42e7e29c3bd 162 //printf("Hello world!\n");
shimniok 35:c42e7e29c3bd 163 char file[32];
shimniok 35:c42e7e29c3bd 164
shimniok 35:c42e7e29c3bd 165 for (int i=30; i < 40; i++) {
shimniok 35:c42e7e29c3bd 166 sprintf(file, "/log/%04d.csv", i);
shimniok 35:c42e7e29c3bd 167 printf("removing <%s>\n", file);
shimniok 35:c42e7e29c3bd 168 int stat = remove(file);
shimniok 35:c42e7e29c3bd 169 printf("return: %d\n", stat);
shimniok 35:c42e7e29c3bd 170 }
shimniok 1:7019a60fd585 171 }
shimniok 1:7019a60fd585 172
shimniok 24:a7f92dfc5310 173 void stats(int argc, char **argv) {
shimniok 24:a7f92dfc5310 174 SystemReport r(200);
shimniok 24:a7f92dfc5310 175 r.report_state();
shimniok 24:a7f92dfc5310 176 return;
shimniok 24:a7f92dfc5310 177 }
shimniok 24:a7f92dfc5310 178
shimniok 24:a7f92dfc5310 179 void read_gps(int argc, char **argv)
shimniok 18:3f8a8f6e3cc1 180 {
shimniok 18:3f8a8f6e3cc1 181 double lat=0;
shimniok 18:3f8a8f6e3cc1 182 double lon=0;
shimniok 18:3f8a8f6e3cc1 183 float course=0;
shimniok 18:3f8a8f6e3cc1 184 float speed=0;
shimniok 18:3f8a8f6e3cc1 185 float hdop=0.0;
shimniok 18:3f8a8f6e3cc1 186 int svcount=0;
shimniok 18:3f8a8f6e3cc1 187
shimniok 43:9a285515f33a 188 gps.read(lat, lon, course, speed, hdop, svcount);
shimniok 18:3f8a8f6e3cc1 189 printf("%3.7f %3.7f\n", lat, lon);
shimniok 18:3f8a8f6e3cc1 190 printf("hdg=%03.1f deg spd=%3.1f m/s\n", course, speed);
shimniok 18:3f8a8f6e3cc1 191 printf("%d %f\n", svcount, hdop);
shimniok 18:3f8a8f6e3cc1 192 }
shimniok 18:3f8a8f6e3cc1 193
shimniok 32:eb673f6f5734 194 void read_imu(int argc, char **argv)
shimniok 9:fc3575d2cbbf 195 {
shimniok 12:3cd91e150d9c 196 int g[3];
shimniok 32:eb673f6f5734 197 int a[3];
shimniok 32:eb673f6f5734 198 int m[3];
shimniok 13:5566df1250f1 199 float dt;
shimniok 12:3cd91e150d9c 200
shimniok 11:8ec858b7c6d1 201 Updater *u = Updater::instance();
shimniok 11:8ec858b7c6d1 202
shimniok 32:eb673f6f5734 203 u->imu(g, a, m, dt);
shimniok 32:eb673f6f5734 204
shimniok 32:eb673f6f5734 205 printf(" Gyro: %d, %d, %d\n", g[0], g[1], g[2]);
shimniok 32:eb673f6f5734 206 printf(" Accel: %d, %d, %d\n", a[0], a[1], a[2]);
shimniok 32:eb673f6f5734 207 printf(" Mag: %d, %d, %d\n", m[0], m[1], m[2]);
shimniok 32:eb673f6f5734 208 printf(" dt: %f\n", dt);
shimniok 12:3cd91e150d9c 209 }
shimniok 12:3cd91e150d9c 210
shimniok 24:a7f92dfc5310 211 void read_enc(int argc, char **argv)
shimniok 14:1dd83e626153 212 {
shimniok 14:1dd83e626153 213 Updater *u = Updater::instance();
shimniok 14:1dd83e626153 214
shimniok 14:1dd83e626153 215 printf("Encoder: %d\n", u->encoder());
shimniok 14:1dd83e626153 216 }
shimniok 14:1dd83e626153 217
shimniok 29:cb2f55fbfe9c 218 void log(int argc, char **argv)
shimniok 29:cb2f55fbfe9c 219 {
shimniok 29:cb2f55fbfe9c 220 char *usage = "usage: log [start|stop]";
shimniok 29:cb2f55fbfe9c 221
shimniok 29:cb2f55fbfe9c 222 if (argc == 1) {
shimniok 29:cb2f55fbfe9c 223 printf("logging ");
shimniok 29:cb2f55fbfe9c 224 if (logger.enabled())
shimniok 29:cb2f55fbfe9c 225 printf("enabled");
shimniok 29:cb2f55fbfe9c 226 else
shimniok 29:cb2f55fbfe9c 227 printf("disabled");
shimniok 29:cb2f55fbfe9c 228 printf("\n");
shimniok 29:cb2f55fbfe9c 229 } else if (argc == 2) {
shimniok 29:cb2f55fbfe9c 230 if (!strcmp("start", argv[1])) {
shimniok 29:cb2f55fbfe9c 231 logger.start();
shimniok 29:cb2f55fbfe9c 232 } else if (!strcmp("stop", argv[1])) {
shimniok 29:cb2f55fbfe9c 233 logger.stop();
shimniok 29:cb2f55fbfe9c 234 } else {
shimniok 29:cb2f55fbfe9c 235 puts(usage);
shimniok 29:cb2f55fbfe9c 236 }
shimniok 29:cb2f55fbfe9c 237 } else {
shimniok 29:cb2f55fbfe9c 238 puts(usage);
shimniok 29:cb2f55fbfe9c 239 }
shimniok 29:cb2f55fbfe9c 240 }
shimniok 29:cb2f55fbfe9c 241
shimniok 29:cb2f55fbfe9c 242
shimniok 24:a7f92dfc5310 243 void bridge_uart1(int argc, char **argv) {
shimniok 20:043987d06f8d 244 RawSerial s(UART1TX, UART1RX, 38400);
shimniok 20:043987d06f8d 245 while (1) {
shimniok 20:043987d06f8d 246 if (pc.readable()) s.putc(pc.getc());
shimniok 20:043987d06f8d 247 if (s.readable()) pc.putc(s.getc());
shimniok 20:043987d06f8d 248 }
shimniok 20:043987d06f8d 249 }
shimniok 20:043987d06f8d 250
shimniok 42:8d99f64f5898 251
shimniok 42:8d99f64f5898 252 void bridge_uart2() {
shimniok 42:8d99f64f5898 253 RawSerial s(UART2TX, UART2RX, 19200);
shimniok 42:8d99f64f5898 254 while (1) {
shimniok 42:8d99f64f5898 255 if (pc.readable()) s.putc(pc.getc());
shimniok 42:8d99f64f5898 256 if (s.readable()) pc.putc(s.getc());
shimniok 42:8d99f64f5898 257 }
shimniok 42:8d99f64f5898 258 }
shimniok 42:8d99f64f5898 259
shimniok 42:8d99f64f5898 260
shimniok 24:a7f92dfc5310 261 void reset(int argc, char **argv)
shimniok 12:3cd91e150d9c 262 {
shimniok 12:3cd91e150d9c 263 NVIC_SystemReset();
shimniok 9:fc3575d2cbbf 264 }
shimniok 9:fc3575d2cbbf 265
shimniok 24:a7f92dfc5310 266 ///////////////////////////////////////////////////////////////////////////////
shimniok 24:a7f92dfc5310 267 // MAIN
shimniok 1:7019a60fd585 268
shimniok 0:7e98bbfd102a 269 // main() runs in its own thread in the OS
shimniok 0:7e98bbfd102a 270 int main()
shimniok 11:8ec858b7c6d1 271 {
shimniok 20:043987d06f8d 272 //bridge_uart1();
shimniok 43:9a285515f33a 273 //bridge_uart2();
shimniok 24:a7f92dfc5310 274
shimniok 25:b8176ebb96c6 275 //Kernel::attach_idle_hook(idler);
shimniok 20:043987d06f8d 276
shimniok 37:b8259500dbd3 277 display.status("Bootup...");
shimniok 0:7e98bbfd102a 278 printf("Bootup...\n");
shimniok 0:7e98bbfd102a 279 fflush(stdout);
shimniok 1:7019a60fd585 280
shimniok 35:c42e7e29c3bd 281 steer = 0.50;
shimniok 35:c42e7e29c3bd 282 esc = 0.00;
shimniok 35:c42e7e29c3bd 283
shimniok 4:de7feb458652 284 printf("Loading config...\n");
shimniok 37:b8259500dbd3 285 display.status("Loading config");
shimniok 7:1f2661b840ed 286 config.add("intercept_distance", Config::DOUBLE);
shimniok 7:1f2661b840ed 287 config.add("waypoint_threshold", Config::DOUBLE);
shimniok 7:1f2661b840ed 288 config.add("minimum_turning_radius", Config::DOUBLE);
shimniok 7:1f2661b840ed 289 config.add("wheelbase", Config::DOUBLE);
shimniok 7:1f2661b840ed 290 config.add("track_width", Config::DOUBLE);
shimniok 7:1f2661b840ed 291 config.add("tire_circumference", Config::DOUBLE);
shimniok 7:1f2661b840ed 292 config.add("encoder_stripes", Config::INT);
shimniok 7:1f2661b840ed 293 config.add("esc_brake", Config::INT);
shimniok 7:1f2661b840ed 294 config.add("esc_off", Config::INT);
shimniok 7:1f2661b840ed 295 config.add("esc_max", Config::INT);
shimniok 7:1f2661b840ed 296 config.add("turn_speed", Config::DOUBLE);
shimniok 7:1f2661b840ed 297 config.add("turn_distance", Config::DOUBLE);
shimniok 7:1f2661b840ed 298 config.add("start_speed", Config::DOUBLE);
shimniok 7:1f2661b840ed 299 config.add("cruise_speed", Config::DOUBLE);
shimniok 7:1f2661b840ed 300 config.add("speed_kp", Config::DOUBLE);
shimniok 7:1f2661b840ed 301 config.add("speed_ki", Config::DOUBLE);
shimniok 7:1f2661b840ed 302 config.add("speed_kd", Config::DOUBLE);
shimniok 7:1f2661b840ed 303 config.add("steer_center", Config::DOUBLE);
shimniok 7:1f2661b840ed 304 config.add("steer_scale", Config::DOUBLE);
shimniok 7:1f2661b840ed 305 config.add("gyro_scale", Config::DOUBLE);
shimniok 7:1f2661b840ed 306 config.add("gps_valid_speed", Config::DOUBLE);
shimniok 35:c42e7e29c3bd 307
shimniok 4:de7feb458652 308 if (config.load("/etc/2018cfg.txt")) {
shimniok 4:de7feb458652 309 printf("error loading config\n");
shimniok 37:b8259500dbd3 310 display.status("config load error");
shimniok 4:de7feb458652 311 }
shimniok 10:9fb3feb38746 312
shimniok 38:6fec81f85221 313 printf("Starting display...\n");
shimniok 39:465213249f71 314 Thread lcdThread(osPriorityNormal, 2048, 0, "lcd");
shimniok 38:6fec81f85221 315 lcdThread.start(callback(&lcdQueue, &EventQueue::dispatch_forever));
shimniok 42:8d99f64f5898 316 //lcdQueue.call_every(sample_time_ms, callback(&compute_cpu_stats));
shimniok 38:6fec81f85221 317
shimniok 30:ed791f1f7f7d 318 printf("Starting buttons...\n");
shimniok 37:b8259500dbd3 319 display.status("Starting buttons");
shimniok 33:74c514aea0a1 320 lbutton.fall(buttonQueue.event(button_event));
shimniok 30:ed791f1f7f7d 321 //cbutton.rise(buttonQueue.event(button_event));
shimniok 30:ed791f1f7f7d 322 //rbutton.rise(buttonQueue.event(button_event));
shimniok 30:ed791f1f7f7d 323 Thread buttonThread(osPriorityNormal, 256, 0, "buttons");
shimniok 30:ed791f1f7f7d 324 buttonThread.start(callback(&buttonQueue, &EventQueue::dispatch_forever));
shimniok 30:ed791f1f7f7d 325
shimniok 24:a7f92dfc5310 326 printf("Starting updater...\n");
shimniok 37:b8259500dbd3 327 display.status("Starting updater");
shimniok 25:b8176ebb96c6 328 u->attach(updater_callback);
shimniok 24:a7f92dfc5310 329 Thread updaterThread(osPriorityRealtime, 512, 0, "updater");
shimniok 26:2dc31a801cc8 330 updaterQueue.call_every(20, u, &Updater::update);
shimniok 26:2dc31a801cc8 331 updaterThread.start(callback(&updaterQueue, &EventQueue::dispatch_forever));
shimniok 24:a7f92dfc5310 332
shimniok 24:a7f92dfc5310 333 printf("Starting gps...\n");
shimniok 37:b8259500dbd3 334 display.status("Starting gps");
shimniok 29:cb2f55fbfe9c 335 Thread gpsThread(osPriorityHigh, 2048, 0, "gps");
shimniok 24:a7f92dfc5310 336 gpsThread.start(callback(&gpsQueue, &EventQueue::dispatch_forever));
shimniok 43:9a285515f33a 337 gps.subscribe(gps_callback);
shimniok 24:a7f92dfc5310 338 s.attach(gps_handler);
shimniok 24:a7f92dfc5310 339
shimniok 37:b8259500dbd3 340 printf("Starting logging...\n");
shimniok 37:b8259500dbd3 341 display.status("Starting logging");
shimniok 29:cb2f55fbfe9c 342 Thread logThread(osPriorityNormal, 2048, 0, "log");
shimniok 24:a7f92dfc5310 343 logThread.start(callback(&logQueue, &EventQueue::dispatch_forever));
shimniok 24:a7f92dfc5310 344
shimniok 13:5566df1250f1 345 printf("Starting shell...\n");
shimniok 37:b8259500dbd3 346 display.status("Starting shell");
shimniok 30:ed791f1f7f7d 347 sh.command(test, "test");
shimniok 32:eb673f6f5734 348 sh.command(read_imu, "imu");
shimniok 30:ed791f1f7f7d 349 sh.command(read_enc, "enc");
shimniok 30:ed791f1f7f7d 350 sh.command(read_gps, "gps");
shimniok 30:ed791f1f7f7d 351 sh.command(reset, "reset");
shimniok 30:ed791f1f7f7d 352 sh.command(stats, "stats");
shimniok 30:ed791f1f7f7d 353 sh.command(log, "log");
shimniok 37:b8259500dbd3 354
shimniok 37:b8259500dbd3 355 display.status("DataBus 2018");
shimniok 24:a7f92dfc5310 356 sh.run();
shimniok 22:4d62bd16f037 357
shimniok 0:7e98bbfd102a 358 while (true) {
shimniok 0:7e98bbfd102a 359 // Blink LED and wait 0.5 seconds
shimniok 0:7e98bbfd102a 360 led1 = !led1;
shimniok 0:7e98bbfd102a 361 wait(0.5f);
shimniok 0:7e98bbfd102a 362 }
shimniok 0:7e98bbfd102a 363 }