wip - doing config structure things

This commit is contained in:
Marcus 2024-10-23 21:14:43 +02:00
parent 13087c0cc1
commit 4f42b64c7e
3 changed files with 96 additions and 37 deletions

View file

@ -34,6 +34,15 @@
* like -DCANGROW_VER="0.x-dev" or -DCANGROW_BUILD="commitid-core-timestamp" * like -DCANGROW_VER="0.x-dev" or -DCANGROW_BUILD="commitid-core-timestamp"
*/ */
/*
*
*
* Constants
*
*
*/
#ifndef CANGROW_VER #ifndef CANGROW_VER
#define CANGROW_VER "0.x-dev" #define CANGROW_VER "0.x-dev"
#endif #endif
@ -43,13 +52,39 @@
#define CANGROW_SSID "CanGrow-unconfigured" #define CANGROW_SSID "CanGrow-unconfigured"
// do we need a restart? (e.g. after wifi settings change) /* actual structure initialization for Pin_Index is done within the header files
bool needRestart = false; * for ESP32 and ESP8266
// this triggers Restart() from the main loop *
bool doRestart = false; * Pin_Index.note explenation:
// previous value of millis within the scheduler loop * 1 - BOOTFAILS_LOW: BootFails when LOW
unsigned long schedulerPrevMillis = 0; * 2 - BOOTFAILS_HIGH: BootFails when HIGH
* 3 - FLASHMODE_LOW: FlashMode needs LOW to enter
* 4 - INPUT_ONLY: Input Only
* 5 - NO_PWM: No PWM output
* 6 - PWM_BOOT: PWM at boot time
*/
const byte BOOTFAILS_LOW = 1;
const byte BOOTFAILS_HIGH = 2;
const byte FLASHMODE_LOW = 3;
const byte INPUT_ONLY = 4;
const byte NO_PWM = 5;
struct Pin_Index {
const byte gpio;
const byte note;
};
/*
*
* Config
*
*/
/*
* Config WiFi
*/
struct Config_WiFi { struct Config_WiFi {
char ssid[32]; char ssid[32];
char password[64]; char password[64];
@ -60,9 +95,27 @@ struct Config_WiFi {
byte dns[4] = {0,0,0,0}; byte dns[4] = {0,0,0,0};
}; };
Config_WiFi configWifi;
/*
* Config System
*/
/*
* Config System Outputs
*
* - type: output type like GPIO, I2C, URL
* - gpio: which gpio
*
*/
struct Config_System_Outputs {
byte type;
byte gpio;
char url[64];
bool httpLogSerial;
unsigned short schedulerInterval = 1000;
};
/* main System struct */
struct Config_System { struct Config_System {
byte ntpOffset; byte ntpOffset;
unsigned short maintenanceDuration; unsigned short maintenanceDuration;
@ -71,13 +124,14 @@ struct Config_System {
char httpPass[32]; char httpPass[32];
bool httpLogSerial; bool httpLogSerial;
unsigned short schedulerInterval = 1000; unsigned short schedulerInterval = 1000;
Config_System_Outputs outputs;
}; };
Config_System configSystem;
/*
* Config Grow
*/
struct Config_Grow { struct Config_Grow {
char growName[64] = "CanGrow"; char growName[64] = "CanGrow";
unsigned short dayOfGrow; unsigned short dayOfGrow;
@ -90,34 +144,39 @@ struct Config_Grow {
byte sunriseMinute; byte sunriseMinute;
bool sunFade; bool sunFade;
byte sunFadeDuration; byte sunFadeDuration;
}; };
Config_Grow configGrow;
/*
* main Config struct
*/
struct Config { struct Config {
char test[16] = "123"; char test[16] = "123";
Config_WiFi wifi;
Config_System system;
Config_Grow grow;
}; };
Config config; Config config;
/* actual structure initialization for Pin_Index is done within the header files
* for ESP32 and ESP8266
/*
*
*
* Global Runtime variables
*
* *
* Pin_Index.note explenation:
* 1 - BF_L: BootFails when LOW
* 2 - BF_H: BootFails when HIGH
* 3 - FM_L: FlashMode needs LOW to enter
* 4 - IN_O: Input Only
*/ */
const byte BF_L = 1;
const byte BF_H = 2;
const byte FM_L = 3;
const byte IN_O = 4;
struct Pin_Index {
const byte gpio;
const byte note;
};
// do we need a restart? (e.g. after wifi settings change)
bool needRestart = false;
// this triggers Restart() from the main loop
bool doRestart = false;
// previous value of millis within the scheduler loop
unsigned long schedulerPrevMillis = 0;

View file

@ -63,10 +63,10 @@
// //
const byte PinIndex_length = 21; const byte PinIndex_length = 21;
// initialize pinIndex with all usable GPIOs // initialize pinIndex with all usable GPIOs
Pin_Index PinIndex[] = { { 0, FM_L }, Pin_Index PinIndex[] = { { 0, FLASHMODE_LOW },
{ 4 }, { 4 },
{ 5 }, { 5 },
{ 12, BF_H }, { 12, BOOTFAILS_HIGH },
{ 13 }, { 13 },
{ 14 }, { 14 },
{ 15 }, { 15 },
@ -80,8 +80,8 @@ Pin_Index PinIndex[] = { { 0, FM_L },
{ 27 }, { 27 },
{ 32 }, { 32 },
{ 33 }, { 33 },
{ 34, IN_O }, { 34, INPUT_ONLY },
{ 35, IN_O }, { 35, INPUT_ONLY },
{ 36, IN_O }, { 36, INPUT_ONLY },
{ 39, IN_O } }; { 39, INPUT_ONLY } };
#endif #endif

View file

@ -47,11 +47,11 @@
const byte PinIndex_length = 6; const byte PinIndex_length = 6;
// initialize pinIndex with all usable GPIOs // initialize pinIndex with all usable GPIOs
Pin_Index PinIndex[] = { { 0, BF_L }, Pin_Index PinIndex[] = { { 0, BOOTFAILS_LOW },
{ 12 }, { 12 },
{ 13 }, { 13 },
{ 14 }, { 14 },
{ 15, BF_H }, { 15, BOOTFAILS_HIGH },
{ 16 } }; { 16, NO_PWM } };
#endif #endif