Giter VIP home page Giter VIP logo

arduinostl's Introduction

ArduinoSTL

This is an implementation of a C++ standard library packaged as an Arduino library. The library supports teaching my CS-11M class by adding key C++ features into the Arduino environment.

The library is ported from uClibc++:

http://git.uclibc.org/uClibc++

With a streams implementation from Andy Brown's Arduino Library:

http://andybrown.me.uk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/

Using printf() and scanf()

The ArduinoSTL header file contains code to bind a serial port of your choice to the stdio primitives. This happens automatically but the user must still call Serial.begin()

#include <ArduinoSTL.h>

void setup() {
  Serial.begin(9600); 
  printf("Hello World\n");
}

Using cin an cout

When you include this header file you automatically get cin and cout based on Serial. See below for how to specify your own device. Here's an example sketch using cin and cout .

#include <ArduinoSTL.h>

using namespace std;

void setup() {
  Serial.begin(9600);
  cout << "Feed me an integers." << endl;
}

void loop() {
  int foo;
  if (cin >> foo) { 
    cout << "You fed me " << foo << endl;
  }else{
    cin.clear();
    cin.ignore();
  }
}

Changing the Serial Port

You can change what serial port that cin, cout and printf() use. You can use built-in serial ports (e.g. Serial1 on Leonardo) or you can use software serial ports that implement Stream.

Using a Built-in Port

In src/ArduinoSTL.cpp change the value of ARDUINOSTL_DEFAULT_SERIAL. Leave the other defaults uncommented.

Using a SoftwareSerial port.

Set ARDUINO_DEFAULT_SERAL to NULL. Comment out the other defaults.

Here's an example sketch that uses SofwareSerial:

#include <ArduinoSTL.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1);

namespace std { 
  ohserialstream cout(mySerial);
  ihserialstream cin(mySerial);
}

void setup() {
  mySerial.begin(9600);
  ArduinoSTL_Serial.connect(mySerial);
}

Avoiding Instantiation of cin and cout

Comment out ARDUINOSTL_DEFAULT_CIN_COUT and nothing will be instantiated. You must comment out this flag if you intend to select a non-default serial port. There's no appreciable overhead for using printf() so you cannot currently avoid initializaing it.

Known Issues

Printing of floats and doubles using cout ignores format specifiers.

uClibc seems to be fairly complete. Strings and vectors both work, even with the limited amount of heap available to Arduino. The uClibc++ status page can be found here:

https://cxx.uclibc.org/status.html

Always use the latest Arduino IDE. This library uses the Arduino IDE Library Specification rev.2.1 with features only available on Arduino 1.6.10 and higher. The specification can be found here:

https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification

License

The uClibc++ library is licensed under the LGPL. This project adopts the LGPL to be compatible with the bulk of the code that it uses. Unless otherwise noted all code is licensed under the LGPL. There's one exception:

arduinostl's People

Contributors

aentinger avatar aldot avatar amomchilov avatar amorosoc avatar amotl avatar barakwei avatar ciband avatar dependabot[bot] avatar dewhisna avatar facchinm avatar garrettkajmowicz avatar labodj avatar lglina avatar luanvso avatar mike-matera avatar neheb avatar per1234 avatar ps-m avatar scrpi avatar sleepdefic1t avatar vapier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinostl's Issues

Failed compilation of code using ArduinoSTL.h and array on Arduino Uno AVR Boards 1.8.3

I have written arduino C++ code in which I used std::array quite a lot. Of course I made sure to #include<ArduinoSTL.h> and #include<array>. The compiler raises multiple compilation errors (see below) without pointing to any line of the code:

/home/salwa/Arduino/libraries/ArduinoSTL/src/del_opvs.cpp:25:53: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/del_ops.cpp:25:50: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/del_opnt.cpp:25:56: error: 'nothrow_t' in namespace 'std' does not name a type _UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() { ^~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: error: declaration of 'operator new' as non-function _UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: error: 'size_t' is not a member of 'std' /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: note: suggested alternative: /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:22:12: error: 'nothrow_t' in namespace 'std' does not name a type const std::nothrow_t std::nothrow = { }; ^~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:25:6: error: 'new_handler' in namespace 'std' does not name a type std::new_handler __new_handler; ^~~~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:27:1: error: '_UCXXEXPORT' does not name a type

A similar issue was opened here https://github.com/mike-matera/ArduinoSTL/issues/56, it was suggested to use #include"ArduinoSTL.h" instead of #include<ArduinoSTL.h>, I did that but it didn't work. I also tried downgrading the AVR boards manager from 1.8.3 to 1.8.2 and to 1.8.1 but that didn't seem to solve the problem.

  • Computer kernel/OS: 5.4.0-67-generic #75~18.04.1-Ubuntu
  • ArduinoIDE: 1.8.13
  • Tested AVR Boards manager: 1.8.1, 1.8.2, 1.8.3 (the problem persists with all these versions)

Any suggestions?

Suggestion: correct Missing info in Documentation

Hello, this is pretty simple as issues go but....

there's Mike-Matera/ArduinoSTL and Mike-matera/avr_stl

  1. documentation for avr_stl is identical to ArduinoSTL even down to saying #include <ArduinoSTL> and not as might be expected #include <avr_stl>

  2. There's no indication what distinuishes these two libraries. Both have similar recent commits and both are available on the Arduino applications library manager.

Maybe indicate in the documentation what differs and what the use cases are intended for.

width() non-functional (for me)

This code:
[code]
// width.cpp -- using the width method
// C++ primer 17.4, page 1080

#include <ArduinoSTL.h>
//#include <PrintStream.h>

void setup() {

Serial.begin(115200);

using std::cout;
int w = cout.width(30);
cout << "default field width = " << w << ":\n";

cout.width(5);
cout << "N" <<':';
cout.width(8);
cout << "N * N" << ":\n";

for (long i = 1; i <= 100; i *= 10)
{
    cout.width(5);
    cout << i <<':';
    cout.width(8);
    cout << i * i << ":\n";
}
// std::cin.get();

}[/code]

void loop() {}

is supposed to print right justified. It doesn't, everything on a line is jammed together.

Am I doing something wrong?

Facing problem with usase of functional

`
typedef std::function<void(uint8_t pin, uint8_t event, uint8_t count, uint16_t length)> TDebounceEventCallback;

`

I have a library which is using function templates like this, and i am little new with this type of code in C++. But i found that in the arduinoSTL library there is no template for function instead only for unary_function and binary_function...
Can somebody help me here how can i use function of that sort...

multiple definition of `std::nothrow'

When compiling the following sketch,

#include <ArduinoSTL.h>

void setup() {}
void loop() {}

this error is raised:

arduino-cli compile --fqbn arduino:avr:pro --warnings all --output-dir build \
    --build-property compiler.cpp.extra_flags="-pedantic"
new.cpp.o (symbol from plugin): In function `operator new(unsigned int)':
(.text+0x0): multiple definition of `std::nothrow'
/tmp/arduino-sketch-DAE3E2C59CB46B47AC6BC234B0EB1886/libraries/ArduinoSTL/new_handler.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

Commenting out line 22 of src/new_handler.cpp seems to fix the issue, but this perhaps introduces other problems.

My set up:

  • arduino-cli Version: 0.25.1 Commit: 436f0bb9 Date: 2022-07-25T15:01:55Z
  • ArduinoSTL version 1.3.3
  • arduino:avr core version 1.8.5

This issue can be reproduced in the Wokwi simulator.

printf blocks for a long time when serial monitor gets disconnected

To reproduce, connect an LED to pin 13 (if one isn't already), copy this file to a new sketch and upload the code to your Arduino.

Then, watch the LED blink. If you then open the serial monitor, you can see "running... " being printed periodically.

If you then close the serial monitor again, the LED blinks very slowly. Instead of 1000ms for one full on-off cycle, it takes about 6500ms. When turning the serial monitor back on, speed reverts to normal.

The same thing happens when using Arduino's built-in Serial.println like this, however the total duration only increases to about 2000ms.

Is this fixable? Can I maybe try and detect a disconnected serial stream to work around this?

Memory usage of this library

This library uses 22 % (468 or 459 bytes) of the dynamic memory (RAM). Since I have trouble with memory with one of my projects, is there a way to reduce your library's memory usage?

Error compiling for board SparkFun Pro Micro.

Arduino: 1.6.9 (Windows 7), Board: "SparkFun Pro Micro, ATmega32U4 (5V, 16 MHz)"

C:\Users\jy\Documents\Arduino\libraries\ArduinoSTL\src\ArduinoSTL.cpp:9:23: error: 'Serial' was not declared in this scope

ohserialstream cout(Serial);

                   ^

C:\Users\jy\Documents\Arduino\libraries\ArduinoSTL\src\ArduinoSTL.cpp:10:22: error: 'Serial' was not declared in this scope

ihserialstream cin(Serial);

                  ^

C:\Users\jy\Documents\Arduino\libraries\ArduinoSTL\src\ArduinoSTL.cpp:28:46: error: 'Serial' was not declared in this scope

static __Arduino_STDIO_hack __stdio_wrapper(&Serial);

                                          ^

exit status 1
Error compiling for board SparkFun Pro Micro.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Trivial sketch won't compile using Arduino 1.8.13

This library worked mostly fine for me in Arduino 1.8.12, but in 1.8.13 the following trivial sketch won't compile. My intuition is that it's an include-order dependency issue.

#include <ArduinoSTL.h>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

with the following errors:

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\del_opvs.cpp:25:53: error: 'std::size_t' has not been declared

_UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){

                                                 ^~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\del_opnt.cpp:25:56: error: 'nothrow_t' in namespace 'std' does not name a type

_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() {

                                                    ^~~~~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\del_ops.cpp:25:50: error: 'std::size_t' has not been declared

_UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){

                                              ^~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\del_opvnt.cpp:25:58: error: 'nothrow_t' in namespace 'std' does not name a type

_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) throw(){

                                                      ^~~~~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_opnt.cpp:25:37: error: declaration of 'operator new' as non-function

_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){

                                 ^~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_opnt.cpp:25:37: error: 'size_t' is not a member of 'std'

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_opnt.cpp:25:37: note: suggested alternative:

In file included from c:\users\nholt\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\stdlib.h:48:0,

             from C:\Users\NHolt\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino/new.h:22,

             from C:\Users\NHolt\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino/new:5,

             from E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_opnt.cpp:20:

c:\users\nholt\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\7.3.0\include\stddef.h:216:23: note: 'size_t'

typedef SIZE_TYPE size_t;

                   ^~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_opnt.cpp:25:54: error: expected primary-expression before 'const'

_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){

                                                  ^~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_handler.cpp:22:12: error: 'nothrow_t' in namespace 'std' does not name a type

const std::nothrow_t std::nothrow = { };

        ^~~~~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_handler.cpp:25:6: error: 'new_handler' in namespace 'std' does not name a type

std::new_handler __new_handler;

  ^~~~~~~~~~~

E:\Users\NHolt\Documents\Arduino\libraries\ArduinoSTL-master\src\new_handler.cpp:27:1: error: '_UCXXEXPORT' does not name a type

_UCXXEXPORT std::new_handler std::set_new_handler(std::new_handler new_p) throw(){

^~~~~~~~~~~

exit status 1

Fails with latest IDE and Arduino

I see some references to this that are quite old. It seemed to say this was fixed. But I just upgraded top the latest of Arduino and the IDE and they have identical issues.

(.text+0x0): multiple definition of `std::nothrow'

I have tried the 1.8.5 and the IDE rc6. Am I missing something here, or has this issue resurfaced?

ISO C++1z does not allow dynamic exception specifications error

When trying compile an Arduino code with IDE 1.8.13 I am getting the error message

ArduinoSTL/src/new:40:54: error: ISO C++1z does not allow dynamic exception specifications
_UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc);

How to overcome this?

Issues using map

Hi Mike.
I'm using your library, and everything seems to work except map.
Here's my declaration in a .h file:
std::map<int, edSession*> sessions;
and the error I get is:
this declaration has no storage class or type specifier
What is wrong, please?
I also can't see how string, map and vector get pulled into my .h file when I add:
#include <ArduinoSTL.h>
Can you please explain? I'm fairly new to Arduino/C/C++
[email protected]

Including <initializer_list> with library

Hi,
I'm currently working on an Arduino library and I would like to use initializer lists to make it easier to use. This is supported on Arduino-compatible boards with ARM, ARM/SAM or Xtensa architectures, but not on AVR.
I'm able to solve this problem by including your initializer_list file. I just copied it to the src folder of my own library as initializer_list.h and added the following to my library source files:

#ifdef __AVR__
#include "initializer_list.h"
#else
#include <initializer_list>
#endif

Everything works great, however, I have no idea if it's allowed to redistribute this file with my library, and if so, how to do it without infringing any copyright laws.

Thanks in advance,
Pieter

Accessing Inner pointer for std::vector

I recently installed the library hoping it would aid my implementation.

What I basically do is I try to access the inner pointer to the data held by std::vector, like in the standard std::vector implementation using vector::data() function. This gives me a ton of errors because I think this functionality is not implemented.

Later edit: What I am trying to do is copy some memory held in a regular C buffer inside of the vector:

std::vector<uint8_t> buffer(10);

// some C buffer here holding some data called let's say buf
// copy it in the vector
memcpy(buffer.data(), buf, 10 * sizeof(uint8_t))

Could this be achieved using ArduinoSTL?

Later, later edit: Just realised that the begin() function does exactly what I am looking for.

a lot of issues during compilation on plateformio / stm32 boards / arduino

having a lot of compilation issues. Please see below my plateformio ini file and compilation errors

compilation errors:

from AruidoSTL/src/cmath:
there are no arguments to 'rand' that depend on a template parameter, so a declaration of 'rand' must be available [-fpermissive]
'::acos' has not been declared
'::asin' has not been declared
...

from ArduinoSTL/src/cstdlib:
'::abort' has not been declared
'::abs' has not been declared
...

etc...

plateformio.ini
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
board_build.mcu = stm32f411ceu6
framework = arduino
debug_tool = blackmagic
upload_protocol = blackmagic
monitor_speed = 115200

build_flags =
-D USER_SETUP_LOADED=1
-include setup_tft.h

lib_deps =

RECOMMENDED

Accept new functionality in a backwards compatible manner and patches

mike-matera/ArduinoSTL @ ^1.3.3
bodmer/TFT_eSPI @ ^2.4.42
SPI
ux

<array>?

I see that there's valarray but not array. This strikes me as strange because it seems like array would be the logical choice to use on a microcontroller for static data, which is what I want array for.

Use case: constant array of instructions to run on some given input, compatible with c++ features and avoiding using a c array.

cout should support const char arrays from flash

It should be possible to use Macro "F()" to store strings (const char*) from flash memory (PROGMEM) like Arduinio print/println does. This saves RAM.

cout << F("\r\nSystem halted!") << endl;

The Arduino library uses class __FlashStringHelper in macro F(). I have added (in "ostream")

template<class charT, class traits> _UCXXEXPORT basic_ostream<charT,traits>&
    operator<<(basic_ostream<charT,traits>& out, const __FlashStringHelper* c)

and

template<class traits> _UCXXEXPORT basic_ostream<char,traits>&
    operator<<(basic_ostream<char,traits>& out, const __FlashStringHelper* c)

With code from Arduino library file Print.cpp. Have given it a short test and it works on Arduino UNO with current IDE / eclipse.

Will try to attach patch.

Will not compile for Teensy 3.1/3.2

I struggled the past days to compile my project, where other libs included ArduinoSTL, even though, they did not use it. It took me some time to figure it out. The following code will not compile on PlatformIO@VSCode and does nothing but include the ArduinoSTL.h @ version 1.1.0.

https://pastebin.com/7KE4puMr

The Error is https://pastebin.com/vm51i2zQ

It looks like, C++11 keywords are not recognized, even though, everything is compiled with at least C++11, if not C++14. I tested this on ArduinoIDE too (with teensyduino-core) and had similar troubles.

Solution to my problem: Exclude ArduinoSTL from compile. But this won't fix the incompatibility of this lib with the compile for the teensy platform

Note: ArduinoSTL compiles perfectly fine on Arduino Uno/Nano though.

Problems compiling

From a minimal setup in a new project, including only:
#include <ArduinoSTL.h>

I'm getting:

... error: '::abort' has not been declared 27 | using ::abort; | ^~~~~

etc... from cstdlib and similarly for all of cmath.

Using:
Arduino IDE 1.8.13
1.8.2, 1.8.8 of Arduino SAMD, 32 bits ARM Cortex-M0+ Board (Adafruit ItsyBitsy M4)
1.6.2 Adafruit SAMD
On Windows 10

Strange thing is that it was working fine and then at some point later in the day I upgraded versions in the board manager ... tried downgrading but never got things working again.

The other thing I did earlier in the day was install Atmel Studio 7. Was able to compile after that, though.

I tried using nholthaus' version from issue 56, as the issue looked possibly similar to mine, but had no luck with it. Same result.

Thanks in advance for any help with this issue.

Client side Serial binding to cin/cout

Hi!

Saw your code comments about it, and yes its needed...

my approach was to remove the .cpp implementation

namespace std
{
  // ohserialstream cout(Serial);
  // ihserialstream cin(Serial);
}

and add this to my sketch

ohserialstream std::cout(Serial);
ihserialstream std::cin(Serial);

for me it sounds as a nice trade-off, no?

P.S. ok looking at __stdio_wrapper ...

License of serstream unclear

This library suggests (through its LICENSE file) that it (exclusively) uses the LGPL license. However, Andy Brown's stream support (which I think is only the serstream file) uses a different license (the serstream file refers to http://andybrown.me.uk/terms-and-conditions/ which shows a BSD license). I'm not sure if there are other files with different licenses?

I would suggest:

  • Adding a note to the README about the license in use (e.g. LGPL for most files, referring to LICENSE and list files with different license
  • Adding the BSD license from Andy's site into the serstream file, to make it clear what license applies (this is really something that Andy should have done, but doing it here at least improves the clarity of the licensing of this library).

How does that sound?

Initializing vector<string> Beyond a Number of Entries Crashes Sketch

Arduino IDE 1.8.13
Board v 1.8.2 Uno

The code below will write to the serial output unless Line 7 with "LK15" (or more values) is include in the initialization list. Then no serial output is produced. Best I can tell it is not exceeding memory limits.

#include "ArduinoSTL.h"
//---------------------------------------------------------------------------------------------------------------------------
static const std::vector<std::string> noTxLocs { "IO78", "IO88", "IO77", "IO87", "IO76", "IO86", "IO75", "IO85", "IO84",
                                           "IO94", "IO83", "IO93", "IO82", "IO92", "JO02", "IO81", "IO91", "JO01",
                                           "IO70", "IO80", "IO90", "IO64", "PN31", "PN41", "PN20", "PN30", "PN40",
                                           "PM29", "PM39", "PM28", "PM38", "LK16",   
//                                           "LK15", // remove comment from this line
//                                           "LK14", // "LK13", // "LK23",
//                                           "LK24", "LK25", "LK26", "LK36", "LK35", "LK34", "LK33", "LK44", "LK45", 
//                                           "LK46", "LK47", "LK48", "LK58", "LK57", "LK56", "LK55"
};
//---------------------------------------------------------------------------------------------------------------------------
void setup() {
    Serial.begin(115200);
    std::cout  << "Setup running\n";
}
//---------------------------------------------------------------------------------------------------------------------------
void loop() {
}

deque - Popping front crashes the arduino

Code:

if(!packet_deque.empty())
  {
    last_consumed_packet = packet_deque.front();
    switch(last_packet.data_m[0])
    {
      case 0: // Motor off
        analogWrite(dc_speed_pin, 0);
        Serial.println("off");
      break;
      case 1: // Motor on
        analogWrite(dc_speed_pin, 100);
        Serial.println("on");
      break;
      case 2: // Motor right
        digitalWrite(dc_direction_pin, 0);
        Serial.println("right");
      break;
      case 3: // Motor left
        digitalWrite(dc_direction_pin, 1);
        Serial.println("left");
      break;
    }
 
    Serial.println(0);
    packet_deque.pop_front();
    Serial.println(1);
  }

The serial monitor output

19:51:53.975 -> Started
19:51:54.997 -> on
19:51:54.997 -> 0

As you can see, the pop_front of the deque causes the arduino to fail in some way.

Additional Information: Arduino Uno, 9600 baud rate

Wont compile with VS Code and PlatformIO

Hi

I tried your previous STL library, that wouldnt compile, but i saw a comment saying that project was dead and to try this one instead. So I scrapped that idea and tried this one. Again I get a failure to compile.

#include "ArduinoSTL.h"
void setup()
{
}

void loop(void)
{
}

In file included from .pio\libdeps\lolin32\ArduinoSTL\src\ArduinoSTL.cpp:2:0:
C:\users\mine.platformio\packages\framework-arduinoespressif32\cores\esp32/Arduino.h:158:12: error: 'std::isinf' has not been declared

Is this project dead too or not supporting VS Code PlatformIO ?

It can not be used,and I do not know how to fix it

In file included from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/string:25:0,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/locale:22,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/ios:22,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/serstream:18,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/ArduinoSTL.h:12,

             from E:\arduino\project\Main\Main.ino:1:

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/vector:43:94: error: macro "swap" passed 4 arguments, but takes just 2

template <class T, class Allocator> void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/vector:523:106: error: macro "swap" passed 4 arguments, but takes just 2

template <class T, class Allocator> _UCXXEXPORT void swap(vector<T,Allocator>& x, vector<T,Allocator>& y){

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/vector:524:11: error: macro "swap" requires 2 arguments, but only 1 given

x.swap(y);

In file included from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/locale:22:0,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/ios:22,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/serstream:18,

             from E:\Arduino\libraries\ArduinoSTL-1.1.0\src/ArduinoSTL.h:12,

             from c:\users\gwj\appdata\local\temp\arduino_build_132997\sketch\define.h:12,

             from E:\arduino\project\Main\Main.ino:1:

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/string:401:48: error: macro "swap" passed 3 arguments, but takes just 2

_UCXXEXPORT void swap(basic_string<Ch,Tr,A>& s){

                                            ^

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/string:404:24: error: macro "swap" requires 2 arguments, but only 1 given

vector<Ch, A>::swap(s);

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/string:1003:91: error: macro "swap" passed 6 arguments, but takes just 2

swap(basic_string<charT,traits,Allocator>& lhs, basic_string<charT,traits,Allocator>& rhs)

                                                                                       ^

E:\Arduino\libraries\ArduinoSTL-1.1.0\src/string:1005:14: error: macro "swap" requires 2 arguments, but only 1 given

lhs.swap(rhs);

Compile error on the MKR1000

I successfully used ArduinoSTL in the past. But now I get a compile error for the MKR1000 just by including ArduinoSTL.h:

In file included from /Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ostream:28:0,
                 from /Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/istream:24,
                 from /Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/serstream:19,
                 from /Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ArduinoSTL.h:12,
                 from /Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ArduinoSTL.cpp:1:
/Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ostream_helpers:34:38: error: 'uint8_t' has not been declared
 int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer_size);
                                      ^
exit status 1
Error compiling for board Arduino/Genuino MKR1000.

Any ideas? I'm using the latest version of the library and the Arduino IDE.

TIA.

Bugs in file complex

In line 310:
return complext(sinh(v.real()) * cos(v.imag()), cosh(v.real()) * sin(v.imag()) );

In line 302:
return polar(pow(v,p.real()), y.imag() * log(x) );

return polar(pow(v,p.real()), y.imag() * log(x) );

return complext<T>(sinh(v.real()) * cos(v.imag()), cosh(v.real()) * sin(v.imag()) );

Support for Error Handing for using with Eclipse plugin

No errors at all when using with the Arduino IDE.
However, I'm one of those who prefers to use the more expansive Eclipse IDE + plugin.
I imported the source code library with no issues, however when attempting to compile receive the error:

"C:\Users\David\Documents\Arduino\libraries\ArduinoSTL\extras\uClibc++-OriginalFiles\tests\testframework.h:32:3: error: exception handling disabled, use -fexceptions to enable
catch (...) {
^
make: *** [ArduinoSTL\extras\uClibc++-OriginalFiles\tests/subdir.mk:98: ArduinoSTL\extras\uClibc++-OriginalFiles\tests\algotest.cpp.o] Error 1"

Any ideas of settings or quick fix to make this compatible?

warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

I'm trying to use the library, but the library would not even compile

When I try to compile, I get a long list of warnings. I will paste only one because they are all the same.

`In file included from D:\Program Files\Arduino\libraries\ArduinoSTL\src/memory:20:0,

             from D:\Program Files\Arduino\libraries\ArduinoSTL\src/char_traits:22,

             from D:\Program Files\Arduino\libraries\ArduinoSTL\src/iosfwd:21,

             from D:\Program Files\Arduino\libraries\ArduinoSTL\src/serstream:48,

             from D:\Program Files\Arduino\libraries\ArduinoSTL\src/ArduinoSTL.h:12,

             from C:\Users\jehad\Desktop\TestCppOnArduino\sketch_nov27a\sketch_nov27a.ino:1:

             D:\Program Files\Arduino\libraries\ArduinoSTL\src/new:40:54: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

              _UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc);

                                                                   ^~~~~`

What am I doing wrong?

Problem with %f in printf and scanf

I'm trying to use printf() and scanf() with %f format specifier, but they not work. For scanf(), the program does not wait for the serial and for printf(), it prints the float number as a "?".

Using cin and cout it works correctly, but with only 2 digits of precision.

I'm using an Arduino Nano with ATMEGA328.

Thanks!

Memory usage

Thank you for your work on this library. When I swapped out StandardCplusplus for your's, I noticed an almost 20% increase in memory requirements. Is this normal and/or expected? Seems like this will be problematic for me using one of my Uno's.

std::function not supported ??

hello
i would like first to thank you for the great work.
i would like to use the following code, but i guess the functional header doesnt have the function template:
#include

class LambdaTest {
public:

LambdaTest(std::function<void (int n)> lambda){
lambda_ptr = &lambda ;
}

void callLambda(int value) {
(*lambda_ptr)(value);
}

protected:
std::function<void (int n)> *lambda_ptr;

};

Reverse order of std::swap_range and std::iter_swap

There is an issue when compiling for a Genuino Zero.
It does not like the fact that the definition for std::iter_swap comes before std::swap_range (which uses it).
The order two functions should be swapped.

Doesn't work with Teensyduino core

Attempting to use PlatformIO with the latest version of this library and a Teensy2 (ATMega32U4) via

[env:teensy2]
platform = teensy
board = teensy2
framework = arduino
build_unflags = -fno-exceptions -std=gnu++11
build_flags = -DTEENSY_OPT_FASTEST -fexceptions -std=gnu++17
; use a more recent 7.3.0 compiler instead of 5.4.1
platform_packages =
   toolchain-atmelavr@~3.70300.0
; fill in missing parts of the standard C++ library
lib_deps =
  https://github.com/mike-matera/ArduinoSTL/archive/refs/heads/master.zip

and code src\main.cpp

#include <Arduino.h>
#include <stdexcept>
void setup(){
  Serial.begin(9600);
  try {
     throw std::runtime_error("Test test");
  } catch(const std::exception& e) {
     Serial.println(e.what());
  }
}
void loop(){
}

Results in

In file included from .pio\libdeps\teensy2\ArduinoSTL\src/memory:20:0,
                 from .pio\libdeps\teensy2\ArduinoSTL\src/char_traits:22,
                 from .pio\libdeps\teensy2\ArduinoSTL\src/string:21,
                 from .pio\libdeps\teensy2\ArduinoSTL\src/stdexcept:22,
                 from src\main.cpp:2:
.pio\libdeps\teensy2\ArduinoSTL\src/new:41:18: error: declaration of 'void operator delete(void*) noexcept' has a different exception specifier
 _UCXXEXPORT void operator delete(void* ptr) _UCXX_USE_NOEXCEPT;
                  ^~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/Printable.h:26:0,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/Print.h:28,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/Stream.h:24,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores/usb_serial/usb_api.h:6,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/usb_api.h:2,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/WProgram.h:22,
                 from C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/Arduino.h:1,
                 from src\main.cpp:1:
Compiling .pio\build\teensy2\lib265\ArduinoSTL\eh_globals.cpp.o
C:\Users\Max\.platformio\packages\framework-arduinoteensy\cores\teensy/new.h:14:6: note: from previous declaration 'void operator delete(void*)'
 void operator delete(void * ptr);
      ^~~~~~~~

So cores/teensy/new.h with its declaration of

 void operator delete(void * ptr);

seems to be clashing with this library's declaration of

 _UCXXEXPORT void operator delete(void* ptr) _UCXX_USE_NOEXCEPT;

Maybe it's possible to detect the Teensyduino core case via TEENSYDUINO global macro and not declare / define the delete operator?

in file .src\limits line24 there throw an err

in file .src\limits line24 there throw an err
but I dont catch the err log,the line detail is:
#warning limits header is nowhere complete or accurate
source:
https://github.com/mike-matera/ArduinoSTL/blob/master/src/limits

the ENV is arduino 1.8.3
my code is

`#include <ArduinoSTL.h>
#include
using namespace std;

void Example_Arduino_Blink_LED(){
/*feedback and shift regs. declarations */

/* END feedback and shift regs declarations */
bool wireUID_424_ = true;
bool wireUID_740_A = true;
long wireUID_705_ = 3;
long wireUID_652_ = 2;
pinMode(wireUID_652_,wireUID_740_A?OUTPUT:INPUT);
pinMode(wireUID_705_,wireUID_740_A?OUTPUT:INPUT);
/***** BEGIN WhileLoop ********/
vector< bool > feedbackNode_615;
bool feedbackNodeInitBool_615 = true;

bool wireUID_430_ = false; //LoopEndRef.
int iteratorUID_289 = 0; //loop iterator
do{
 //shift register init and get front value
    /*feedback and shift regs. declarations */
    
    /* END feedback and shift regs declarations */
    bool wireUID_317_B;
    bool wireUID_642_;
    long wireUID_1157_ = 2;
    long wireUID_921_ = 3;
    long wireUID_426_ = 220;
    if (feedbackNodeInitBool_615){
        feedbackNode_615.push_back(wireUID_424_);
        feedbackNodeInitBool_615 = false;
    }
    wireUID_642_ = feedbackNode_615.front(); feedbackNode_615.erase(feedbackNode_615.begin());
    delay(wireUID_426_);
    wireUID_317_B = !wireUID_642_;
    digitalWrite(wireUID_921_,wireUID_642_?HIGH:LOW);
    /* Don't know how to translate class "Generic ->GObject ->Node": "" */
    digitalWrite(wireUID_1157_,wireUID_317_B?HIGH:LOW);
    feedbackNode_615.push_back(wireUID_317_B);
    
    
     //C code
    
     //output assgn.
    iteratorUID_289++; //iterator increment
}while(!wireUID_430_); //negation because in LabVIEW it is when stop (oposite)

/****** END WhileLoop */

}

void setup(){
Example_Arduino_Blink_LED();
}
void loop(){
}
`

In my project I removed line 24 then seems OK.

std::string and FreeRTOS fails

Hello,
I am relatively new to Arduino and my C++ knowledge is a bit rusty so please excuse if i'm wrong with my post.
There seems to be a memory allocation problem with strings in combination with FreeRTOS. The following code works fine:

#include <Arduino_FreeRTOS.h>
#include <Controllino.h> 
#include <ArduinoSTL.h>

void StringTestTask(void *pvParameters);

void setup() {
  Serial.begin(9600);
  while(!Serial);
  std::string s("Hello World!");
  Serial.println(s.c_str());
  xTaskCreate(
    StringTestTask,
    "StringTestTask",
    512,
    NULL,
    2,
    NULL);
}

void loop() {}

void StringTestTask(void *pvParameters) {
  std::string s("Hello World!");
  Serial.println(s.c_str());

  for(;;) {}
}

I get "Hello World!" on my serial console. When I comment out the string in the setup() function like this:

#include <Arduino_FreeRTOS.h>
#include <Controllino.h> 
#include <ArduinoSTL.h>

void StringTestTask(void *pvParameters);

void setup() {
  Serial.begin(9600);
  while(!Serial);
  //std::string s("Hello World!");
  //Serial.println(s.c_str());
  xTaskCreate(
    StringTestTask,
    "StringTestTask",
    512,
    NULL,
    2,
    NULL);
}

void loop() {}

void StringTestTask(void *pvParameters) {
  std::string s("Hello World!");
  Serial.println(s.c_str());

  for(;;) {}
}

Nothing is written to the console. The rest of the library seems to work (at least the parts I have tested).
Any suggestions about this? Thank you for your help.

Alex

"Stream has not been declared" with PlatformIO and [email protected]

When compiling a simple sketch (even an empty one) when ArduinoSTL is added to lib_deps in platformio.ini for an Arduiono Nano Every board (board=nano_every), I get the following error:

Compiling .pio/build/nano_every/FrameworkArduino/NANO_compat.cpp.o
In file included from .pio/libdeps/nano_every/ArduinoSTL/src/ArduinoSTL.h:12:0,
                 from .pio/libdeps/nano_every/ArduinoSTL/src/ArduinoSTL.cpp:1:
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:307:9: error: '::Stream' has not been declared
 
         ^     
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:309:73: error: 'Stream' does not name a type; did you mean 'fstream'?
 template <class charT, class traits = char_traits<charT>, class Tserial=Stream> class basic_iserialstream;
                                                                         ^~~~~~
                                                                         fstream
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:310:73: error: 'Stream' does not name a type; did you mean 'fstream'?
 template <class charT, class traits = char_traits<charT>, class Tserial=Stream> class basic_oserialstream;
                                                                         ^~~~~~
                                                                         fstream
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:311:73: error: 'Stream' does not name a type; did you mean 'fstream'?
 
                                                                         ^     
                                                                         fstream
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:313:33: error: template argument 3 is invalid
 typedef basic_oserialstream<char> ohserialstream;
                                 ^
.pio/libdeps/nano_every/ArduinoSTL/src/serstream:314:33: error: template argument 3 is invalid
 
                                 ^

Not working for a MKR1000

I'm getting the error message below when compiling for the MKR1000. Is this something that can easily be fixed or is there a bigger issue here?

Arduino: 1.6.11 (Mac OS X), Board: "Arduino/Genuino MKR1000"

Build options changed, rebuilding all
WARNING: library ArduinoSTL claims to run on [avr] architecture(s) and may be incompatible with your current board which runs on [samd] architecture(s).
/Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ArduinoSTL.cpp: In constructor '__Arduino_STDIO_hack::__Arduino_STDIO_hack(Stream*)':
/Users/arno/Documents/Arduino/libraries/ArduinoSTL/src/ArduinoSTL.cpp:60:44: error: 'fdevopen' was not declared in this scope
fdevopen(arduino_putchar, arduino_getchar);
^
exit status 1
Error compiling for board Arduino/Genuino MKR1000.

ArduinoSTL and Visual Micro

Hello,

I recently decided to code for the STM32s I got a couple of years ago. And indeed, I decided to use the STL... (on a Black Pill)

But, is STM32 supported ?

In Arduino IDE : it seems it is.

In Visual Studio + Visual Micro, your library is not recognized, and headers not included until "architectures" is set to "*" in file library properties. And even with this change, I immediatly ran into problems (Visual Micro only). I don't understand why... They share the same gcc.

I found nothing on the web about such an issue, and STM32duino website is down (Server quota exceeded).

Here's some code that compiles and run fine with Arduino IDE, but not Visual Micro :

#include <ArduinoSTL.h>

class Item
{
	public:
	Item(uint32_t i, std::string s): index(i), str(s) {}
	std::string str;
	uint32_t index;
};

std::vector<Item> Vector;
Item item0(5, std::string("five"));
Item item1(4, std::string("four"));
Item item2(3, std::string("three"));
Item item3(2, std::string("two"));
Item item4(1, std::string("one"));
Item item5(0, std::string("zero"));

bool compare(Item& item1, Item& item2)
{
	return item1.index < item2.index;
}

void setup()
{
	Serial.begin(9600);
	while (!Serial) ;
	Serial.print("hello\n\n");
	Vector.push_back(item0);
	Vector.push_back(item1);
	Vector.push_back(item2);
	Vector.push_back(item3);
	Vector.push_back(item4);
	Vector.push_back(item5);

for (auto& iter : Vector)
   Serial.println(iter.str.c_str());

Serial.println("\nsort :\n");

std::sort(Vector.begin(), Vector.end(), compare);

for (auto& iter : Vector)
   Serial.println(iter.str.c_str());
}

void loop()
{
}

Errors in Visual Micro ; seems to be related to std::sort()


TestSTL.ino: 4:14: error: 'Item' was not declared in this scope
 
TestSTL.ino: 4:20: error: 'item1' was not declared in this scope
 
TestSTL.ino: 4:27: error: 'Item' was not declared in this scope
 
TestSTL.ino: 4:33: error: 'item2' was not declared in this scope
 
Error compiling project sources
TestSTL.ino: 4:38: error: expression list treated as compound expression in initializer [-fpermissive]
TestSTL.ino: In constructor Item::Item(uint32_t, std::string)
TestSTL.ino: 9:11: warning: 'Item::index' will be initialized after [-Wreorder]
   uint32_t index
TestSTL.ino: 8:14: warning:   'std::string Item::str' [-Wreorder]
  std*: string str
TestSTL.ino: 6:2: warning:   when initialized here [-Wreorder]
  Item(uint32_t i, std*: string s): index(i), str(s) {}
 
TestSTL.ino: In function bool compare(Item&, Item&)
 
TestSTL.ino: 20:38: error: 'bool compare(Item&, Item&)' redeclared as different kind of symbol
   bool compare(Item& item1, Item& item2)
 
TestSTL.ino: 4:6: error: previous declaration of 'bool compare
 
vector:25: In file included from
string:25: from
locale:22: from
ios:22: from
serstream:49: from
ArduinoSTL.h:12: from
TestSTL.ino:1: from
algorithm: In instantiation of void std::stable_sort(RandomAccessIterator, RandomAccessIterator, Compare) [with RandomAccessIterator = Item*; Compare = bool]
Build failed for project 'TestSTL'
algorithm:861: required from void std  sort(RandomAccessIterator, RandomAccessIterator, Compare) [with RandomAccessIterator = Item*; Compare = bool]
TestSTL.ino:43: required from here
 
algorithm:849: error  comp cannot be used as a function
   if( comp( *temp, *(temp-1) ) ){



ESP-32 support?

Due to some issues on my current project, I've decided to switch from an Arduino Nano to an ESP-32, however I'm getting these errors whenever compiling my code:

WARNING: library ArduinoSTL-master claims to run on (avr, samd) architecture(s) and may be incompatible with your current board which runs on (esp32) architecture(s).
In file included from sketch\ino.ino.cpp:1:0:

C:\Users\azedo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/Arduino.h:163:12: error: 'std::isinf' has not been declared

 using std::isinf;

            ^

C:\Users\azedo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/Arduino.h:164:12: error: 'std::isnan' has not been declared

 using std::isnan;

exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.

Weird issue with Serial commands

After swapping out another library for you'rs, I noticed an issue with Serial.println() invocations. They don't seem to work outside of the setup method. And if I include Serial.println() commands with other functions contained in previously working lambdas on timed intervals, it prevents them from functioning.

Have you encountered this before?

Support for unordered_map

I noticed not all of the STL types are present, like unordered_map for example. Are these planned for the future?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.