feat: started game design
This commit is contained in:
@@ -5,8 +5,11 @@
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
const char *tagConfigfile = "/tagconfig.json";
|
||||
DynamicJsonDocument tagDoc(512);
|
||||
|
||||
struct tagConfig {
|
||||
bool configInitOK = false;
|
||||
struct tagConfig
|
||||
{
|
||||
char filename[64];
|
||||
char tagID[64];
|
||||
};
|
||||
@@ -15,28 +18,67 @@ std::vector<tagConfig> tags;
|
||||
|
||||
void loadConfig(const char *fname)
|
||||
{
|
||||
Serial.println("config: load");
|
||||
log_i("config: load");
|
||||
File file = LITTLEFS.open(fname);
|
||||
StaticJsonDocument<512> doc;
|
||||
DeserializationError error = deserializeJson(doc, file);
|
||||
if (error)
|
||||
Serial.println(F("Failed to read file"));
|
||||
|
||||
serializeJsonPretty(doc, Serial);
|
||||
Serial.println("config: load done");
|
||||
|
||||
DeserializationError error = deserializeJson(tagDoc, file);
|
||||
if (error)
|
||||
{
|
||||
log_e("Failed to deserialize err=%s", error.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
serializeJsonPretty(tagDoc, Serial);
|
||||
|
||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
||||
log_i("JsonArray size = %d", array.size());
|
||||
bool hasError = false;
|
||||
for (JsonVariant v : array)
|
||||
{
|
||||
if (!v.containsKey("TagUID"))
|
||||
{
|
||||
log_e("key TAGUID not found");
|
||||
hasError = true;
|
||||
}
|
||||
if (!v.containsKey("audiofile"))
|
||||
{
|
||||
log_e("Key: audiofile not found");
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
configInitOK = !hasError;
|
||||
}
|
||||
log_i("config: load done");
|
||||
}
|
||||
|
||||
void initConfig(void)
|
||||
{
|
||||
Serial.println("config: init");
|
||||
log_i("config: init start");
|
||||
|
||||
loadConfig(tagConfigfile);
|
||||
Serial.println("config: init done");
|
||||
|
||||
log_i("config: init done");
|
||||
}
|
||||
|
||||
void handleConfig(void)
|
||||
{
|
||||
}
|
||||
|
||||
String getConfigSong(String uid)
|
||||
{
|
||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
||||
|
||||
const char* filename = "";
|
||||
|
||||
for (JsonVariant v : array)
|
||||
{
|
||||
const char *taguid = v["TagUID"];
|
||||
if (!strcmp(uid.c_str(), taguid))
|
||||
{
|
||||
filename = v["audiofile"];
|
||||
String retval(filename);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
log_e("taguid %s not found",uid );
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user