forked from electro/esp-irblaster
wipstate machine, rename g_Settings to gSettings
This commit is contained in:
@@ -21,7 +21,7 @@ static int cmd_dump(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
console_printf("WiFi enabled: %d\r\n", g_Settings.wifi_enabled);
|
||||
console_printf("WiFi enabled: %d\r\n", gSettings.wifi_enabled);
|
||||
|
||||
// TODO show more settings
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ static int cmd_ip_status(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
{
|
||||
EMPTY_CMD_SETUP("Show IP status");
|
||||
|
||||
if (!g_Settings.wifi_enabled || !g_State.wifi_inited) {
|
||||
if (!gSettings.wifi_enabled || !g_State.wifi_inited) {
|
||||
console_color_printf(COLOR_RED, "WiFi interface is disabled\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -40,13 +40,13 @@ static int cmd_ip_status(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
tcpip_adapter_ip_info_t ipinfo;
|
||||
if (ESP_OK == tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipinfo)) {
|
||||
// ! inet_ntoa uses a global static buffer, cant use multiple in one printf call
|
||||
console_printf("DHCP: %s\n", g_Settings.dhcp_enable ? MSG_ENABLED : MSG_DISABLED " (static IP)");
|
||||
console_printf("DHCP: %s\n", gSettings.dhcp_enable ? MSG_ENABLED : MSG_DISABLED " (static IP)");
|
||||
console_printf("IP: %s\n", inet_ntoa(ipinfo.ip.addr));
|
||||
console_printf("Mask: %s\n", inet_ntoa(ipinfo.netmask.addr));
|
||||
console_printf("Gateway: %s\n", inet_ntoa(ipinfo.gw.addr));
|
||||
|
||||
if (!g_Settings.dhcp_enable) {
|
||||
console_printf("DNS: %s\n", inet_ntoa(g_Settings.static_dns));
|
||||
if (!gSettings.dhcp_enable) {
|
||||
console_printf("DNS: %s\n", inet_ntoa(gSettings.static_dns));
|
||||
}
|
||||
|
||||
uint8_t mac[6];
|
||||
@@ -85,11 +85,11 @@ static int cmd_ip_pingwd(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
if (cmd_args.cmd->count) {
|
||||
int b = parse_boolean_arg(cmd_args.cmd->sval[0]);
|
||||
if (b < 0) return CONSOLE_ERR_INVALID_ARG;
|
||||
g_Settings.dhcp_wd_enable = b;
|
||||
gSettings.dhcp_wd_enable = b;
|
||||
settings_persist(SETTINGS_dhcp_wd_enable);
|
||||
}
|
||||
|
||||
console_printf("Ping WD = %s\n", g_Settings.dhcp_wd_enable? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("Ping WD = %s\n", gSettings.dhcp_wd_enable ? MSG_ENABLED : MSG_DISABLED);
|
||||
|
||||
if (cmd_args.cmd->count) {
|
||||
console_printf("Restart to apply changes\n");
|
||||
@@ -200,7 +200,7 @@ static int cmd_ip_static_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
console_println("Invalid IP");
|
||||
return CONSOLE_ERR_INVALID_ARG;
|
||||
}
|
||||
g_Settings.static_ip = a; // aton output is already in network byte order
|
||||
gSettings.static_ip = a; // aton output is already in network byte order
|
||||
settings_persist(SETTINGS_static_ip);
|
||||
any_change = true;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ static int cmd_ip_static_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
console_println("Invalid GW");
|
||||
return CONSOLE_ERR_INVALID_ARG;
|
||||
}
|
||||
g_Settings.static_ip_gw = a; // aton output is already in network byte order
|
||||
gSettings.static_ip_gw = a; // aton output is already in network byte order
|
||||
settings_persist(SETTINGS_static_ip_gw);
|
||||
any_change = true;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ static int cmd_ip_static_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
console_println("Invalid mask");
|
||||
return CONSOLE_ERR_INVALID_ARG;
|
||||
}
|
||||
g_Settings.static_ip_mask = a; // aton output is already in network byte order
|
||||
gSettings.static_ip_mask = a; // aton output is already in network byte order
|
||||
settings_persist(SETTINGS_static_ip_mask);
|
||||
any_change = true;
|
||||
}
|
||||
@@ -233,7 +233,7 @@ static int cmd_ip_static_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
console_println("Invalid DNS IP");
|
||||
return CONSOLE_ERR_INVALID_ARG;
|
||||
}
|
||||
g_Settings.static_dns = a; // aton output is already in network byte order
|
||||
gSettings.static_dns = a; // aton output is already in network byte order
|
||||
settings_persist(SETTINGS_static_dns);
|
||||
any_change = true;
|
||||
}
|
||||
@@ -241,16 +241,16 @@ static int cmd_ip_static_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
if (args.cmd->count) {
|
||||
int b = parse_boolean_arg(args.cmd->sval[0]);
|
||||
if (b < 0) return CONSOLE_ERR_INVALID_ARG;
|
||||
g_Settings.dhcp_enable = !b;
|
||||
gSettings.dhcp_enable = !b;
|
||||
settings_persist(SETTINGS_dhcp_enable);
|
||||
any_change = true;
|
||||
}
|
||||
|
||||
console_printf("Static IP: %s\n", g_Settings.dhcp_enable ? MSG_DISABLED : MSG_ENABLED);
|
||||
console_printf("- IP: %s\n", inet_ntoa(g_Settings.static_ip));
|
||||
console_printf("- Mask: %s\n", inet_ntoa(g_Settings.static_ip_mask));
|
||||
console_printf("- Gateway: %s\n", inet_ntoa(g_Settings.static_ip_gw));
|
||||
console_printf("- DNS: %s\n", inet_ntoa(g_Settings.static_dns));
|
||||
console_printf("Static IP: %s\n", gSettings.dhcp_enable ? MSG_DISABLED : MSG_ENABLED);
|
||||
console_printf("- IP: %s\n", inet_ntoa(gSettings.static_ip));
|
||||
console_printf("- Mask: %s\n", inet_ntoa(gSettings.static_ip_mask));
|
||||
console_printf("- Gateway: %s\n", inet_ntoa(gSettings.static_ip_gw));
|
||||
console_printf("- DNS: %s\n", inet_ntoa(gSettings.static_dns));
|
||||
|
||||
if (any_change) {
|
||||
console_println("Restart to apply changes.");
|
||||
@@ -278,10 +278,10 @@ static int cmd_ip_ntp(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
}
|
||||
|
||||
if (cmd_args.addr->count) {
|
||||
strncpy(g_Settings.ntp_srv, cmd_args.addr->sval[0], NTP_SRV_LEN);
|
||||
g_Settings.ntp_srv[NTP_SRV_LEN-1] = 0;
|
||||
strncpy(gSettings.ntp_srv, cmd_args.addr->sval[0], NTP_SRV_LEN);
|
||||
gSettings.ntp_srv[NTP_SRV_LEN - 1] = 0;
|
||||
settings_persist(SETTINGS_ntp_srv);
|
||||
console_printf("NTP server set to %s\n", g_Settings.ntp_srv);
|
||||
console_printf("NTP server set to %s\n", gSettings.ntp_srv);
|
||||
}
|
||||
|
||||
if (cmd_args.cmd->count) {
|
||||
@@ -297,13 +297,13 @@ static int cmd_ip_ntp(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
|
||||
int b = parse_boolean_arg(cmd_args.cmd->sval[0]);
|
||||
if (b < 0) return CONSOLE_ERR_INVALID_ARG;
|
||||
g_Settings.ntp_enable = b;
|
||||
gSettings.ntp_enable = b;
|
||||
|
||||
settings_persist(SETTINGS_ntp_enable);
|
||||
}
|
||||
|
||||
console_printf("Client status: %s\n", g_Settings.ntp_enable? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("NTP server: %s\n", g_Settings.ntp_srv);
|
||||
console_printf("Client status: %s\n", gSettings.ntp_enable ? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("NTP server: %s\n", gSettings.ntp_srv);
|
||||
|
||||
/* show the current date */
|
||||
time_t now;
|
||||
|
||||
@@ -16,7 +16,7 @@ static int cmd_clear(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
{
|
||||
EMPTY_CMD_SETUP("Clear access password");
|
||||
console_printf("Access password cleared.\n");
|
||||
g_Settings.console_pw[0] = 0;
|
||||
gSettings.console_pw[0] = 0;
|
||||
settings_persist(SETTINGS_console_pw);
|
||||
return 0;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ static int cmd_set(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
return CONSOLE_OK;
|
||||
}
|
||||
|
||||
strncpy(g_Settings.console_pw, args.pw->sval[0], CONSOLE_PW_LEN-1);
|
||||
strncpy(gSettings.console_pw, args.pw->sval[0], CONSOLE_PW_LEN - 1);
|
||||
console_printf("Access pw set to: \"%.*s\"\n", CONSOLE_PW_LEN, args.pw->sval[0]);
|
||||
settings_persist(SETTINGS_console_pw);
|
||||
return 0;
|
||||
|
||||
@@ -17,7 +17,7 @@ static int cmd_disable(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
{
|
||||
EMPTY_CMD_SETUP("Disable WiFi");
|
||||
console_printf("WiFi "MSG_DISABLED"\nRestart to apply.\n");
|
||||
g_Settings.wifi_enabled = false;
|
||||
gSettings.wifi_enabled = false;
|
||||
settings_persist(SETTINGS_wifi_enabled);
|
||||
return 0;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ static int cmd_enable(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
{
|
||||
EMPTY_CMD_SETUP("Enable WiFi");
|
||||
console_printf("WiFi "MSG_ENABLED"\nRestart to apply.\n");
|
||||
g_Settings.wifi_enabled = true;
|
||||
gSettings.wifi_enabled = true;
|
||||
settings_persist(SETTINGS_wifi_enabled);
|
||||
return 0;
|
||||
}
|
||||
@@ -70,13 +70,13 @@ static int cmd_ap_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
switch (match) {
|
||||
case 0:
|
||||
console_printf("AP mode "MSG_DISABLED"\nRestart to apply.\n");
|
||||
g_Settings.ap_enabled = false;
|
||||
gSettings.ap_enabled = false;
|
||||
settings_persist(SETTINGS_ap_enabled);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
console_printf("AP mode "MSG_ENABLED"\nRestart to apply.\n");
|
||||
g_Settings.ap_enabled = true;
|
||||
gSettings.ap_enabled = true;
|
||||
settings_persist(SETTINGS_ap_enabled);
|
||||
break;
|
||||
|
||||
@@ -85,7 +85,7 @@ static int cmd_ap_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
}
|
||||
} else {
|
||||
// No cmd
|
||||
console_printf("AP mode: %s\n", g_Settings.ap_enabled? MSG_ENABLED: MSG_DISABLED);
|
||||
console_printf("AP mode: %s\n", gSettings.ap_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
}
|
||||
|
||||
if (args.ip->count) {
|
||||
@@ -94,7 +94,7 @@ static int cmd_ap_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
console_println("Invalid IP");
|
||||
return CONSOLE_ERR_INVALID_ARG;
|
||||
}
|
||||
g_Settings.ap_ip = a; // aton output is already in network byte order
|
||||
gSettings.ap_ip = a; // aton output is already in network byte order
|
||||
settings_persist(SETTINGS_ap_ip);
|
||||
|
||||
console_println("AP IP changed, restart to apply.\n");
|
||||
@@ -138,7 +138,7 @@ static int cmd_ap_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
|
||||
console_printf("AP SSID: \"%s\"\n", apconf.ap.ssid);
|
||||
console_printf("AP PW: \"%s\"\n", apconf.ap.password);
|
||||
console_printf("AP own IP: %s/24\n", inet_ntoa(g_Settings.ap_ip));
|
||||
console_printf("AP own IP: %s/24\n", inet_ntoa(gSettings.ap_ip));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -169,13 +169,13 @@ static int cmd_sta_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
switch (match) {
|
||||
case 0:
|
||||
console_printf("STA mode "MSG_DISABLED"\nRestart to apply.\n");
|
||||
g_Settings.sta_enabled = false;
|
||||
gSettings.sta_enabled = false;
|
||||
settings_persist(SETTINGS_sta_enabled);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
console_printf("STA mode "MSG_ENABLED"\nRestart to apply.\n");
|
||||
g_Settings.sta_enabled = true;
|
||||
gSettings.sta_enabled = true;
|
||||
settings_persist(SETTINGS_sta_enabled);
|
||||
break;
|
||||
|
||||
@@ -184,7 +184,7 @@ static int cmd_sta_conf(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
}
|
||||
} else {
|
||||
// No cmd
|
||||
console_printf("STA mode: %s\n", g_Settings.sta_enabled? MSG_ENABLED: MSG_DISABLED);
|
||||
console_printf("STA mode: %s\n", gSettings.sta_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -309,13 +309,13 @@ static int cmd_wifi_status(console_ctx_t *ctx, cmd_signature_t *reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
console_printf("WiFi support: %s\n", g_Settings.wifi_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("STA mode: %s\n", g_Settings.sta_enabled? MSG_ENABLED: MSG_DISABLED);
|
||||
console_printf("AP mode: %s\n", g_Settings.ap_enabled? MSG_ENABLED: MSG_DISABLED);
|
||||
console_printf("WiFi support: %s\n", gSettings.wifi_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("STA mode: %s\n", gSettings.sta_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
console_printf("AP mode: %s\n", gSettings.ap_enabled ? MSG_ENABLED : MSG_DISABLED);
|
||||
|
||||
console_printf("\n");
|
||||
|
||||
if (g_Settings.wifi_enabled) {
|
||||
if (gSettings.wifi_enabled) {
|
||||
wifi_config_t config;
|
||||
if (ESP_OK == esp_wifi_get_config(ESP_IF_WIFI_STA, &config)) {
|
||||
if (config.sta.ssid[0]) {
|
||||
|
||||
Reference in New Issue
Block a user