Skip to content

Commit 735d296

Browse files
filipwasilrestyled-commitsandy31415
authored
Imgui additional components for linux air-purifier example (project-chip#41600)
* Imgui additional components for linux examples - temperature measurements - humidity measurements - fan control - temperature measurements - air quality * Restyled by gn * fix: newline at the end of gitignore * fix: build system level cleanup * fix: handling multiple flags set for wind and rock * fix: table instread of sliders for bitmasks * fix: remove comment * fix: rock and wind * Restyled by clang-format * fix: not used helper function * refactor: not used variables. cleanup * fix: simplified updates * fix: includes * fix: includes order * fix: warning message for enum values exceeding current maximumum * fix: better handling of updated enumerators * Restyled by clang-format * refactor: removed unused header * refactor: macos build fails due to warnings * fix: leveraging matter TypeTraits.h * fix: renamed helpers to asseccor_updaters * fix: the settings and support values are now separated --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Andrei Litvin <[email protected]>
1 parent 9bf202b commit 735d296

File tree

11 files changed

+766
-0
lines changed

11 files changed

+766
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ examples/*/esp32/dependencies.lock
8989

9090
# jupyter temporary files
9191
.ipynb_checkpoints
92+
93+
# Initial layout generated by imgui
94+
imgui.ini

examples/air-purifier-app/linux/BUILD.gn

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("//build_overrides/chip.gni")
1616

1717
import("${chip_root}/build/chip/tools.gni")
1818
import("${chip_root}/src/app/common_flags.gni")
19+
import("${chip_root}/third_party/imgui/imgui.gni")
1920

2021
assert(chip_build_tools)
2122

@@ -44,6 +45,17 @@ executable("chip-air-purifier-app") {
4445
"${chip_root}/src/lib",
4546
]
4647

48+
if (chip_examples_enable_imgui_ui) {
49+
deps += [
50+
"${chip_root}/examples/common/imgui_ui",
51+
"${chip_root}/examples/common/imgui_ui/windows:connectivity",
52+
"${chip_root}/examples/common/imgui_ui/windows:fan_control",
53+
"${chip_root}/examples/common/imgui_ui/windows:humidity_measurement",
54+
"${chip_root}/examples/common/imgui_ui/windows:qrcode",
55+
"${chip_root}/examples/common/imgui_ui/windows:temperature_measurement",
56+
]
57+
}
58+
4759
cflags = [ "-Wconversion" ]
4860

4961
include_dirs = [

examples/air-purifier-app/linux/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@
2222
#include <app/ConcreteAttributePath.h>
2323
#include <lib/support/logging/CHIPLogging.h>
2424

25+
#if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED
26+
#include <imgui_ui/ui.h>
27+
#include <imgui_ui/windows/connectivity.h>
28+
#include <imgui_ui/windows/fan_control.h>
29+
#include <imgui_ui/windows/humidity_measurement.h>
30+
#include <imgui_ui/windows/qrcode.h>
31+
#include <imgui_ui/windows/temperature_measurement.h>
32+
#endif
33+
2534
#define AIR_PURIFIER_ENDPOINT 1
35+
#define FAN_CONTROL_ENDPOINT 1
2636
#define AIR_QUALITY_SENSOR_ENDPOINT 2
2737
#define TEMPERATURE_SENSOR_ENDPOINT 3
2838
#define RELATIVE_HUMIDITY_SENSOR_ENDPOINT 4
@@ -68,6 +78,18 @@ int main(int argc, char * argv[])
6878
return -1;
6979
}
7080

81+
#if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED
82+
example::Ui::ImguiUi ui;
83+
84+
ui.AddWindow(std::make_unique<example::Ui::Windows::QRCode>());
85+
ui.AddWindow(std::make_unique<example::Ui::Windows::Connectivity>());
86+
ui.AddWindow(std::make_unique<example::Ui::Windows::FanControl>(chip::EndpointId(FAN_CONTROL_ENDPOINT)));
87+
ui.AddWindow(std::make_unique<example::Ui::Windows::HumidityMeasurement>(chip::EndpointId(RELATIVE_HUMIDITY_SENSOR_ENDPOINT)));
88+
ui.AddWindow(std::make_unique<example::Ui::Windows::TemperatureMeasurement>(chip::EndpointId(TEMPERATURE_SENSOR_ENDPOINT)));
89+
ChipLinuxAppMainLoop(&ui);
90+
#else
7191
ChipLinuxAppMainLoop();
92+
#endif
93+
7294
return 0;
7395
}

examples/common/imgui_ui/windows/BUILD.gn

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ source_set("windows") {
2020
sources = [ "window.h" ]
2121
}
2222

23+
source_set("accessor_updaters") {
24+
sources = [ "accessor_updaters.h" ]
25+
}
26+
2327
static_library("connectivity") {
2428
sources = [
2529
"connectivity.cpp",
@@ -73,6 +77,54 @@ static_library("light") {
7377
public_configs = [ "${chip_root}/src:includes" ]
7478
}
7579

80+
static_library("humidity_measurement") {
81+
sources = [
82+
"humidity_measurement.cpp",
83+
"humidity_measurement.h",
84+
]
85+
86+
deps = [
87+
":accessor_updaters",
88+
":windows",
89+
"${chip_root}/src/app/common:cluster-objects",
90+
"${chip_root}/third_party/imgui",
91+
]
92+
93+
public_configs = [ "${chip_root}/src:includes" ]
94+
}
95+
96+
static_library("temperature_measurement") {
97+
sources = [
98+
"temperature_measurement.cpp",
99+
"temperature_measurement.h",
100+
]
101+
102+
deps = [
103+
":accessor_updaters",
104+
":windows",
105+
"${chip_root}/src/app/common:cluster-objects",
106+
"${chip_root}/third_party/imgui",
107+
]
108+
109+
public_configs = [ "${chip_root}/src:includes" ]
110+
}
111+
112+
static_library("fan_control") {
113+
sources = [
114+
"fan_control.cpp",
115+
"fan_control.h",
116+
]
117+
118+
deps = [
119+
":accessor_updaters",
120+
":windows",
121+
"${chip_root}/src/app/common:cluster-objects",
122+
"${chip_root}/third_party/imgui",
123+
]
124+
125+
public_configs = [ "${chip_root}/src:includes" ]
126+
}
127+
76128
static_library("boolean_state") {
77129
sources = [
78130
"boolean_state.cpp",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <app-common/zap-generated/attributes/Accessors.h>
19+
#include <app-common/zap-generated/cluster-enums.h>
20+
#include <app/data-model/Nullable.h>
21+
#include <lib/support/logging/CHIPLogging.h>
22+
23+
namespace example {
24+
namespace Ui {
25+
namespace Windows {
26+
27+
template <typename T>
28+
void UpdateStateEnum(chip::EndpointId endpointId, T & targetValue, T & value,
29+
chip::Protocols::InteractionModel::Status (*setter)(chip::EndpointId endpoint, T value),
30+
chip::Protocols::InteractionModel::Status (*getter)(chip::EndpointId endpoint, T * value))
31+
{
32+
if (targetValue != value)
33+
{
34+
setter(endpointId, targetValue);
35+
}
36+
37+
auto status = getter(endpointId, &value);
38+
if (status != chip::Protocols::InteractionModel::Status::Success)
39+
{
40+
ChipLogError(NotSpecified, "ImGuiHelper::UpdateStateEnum: failed to get enum value: %d", chip::to_underlying(status));
41+
}
42+
43+
targetValue = value;
44+
}
45+
46+
template <typename T>
47+
void UpdateStateReadOnly(chip::EndpointId endpointId, T & targetValue, T & value,
48+
chip::Protocols::InteractionModel::Status (*getter)(chip::EndpointId endpoint, T * value))
49+
{
50+
auto status = getter(endpointId, &value);
51+
if (status != chip::Protocols::InteractionModel::Status::Success)
52+
{
53+
ChipLogError(NotSpecified, "ImGuiHelper::UpdateStateReadOnly: failed to get read only value: %d",
54+
chip::to_underlying(status));
55+
}
56+
57+
targetValue = value;
58+
}
59+
60+
template <typename T, typename V>
61+
void UpdateStateNullable(chip::EndpointId endpointId, chip::app::DataModel::Nullable<T> & targetValue, T & value,
62+
chip::Protocols::InteractionModel::Status (*setter)(chip::EndpointId endpoint, V value),
63+
chip::Protocols::InteractionModel::Status (*getter)(chip::EndpointId endpoint,
64+
chip::app::DataModel::Nullable<V> & value))
65+
{
66+
if (!targetValue.IsNull())
67+
{
68+
setter(endpointId, targetValue.Value());
69+
targetValue.SetNull();
70+
}
71+
72+
chip::app::DataModel::Nullable<T> result{};
73+
auto status = getter(endpointId, result);
74+
if (status != chip::Protocols::InteractionModel::Status::Success)
75+
{
76+
ChipLogError(NotSpecified, "ImGuiHelper::UpdateStateNullable: failed to get writable value: %d",
77+
chip::to_underlying(status));
78+
}
79+
80+
if (!result.IsNull())
81+
{
82+
value = result.Value();
83+
}
84+
}
85+
86+
template <typename T, typename V>
87+
void UpdateStateNullable(chip::EndpointId endpointId, chip::app::DataModel::Nullable<T> & targetValue, T & value,
88+
chip::Protocols::InteractionModel::Status (*getter)(chip::EndpointId endpoint,
89+
chip::app::DataModel::Nullable<V> & value))
90+
{
91+
chip::app::DataModel::Nullable<T> result{};
92+
auto status = getter(endpointId, result);
93+
if (status != chip::Protocols::InteractionModel::Status::Success)
94+
{
95+
ChipLogError(NotSpecified, "ImGuiHelper::UpdateStateNullable: failed to get read only value: %d",
96+
chip::to_underlying(status));
97+
}
98+
99+
value = result.Value();
100+
}
101+
102+
} // namespace Windows
103+
} // namespace Ui
104+
} // namespace example

0 commit comments

Comments
 (0)