![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Port of Adafruit Arduino code
Fork of Adafruit9-DOf by
Header/Serial_base.h@2:fe10a40b42e8, 2015-11-29 (annotated)
- Committer:
- jatinsha
- Date:
- Sun Nov 29 18:41:42 2015 +0000
- Revision:
- 2:fe10a40b42e8
- Parent:
- 0:772bf4786416
none
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bmanga95 | 0:772bf4786416 | 1 | #ifndef SERIAL_BASE_H |
bmanga95 | 0:772bf4786416 | 2 | #define SERIAL_BASE_H |
bmanga95 | 0:772bf4786416 | 3 | |
bmanga95 | 0:772bf4786416 | 4 | #define _MBED_ |
bmanga95 | 0:772bf4786416 | 5 | |
bmanga95 | 0:772bf4786416 | 6 | class Serial_base |
bmanga95 | 0:772bf4786416 | 7 | { |
bmanga95 | 0:772bf4786416 | 8 | public: |
bmanga95 | 0:772bf4786416 | 9 | |
bmanga95 | 0:772bf4786416 | 10 | virtual void print(const char* data) = 0; |
bmanga95 | 0:772bf4786416 | 11 | virtual void print(int data) = 0; |
bmanga95 | 0:772bf4786416 | 12 | virtual void print(double data) = 0; |
bmanga95 | 0:772bf4786416 | 13 | |
bmanga95 | 0:772bf4786416 | 14 | virtual void println(const char* data) = 0; |
bmanga95 | 0:772bf4786416 | 15 | virtual void println(int data) = 0; |
bmanga95 | 0:772bf4786416 | 16 | virtual void println(double data) = 0; |
bmanga95 | 0:772bf4786416 | 17 | |
bmanga95 | 0:772bf4786416 | 18 | virtual void setPrecision(int prec) = 0; |
bmanga95 | 0:772bf4786416 | 19 | }; |
bmanga95 | 0:772bf4786416 | 20 | |
bmanga95 | 0:772bf4786416 | 21 | extern Serial_base* s_com; |
bmanga95 | 0:772bf4786416 | 22 | |
bmanga95 | 0:772bf4786416 | 23 | |
bmanga95 | 0:772bf4786416 | 24 | #ifdef _MBED_ |
bmanga95 | 0:772bf4786416 | 25 | #include <iostream> |
bmanga95 | 0:772bf4786416 | 26 | #include <iomanip> |
bmanga95 | 0:772bf4786416 | 27 | |
bmanga95 | 0:772bf4786416 | 28 | class Serial_MBED: public Serial_base |
bmanga95 | 0:772bf4786416 | 29 | { |
bmanga95 | 0:772bf4786416 | 30 | public: |
bmanga95 | 0:772bf4786416 | 31 | virtual void print(const char* data){ |
bmanga95 | 0:772bf4786416 | 32 | _print(data); |
bmanga95 | 0:772bf4786416 | 33 | } |
bmanga95 | 0:772bf4786416 | 34 | virtual void print(int data){ |
bmanga95 | 0:772bf4786416 | 35 | _print(data); |
bmanga95 | 0:772bf4786416 | 36 | } |
bmanga95 | 0:772bf4786416 | 37 | virtual void print(double data){ |
bmanga95 | 0:772bf4786416 | 38 | _print(data); |
bmanga95 | 0:772bf4786416 | 39 | } |
bmanga95 | 0:772bf4786416 | 40 | |
bmanga95 | 0:772bf4786416 | 41 | virtual void println(const char* data){ |
bmanga95 | 0:772bf4786416 | 42 | _println(data); |
bmanga95 | 0:772bf4786416 | 43 | } |
bmanga95 | 0:772bf4786416 | 44 | virtual void println(int data){ |
bmanga95 | 0:772bf4786416 | 45 | _println(data); |
bmanga95 | 0:772bf4786416 | 46 | } |
bmanga95 | 0:772bf4786416 | 47 | virtual void println(double data){ |
bmanga95 | 0:772bf4786416 | 48 | _println(data); |
bmanga95 | 0:772bf4786416 | 49 | } |
bmanga95 | 0:772bf4786416 | 50 | virtual void setPrecision(int p){ |
bmanga95 | 0:772bf4786416 | 51 | std::cout.precision(p); |
bmanga95 | 0:772bf4786416 | 52 | //std::cout.setf( std::ios::fixed, std:: ios::floatfield ); |
bmanga95 | 0:772bf4786416 | 53 | } |
bmanga95 | 0:772bf4786416 | 54 | private: |
bmanga95 | 0:772bf4786416 | 55 | template<typename T> |
bmanga95 | 0:772bf4786416 | 56 | void _print(T data) { |
bmanga95 | 0:772bf4786416 | 57 | std::cout<<data<<std::flush; |
bmanga95 | 0:772bf4786416 | 58 | } |
bmanga95 | 0:772bf4786416 | 59 | template<typename T> |
bmanga95 | 0:772bf4786416 | 60 | void _println(T data){ |
bmanga95 | 0:772bf4786416 | 61 | std::cout<<data<<std::endl<<std::flush; |
bmanga95 | 0:772bf4786416 | 62 | } |
bmanga95 | 0:772bf4786416 | 63 | |
bmanga95 | 0:772bf4786416 | 64 | }; |
bmanga95 | 0:772bf4786416 | 65 | |
bmanga95 | 0:772bf4786416 | 66 | |
bmanga95 | 0:772bf4786416 | 67 | #endif //_MBED_ |
bmanga95 | 0:772bf4786416 | 68 | |
bmanga95 | 0:772bf4786416 | 69 | #endif |