This is my quadcopter prototype software, still in development!
quadv3/mbed/Stream.h@1:ac68f0368a77, 2013-07-23 (annotated)
- Committer:
- Anaesthetix
- Date:
- Tue Jul 23 14:01:42 2013 +0000
- Revision:
- 1:ac68f0368a77
- Parent:
- 0:978110f7f027
Other accelerometer added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:978110f7f027 | 1 | /* mbed Microcontroller Library - Stream |
Anaesthetix | 0:978110f7f027 | 2 | * Copyright (c) 2007-2009 ARM Limited. All rights reserved. |
Anaesthetix | 0:978110f7f027 | 3 | */ |
Anaesthetix | 0:978110f7f027 | 4 | |
Anaesthetix | 0:978110f7f027 | 5 | #ifndef MBED_STREAM_H |
Anaesthetix | 0:978110f7f027 | 6 | #define MBED_STREAM_H |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #include "FileLike.h" |
Anaesthetix | 0:978110f7f027 | 9 | #include "platform.h" |
Anaesthetix | 0:978110f7f027 | 10 | #include <cstdio> |
Anaesthetix | 0:978110f7f027 | 11 | |
Anaesthetix | 0:978110f7f027 | 12 | namespace mbed { |
Anaesthetix | 0:978110f7f027 | 13 | |
Anaesthetix | 0:978110f7f027 | 14 | class Stream : public FileLike { |
Anaesthetix | 0:978110f7f027 | 15 | |
Anaesthetix | 0:978110f7f027 | 16 | public: |
Anaesthetix | 0:978110f7f027 | 17 | |
Anaesthetix | 0:978110f7f027 | 18 | Stream(const char *name = NULL); |
Anaesthetix | 0:978110f7f027 | 19 | virtual ~Stream(); |
Anaesthetix | 0:978110f7f027 | 20 | |
Anaesthetix | 0:978110f7f027 | 21 | int putc(int c) { |
Anaesthetix | 0:978110f7f027 | 22 | fflush(_file); |
Anaesthetix | 0:978110f7f027 | 23 | return std::fputc(c, _file); |
Anaesthetix | 0:978110f7f027 | 24 | } |
Anaesthetix | 0:978110f7f027 | 25 | int puts(const char *s) { |
Anaesthetix | 0:978110f7f027 | 26 | fflush(_file); |
Anaesthetix | 0:978110f7f027 | 27 | return std::fputs(s, _file); |
Anaesthetix | 0:978110f7f027 | 28 | } |
Anaesthetix | 0:978110f7f027 | 29 | int getc() { |
Anaesthetix | 0:978110f7f027 | 30 | fflush(_file); |
Anaesthetix | 0:978110f7f027 | 31 | return std::fgetc(_file); |
Anaesthetix | 0:978110f7f027 | 32 | } |
Anaesthetix | 0:978110f7f027 | 33 | char *gets(char *s, int size) { |
Anaesthetix | 0:978110f7f027 | 34 | fflush(_file); |
Anaesthetix | 0:978110f7f027 | 35 | return std::fgets(s,size,_file);; |
Anaesthetix | 0:978110f7f027 | 36 | } |
Anaesthetix | 0:978110f7f027 | 37 | int printf(const char* format, ...); |
Anaesthetix | 0:978110f7f027 | 38 | int scanf(const char* format, ...); |
Anaesthetix | 0:978110f7f027 | 39 | |
Anaesthetix | 0:978110f7f027 | 40 | operator std::FILE*() { return _file; } |
Anaesthetix | 0:978110f7f027 | 41 | |
Anaesthetix | 0:978110f7f027 | 42 | #ifdef MBED_RPC |
Anaesthetix | 0:978110f7f027 | 43 | virtual const struct rpc_method *get_rpc_methods(); |
Anaesthetix | 0:978110f7f027 | 44 | #endif |
Anaesthetix | 0:978110f7f027 | 45 | |
Anaesthetix | 0:978110f7f027 | 46 | protected: |
Anaesthetix | 0:978110f7f027 | 47 | |
Anaesthetix | 0:978110f7f027 | 48 | virtual int close(); |
Anaesthetix | 0:978110f7f027 | 49 | virtual ssize_t write(const void* buffer, size_t length); |
Anaesthetix | 0:978110f7f027 | 50 | virtual ssize_t read(void* buffer, size_t length); |
Anaesthetix | 0:978110f7f027 | 51 | virtual off_t lseek(off_t offset, int whence); |
Anaesthetix | 0:978110f7f027 | 52 | virtual int isatty(); |
Anaesthetix | 0:978110f7f027 | 53 | virtual int fsync(); |
Anaesthetix | 0:978110f7f027 | 54 | virtual off_t flen(); |
Anaesthetix | 0:978110f7f027 | 55 | |
Anaesthetix | 0:978110f7f027 | 56 | virtual int _putc(int c) = 0; |
Anaesthetix | 0:978110f7f027 | 57 | virtual int _getc() = 0; |
Anaesthetix | 0:978110f7f027 | 58 | |
Anaesthetix | 0:978110f7f027 | 59 | std::FILE *_file; |
Anaesthetix | 0:978110f7f027 | 60 | |
Anaesthetix | 0:978110f7f027 | 61 | }; |
Anaesthetix | 0:978110f7f027 | 62 | |
Anaesthetix | 0:978110f7f027 | 63 | } // namespace mbed |
Anaesthetix | 0:978110f7f027 | 64 | |
Anaesthetix | 0:978110f7f027 | 65 | #endif |
Anaesthetix | 0:978110f7f027 | 66 |