Skip to content

Commit d919622

Browse files
committed
Wifi Scanner as menu
1 parent e5f86a8 commit d919622

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

src/Sreens/WiFiScannerScreen.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ class WiFiScannerScreen {
1818
MenuAction action = [this](MenuItem&item) {
1919
this->tft->fillScreen(MENU_BACKGROUND_COLOR);
2020
this->mainMenu->reInitButtons(this->btnUp, this->btnDown); //reset main menu buttons
21-
/*this->btnDown->setLongClickDetectedHandler([this](Button2&b) {
22-
this->tft->fillScreen(MENU_BACKGROUND_COLOR);
23-
this->mainMenu->buttonsInit(this->btnUp, this->btnDown);
24-
this->mainMenu->redrawMenuItems();
25-
});*/
2621

2722
this->wifiScan();
2823

24+
2925
return false;
3026
};
3127

@@ -39,17 +35,7 @@ class WiFiScannerScreen {
3935
Menu wifiMenu;
4036

4137
void wifiScan() {
42-
MenuAction backAction = [this](MenuItem&item) {
43-
this->wifiMenu.reInitButtons(this->btnUp, this->btnDown);
44-
this->mainMenu->buttonsInit(this->btnUp, this->btnDown); //enable main menu buttons
45-
this->mainMenu->redrawMenuItems();
46-
47-
return true;
48-
};
49-
50-
std::vector<MenuItem> menuItems = {
51-
MenuItem("<< Back", {{"delayTime", "500"}}, backAction)
52-
};
38+
std::vector<MenuItem> menuItems = {};
5339

5440
this->tft->setTextColor(TFT_GREEN, MENU_BACKGROUND_COLOR);
5541
this->tft->fillScreen(MENU_BACKGROUND_COLOR);
@@ -77,12 +63,20 @@ class WiFiScannerScreen {
7763
"%s(%d)",
7864
WiFi.SSID(i).c_str(),
7965
WiFi.RSSI(i));
80-
menuItems.push_back(MenuItem(buff, {}, [](MenuItem&item) { //connect to selected AP and return to main menu
66+
menuItems.push_back(MenuItem(buff, {}, [](MenuItem&item) {
67+
//connect to selected AP and return to main menu
8168
return false; //do nothing
8269
}));
8370
}
8471
this->wifiMenu.setItems(menuItems);
8572
this->wifiMenu.buttonsInit(this->btnUp, this->btnDown); //start wifi menu buttons
73+
this->btnDown->setLongClickDetectedHandler([this](Button2&b) {
74+
this->wifiMenu.reInitButtons(this->btnUp, this->btnDown);
75+
76+
this->tft->fillScreen(MENU_BACKGROUND_COLOR);
77+
this->mainMenu->buttonsInit(this->btnUp, this->btnDown);
78+
this->mainMenu->redrawMenuItems();
79+
});
8680
this->wifiMenu.redrawMenuItems();
8781
}
8882
WiFi.mode(WIFI_OFF);

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::vector<MenuItem> menuItems = {
7373
MenuItem("Info", {}, infoScreen.action),
7474
MenuItem("Stars", {}, starsScreen.action),
7575
MenuItem("WiFi Scanner", {}, wiFiScannerScreen.action),
76-
MenuItem("Run", {{"flashTime", "500"}}, defaultAction),
76+
MenuItem("Nothing", {{"flashTime", "500"}}, defaultAction),
7777
MenuItem("Backlight", {{"value", String(ledBacklight)}}, [](MenuItem&item) {
7878
ledBacklight += 50;
7979
if (ledBacklight > 255) {
@@ -85,7 +85,7 @@ std::vector<MenuItem> menuItems = {
8585

8686
return false;
8787
}),
88-
MenuItem("Menu 3", {}, defaultAction),
88+
MenuItem("Nothing", {}, defaultAction),
8989
MenuItem("Maro", {{"value", "OFF"}, {"flashTime", "100"}}, [](MenuItem&item) {
9090
tft.fillScreen(TFT_BLACK);
9191
tft.setTextColor(TFT_WHITE, TFT_BLACK);

src/menu.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ struct Menu {
127127
btnDown->reset();
128128
btnUp->begin(BUTTON_1);
129129
btnDown->begin(BUTTON_2);
130-
btnUp->setLongClickTime(700);
130+
btnUp->setLongClickTime(1000);
131131
btnUp->setDebounceTime(50);
132-
btnDown->setLongClickTime(700);
132+
btnDown->setLongClickTime(1000);
133133
btnDown->setDebounceTime(50);
134134
}
135135

@@ -141,29 +141,20 @@ struct Menu {
141141
this->blockedButton = true;
142142
Serial.println("Select Menu Item: " + this->title);
143143
bool flash = this->items[this->selectedMenuItem].onSelect(this->items[this->selectedMenuItem]);
144-
unsigned int delay = 100;
145-
int delayTime = 0;
144+
unsigned int delay = 500;
146145

147146
if (this->items[this->selectedMenuItem].parameters.find("flashTime") != this->items[this->selectedMenuItem].
148147
parameters.end()) {
149148
const String flashTime = this->items[this->selectedMenuItem].parameters["flashTime"];
150149
delay = flashTime.toInt();
151150
}
152151

153-
if (this->items[this->selectedMenuItem].parameters.find("delayTime") != this->items[this->selectedMenuItem].
154-
parameters.end()) {
155-
delayTime = this->items[this->selectedMenuItem].parameters["delayTime"].toInt();
156-
}
157-
158152
if (flash != false) {
153+
Serial.println("Delay: " + String(delay));
159154
espDelay(delay);
160155

161156
this->redrawMenuItems();
162157
}
163-
164-
if (delayTime > 0) {
165-
espDelay(delayTime);
166-
}
167158
});
168159

169160
btnUp->setReleasedHandler([this](Button2&b) {

0 commit comments

Comments
 (0)