I'm using library ArduinoJson and I need to create a function which will open a file on SD card, deserialize JSON and then calls a mapping function which will map deserialized values into a struct. I need one of the function parameters be a maping function but not sure how to do that. This does not compile:
#include <ArduinoJson.h>
// This is an attempt to define a type of function that accepts StaticJsonDocument as a parameter
// and it does not compile here.
typedef void mappingFunctionType(StaticJsonDocument);
class ConfigurationLoader {
private:
void _loadConfigFile(String filePath, mappingFunctionType mappingFunction)
void _loadAppConfig();
}
The message error is:
In file included from sketch\RealTime.h:13:0,
from sketch\RealTime.cpp:1:
Config.h:22:52: error: typedef 'mappingFunctionType' is initialized (use decltype instead)
typedef void mappingFunctionType(StaticJsonDocument);
The mapping function should be called like this:
void _loadAppConfig() {
_deserializeJson(WIFI_CONFIG_FILEPATH, []() -> {
// This is a mapping function that maps deserialiyed values to a struct
config.interval = doc["interval"];
});
}
Please advise. Thank you!