Settings.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <Arduino.h>
  2. #include <StringStream.h>
  3. #include <ArduinoJson.h>
  4. #ifndef _SETTINGS_H_INCLUDED
  5. #define _SETTINGS_H_INCLUDED
  6. #ifndef FIRMWARE_VARIANT
  7. #define FIRMWARE_VARIANT "unknown"
  8. #endif
  9. #ifndef MILIGHT_HUB_VERSION
  10. #define MILIGHT_HUB_VERSION "unknown"
  11. #endif
  12. #define SETTINGS_FILE "/config.json"
  13. #define SETTINGS_TERMINATOR '\0'
  14. #define WEB_INDEX_FILENAME "/web/index.html"
  15. #define MILIGHT_GITHUB_USER "sidoh"
  16. #define MILIGHT_GITHUB_REPO "esp8266_milight_hub"
  17. #define MILIGHT_REPO_WEB_PATH "/data/web/index.html"
  18. #define MINIMUM_RESTART_PERIOD 1
  19. enum eRadioInterfaceType
  20. {
  21. nRF24 = 0,
  22. PL1167_LT8900 =1,
  23. };
  24. class GatewayConfig {
  25. public:
  26. GatewayConfig(uint16_t deviceId, uint16_t port, uint8_t protocolVersion)
  27. : deviceId(deviceId),
  28. port(port),
  29. protocolVersion(protocolVersion)
  30. { }
  31. const uint16_t deviceId;
  32. const uint16_t port;
  33. const uint8_t protocolVersion;
  34. };
  35. class Settings {
  36. public:
  37. Settings() :
  38. adminUsername(""),
  39. adminPassword(""),
  40. // CE and CSN pins from nrf24l01
  41. cePin(D0),
  42. csnPin(D8),
  43. resetPin(0),
  44. radioInterfaceType(PL1167_LT8900),
  45. deviceIds(NULL),
  46. gatewayConfigs(NULL),
  47. numDeviceIds(0),
  48. numGatewayConfigs(0),
  49. packetRepeats(10),
  50. httpRepeatFactor(5),
  51. _autoRestartPeriod(0)
  52. { }
  53. ~Settings() {
  54. if (deviceIds) {
  55. delete deviceIds;
  56. }
  57. }
  58. bool hasAuthSettings();
  59. bool isAutoRestartEnabled();
  60. size_t getAutoRestartPeriod();
  61. static void deserialize(Settings& settings, String json);
  62. static void deserialize(Settings& settings, JsonObject& json);
  63. static void load(Settings& settings);
  64. void save();
  65. String toJson(const bool prettyPrint = true);
  66. void serialize(Stream& stream, const bool prettyPrint = false);
  67. void updateDeviceIds(JsonArray& arr);
  68. void updateGatewayConfigs(JsonArray& arr);
  69. void patch(JsonObject& obj);
  70. String adminUsername;
  71. String adminPassword;
  72. uint8_t cePin;
  73. uint8_t csnPin;
  74. uint8_t resetPin;
  75. eRadioInterfaceType radioInterfaceType;
  76. uint16_t *deviceIds;
  77. GatewayConfig **gatewayConfigs;
  78. size_t numGatewayConfigs;
  79. size_t numDeviceIds;
  80. size_t packetRepeats;
  81. size_t httpRepeatFactor;
  82. protected:
  83. size_t _autoRestartPeriod;
  84. };
  85. #endif