|
|
|
//
|
|
|
|
// Created by MightyPork on 2018/11/18.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CSPEMU_SETTINGS_H
|
|
|
|
#define CSPEMU_SETTINGS_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <nvs.h>
|
|
|
|
#include <driver/uart.h>
|
|
|
|
#include <sdkconfig.h>
|
|
|
|
|
|
|
|
#define CONSOLE_TELNET_PORT CONFIG_CONSOLE_TELNET_PORT
|
|
|
|
#define CONSOLE_PW_LEN CONFIG_CONSOLE_PW_LEN
|
|
|
|
#define USE_CAPTIVE_PORTAL 0
|
|
|
|
|
|
|
|
extern nvs_handle g_nvs_storage;
|
|
|
|
|
|
|
|
#define NTP_SRV_LEN 32
|
|
|
|
#define DEF_NTP_SRV "pool.ntp.org"
|
|
|
|
|
|
|
|
/* type , name , suffix , defval , generate load/save funcs
|
|
|
|
* , , save fn - use 'none' if unused to avoid build errors
|
|
|
|
* , , , save fn var prefix */
|
|
|
|
#define SETTINGS_XTABLE() \
|
|
|
|
X(bool , wifi_enabled , , 1 , true , bool , &) /* ssid and pass are stored in flash by SDK funcs */ \
|
|
|
|
X(bool , sta_enabled , , 1 , true , bool , &) \
|
|
|
|
X(bool , ap_enabled , , 0 , true , bool , &) \
|
|
|
|
X(bool , console_echo , , 1 , true , bool , &) /* Console modes */ \
|
|
|
|
X(bool , console_ansi , , 1 , true , bool , &) \
|
|
|
|
X(char , console_pw, [CONSOLE_PW_LEN], "" , false , none , ) \
|
|
|
|
X(bool , ntp_enable , , 1 , true , bool , &) \
|
|
|
|
X(char , ntp_srv ,[NTP_SRV_LEN], DEF_NTP_SRV , false, none , ) \
|
|
|
|
X(bool , dhcp_wd_enable , , 1 , true , bool , &) \
|
|
|
|
X(bool , dhcp_enable , , 1 , true , bool , &) \
|
|
|
|
X(uint32_t , static_ip , , 0 , true , u32 , &) \
|
|
|
|
X(uint32_t , static_ip_mask , , 0x00ffffff , true , u32 , &) /* 255.255.255.0 */ \
|
|
|
|
X(uint32_t , static_ip_gw , , 0x0100a8c0 , true , u32 , &) /* 192.168.0.1 */ \
|
|
|
|
X(uint32_t , ap_ip , , 0x0100a8c0 , true , u32 , &) /* 192.168.0.1 */ \
|
|
|
|
X(uint32_t , static_dns , , 0x08080808 , true , u32 , &) /* 8.8.8.8 */ \
|
|
|
|
X(uint16_t , recup_mode , , 0 , true , u16 , &) /* recuperator control mode - 0=time, 1=min time+temp equilibrium */ \
|
|
|
|
X(uint16_t , recup_time , , 60 , true , u16 , &) /* seconds */ \
|
|
|
|
X(uint16_t , recup_factor , , 80 , true , u16 , &) /* perc */ \
|
|
|
|
X(uint16_t , min_recup_time , , 30 , true , u16 , &) /* seconds */ \
|
|
|
|
X(uint16_t , max_recup_time , , 180 , true , u16 , &) /* seconds */ \
|
|
|
|
X(uint16_t , ramp_time , , 6 , true , u16 , &) /* cas rozjezdu nebo zastaveni motoru (s) */ \
|
|
|
|
X(uint16_t , blind_time , , 35 , true , u16 , &) /* cas otevreni nebo zavreni rolety (s) */ \
|
|
|
|
X(uint16_t , initial_mode , , 0 , true , u16 , &) /* rezim po zapnuti napajeni */ \
|
|
|
|
X(uint16_t , initial_power , , 50 , true , u16 , &) /* vychozi vykon */ \
|
|
|
|
X(uint16_t , min_power , , 5 , true , u16 , &) /* min power % */ \
|
|
|
|
X(bool , summer_mode , , 0 , true , bool , &) /* rezim po zapnuti napajeni */ \
|
|
|
|
X(bool , swap_temps , , 0 , true , bool , &) /* swap t0/t1 */ \
|
|
|
|
X(bool , swap_pwm_dir , , 0 , true , bool , &) /* swap pwm/dir signal */
|
|
|
|
|
|
|
|
enum settings_key_enum {
|
|
|
|
#undef X
|
|
|
|
#define X(pre,name,post,def,gen_nvs,nvs_format,save_prefix) \
|
|
|
|
SETTINGS_##name,
|
|
|
|
|
|
|
|
SETTINGS_ALL,
|
|
|
|
SETTINGS_XTABLE() // unfortunately the last bit is lowercase
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the NVS namespace
|
|
|
|
*/
|
|
|
|
void settings_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load settings from the NVS
|
|
|
|
*/
|
|
|
|
void settings_load(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the settings object to NVS
|
|
|
|
*/
|
|
|
|
void settings_persist(enum settings_key_enum what);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change blind time. This must be used instead of just writing the settings struct, because of side effects
|
|
|
|
*/
|
|
|
|
extern void settings_blind_time_set(uint16_t blind_time);
|
|
|
|
|
|
|
|
extern struct cspemu_settings gSettings;
|
|
|
|
extern struct cspemu_globals g_State;
|
|
|
|
|
|
|
|
|
|
|
|
struct cspemu_globals {
|
|
|
|
bool wifi_inited;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cspemu_settings {
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
#define X(pre,name,post,def,gen_nvs,nvs_format,save_prefix) \
|
|
|
|
pre name post;
|
|
|
|
|
|
|
|
SETTINGS_XTABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
uint16_t app_get_bootcount();
|
|
|
|
|
|
|
|
#endif //CSPEMU_SETTINGS_H
|