-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathEmotiBitConfigManager.h
More file actions
67 lines (65 loc) · 2.3 KB
/
EmotiBitConfigManager.h
File metadata and controls
67 lines (65 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef EMOTIBIT_CONFIG_MANAGER_H
#define EMOTIBIT_CONFIG_MANAGER_H
#include <Arduino.h>
#include <EmotiBitSerial.h>
#include <EmotiBitFactoryTest.h>
#include <ArduinoJson.h>
#include <EmotiBitPacket.h>
#ifdef ARDUINO_FEATHER_ESP32
#include <SD.h>
#else
#include <SdFat.h>
#endif
// ToDo: This may not be the best place for this functionality. Consider a better place in the codebase.
class EmotiBitConfigManager
{
public:
enum Status{
OK = 0,
INIT_FAIL,
FILE_NOT_FOUND,
FILE_PARSE_FAIL
};
#ifdef ARDUINO_FEATHER_ESP32
// SD is already defined in ESP32
fs::SDFS* SD;
/*!
* @brief initialize sd card
* @param sd pointer to emotibit SD
* @return true if pointer initialized
*/
bool init(fs::SDFS* sd);
#else
SdFat* SD; // Use SdFat library
/*!
* @brief initialize sd card
* @param sd pointer to emotibit SD
* @return true if pointer initialized
*/
bool init(SdFat* sd);
#endif
/*!
* @brief function to load credentials from config file
* @param filename Name of config file
* @param jsonDoc Json Element that holds credentials data
* @return returns Status::OK, if config file was successfully parsed, else error
*/
uint8_t loadConfigFile(const String &filename, JsonDocument& jsonDoc);
/*!
* @brief create a new config file from JsonDocument element
* @param configFilename Name of config file
* @param file instance of file that will handle file I/O
* @param configAsJson Json Element that holds credentials data
* @return returns true, if config file is successfully created.
*/
bool createNewConfigFile(String configFilename, File& file, JsonDocument& configAsJson);
/*!
* @brief Function to update WiFi credentials over Serial.
* @param emotibitFwVersion Current EmotiBit firmware version. Added for future compatibility for software-firmware handshaking
* @param configFilename name of the config file on the SD card
* @param maxCreds Maximum allowed credentials on the SD card
*/
void updateWiFiCredentials(String emotibitFwVersion, String configFilename, const uint8_t maxCreds);
// ToDo: In the future, we may want to update creds through WiFi, so this functio can act as a wrapper to call other functions that handle WiFi/serial process.
};
#endif