mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/freopen/main.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "mbed.h" |
elessair | 0:f269e3021894 | 2 | |
elessair | 0:f269e3021894 | 3 | #if !DEVICE_LOCALFILESYSTEM |
elessair | 0:f269e3021894 | 4 | #error [NOT_SUPPORTED] LocalFileSystem not supported |
elessair | 0:f269e3021894 | 5 | #endif |
elessair | 0:f269e3021894 | 6 | |
elessair | 0:f269e3021894 | 7 | #include "TextLCD.h" |
elessair | 0:f269e3021894 | 8 | |
elessair | 0:f269e3021894 | 9 | int main() { |
elessair | 0:f269e3021894 | 10 | printf("printf to stdout\n"); |
elessair | 0:f269e3021894 | 11 | |
elessair | 0:f269e3021894 | 12 | // printf to specific peripherals |
elessair | 0:f269e3021894 | 13 | Serial pc(USBTX, USBRX); |
elessair | 0:f269e3021894 | 14 | pc.printf("Serial(USBTX, USBRX).printf\n"); |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | TextLCD lcd(p14, p15, p16, p17, p18, p19, p20, "lcd"); // rs, rw, e, d0-d3, name |
elessair | 0:f269e3021894 | 17 | lcd.printf("TextLCD.printf\n"); |
elessair | 0:f269e3021894 | 18 | |
elessair | 0:f269e3021894 | 19 | // change stdout to file |
elessair | 0:f269e3021894 | 20 | LocalFileSystem local("local"); |
elessair | 0:f269e3021894 | 21 | freopen("/local/output.txt", "w", stdout); |
elessair | 0:f269e3021894 | 22 | printf("printf redirected to LocalFileSystem\n"); |
elessair | 0:f269e3021894 | 23 | fclose(stdout); |
elessair | 0:f269e3021894 | 24 | |
elessair | 0:f269e3021894 | 25 | // change stdout to LCD |
elessair | 0:f269e3021894 | 26 | freopen("/lcd", "w", stdout); |
elessair | 0:f269e3021894 | 27 | printf("printf redirected to TextLCD\n"); |
elessair | 0:f269e3021894 | 28 | fclose(stdout); |
elessair | 0:f269e3021894 | 29 | |
elessair | 0:f269e3021894 | 30 | DigitalOut led(LED1); |
elessair | 0:f269e3021894 | 31 | while (true) { |
elessair | 0:f269e3021894 | 32 | led = !led; |
elessair | 0:f269e3021894 | 33 | wait(1); |
elessair | 0:f269e3021894 | 34 | } |
elessair | 0:f269e3021894 | 35 | } |