Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I wrote the code below. But Serial.println occurred errors.
I believe in the code is wrong. But I don't know what is wrong.
Could you tell me how to fix the issue?
class Move {
public:
int x;
int y;
void go(int w, int h);
};
void Move::go(int w, int h) {
x += w;
y += h;
}
Move m;
void setup() {
Serial.begin(9600);
m.x = 10;
m.y = 20;
Serial.println("at start: x is %d, y is %d", m.x, m.y);
}
void loop() {
m.go(10, 20);
Serial.println("x is %d, y is %d", m.x, m.y);
}
The error is below:
c:\Users\a\Dropbox\!Arduino\class\classes.ino: In function 'void setup()':
classes:19:58: error: no matching function for call to 'HardwareSerial::println(const char [27], int&, int&)'
Serial.println("at start: x is %d, y is %d", m.x, m.y);
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:233,
from sketch\classes.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:77:12: note: candidate: size_t Print::println(const __FlashStringHelper*)
size_t println(const __FlashStringHelper *);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:77:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:78:12: note: candidate: size_t Print::println(const String&)
size_t println(const String &s);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:78:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:79:12: note: candidate: size_t Print::println(const char*)
size_t println(const char[]);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:79:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:80:12: note: candidate: size_t Print::println(char)
size_t println(char);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:80:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:81:12: note: candidate: size_t Print::println(unsigned char, int)
size_t println(unsigned char, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:81:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:82:12: note: candidate: size_t Print::println(int, int)
size_t println(int, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:82:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:83:12: note: candidate: size_t Print::println(unsigned int, int)
size_t println(unsigned int, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:83:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:84:12: note: candidate: size_t Print::println(long int, int)
size_t println(long, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:84:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:85:12: note: candidate: size_t Print::println(long unsigned int, int)
size_t println(unsigned long, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:85:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:86:12: note: candidate: size_t Print::println(double, int)
size_t println(double, int = 2);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:86:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:87:12: note: candidate: size_t Print::println(const Printable&)
size_t println(const Printable&);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:87:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:88:12: note: candidate: size_t Print::println()
size_t println(void);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:88:12: note: candidate expects 0 arguments, 3 provided
c:\Users\a\Dropbox\!Arduino\class\classes.ino: In function 'void loop()':
classes:24:48: error: no matching function for call to 'HardwareSerial::println(const char [17], int&, int&)'
Serial.println("x is %d, y is %d", m.x, m.y);
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:233,
from sketch\classes.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:77:12: note: candidate: size_t Print::println(const __FlashStringHelper*)
size_t println(const __FlashStringHelper *);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:77:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:78:12: note: candidate: size_t Print::println(const String&)
size_t println(const String &s);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:78:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:79:12: note: candidate: size_t Print::println(const char*)
size_t println(const char[]);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:79:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:80:12: note: candidate: size_t Print::println(char)
size_t println(char);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:80:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:81:12: note: candidate: size_t Print::println(unsigned char, int)
size_t println(unsigned char, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:81:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:82:12: note: candidate: size_t Print::println(int, int)
size_t println(int, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:82:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:83:12: note: candidate: size_t Print::println(unsigned int, int)
size_t println(unsigned int, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:83:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:84:12: note: candidate: size_t Print::println(long int, int)
size_t println(long, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:84:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:85:12: note: candidate: size_t Print::println(long unsigned int, int)
size_t println(unsigned long, int = DEC);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:85:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:86:12: note: candidate: size_t Print::println(double, int)
size_t println(double, int = 2);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:86:12: note: candidate expects 2 arguments, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:87:12: note: candidate: size_t Print::println(const Printable&)
size_t println(const Printable&);
^~~~~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:87:12: note: candidate expects 1 argument, 3 provided
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:88:12: note: candidate: size_t Print::println()
size_t println(void);
^~~~~~~
Please tell me what is wrong with me.
The problem is that you are using Serial.println() as if it where printf(). Serial.println(), as specified in the documentation, takes only two arguments, the first being the value that you want to print through the serial port, and the second being the format that you want that value to be sent as.
What you need to do to achieve what you originaly wanted is first concatenate the values that you want to send over and then send them with Serial.println().
If you want to print four things, most often the fastest and most efficient way is to simply call print 4 times. Print is pretty lightweight compared to involving format strings. If you're writing for a PC who cares. But if you're writing for a ATTINY or an UNO or something then you can usually use the savings.
Serial.println("at start: x is %d, y is %d", m.x, m.y);
becomes:
Serial.print("at start: x is ");
Serial.print(m.x);
Serial.print(", y is ");
Serial.println(m.y);
Note that I'm using print on all but the last one. Only the last one is println. That way only the last one gives a line break and the receiver doesn't have any way to know if I sent with one statement or three. It all goes in the same buffer and comes out the same way.
Related
The code :
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout << "this file works";
return 0;
}
Compiler output was ridiculously long. Some 114000 characters long. This is only a portion of it.
Compiler output on compilation :
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:174:5: note: no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'std::filesystem::__cxx11::path::string_type&&' {aka 'std::__cxx11::basic_string<wchar_t>&&'}
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:167:5: note: candidate: 'std::filesystem::__cxx11::path::path(std::filesystem::__cxx11::path&&)'
path(path&& __p) noexcept
^~~~
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:167:5: note: no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'std::filesystem::__cxx11::path&&'
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note: candidate: 'std::filesystem::__cxx11::path::path(const std::filesystem::__cxx11::path&)'
path(const path& __p) = default;
^~~~
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note: no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'const std::filesystem::__cxx11::path&'
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:163:5: note: candidate: 'std::filesystem::__cxx11::path::path()'
path() noexcept { }
^~~~
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:163:5: note: candidate expects 0 arguments, 1 provided
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
So, what you are seeing is an error message, not an output.
If the file bits/stdc++.h is not a file that you created,
then what you need to do is to replace
#include <bits/stdc++.h>
with
#include <iostream>
and that's gonna solve it for you.
I'm new to c++, and trying to compile simple arduino project in the Platformio.
platformio.ini file:
[platformio]
src_dir = .
lib_extra_dirs = .piolibdeps/, ../../
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
# PubSubClient
painlessMesh
main.ino file:
#include <Arduino.h>
#include <painlessMesh.h>
void setup()
{
}
void loop()
{
}
Should be something simple, but I'm getting next error:
'ArduinoJson6100_100::DynamicJsonDocument' has no member named
'nestingLimit'
Full compiler stack:
Executing task in folder test4: platformio run <
Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2;
framework: arduino)
------------------------------------------------------------------------------------------------------------ Verbose mode can be enabled via -v, --verbose option CONFIGURATION:
https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 > NodeMCU 1.0 (ESP-12E Module) HARDWARE:
ESP8266 80MHz 80KB RAM (4MB Flash) Converting main.ino Library
Dependency Finder -> LDF MODES:
FINDER(chain) COMPATIBILITY(soft) Collected 35 compatible libraries
Scanning dependencies... Dependency Graph |-- 1.3.0 |
|-- 6.10.0 | |-- 3.0.2 | |--
1.2.0 | | |-- 1.0 | |--
1.0 Compiling .pioenvs/nodemcuv2/src/main.ino.cpp.o
Generating LD script
.pioenvs/nodemcuv2/ld/local.eagle.app.v6.common.ld Archiving
.pioenvs/nodemcuv2/libef5/libArduinoJson_ID64.a Archiving
.pioenvs/nodemcuv2/libca3/libTaskScheduler_ID721.a Indexing
.pioenvs/nodemcuv2/libef5/libArduinoJson_ID64.a Indexing
.pioenvs/nodemcuv2/libca3/libTaskScheduler_ID721.a Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/BearSSLHelpers.cpp.o Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/CertStoreBearSSL.cpp.o Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFi.cpp.o Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiAP.cpp.o Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiGeneric.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiMulti.cpp.o
Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiSTA-WPS.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiSTA.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/ESP8266WiFiScan.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiClient.cpp.o
Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiClientSecureAxTLS.cpp.o
Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiClientSecureBearSSL.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiServer.cpp.o
Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiServerSecureAxTLS.cpp.o
Compiling
.pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiServerSecureBearSSL.cpp.o
Compiling .pioenvs/nodemcuv2/lib6c2/ESP8266WiFi/WiFiUdp.cpp.o
Compiling
.pioenvs/nodemcuv2/lib129/ESPAsyncTCP_ID305/AsyncPrinter.cpp.o
Compiling
.pioenvs/nodemcuv2/lib129/ESPAsyncTCP_ID305/ESPAsyncTCP.cpp.o
Compiling
.pioenvs/nodemcuv2/lib129/ESPAsyncTCP_ID305/ESPAsyncTCPbuffer.cpp.o
Archiving .pioenvs/nodemcuv2/lib6c2/libESP8266WiFi.a Indexing
.pioenvs/nodemcuv2/lib6c2/libESP8266WiFi.a Compiling
.pioenvs/nodemcuv2/lib129/ESPAsyncTCP_ID305/SyncClient.cpp.o Compiling
.pioenvs/nodemcuv2/lib129/ESPAsyncTCP_ID305/tcp_axtls.c.o Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/TaskScheduler.cpp.o
Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMesh.cpp.o
Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshAP.cpp.o
Archiving .pioenvs/nodemcuv2/lib129/libESPAsyncTCP_ID305.a Indexing
.pioenvs/nodemcuv2/lib129/libESPAsyncTCP_ID305.a Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshComm.cpp.o
Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshConnection.cpp.o
Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshDebug.cpp.o
Compiling
.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshJson.cpp.o
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp: In member
function 'String painlessMesh::buildMeshPackage(uint32_t, uint32_t,
meshPackageType, String&)':
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp:68:25: error:
no matching function for call to
'ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument()'
DynamicJsonDocument jsonBuffer; ^
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp:68:25: note:
candidates are: In file included from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/DynamicJsonDocument.hpp:7:0,
from .piolibdeps/ArduinoJson_ID64/src/ArduinoJson.hpp:21, from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson.h:9, from
.piolibdeps/painlessMesh_ID1269/src/painlessMesh.h:12, from
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp:8:
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:50:3:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(ArduinoJson6100_100::VariantRef)
[with TAllocator = ArduinoJson6100_100::DefaultAllocator]
BasicJsonDocument(VariantRef src) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:50:3:
note: candidate expects 1 argument, 0 provided
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:43:3:
note: template
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(const
T&, typename
ArduinoJson6100_100::enable_if::value>::type*)
BasicJsonDocument(const T& src, ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:43:3:
note: template argument deduction/substitution failed:
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp:68:25: note:
candidate expects 2 arguments, 0 provided DynamicJsonDocument
jsonBuffer; ^ In file included from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/DynamicJsonDocument.hpp:7:0,
from .piolibdeps/ArduinoJson_ID64/src/ArduinoJson.hpp:21, from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson.h:9, from
.piolibdeps/painlessMesh_ID1269/src/painlessMesh.h:12, from
.piolibdeps/painlessMesh_ID1269/src/painlessMeshComm.cpp:8:
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:36:3:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(const
ArduinoJson6100_100::BasicJsonDocument&) [with TAllocator
= ArduinoJson6100_100::DefaultAllocator] BasicJsonDocument(const BasicJsonDocument& src) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:36:3:
note: candidate expects 1 argument, 0 provided
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:33:12:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(size_t,
TAllocator) [with TAllocator = ArduinoJson6100_100::DefaultAllocator;
size_t = unsigned int] explicit BasicJsonDocument(size_t capa,
TAllocator allocator = TAllocator()) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:33:12:
note: candidate expects 2 arguments, 0 provided
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp: In
member function 'void MeshConnection::handleMessage(String&,
uint32_t)':
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:543:25:
error: no matching function for call to
'ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument()'
DynamicJsonDocument jsonBuffer; ^
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:543:25:
note: candidates are: In file included from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/DynamicJsonDocument.hpp:7:0,
from .piolibdeps/ArduinoJson_ID64/src/ArduinoJson.hpp:21, from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson.h:9, from
.piolibdeps/painlessMesh_ID1269/src/painlessMesh.h:12, from
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:9:
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:50:3:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(ArduinoJson6100_100::VariantRef)
[with TAllocator = ArduinoJson6100_100::DefaultAllocator]
BasicJsonDocument(VariantRef src) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:50:3:
note: candidate expects 1 argument, 0 provided
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:43:3:
note: template
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(const
T&, typename
ArduinoJson6100_100::enable_if::value>::type*)
BasicJsonDocument(const T& src, ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:43:3:
note: template argument deduction/substitution failed:
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:543:25:
note: candidate expects 2 arguments, 0 provided DynamicJsonDocument
jsonBuffer; ^ In file included from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/DynamicJsonDocument.hpp:7:0,
from .piolibdeps/ArduinoJson_ID64/src/ArduinoJson.hpp:21, from
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson.h:9, from
.piolibdeps/painlessMesh_ID1269/src/painlessMesh.h:12, from
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:9:
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:36:3:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(const
ArduinoJson6100_100::BasicJsonDocument&) [with TAllocator
= ArduinoJson6100_100::DefaultAllocator] BasicJsonDocument(const BasicJsonDocument& src) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:36:3:
note: candidate expects 1 argument, 0 provided
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:33:12:
note:
ArduinoJson6100_100::BasicJsonDocument::BasicJsonDocument(size_t,
TAllocator) [with TAllocator = ArduinoJson6100_100::DefaultAllocator;
size_t = unsigned int] explicit BasicJsonDocument(size_t capa,
TAllocator allocator = TAllocator()) ^
.piolibdeps/ArduinoJson_ID64/src/ArduinoJson/Document/BasicJsonDocument.hpp:33:12:
note: candidate expects 2 arguments, 0 provided
.piolibdeps/painlessMesh_ID1269/src/painlessMeshConnection.cpp:544:16:
error: 'ArduinoJson6100_100::DynamicJsonDocument' has no member named
'nestingLimit' jsonBuffer.nestingLimit = 255; ^
* [.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshComm.cpp.o]
Error 1
* [.pioenvs/nodemcuv2/lib3f1/painlessMesh_ID1269/painlessMeshConnection.cpp.o]
Error 1
======================================== [ERROR] Took 10.54 seconds ======================================== The terminal process terminated with exit code: 1
What am I doing wrong?
Thanks!
Solved in the library source: https://gitlab.com/painlessMesh/painlessMesh/issues/253
Author comment:
Thanks for reporting. This should be fixed in the latest version
(1.3.1). Let me know if you still have problems
This question already has an answer here:
mex compilation error C2440: 'initializing': cannot convert from 'const mwSize *' to 'const int32_t *'
(1 answer)
Closed 6 months ago.
I was trying to compile the function c_eoverlap in matlab following the instruction here:
http://www.robots.ox.ac.uk/~vgg/research/affine/evaluation.html#eval_soft
Of course, it wouldn't work out... My Matlab version is 2018a which is pretty new and the gcc -v outputs the following
Also attach this long error log, as I am pretty new to C++, please let me know if there is any other information needed, appreciate for your help!
>> mex repeatability/c_eoverlap.cxx
Building with 'Xcode Clang++'.
Error using mex
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:34:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims1 = mxGetDimensions(prhs[0]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:36:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims2 = mxGetDimensions(prhs[1]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:38:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims3 = mxGetDimensions(prhs[2]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:46:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[0] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:47:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[1] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:48:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[2] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:49:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[3] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:198:3: warning: 'delete[]'
applied to a pointer that was allocated with 'new'; did you mean 'delete'?
[-Wmismatched-new-delete]
delete []tdesc_out;
^ ~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:62:22: note: allocated with
'new' here
float *tdesc_out = new float[dims2[1]*dims1[1]];
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:199:3: warning: 'delete[]'
applied to a pointer that was allocated with 'new'; did you mean 'delete'?
[-Wmismatched-new-delete]
delete []tover_out;
^ ~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:63:22: note: allocated with
'new' here
float *tover_out = new float[dims2[1]*dims1[1]];
^
2 warnings and 7 errors generated.
You need to add -compatibleArrayDims to your mex command:
mex -compatibleArrayDims c_eoverlap.cxx
The code is written for older MATLABs that used 32-bit integers (int) for array sizes. Nowadays these are 64-bits (mwSize). This option forces the interface to work like it did in the older MATLABs. See the mex documentation for details.
There are some scary warnings about using delete[] instead of delete. It's just warnings, so it will compile, but you don't know if the code will do what it is supposed to.
Update 3 Jan. 2016: I have answered my own question now too.
I need some help formatting my "if" statement in this C++ macro please:
#define updateEEPROMVal(address,val) if (EEPROM.get(address)!=val) \
EEPROM.put(address,val)
I'm getting pages of errors, so I'm assuming it's a simple formatting problem.
Update Apr. 2020: Jump straight to my answer. My macro was fine (surrounding it with do {} while (false) would have been better of course, but it was fine as-is). I was simply forgetting the 2nd parameter in EEPROM.get() is all. The 2nd parameter is passed by NON-const C++ reference, and at the time I didn't really know what a reference was or how it worked, so I didn't use the .get() method correctly. That's it!
Back to my original question from 2016:
Here's the full context:
//----------------------------------------------------------------------------------------------------------------------------------
//storeXYValsIntoEEPROM
//-store the current global variable x and y low, center, and high values into EEPROM
//----------------------------------------------------------------------------------------------------------------------------------
#define updateEEPROMVal(address,val) if (EEPROM.get(address)!=val) \
EEPROM.put(address,val)
void storeXYValsIntoEEPROM()
{
//update EEPROM values *only* if necessary, this way you minimize writes (and wear-and-tear) on the EEPROM, since it is limited to
//100k writes per cell I believe (see datasheet)
updateEEPROMVal(0,x_low);
updateEEPROMVal(2,x_ctr);
updateEEPROMVal(4,x_high);
updateEEPROMVal(6,y_low);
updateEEPROMVal(8,y_ctr);
updateEEPROMVal(10,y_high);
}
UPDATE: HERE's my error output:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"
Using library IRremote in folder: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote (legacy)
Using library eRCaGuy_ButtonReader in folder: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\eRCaGuy_ButtonReader (legacy)
Using library EEPROM in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote -IC:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\eRCaGuy_ButtonReader -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM C:\Users\Gabriel\AppData\Local\Temp\build6111239347405487460.tmp\IR_Tx_code5_w_calibration_mode.cpp -o C:\Users\Gabriel\AppData\Local\Temp\build6111239347405487460.tmp\IR_Tx_code5_w_calibration_mode.cpp.o
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:43:30: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
operator const uint8_t() const { return **this; }
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:92:26: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
operator const int() const { return index; }
^
IR_Tx_code5_w_calibration_mode.ino: In function 'void storeXYValsIntoEEPROM()':
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:436:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:437:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:438:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:439:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:440:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: error: no matching function for call to 'EEPROMClass::get(int)'
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate is:
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
In file included from IR_Tx_code5_w_calibration_mode.ino:27:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template<class T> T& EEPROMClass::get(int, T&)
template< typename T > T &get( int idx, T &t ){
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM/EEPROM.h:130:31: note: template argument deduction/substitution failed:
IR_Tx_code5_w_calibration_mode.ino:430:61: note: candidate expects 2 arguments, 1 provided
IR_Tx_code5_w_calibration_mode.ino:441:3: note: in expansion of macro 'updateEEPROMVal'
Multiple libraries were found for "IRremote.h"
Used: C:\Gabe\Gabe - RC-extra\Arduino\Sketches\libraries\IRremote
Not used: C:\Program Files (x86)\Arduino\libraries\RobotIRremote
no matching function for call to 'EEPROMClass::get(int)'
Code with do{...}while(0) your macro (and don't forget the semicolon):
#define updateEEPROMVal(address,val) do{if (EEPROM.get(address)!=val) \
EEPROM.put(address,val);}while(0)
See also this
Better yet, make that a static inline function (to be put in some header file).
Also, use g++ -C -E source.cc > source.ii to get the preprocessed form, you can look inside it.
There is no need for this. When I wrote the library I made sure it minimizes the wear & tear.
The EEPROM function put() uses the update method on the byte level.
You are simply duplicating functionality.
If you have more questions regarding the EEPROM lib, ask on the forum.
I created a thread just for my library: https://forum.arduino.cc/index.php?topic=312645
My Answer:
Sorry for the trouble, it turns out I was misusing the EEPROM.get function, and the problem wasn't my macro at all. The EEPROM library get() method is defined: https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/EEPROM/src/EEPROM.h#L130, and the documentation here: https://www.arduino.cc/en/Reference/EEPROMGet.
I was simply missing the 2nd argument, accidentally using this:
EEPROM.get(address);
...instead of this:
any_type val_in_EEPROM;
EEPROM.get(address, val_in_EEPROM);
Here are 2 solutions I came up with that work.
1) Using a separate function:
-I prefer this method. It turns out the word "inline" in this case is optional, and makes no difference.
-This method makes my program 7610 bytes, with 472 bytes used for global variables. It takes 162 bytes less memory than option 2 below.
inline void updateEEPROMVal(uint16_t address, uint16_t val)
{
uint16_t val_in_EEPROM;
EEPROM.get(address,val_in_EEPROM);
if (val_in_EEPROM!=val)
EEPROM.put(address,val);
}
void storeGlobalXYValsIntoEEPROM()
{
updateEEPROMVal(0,x_low);
updateEEPROMVal(2,x_ctr);
updateEEPROMVal(4,x_high);
updateEEPROMVal(6,y_low);
updateEEPROMVal(8,y_ctr);
updateEEPROMVal(10,y_high);
}
2) Using a macro, as follows:
-I prefer the above method.
-This method takes 7772 bytes for program space, and 472 bytes for global variables. It takes 162 bytes more than the above method.
uint16_t val_in_EEPROM;
#define updateEEPROMVal(address,val) EEPROM.get(address,val_in_EEPROM); \
if (val_in_EEPROM!=val) \
EEPROM.put(address,val)
void storeGlobalXYValsIntoEEPROM()
{
uint16_t val_in_EEPROM;
updateEEPROMVal(0,x_low);
updateEEPROMVal(2,x_ctr);
updateEEPROMVal(4,x_high);
updateEEPROMVal(6,y_low);
updateEEPROMVal(8,y_ctr);
updateEEPROMVal(10,y_high);
}
Thanks for everyone's help!
3) (Updated answer) EEPROM.put(address,val) already does the functionality I'm trying to achieve above to avoid unnecessary wear on the EEPROM, so just use the .put() function by itself, as-is!
See #Chris A's answer here.
Yet again I have failed to fully read the documentation. The EEPROM library Put function documentation here (https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/libraries/EEPROM) says, "This function uses the update method to write its data, and therefore only rewrites changed cells." Therefore, my update code is redundant. I just need to use the "put" function as-is. Refer to the EEPROM library's author's (Chris A) answer here too.
So, I've learned a lot, and here's my final answer:
Get rid of my support function and macro, and just use the put function as-is. It already minimizes EEPROM wear and only writes if the contents are different. Nevertheless, I'll leave my above answers for completeness' sake for those who are looking for what the macro or function solution otherwise would have been.
I am trying to compile 3 files total and can not get it to. The code works in visual++. I have uploaded all 3 files in the same dir and used the following command.
g++ -o edit Album.cpp lab8.cpp
My file names are listed below
Album.cpp
Album.h
lab8.cpp
Note the code was written in visual studio C++ and compiled just fine there.
Results in the following
lab8.cpp: In function ‘std::vector read_album_file(std::string)’:
lab8.cpp:142:25: error: no matching function for call to ‘std::basic_ifstream::basic_ifstream(std::string&)’
ifstream read (filename);// the ifstream is used to read from the file
^
lab8.cpp:142:25: note: candidates are:
In file included from lab8.cpp:38:0:
/usr/include/c++/4.8/fstream:467:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits; std::ios_base::openmode = std::_Ios_Openmode]
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
^
/usr/include/c++/4.8/fstream:467:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const char*’
/usr/include/c++/4.8/fstream:453:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits]
basic_ifstream() : __istream_type(), _M_filebuf()
^
/usr/include/c++/4.8/fstream:453:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.8/fstream:427:11: note: std::basic_ifstream::basic_ifstream(const std::basic_ifstream&)
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
/usr/include/c++/4.8/fstream:427:11: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::basic_ifstream&’
Look at the constructor prototype of ifstream. It takes a const char * and a optional argument, soyou need to write filename.c_str()