-
Notifications
You must be signed in to change notification settings - Fork 0
/
nebulo-cfg.h.py
executable file
·99 lines (90 loc) · 2.39 KB
/
nebulo-cfg.h.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
configshape_in = """
Bool has_wifi
Bool has_lora
Hex appeui
Hex deveui
Hex appkey
String current_lang
String wlanssid
Password wlanpwd
String www_username
Password www_password
String fs_ssid
Password fs_pwd
Bool www_basicauth_enabled
Bool sds_read
Bool npm_read
Bool npm_fulltime
Bool bmx280_read
String height_above_sealevel
Bool gps_read
Bool send2dusti
Bool ssl_dusti
Bool send2madavi
Bool ssl_madavi
Bool send2csv
Bool has_ssd1306
Bool display_wifi_info
Bool display_lora_info
Bool display_device_info
UInt debug
Time sending_intervall_ms
Time time_for_wifi_config
Bool send2custom
String host_custom
String url_custom
UInt port_custom
String user_custom
Password pwd_custom
Bool ssl_custom
Bool send2custom2
String host_custom2
String url_custom2
UInt port_custom2
String user_custom2
Password pwd_custom2
Bool ssl_custom2
"""
with open("nebulo-cfg.h", "w") as h:
print("""
// This file is generated, please do not edit.
// Change nebulo-cfg.h.py instead.
enum ConfigEntryType : unsigned short {
Config_Type_Bool,
Config_Type_UInt,
Config_Type_Time,
Config_Type_String,
Config_Type_Password,
Config_Type_Hex
};
struct ConfigShapeEntry {
enum ConfigEntryType cfg_type;
unsigned short cfg_len;
const char* _cfg_key;
union {
void* as_void;
bool* as_bool;
unsigned int* as_uint;
char* as_str;
} cfg_val;
const __FlashStringHelper* cfg_key() const { return FPSTR(_cfg_key); }
};
enum ConfigShapeId {""", file=h)
for cfgentry in configshape_in.strip().split('\n'):
print("\tConfig_", cfgentry.split()[1], ",", sep='', file=h)
print("};", file=h)
for cfgentry in configshape_in.strip().split('\n'):
_, cfgkey = cfgentry.split()
print("static constexpr char CFG_KEY_", cfgkey.upper(),
"[] PROGMEM = \"", cfgkey, "\";", sep='', file=h)
print("static constexpr ConfigShapeEntry configShape[] PROGMEM = {",
file=h)
for cfgentry in configshape_in.strip().split('\n'):
cfgtype, cfgkey = cfgentry.split()
print("\t{ Config_Type_", cfgtype,
", sizeof(cfg::" + cfgkey + ")-1" if cfgtype in ('String', 'Password', 'Hex') else ", 0",
", CFG_KEY_", cfgkey.upper(),
", ", "" if cfgtype in ('String', 'Password', 'Hex') else "&",
"cfg::", cfgkey, " },", sep='', file=h)
print("};", file=h)