External config
Allow config to be accessed from outside the framework core code.
This commit is contained in:
		@@ -9,7 +9,7 @@ DemoProject::~DemoProject() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DemoProject::loop() {
 | 
			
		||||
  unsigned delay = MAX_DELAY / 255 * (255 - _blinkSpeed);
 | 
			
		||||
  unsigned delay = MAX_DELAY / 255 * (255 - _settings.blinkSpeed);
 | 
			
		||||
  unsigned long currentMillis = millis();
 | 
			
		||||
  if (!_lastBlink || (unsigned long)(currentMillis - _lastBlink) >= delay) {
 | 
			
		||||
    _lastBlink = currentMillis;
 | 
			
		||||
@@ -18,10 +18,10 @@ void DemoProject::loop() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DemoProject::readFromJsonObject(JsonObject& root) {
 | 
			
		||||
  _blinkSpeed = root["blink_speed"] | DEFAULT_BLINK_SPEED;
 | 
			
		||||
  _settings.blinkSpeed = root["blink_speed"] | DEFAULT_BLINK_SPEED;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DemoProject::writeToJsonObject(JsonObject& root) {
 | 
			
		||||
  // connection settings
 | 
			
		||||
  root["blink_speed"] = _blinkSpeed;
 | 
			
		||||
  root["blink_speed"] = _settings.blinkSpeed;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
#define DemoProject_h
 | 
			
		||||
 | 
			
		||||
#include <AdminSettingsService.h>
 | 
			
		||||
#include <ESP8266React.h>
 | 
			
		||||
 | 
			
		||||
#define BLINK_LED 2
 | 
			
		||||
#define MAX_DELAY 1000
 | 
			
		||||
@@ -10,7 +11,12 @@
 | 
			
		||||
#define DEMO_SETTINGS_FILE "/config/demoSettings.json"
 | 
			
		||||
#define DEMO_SETTINGS_PATH "/rest/demoSettings"
 | 
			
		||||
 | 
			
		||||
class DemoProject : public AdminSettingsService {
 | 
			
		||||
class DemoSettings {
 | 
			
		||||
 public:
 | 
			
		||||
  uint8_t blinkSpeed;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class DemoProject : public AdminSettingsService<DemoSettings> {
 | 
			
		||||
 public:
 | 
			
		||||
  DemoProject(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
 | 
			
		||||
  ~DemoProject();
 | 
			
		||||
@@ -19,7 +25,6 @@ class DemoProject : public AdminSettingsService {
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  unsigned long _lastBlink = 0;
 | 
			
		||||
  uint8_t _blinkSpeed = 255;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  void readFromJsonObject(JsonObject& root);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user