Skip to content

Commit f82dd73

Browse files
committed
Rearranged the libC++ files to work like an Arduino library
1 parent d841ce2 commit f82dd73

File tree

319 files changed

+96
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+96
-76
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

include/Makefile

-5
This file was deleted.

include/Makefile.in

-7
This file was deleted.

keywords.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cin KEYWORD1
2+
cout KEYWORD1
3+
printf KEYWORD1
4+
scanf KEYWORD1

library.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=ArduinoSTL
2+
version=1.0.1
3+
author=Mike Matera <[email protected]>
4+
maintainer=Mike Matera <[email protected]>
5+
sentence=A port of uClibc++ packaged as an Arduino library.
6+
paragraph=This library includes cout/cin printf() and the STL.
7+
category=Other
8+
url=https://github.com/mike-matera/ArduinoSTL
9+
architectures=avr
10+
include=ArduinoSTL.h

src/ArduinoSTL.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <ArduinoSTL.h>
2+
3+
using namespace std;
4+
5+
// Create cout and cin.. there doesn't seem to be a way
6+
// to control what serial device at runtime. Grr.
7+
namespace std
8+
{
9+
ohserialstream cout(Serial);
10+
ihserialstream cin(Serial);
11+
}
12+
13+
//
14+
// This is a hack to make C stdio work on "Serial" without
15+
// having to be manually initialized. It works becuase I can
16+
// call a constructor before setup().
17+
//
18+
class __Arduino_STDIO_hack {
19+
public:
20+
__Arduino_STDIO_hack(Stream *u);
21+
Stream *getUart() {
22+
return uart;
23+
}
24+
private:
25+
Stream *uart;
26+
};
27+
28+
static __Arduino_STDIO_hack __stdio_wrapper(&Serial);
29+
30+
// arduino_putchar(char, FILE*)
31+
// Output a single character to the serial port.
32+
// returns: 0 on success, 1 on error
33+
// note:
34+
// To maintain serial port compatibility this function
35+
// automatically addes a \r when it sees a \n
36+
//
37+
static int arduino_putchar(char c, FILE* f) {
38+
Stream *uart = __stdio_wrapper.getUart();
39+
if (c == '\n') uart->write('\r');
40+
return uart->write(c) == 1? 0 : 1;
41+
}
42+
43+
// arduino_getchar(FILE*)
44+
// Take a character from the serial port. This function
45+
// must block until a character is ready.
46+
// returns: The character or -1 on a read error
47+
//
48+
static int arduino_getchar(FILE *f) {
49+
Stream *uart = __stdio_wrapper.getUart();
50+
while (! uart->available()) { /* wait */ }
51+
return uart->read();
52+
}
53+
54+
// Initialize STDIO using a pointer to whatever Serial is.
55+
// Serial.begin() must be called at some point.
56+
//
57+
__Arduino_STDIO_hack::__Arduino_STDIO_hack(Stream *u) {
58+
uart = u;
59+
fdevopen(arduino_putchar, arduino_getchar);
60+
}

src/ArduinoSTL.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------
2+
*
3+
* ArduinoSTL Core Library
4+
*
5+
* This header has some glue to make STL and Streams work from a sketch.
6+
*
7+
*/
8+
9+
#ifndef ARDUINOSTL_M_H
10+
#define ARDUINOSTL_M_H
11+
12+
#include <serstream>
13+
14+
// Create cout and cin.. there doesn't seem to be a way
15+
// to control what serial device at runtime. Grr.
16+
namespace std
17+
{
18+
extern ohserialstream cout;
19+
extern ihserialstream cin;
20+
}
21+
22+
#endif

src/Makefile

-6
This file was deleted.

src/Makefile.in

-58
This file was deleted.

include/algorithm src/algorithm

File renamed without changes.
File renamed without changes.
File renamed without changes.

include/bitset src/bitset

File renamed without changes.

include/cassert src/cassert

File renamed without changes.

include/cctype src/cctype

File renamed without changes.

include/cerrno src/cerrno

File renamed without changes.

include/cfloat src/cfloat

File renamed without changes.
File renamed without changes.

include/climits src/climits

File renamed without changes.

include/clocale src/clocale

File renamed without changes.

include/cmath src/cmath

File renamed without changes.

include/complex src/complex

File renamed without changes.

include/csetjmp src/csetjmp

File renamed without changes.

include/csignal src/csignal

File renamed without changes.

include/cstdarg src/cstdarg

File renamed without changes.

include/cstddef src/cstddef

File renamed without changes.

include/cstdio src/cstdio

File renamed without changes.

include/cstdlib src/cstdlib

File renamed without changes.

include/cstring src/cstring

File renamed without changes.

include/ctime src/ctime

File renamed without changes.

include/cwchar src/cwchar

File renamed without changes.

include/cwctype src/cwctype

File renamed without changes.

include/deque src/deque

File renamed without changes.

include/exception src/exception

File renamed without changes.

include/fstream src/fstream

File renamed without changes.
File renamed without changes.

include/functional src/functional

File renamed without changes.

include/iomanip src/iomanip

File renamed without changes.

include/ios src/ios

File renamed without changes.

include/iosfwd src/iosfwd

File renamed without changes.

include/iostream src/iostream

File renamed without changes.

include/istream src/istream

File renamed without changes.
File renamed without changes.

include/iterator src/iterator

File renamed without changes.
File renamed without changes.

include/limits src/limits

File renamed without changes.

include/list src/list

File renamed without changes.

include/locale src/locale

File renamed without changes.

include/map src/map

File renamed without changes.

include/memory src/memory

File renamed without changes.

0 commit comments

Comments
 (0)