Skip to content

Commit 34f3e5b

Browse files
committed
Merge branch 'contrycode' into dev
2 parents a30d6e3 + 907e929 commit 34f3e5b

File tree

7 files changed

+181
-6
lines changed

7 files changed

+181
-6
lines changed

firmware/components/wifi_controller/wifi_controller.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void wifi_driver_init_null(void) {
144144
}
145145
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
146146
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
147-
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
147+
// ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
148148
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
149149
wifi_driver_initialized = true;
150150
}

firmware/main/modules/menus_module/menus_include/menus.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "warthread_module.h"
3333
#include "web_file_browser_module.h"
3434
#include "wifi_analyzer.h"
35-
#include "wifi_settings.h"
35+
#include "wifi_settings_scenes.h"
3636
#include "zigbee_module.h"
3737

3838
typedef enum {
@@ -545,7 +545,7 @@ menu_t menus[] = { //////////////////////////////////
545545
.menu_idx = MENU_SETTINGS_WIFI,
546546
.parent_idx = MENU_SETTINGS_SYSTEM,
547547
.last_selected_submenu = 0,
548-
.on_enter_cb = wifi_settings_begin,
548+
.on_enter_cb = wifi_settings_scenes_main,
549549
.on_exit_cb = NULL,
550550
.is_visible = true},
551551
{.display_name = "Info",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef WIFI_REGIONS_H
2+
#define WIFI_REGIONS_H
3+
4+
#include "esp_wifi.h"
5+
6+
#define WIFI_REGION_MEM "wifi_region"
7+
8+
#define WIFI_REGION_AMERICA() \
9+
(wifi_country_t) { \
10+
.cc = "US", .schan = 1, .nchan = 11, .max_tx_power = 20, \
11+
.policy = WIFI_COUNTRY_POLICY_AUTO \
12+
}
13+
14+
#define WIFI_REGION_ASIA_JAPAN() \
15+
(wifi_country_t) { \
16+
.cc = "JP", .schan = 1, .nchan = 14, .max_tx_power = 20, \
17+
.policy = WIFI_COUNTRY_POLICY_AUTO \
18+
}
19+
20+
#define WIFI_REGION_ASIA_CHINA() \
21+
(wifi_country_t) { \
22+
.cc = "CN", .schan = 1, .nchan = 13, .max_tx_power = 20, \
23+
.policy = WIFI_COUNTRY_POLICY_AUTO \
24+
}
25+
26+
#define WIFI_REGION_EUROPA() \
27+
(wifi_country_t) { \
28+
.cc = "DE", .schan = 1, .nchan = 13, .max_tx_power = 20, \
29+
.policy = WIFI_COUNTRY_POLICY_AUTO \
30+
}
31+
32+
#define WIFI_REGION_GLOBAL() \
33+
(wifi_country_t) { \
34+
.cc = "01", .schan = 1, .nchan = 11, .max_tx_power = 20, \
35+
.policy = WIFI_COUNTRY_POLICY_AUTO \
36+
}
37+
38+
esp_err_t wifi_regions_set_country();
39+
40+
#endif // WIFI_REGIONS_H
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "wifi_regions.h"
2+
3+
#include "esp_err.h"
4+
#include "esp_log.h"
5+
6+
#include "preferences.h"
7+
#include "wifi_controller.h"
8+
9+
#define TAG "WIFI REGIONS"
10+
11+
typedef enum {
12+
GLOBAL_REGION,
13+
AMERICA_REGION,
14+
EUROPA_REGION,
15+
ASIA_REGION,
16+
JAPAN_REGION
17+
} wifi_regions_e;
18+
19+
esp_err_t wifi_regions_set_country() {
20+
wifi_driver_init_null();
21+
esp_err_t err = ESP_OK;
22+
wifi_country_t country;
23+
uint8_t country_idx = preferences_get_uchar(WIFI_REGION_MEM, 0);
24+
25+
switch (country_idx) {
26+
case AMERICA_REGION:
27+
country = WIFI_REGION_AMERICA();
28+
break;
29+
case EUROPA_REGION:
30+
country = WIFI_REGION_EUROPA();
31+
break;
32+
case ASIA_REGION:
33+
country = WIFI_REGION_ASIA_CHINA();
34+
break;
35+
case JAPAN_REGION:
36+
country = WIFI_REGION_ASIA_JAPAN();
37+
break;
38+
default:
39+
country = WIFI_REGION_GLOBAL();
40+
break;
41+
}
42+
err = esp_wifi_set_country(&country);
43+
if (err != ESP_OK) {
44+
ESP_LOGE(TAG, "Error setting WiFi Country code configuration: %s",
45+
esp_err_to_name(err));
46+
return err;
47+
}
48+
49+
return err;
50+
}

firmware/main/modules/settings/wifi/wifi_settings.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "modals_module.h"
99
#include "oled_screen.h"
1010
#include "preferences.h"
11+
#include "wifi_settings_scenes.h"
1112

1213
#define TAG_CONFIG_MODULE "CONFIG_MODULE"
1314

@@ -117,7 +118,8 @@ static void config_module_wifi_display_connected() {
117118
modals_module_show_banner("Connected");
118119
vTaskDelay(2000 / portTICK_PERIOD_MS);
119120
cmd_wifi_unregister_callback();
120-
menus_module_exit_app();
121+
// menus_module_exit_app();
122+
wifi_settings_scenes_main();
121123
}
122124

123125
static void config_module_wifi_handle_connection(bool state) {
@@ -242,7 +244,8 @@ static void only_exit_input_cb(uint8_t button_name, uint8_t button_event) {
242244
}
243245
if (button_name == BUTTON_LEFT) {
244246
cmd_wifi_unregister_callback();
245-
menus_module_exit_app();
247+
// menus_module_exit_app();
248+
wifi_settings_scenes_main();
246249
}
247250
}
248251
static void config_module_state_machine(uint8_t button_name,
@@ -257,7 +260,8 @@ static void config_module_state_machine(uint8_t button_name,
257260
switch (button_name) {
258261
case BUTTON_LEFT:
259262
cmd_wifi_unregister_callback();
260-
menus_module_exit_app();
263+
// menus_module_exit_app();
264+
wifi_settings_scenes_main();
261265
break;
262266
case BUTTON_RIGHT:
263267
ESP_LOGI(TAG_CONFIG_MODULE, "Selected item: %d", selected_item);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "wifi_settings_scenes.h"
2+
3+
#include "general_radio_selection.h"
4+
#include "general_submenu.h"
5+
#include "menus_module.h"
6+
#include "preferences.h"
7+
#include "wifi_settings.h"
8+
9+
#include "wifi_regions.h"
10+
11+
static uint8_t last_main_selection = 0;
12+
13+
void wifi_settings_scenes_main();
14+
void wifi_settings_scenes_region();
15+
16+
typedef enum {
17+
APS_MANAGER_OPTION,
18+
WIFI_REGION_OPTOIN,
19+
} wifi_settings_main_options_e;
20+
21+
static const char* main_options[] = {"APs Manager", "Wifi Region"};
22+
23+
static void main_handler(uint8_t selection) {
24+
last_main_selection = selection;
25+
switch (selection) {
26+
case APS_MANAGER_OPTION:
27+
wifi_settings_begin();
28+
break;
29+
case WIFI_REGION_OPTOIN:
30+
wifi_settings_scenes_region();
31+
break;
32+
default:
33+
break;
34+
}
35+
}
36+
37+
static void main_exit() {
38+
last_main_selection = 0;
39+
menus_module_exit_app();
40+
}
41+
42+
void wifi_settings_scenes_main() {
43+
general_submenu_menu_t main = {0};
44+
main.options = main_options;
45+
main.options_count = sizeof(main_options) / sizeof(char*);
46+
main.selected_option = last_main_selection;
47+
main.select_cb = main_handler;
48+
main.exit_cb = main_exit;
49+
50+
general_submenu(main);
51+
}
52+
53+
static const char* wifi_regions[] = {"Global", "America", "Europa", "Asia",
54+
"Japan"};
55+
56+
static void regions_handler(uint8_t selection) {
57+
preferences_put_uchar(WIFI_REGION_MEM, selection);
58+
wifi_regions_set_country();
59+
}
60+
61+
void wifi_settings_scenes_region() {
62+
general_radio_selection_menu_t region = {0};
63+
region.banner = "Set region";
64+
region.options = wifi_regions;
65+
region.options_count = sizeof(wifi_regions) / sizeof(char*);
66+
region.style = RADIO_SELECTION_OLD_STYLE;
67+
region.current_option = preferences_get_uchar(WIFI_REGION_MEM, 0);
68+
region.select_cb = regions_handler;
69+
region.exit_cb = wifi_settings_scenes_main;
70+
71+
general_radio_selection(region);
72+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _WIFI_SETTINGS_SCENES_H_
2+
#define _WIFI_SETTINGS_SCENES_H_
3+
4+
#include <stdio.h>
5+
6+
void wifi_settings_scenes_main();
7+
void wifi_settings_scenes_region();
8+
9+
#endif

0 commit comments

Comments
 (0)