| 1 | /* |
| 2 | Copyright (C) 2011 J. Coliz <maniacbug@ymail.com> |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU General Public License |
| 6 | version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | /* Galileo support from spaniakos <spaniakos@gmail.com> */ |
| 9 | |
| 10 | /** |
| 11 | * @file printf.h |
| 12 | * |
| 13 | * Setup necessary to direct stdout to the Arduino Serial library, which |
| 14 | * enables 'printf' |
| 15 | */ |
| 16 | |
| 17 | #ifndef RF24_PRINTF_H_ |
| 18 | #define RF24_PRINTF_H_ |
| 19 | |
| 20 | #if defined(ARDUINO_ARCH_AVR) || defined(__ARDUINO_X86__) || defined(ARDUINO_ARCH_MEGAAVR) |
| 21 | |
| 22 | int serial_putc(char c, FILE*) |
| 23 | { |
| 24 | Serial.write(c); |
| 25 | return c; |
| 26 | } |
| 27 | |
| 28 | #elif defined(ARDUINO_ARCH_MBED) |
| 29 | REDIRECT_STDOUT_TO(Serial); |
| 30 | |
| 31 | #endif // defined (ARDUINO_ARCH_AVR) || defined (__ARDUINO_X86__) || defined (ARDUINO_ARCH_MBED) || defined (ARDUINO_ARCH_MEGAAVR) |
| 32 | |
| 33 | void printf_begin(void) |
| 34 | { |
| 35 | #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) |
| 36 | fdevopen(&serial_putc, 0); |
| 37 | |
| 38 | #elif defined(__ARDUINO_X86__) |
| 39 | // For redirect stdout to /dev/ttyGS0 (Serial Monitor port) |
| 40 | stdout = freopen("/dev/ttyGS0", "w", stdout); |
| 41 | delay(500); |
| 42 | printf("Redirecting to Serial..."); |
| 43 | #endif // defined(__ARDUINO_X86__) |
| 44 | } |
| 45 | |
| 46 | #endif // RF24_PRINTF_H_ |