![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
main.cpp@4:de7feb458652, 2018-12-03 (annotated)
- Committer:
- shimniok
- Date:
- Mon Dec 03 21:51:14 2018 +0000
- Revision:
- 4:de7feb458652
- Parent:
- 1:7019a60fd585
- Child:
- 7:1f2661b840ed
implemented part of config read/parse
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:7e98bbfd102a | 9 | #include "stats_report.h" |
shimniok | 0:7e98bbfd102a | 10 | #include "SDBlockDevice.h" |
shimniok | 0:7e98bbfd102a | 11 | #include "FATFileSystem.h" |
shimniok | 0:7e98bbfd102a | 12 | #include "SimpleShell.h" |
shimniok | 4:de7feb458652 | 13 | #include "Config.h" |
shimniok | 0:7e98bbfd102a | 14 | |
shimniok | 0:7e98bbfd102a | 15 | Serial pc(USBTX, USBRX); |
shimniok | 0:7e98bbfd102a | 16 | //SDBlockDevice bd(p5, p6, p7, p8); // MOSI, MISO, CLK, CS |
shimniok | 0:7e98bbfd102a | 17 | //FATFileSystem ffs("log", &bd); |
shimniok | 0:7e98bbfd102a | 18 | LocalFileSystem lfs("etc"); |
shimniok | 4:de7feb458652 | 19 | Config config; |
shimniok | 0:7e98bbfd102a | 20 | SimpleShell sh; |
shimniok | 0:7e98bbfd102a | 21 | |
shimniok | 0:7e98bbfd102a | 22 | DigitalOut led1(LED1); |
shimniok | 0:7e98bbfd102a | 23 | |
shimniok | 0:7e98bbfd102a | 24 | Thread thread; |
shimniok | 0:7e98bbfd102a | 25 | |
shimniok | 1:7019a60fd585 | 26 | void test() { |
shimniok | 1:7019a60fd585 | 27 | printf("Hello world!\n"); |
shimniok | 1:7019a60fd585 | 28 | } |
shimniok | 1:7019a60fd585 | 29 | |
shimniok | 1:7019a60fd585 | 30 | |
shimniok | 0:7e98bbfd102a | 31 | // main() runs in its own thread in the OS |
shimniok | 0:7e98bbfd102a | 32 | int main() |
shimniok | 0:7e98bbfd102a | 33 | { |
shimniok | 0:7e98bbfd102a | 34 | printf("Bootup...\n"); |
shimniok | 0:7e98bbfd102a | 35 | fflush(stdout); |
shimniok | 1:7019a60fd585 | 36 | |
shimniok | 4:de7feb458652 | 37 | printf("Loading config...\n"); |
shimniok | 4:de7feb458652 | 38 | if (config.load("/etc/2018cfg.txt")) { |
shimniok | 4:de7feb458652 | 39 | printf("error loading config\n"); |
shimniok | 4:de7feb458652 | 40 | } |
shimniok | 4:de7feb458652 | 41 | |
shimniok | 1:7019a60fd585 | 42 | sh.attach(test, "test"); |
shimniok | 1:7019a60fd585 | 43 | |
shimniok | 0:7e98bbfd102a | 44 | thread.start(callback(&sh, &SimpleShell::run)); |
shimniok | 0:7e98bbfd102a | 45 | |
shimniok | 0:7e98bbfd102a | 46 | /* |
shimniok | 0:7e98bbfd102a | 47 | FILE *fp; |
shimniok | 0:7e98bbfd102a | 48 | char buf[128]; |
shimniok | 0:7e98bbfd102a | 49 | printf("Initializing the block device... "); |
shimniok | 0:7e98bbfd102a | 50 | fflush(stdout); |
shimniok | 0:7e98bbfd102a | 51 | int err = bd.init(); |
shimniok | 0:7e98bbfd102a | 52 | printf("%s\n", (err ? "Fail :(" : "OK")); |
shimniok | 0:7e98bbfd102a | 53 | |
shimniok | 0:7e98bbfd102a | 54 | printf("Opening sdtest.txt..."); |
shimniok | 0:7e98bbfd102a | 55 | fp = fopen("/log/sdtest.txt", "r"); |
shimniok | 0:7e98bbfd102a | 56 | if(fp) { |
shimniok | 0:7e98bbfd102a | 57 | while (!feof(fp)) { |
shimniok | 0:7e98bbfd102a | 58 | fgets(buf, 127, fp); |
shimniok | 0:7e98bbfd102a | 59 | printf(buf); |
shimniok | 0:7e98bbfd102a | 60 | } |
shimniok | 0:7e98bbfd102a | 61 | fclose(fp); |
shimniok | 0:7e98bbfd102a | 62 | } |
shimniok | 0:7e98bbfd102a | 63 | |
shimniok | 0:7e98bbfd102a | 64 | printf("Opening config.txt..."); |
shimniok | 0:7e98bbfd102a | 65 | fp = fopen("/etc/config.txt", "r"); |
shimniok | 0:7e98bbfd102a | 66 | if(fp) { |
shimniok | 0:7e98bbfd102a | 67 | while (!feof(fp)) { |
shimniok | 0:7e98bbfd102a | 68 | fgets(buf, 127, fp); |
shimniok | 0:7e98bbfd102a | 69 | printf(buf); |
shimniok | 0:7e98bbfd102a | 70 | } |
shimniok | 0:7e98bbfd102a | 71 | fclose(fp); |
shimniok | 0:7e98bbfd102a | 72 | } |
shimniok | 0:7e98bbfd102a | 73 | */ |
shimniok | 0:7e98bbfd102a | 74 | |
shimniok | 0:7e98bbfd102a | 75 | //SystemReport sys_state(500); |
shimniok | 0:7e98bbfd102a | 76 | |
shimniok | 0:7e98bbfd102a | 77 | while (true) { |
shimniok | 0:7e98bbfd102a | 78 | // Blink LED and wait 0.5 seconds |
shimniok | 0:7e98bbfd102a | 79 | led1 = !led1; |
shimniok | 0:7e98bbfd102a | 80 | wait(0.5f); |
shimniok | 0:7e98bbfd102a | 81 | |
shimniok | 0:7e98bbfd102a | 82 | // Following the main thread wait, report on the current system status |
shimniok | 0:7e98bbfd102a | 83 | //sys_state.report_state(); |
shimniok | 0:7e98bbfd102a | 84 | } |
shimniok | 0:7e98bbfd102a | 85 | } |