Skip to content

Commit 2767419

Browse files
committed
Merge branch 'master' of github.com:arduino/Arduino into diskloader_reboot
Conflicts: app/src/processing/app/Editor.java app/src/processing/app/Sketch.java build/shared/examples/4.Communication/SerialCallResponse/SerialCallResponse.pde build/shared/lib/theme/theme.txt hardware/arduino/cores/arduino/HardwareSerial.h hardware/arduino/cores/arduino/Print.cpp hardware/arduino/cores/arduino/WString.h hardware/arduino/variants/mega/pins_arduino.h libraries/Ethernet/examples/PachubeClient/PachubeClient.ino libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino libraries/Firmata/examples/EchoString/EchoString.ino libraries/SD/File.cpp libraries/SoftwareSerial/SoftwareSerial.cpp libraries/SoftwareSerial/SoftwareSerial.h libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino libraries/SoftwareSerial/keywords.txt
2 parents 0e9187d + cd36339 commit 2767419

File tree

4 files changed

+333
-371
lines changed

4 files changed

+333
-371
lines changed

hardware/arduino/cores/arduino/HardwareSerial.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class HardwareSerial : public Stream
3232
{
3333
private:
3434
ring_buffer *_rx_buffer;
35-
ring_buffer *_tx_buffer;
3635
volatile uint8_t *_ubrrh;
3736
volatile uint8_t *_ubrrl;
3837
volatile uint8_t *_ucsra;
@@ -41,29 +40,28 @@ class HardwareSerial : public Stream
4140
uint8_t _rxen;
4241
uint8_t _txen;
4342
uint8_t _rxcie;
44-
uint8_t _udrie;
43+
uint8_t _udre;
4544
uint8_t _u2x;
4645
public:
47-
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
46+
HardwareSerial(ring_buffer *rx_buffer,
4847
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
4948
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
5049
volatile uint8_t *udr,
51-
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
50+
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
5251
void begin(unsigned long);
5352
void end();
5453
virtual int available(void);
5554
virtual int peek(void);
5655
virtual int read(void);
5756
virtual void flush(void);
58-
virtual size_t write(uint8_t);
57+
virtual void write(uint8_t);
5958
using Print::write; // pull in write(str) and write(buf, size) from Print
6059
};
6160

6261
#if defined(UBRRH) || defined(UBRR0H)
6362
extern HardwareSerial Serial;
6463
#elif defined(USBCON)
65-
#include "USBAPI.h"
66-
// extern HardwareSerial Serial_;
64+
#include "usb_api.h"
6765
#endif
6866
#if defined(UBRR1H)
6967
extern HardwareSerial Serial1;
@@ -75,6 +73,4 @@ class HardwareSerial : public Stream
7573
extern HardwareSerial Serial3;
7674
#endif
7775

78-
extern void serialEventRun(void) __attribute__((weak));
79-
8076
#endif

hardware/arduino/cores/arduino/Print.cpp

Lines changed: 82 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -23,213 +23,173 @@
2323
#include <stdio.h>
2424
#include <string.h>
2525
#include <math.h>
26-
#include "Arduino.h"
26+
#include "wiring.h"
2727

2828
#include "Print.h"
2929

3030
// Public Methods //////////////////////////////////////////////////////////////
3131

3232
/* default implementation: may be overridden */
33-
size_t Print::write(const uint8_t *buffer, size_t size)
33+
void Print::write(const char *str)
3434
{
35-
size_t n = 0;
36-
while (size--) {
37-
n += write(*buffer++);
38-
}
39-
return n;
35+
while (*str)
36+
write(*str++);
4037
}
4138

42-
size_t Print::print(const __FlashStringHelper *ifsh)
39+
/* default implementation: may be overridden */
40+
void Print::write(const uint8_t *buffer, size_t size)
4341
{
44-
const prog_char *p = (const prog_char *)ifsh;
45-
size_t n = 0;
46-
while (1) {
47-
unsigned char c = pgm_read_byte(p++);
48-
if (c == 0) break;
49-
n += write(c);
50-
}
51-
return n;
42+
while (size--)
43+
write(*buffer++);
5244
}
5345

54-
size_t Print::print(const String &s)
46+
void Print::print(const String &s)
5547
{
56-
size_t n = 0;
57-
for (uint16_t i = 0; i < s.length(); i++) {
58-
n += write(s[i]);
48+
for (unsigned int i = 0; i < s.length(); i++) {
49+
write(s[i]);
5950
}
60-
return n;
6151
}
6252

63-
size_t Print::print(const char str[])
53+
void Print::print(const char str[])
6454
{
65-
return write(str);
55+
write(str);
6656
}
6757

68-
size_t Print::print(char c)
58+
void Print::print(char c, int base)
6959
{
70-
return write(c);
60+
print((long) c, base);
7161
}
7262

73-
size_t Print::print(unsigned char b, int base)
63+
void Print::print(unsigned char b, int base)
7464
{
75-
return print((unsigned long) b, base);
65+
print((unsigned long) b, base);
7666
}
7767

78-
size_t Print::print(int n, int base)
68+
void Print::print(int n, int base)
7969
{
80-
return print((long) n, base);
70+
print((long) n, base);
8171
}
8272

83-
size_t Print::print(unsigned int n, int base)
73+
void Print::print(unsigned int n, int base)
8474
{
85-
return print((unsigned long) n, base);
75+
print((unsigned long) n, base);
8676
}
8777

88-
size_t Print::print(long n, int base)
78+
void Print::print(long n, int base)
8979
{
9080
if (base == 0) {
91-
return write(n);
81+
write(n);
9282
} else if (base == 10) {
9383
if (n < 0) {
94-
int t = print('-');
84+
print('-');
9585
n = -n;
96-
return printNumber(n, 10) + t;
9786
}
98-
return printNumber(n, 10);
87+
printNumber(n, 10);
9988
} else {
100-
return printNumber(n, base);
89+
printNumber(n, base);
10190
}
10291
}
10392

104-
size_t Print::print(unsigned long n, int base)
105-
{
106-
if (base == 0) return write(n);
107-
else return printNumber(n, base);
108-
}
109-
110-
size_t Print::print(double n, int digits)
93+
void Print::print(unsigned long n, int base)
11194
{
112-
return printFloat(n, digits);
95+
if (base == 0) write(n);
96+
else printNumber(n, base);
11397
}
11498

115-
size_t Print::println(const __FlashStringHelper *ifsh)
99+
void Print::print(double n, int digits)
116100
{
117-
size_t n = print(ifsh);
118-
n += println();
119-
return n;
101+
printFloat(n, digits);
120102
}
121103

122-
size_t Print::print(const Printable& x)
104+
void Print::println(void)
123105
{
124-
return x.printTo(*this);
106+
print('\r');
107+
print('\n');
125108
}
126109

127-
size_t Print::println(void)
110+
void Print::println(const String &s)
128111
{
129-
size_t n = print('\r');
130-
n += print('\n');
131-
return n;
112+
print(s);
113+
println();
132114
}
133115

134-
size_t Print::println(const String &s)
116+
void Print::println(const char c[])
135117
{
136-
size_t n = print(s);
137-
n += println();
138-
return n;
118+
print(c);
119+
println();
139120
}
140121

141-
size_t Print::println(const char c[])
122+
void Print::println(char c, int base)
142123
{
143-
size_t n = print(c);
144-
n += println();
145-
return n;
124+
print(c, base);
125+
println();
146126
}
147127

148-
size_t Print::println(char c)
128+
void Print::println(unsigned char b, int base)
149129
{
150-
size_t n = print(c);
151-
n += println();
152-
return n;
130+
print(b, base);
131+
println();
153132
}
154133

155-
size_t Print::println(unsigned char b, int base)
134+
void Print::println(int n, int base)
156135
{
157-
size_t n = print(b, base);
158-
n += println();
159-
return n;
136+
print(n, base);
137+
println();
160138
}
161139

162-
size_t Print::println(int num, int base)
140+
void Print::println(unsigned int n, int base)
163141
{
164-
size_t n = print(num, base);
165-
n += println();
166-
return n;
142+
print(n, base);
143+
println();
167144
}
168145

169-
size_t Print::println(unsigned int num, int base)
146+
void Print::println(long n, int base)
170147
{
171-
size_t n = print(num, base);
172-
n += println();
173-
return n;
148+
print(n, base);
149+
println();
174150
}
175151

176-
size_t Print::println(long num, int base)
152+
void Print::println(unsigned long n, int base)
177153
{
178-
size_t n = print(num, base);
179-
n += println();
180-
return n;
154+
print(n, base);
155+
println();
181156
}
182157

183-
size_t Print::println(unsigned long num, int base)
158+
void Print::println(double n, int digits)
184159
{
185-
size_t n = print(num, base);
186-
n += println();
187-
return n;
188-
}
189-
190-
size_t Print::println(double num, int digits)
191-
{
192-
size_t n = print(num, digits);
193-
n += println();
194-
return n;
195-
}
196-
197-
size_t Print::println(const Printable& x)
198-
{
199-
size_t n = print(x);
200-
n += println();
201-
return n;
160+
print(n, digits);
161+
println();
202162
}
203163

204164
// Private Methods /////////////////////////////////////////////////////////////
205165

206-
size_t Print::printNumber(unsigned long n, uint8_t base) {
207-
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
208-
char *str = &buf[sizeof(buf) - 1];
209-
210-
*str = '\0';
166+
void Print::printNumber(unsigned long n, uint8_t base)
167+
{
168+
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
169+
unsigned long i = 0;
211170

212-
// prevent crash if called with base == 1
213-
if (base < 2) base = 10;
171+
if (n == 0) {
172+
print('0');
173+
return;
174+
}
214175

215-
do {
216-
unsigned long m = n;
176+
while (n > 0) {
177+
buf[i++] = n % base;
217178
n /= base;
218-
char c = m - base * n;
219-
*--str = c < 10 ? c + '0' : c + 'A' - 10;
220-
} while(n);
179+
}
221180

222-
return write(str);
181+
for (; i > 0; i--)
182+
print((char) (buf[i - 1] < 10 ?
183+
'0' + buf[i - 1] :
184+
'A' + buf[i - 1] - 10));
223185
}
224186

225-
size_t Print::printFloat(double number, uint8_t digits)
187+
void Print::printFloat(double number, uint8_t digits)
226188
{
227-
size_t n = 0;
228-
229189
// Handle negative numbers
230190
if (number < 0.0)
231191
{
232-
n += print('-');
192+
print('-');
233193
number = -number;
234194
}
235195

@@ -243,21 +203,18 @@ size_t Print::printFloat(double number, uint8_t digits)
243203
// Extract the integer part of the number and print it
244204
unsigned long int_part = (unsigned long)number;
245205
double remainder = number - (double)int_part;
246-
n += print(int_part);
206+
print(int_part);
247207

248208
// Print the decimal point, but only if there are digits beyond
249-
if (digits > 0) {
250-
n += print(".");
251-
}
209+
if (digits > 0)
210+
print(".");
252211

253212
// Extract digits from the remainder one at a time
254213
while (digits-- > 0)
255214
{
256215
remainder *= 10.0;
257216
int toPrint = int(remainder);
258-
n += print(toPrint);
217+
print(toPrint);
259218
remainder -= toPrint;
260219
}
261-
262-
return n;
263220
}

0 commit comments

Comments
 (0)