您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Stream.h - base class for character-based streams.
  3. Copyright (c) 2010 David A. Mellis. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #ifndef Stream_h
  17. #define Stream_h
  18. #include <inttypes.h>
  19. #include "Print.h"
  20. class Stream : public Print
  21. {
  22. public:
  23. Stream() : _timeout(1000), read_error(0) {}
  24. virtual int available() = 0;
  25. virtual int read() = 0;
  26. virtual int peek() = 0;
  27. virtual void flush() = 0;
  28. void setTimeout(unsigned long timeout);
  29. bool find(char *target);
  30. bool find(char *target, size_t length);
  31. bool findUntil(char *target, char *terminator);
  32. bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen);
  33. long parseInt();
  34. long parseInt(char skipChar);
  35. float parseFloat();
  36. float parseFloat(char skipChar);
  37. size_t readBytes(char *buffer, size_t length);
  38. size_t readBytesUntil(char terminator, char *buffer, size_t length);
  39. String readString(size_t max = 120);
  40. String readStringUntil(char terminator, size_t max = 120);
  41. int getReadError() { return read_error; }
  42. void clearReadError() { setReadError(0); }
  43. protected:
  44. void setReadError(int err = 1) { read_error = err; }
  45. unsigned long _timeout;
  46. private:
  47. char read_error;
  48. int timedRead();
  49. int timedPeek();
  50. int peekNextDigit();
  51. };
  52. #endif