Soldered SD Card Arduino Library 1.0.0
Easily read and write files to and form the SD card breakout! A fork of the original SDFat library by Bill Greiman.
Loading...
Searching...
No Matches
ArduinoStream.h
Go to the documentation of this file.
1
25#ifndef ArduinoStream_h
26#define ArduinoStream_h
31#include "SdFatConfig.h"
32#include "bufstream.h"
33//==============================================================================
39{
40 public:
47 ArduinoInStream(Stream &hws, char *buf, size_t size)
48 {
49 m_hw = &hws;
50 m_line = buf;
51 m_size = size;
52 }
54 void readline()
55 {
56 size_t i = 0;
57 uint32_t t;
58 m_line[0] = '\0';
59 while (!m_hw->available())
60 {
62 }
63
64 while (1)
65 {
66 t = millis();
67 while (!m_hw->available())
68 {
69 if ((millis() - t) > 10)
70 {
71 goto done;
72 }
73 }
74 if (i >= (m_size - 1))
75 {
77 return;
78 }
79 m_line[i++] = m_hw->read();
80 m_line[i] = '\0';
81 }
82 done:
83 init(m_line);
84 }
85
86 protected:
92 bool seekoff(off_type off, seekdir way)
93 {
94 (void)off;
95 (void)way;
96 return false;
97 }
103 {
104 (void)pos;
105 return false;
106 }
107
108 private:
109 char *m_line;
110 size_t m_size;
111 Stream *m_hw;
112};
113//==============================================================================
119{
120 public:
125 explicit ArduinoOutStream(Print &pr) : m_pr(&pr)
126 {
127 }
128
129 protected:
131
135 void putch(char c)
136 {
137 if (c == '\n')
138 {
139 m_pr->write('\r');
140 }
141 m_pr->write(c);
142 }
143 void putstr(const char *str)
144 {
145 m_pr->write(str);
146 }
147 bool seekoff(off_type off, seekdir way)
148 {
149 (void)off;
150 (void)way;
151 return false;
152 }
153 bool seekpos(pos_type pos)
154 {
155 (void)pos;
156 return false;
157 }
158 bool sync()
159 {
160 return true;
161 }
162 pos_type tellpos()
163 {
164 return 0;
165 }
167 private:
169 {
170 }
171 Print *m_pr;
172};
173#endif // ArduinoStream_h
configuration definitions
ibufstream and obufstream classes
Input stream for Arduino Stream objects.
Definition ArduinoStream.h:39
Stream * m_hw
Definition ArduinoStream.h:111
char * m_line
Definition ArduinoStream.h:109
size_t m_size
Definition ArduinoStream.h:110
ArduinoInStream(Stream &hws, char *buf, size_t size)
Definition ArduinoStream.h:47
bool seekpos(pos_type pos)
Definition ArduinoStream.h:102
bool seekoff(off_type off, seekdir way)
Definition ArduinoStream.h:92
void readline()
Definition ArduinoStream.h:54
Output stream for Arduino Print objects.
Definition ArduinoStream.h:119
ArduinoOutStream()
Definition ArduinoStream.h:168
ArduinoOutStream(Print &pr)
Definition ArduinoStream.h:125
Print * m_pr
Definition ArduinoStream.h:171
static void yield()
Definition SysCall.h:85
parse a char string
Definition bufstream.h:39
void init(const char *str)
Definition bufstream.h:57
static const iostate failbit
Definition ios.h:63
int32_t off_type
Definition ios.h:73
seekdir
Definition ios.h:87
uint32_t pos_type
Definition ios.h:71
void setstate(iostate state)
Definition ios.h:488
Output Stream.
Definition ostream.h:38