config: implement commands to change profiles and save settings
This commit is contained in:
54
src/Config.h
54
src/Config.h
@@ -2,6 +2,7 @@
|
||||
#include <Figments.h>
|
||||
#include "JsonCoordinateMapping.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
@@ -59,6 +60,59 @@ struct ConfigService: public Task {
|
||||
const char* loadedProfile() const;
|
||||
void overrideProfile(const char* profileName);
|
||||
const char* getConfigValue(const char* key) const;
|
||||
const std::vector<Command>& commands() const override;
|
||||
|
||||
struct filename_iterator: public std::iterator<std::input_iterator_tag, const char*> {
|
||||
Dir dir;
|
||||
String ret;
|
||||
bool valid;
|
||||
const char* suffix;
|
||||
explicit filename_iterator() : suffix(NULL), valid(false) {}
|
||||
explicit filename_iterator(const char* path, const char* suffix) : dir(LittleFS.openDir(path)), valid(true), suffix(suffix) {
|
||||
next();
|
||||
}
|
||||
|
||||
void next() {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
int extPos = -1;
|
||||
do {
|
||||
valid = dir.next();
|
||||
Log.info("valid %F", valid);
|
||||
if (valid) {
|
||||
String fname = dir.fileName();
|
||||
extPos = fname.lastIndexOf(suffix);
|
||||
Log.info("compare %s %d", fname.c_str(), extPos);
|
||||
if (extPos != -1) {
|
||||
ret = fname.substring(0, extPos);
|
||||
Log.info("found %s", ret.c_str());
|
||||
}
|
||||
}
|
||||
} while (valid && extPos == -1);
|
||||
}
|
||||
|
||||
filename_iterator& operator++() {
|
||||
next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
filename_iterator& operator++(int) {filename_iterator ret = *this; ++(*this); return ret;}
|
||||
bool operator==(const filename_iterator &other) const { return valid == other.valid;}
|
||||
bool operator!=(const filename_iterator &other) const { return !(*this == other); }
|
||||
const char* operator*() const {
|
||||
if (!valid) {
|
||||
return NULL;
|
||||
}
|
||||
return ret.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
filename_iterator mapsBegin() const { return filename_iterator("/maps/", ".json"); }
|
||||
filename_iterator mapsEnd() const { return filename_iterator(); }
|
||||
|
||||
filename_iterator profilesBegin() const { return filename_iterator("/profiles/", ".json"); }
|
||||
filename_iterator profilesEnd() const { return filename_iterator(); }
|
||||
|
||||
private:
|
||||
HardwareConfig m_config;
|
||||
|
Reference in New Issue
Block a user