-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpages.h
More file actions
91 lines (82 loc) · 2.48 KB
/
pages.h
File metadata and controls
91 lines (82 loc) · 2.48 KB
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
// pages.h
#pragma once
#include <array>
#include <cstdint>
#include <cstring>
#include <initializer_list>
#include <string>
#include "esphome/core/string_ref.h" // For StringRef
/**
* @file pages.h
* Defines constants and functions related to page names for the NSPanel HA Blueprint project.
*/
namespace nspanel_easy {
// Constants
/**
* A compile-time constant array containing the names of pages.
* These names correspond to various pages of the Nextion TFT file in use,
* such as settings, home, weather information, and more.
*/
constexpr const char* const page_names[] = {
"boot",
"home",
"weather01",
"weather02",
"weather03",
"weather04",
"weather05",
"climate",
"settings",
"screensaver",
"light",
"cover",
"buttonpage01",
"buttonpage02",
"buttonpage03",
"buttonpage04",
"notification",
"qrcode",
"entitypage01",
"entitypage02",
"entitypage03",
"entitypage04",
"fan",
"alarm",
"keyb_num",
"media_player",
"confirm",
"utilities",
"home_smpl",
"debug",
"water_heater"
};
constexpr size_t PAGE_COUNT = sizeof(page_names) / sizeof(page_names[0]);
static_assert(PAGE_COUNT <= UINT8_MAX, "PAGE_COUNT exceeds uint8_t range");
// Global system flags - initialized to 0 (all flags false)
extern uint8_t current_page_id;
extern uint8_t last_page_id;
extern uint8_t wakeup_page_id;
/**
* Retrieves the index of a given page name within the page_names array.
*
* @param page_name The name of the page to find.
* @return The index of the page_name in the page_names array. If the page_name
* is not found, returns UINT8_MAX as an indicator that no matching page was found.
*/
inline uint8_t get_page_id(const char* page_name) {
if (page_name == nullptr || *page_name == '\0') return UINT8_MAX;
for (uint8_t i = 0; i < PAGE_COUNT; ++i) {
if (strcmp(page_names[i], page_name) == 0)
return i;
}
return UINT8_MAX;
}
inline uint8_t get_page_id(const esphome::StringRef& page_name) {
if (page_name.empty()) return UINT8_MAX;
for (uint8_t i = 0; i < PAGE_COUNT; ++i) {
if (page_name == page_names[i])
return i;
}
return UINT8_MAX;
}
} // namespace nspanel_easy