@@ -30,20 +30,20 @@ namespace arduino {
30
30
// using a ring buffer (I think), in which head is the index of the location
31
31
// to which to write the next incoming character and tail is the index of the
32
32
// location from which to read.
33
- #define SERIAL_BUFFER_SIZE 64
33
+ #define SERIAL_BUFFER_SIZE 256
34
34
35
35
template <int N>
36
36
class RingBufferN
37
37
{
38
38
public:
39
- uint8_t _aucBuffer[N] ;
39
+ uint16_t _aucBuffer[N] ;
40
40
volatile int _iHead ;
41
41
volatile int _iTail ;
42
42
volatile int _numElems;
43
43
44
44
public:
45
45
RingBufferN ( void ) ;
46
- void store_char ( uint8_t c ) ;
46
+ void store_char ( uint16_t c ) ;
47
47
void clear ();
48
48
int read_char ();
49
49
int available ();
@@ -62,12 +62,12 @@ typedef RingBufferN<SERIAL_BUFFER_SIZE> RingBuffer;
62
62
template <int N>
63
63
RingBufferN<N>::RingBufferN( void )
64
64
{
65
- memset ( _aucBuffer, 0 , N ) ;
65
+ memset ( _aucBuffer, 0 , (N * 2 ) ) ;
66
66
clear ();
67
67
}
68
68
69
69
template <int N>
70
- void RingBufferN<N>::store_char( uint8_t c )
70
+ void RingBufferN<N>::store_char( uint16_t c )
71
71
{
72
72
// if we should be storing the received character into the location
73
73
// just before the tail (meaning that the head would advance to the
@@ -77,7 +77,7 @@ void RingBufferN<N>::store_char( uint8_t c )
77
77
{
78
78
_aucBuffer[_iHead] = c ;
79
79
_iHead = nextIndex (_iHead);
80
- _numElems = _numElems + 1 ;
80
+ _numElems++ ;
81
81
}
82
82
}
83
83
@@ -95,9 +95,9 @@ int RingBufferN<N>::read_char()
95
95
if (isEmpty ())
96
96
return -1 ;
97
97
98
- uint8_t value = _aucBuffer[_iTail];
98
+ uint16_t value = _aucBuffer[_iTail];
99
99
_iTail = nextIndex (_iTail);
100
- _numElems = _numElems - 1 ;
100
+ _numElems-- ;
101
101
102
102
return value;
103
103
}
@@ -138,4 +138,4 @@ bool RingBufferN<N>::isFull()
138
138
}
139
139
140
140
#endif /* _RING_BUFFER_ */
141
- #endif /* __cplusplus */
141
+ #endif /* __cplusplus */
0 commit comments