ampel-cfg.h.py 2.78 KB
Newer Older
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3

configshape_in = """
String		current_lang
String		wlanssid
Password		wlanpwd
String		www_username
Password		www_password
String		fs_ssid
Password		fs_pwd
Bool		www_basicauth_enabled
Bool		dht_read
Bool		htu21d_read
Bool		ppd_read
Bool		sds_read
Bool		pms_read
Bool		hpm_read
Bool		npm_read
Bool		sps30_read
Bool		bmp_read
Bool		bmx280_read
Bool		sht3x_read
Bool		scd30_read
Bool		ds18b20_read
Bool		dnms_read
String		dnms_correction
String		temp_correction
String		height_above_sealevel
Bool		gps_read
Bool		send2dusti
Bool		ssl_dusti
Bool		send2madavi
Bool		ssl_madavi
Bool		send2sensemap
Bool		send2fsapp
Bool		send2aircms
Bool		send2csv
Bool		auto_update
Bool		use_beta
Bool		has_display
Bool		has_sh1106
Bool		has_flipped_display
Bool		has_lcd1602
Bool		has_lcd1602_27
Bool		has_lcd2004
Bool		has_lcd2004_27
Bool		display_wifi_info
Bool		display_device_info
String		static_ip
String		static_subnet
String		static_gateway
String		static_dns
UInt		debug
Time		sending_intervall_ms
Time		time_for_wifi_config
String		senseboxid
Bool		send2custom
String		host_custom
String		url_custom
UInt		port_custom
String		user_custom
Password		pwd_custom
Bool		ssl_custom
Bool		send2influx
String		host_influx
String		url_influx
UInt		port_influx
String		user_influx
Password		pwd_influx
String		measurement_name_influx
Bool		ssl_influx
"""

with open("airrohr-cfg.h", "w") as h:
    print("""

// This file is generated, please do not edit.
// Change airrohr-cfg.h.py instead.

enum ConfigEntryType : unsigned short {
	Config_Type_Bool,
	Config_Type_UInt,
	Config_Type_Time,
	Config_Type_String,
	Config_Type_Password
};

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') else ", 0",
              ", CFG_KEY_", cfgkey.upper(),
              ", ", "" if cfgtype in ('String', 'Password') else "&",
              "cfg::", cfgkey, " },", sep='', file=h)
    print("};", file=h)