-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
392 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "boolean_state.h" | ||
|
||
#include <imgui.h> | ||
|
||
#include <math.h> | ||
|
||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <app-common/zap-generated/cluster-enums.h> | ||
|
||
namespace example { | ||
namespace Ui { | ||
namespace Windows { | ||
|
||
using namespace chip::app::Clusters; | ||
using chip::app::DataModel::Nullable; | ||
|
||
void BooleanState::UpdateState() | ||
{ | ||
if (mTargetState.HasValue()) { | ||
chip::app::Clusters::BooleanState::Attributes::StateValue::Set(mEndpointId, mTargetState.Value()); | ||
mTargetState.ClearValue(); | ||
} | ||
|
||
chip::app::Clusters::BooleanState::Attributes::StateValue::Get(mEndpointId, &mState); | ||
} | ||
|
||
void BooleanState::Render() | ||
{ | ||
ImGui::Begin(mTitle.c_str()); | ||
ImGui::Text("On Endpoint %d", mEndpointId); | ||
|
||
bool uiState = mState; | ||
ImGui::Checkbox("State Value", &uiState); | ||
|
||
if (uiState != mState) { | ||
// toggle value on the next 'UpdateState' call | ||
mTargetState.SetValue(uiState); | ||
} | ||
|
||
ImGui::End(); | ||
} | ||
|
||
} // namespace Windows | ||
} // namespace Ui | ||
} // namespace example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include "window.h" | ||
|
||
#include <stdint.h> | ||
#include <string> | ||
|
||
#include <app/data-model/Nullable.h> | ||
#include <lib/core/DataModelTypes.h> | ||
#include <lib/core/Optional.h> | ||
|
||
#include <app-common/zap-generated/cluster-enums.h> | ||
|
||
namespace example { | ||
namespace Ui { | ||
namespace Windows { | ||
|
||
class BooleanState : public Window | ||
{ | ||
public: | ||
BooleanState(chip::EndpointId endpointId, const char *title) : mEndpointId(endpointId), mTitle(title) {} | ||
|
||
void UpdateState() override; | ||
void Render() override; | ||
|
||
private: | ||
const chip::EndpointId mEndpointId; | ||
const std::string mTitle; | ||
|
||
bool mState = false; | ||
chip::Optional<bool> mTargetState; | ||
}; | ||
|
||
} // namespace Windows | ||
} // namespace Ui | ||
} // namespace example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//build_overrides/build.gni") | ||
|
||
# The location of the build configuration file. | ||
buildconfig = "${build_root}/config/BUILDCONFIG.gn" | ||
|
||
# CHIP uses angle bracket includes. | ||
check_system_includes = true | ||
|
||
default_args = { | ||
import("//args.gni") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/build/chip/tools.gni") | ||
import("${chip_root}/src/app/common_flags.gni") | ||
import("${chip_root}/third_party/imgui/imgui.gni") | ||
|
||
assert(chip_build_tools) | ||
|
||
config("includes") { | ||
include_dirs = [ | ||
".", | ||
"include", | ||
] | ||
} | ||
|
||
executable("contact-sensor-app") { | ||
sources = [ | ||
"include/CHIPProjectAppConfig.h", | ||
"main.cpp", | ||
] | ||
|
||
deps = [ | ||
"${chip_root}/examples/contact-sensor-app/contact-sensor-common", | ||
"${chip_root}/examples/platform/linux:app-main", | ||
"${chip_root}/src/lib", | ||
] | ||
|
||
if (chip_examples_enable_imgui_ui) { | ||
deps += [ | ||
"${chip_root}/examples/common/imgui_ui", | ||
"${chip_root}/examples/common/imgui_ui/windows:boolean_state", | ||
"${chip_root}/examples/common/imgui_ui/windows:qrcode", | ||
] | ||
} | ||
|
||
include_dirs = [ "include" ] | ||
|
||
cflags = [ "-Wconversion" ] | ||
|
||
output_dir = root_out_dir | ||
} | ||
|
||
group("linux") { | ||
deps = [ ":contact-sensor-app" ] | ||
} | ||
|
||
group("default") { | ||
deps = [ ":linux" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# CHIPProjectConfig.h | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/config/standalone/args.gni") | ||
|
||
chip_device_project_config_include = "<CHIPProjectAppConfig.h>" | ||
chip_project_config_include = "<CHIPProjectAppConfig.h>" | ||
chip_system_project_config_include = "<SystemProjectConfig.h>" | ||
|
||
chip_project_config_include_dirs = | ||
[ "${chip_root}/examples/contact-sensor-app/linux/include" ] | ||
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../build_overrides |
46 changes: 46 additions & 0 deletions
46
examples/contact-sensor-app/linux/include/CHIPProjectAppConfig.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* Example project configuration file for CHIP. | ||
* | ||
* This is a place to put application or project-specific overrides | ||
* to the default configuration values for general CHIP features. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
// include the CHIPProjectConfig from config/standalone | ||
#include <CHIPProjectConfig.h> | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0 | ||
|
||
// Bulbs do not typically use this - enabled so we can use shell to discover commissioners | ||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 257 // 0x0101 = 257 = Dimmable Bulb | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Test Bulb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <AppMain.h> | ||
|
||
#include <app-common/zap-generated/ids/Attributes.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app/ConcreteAttributePath.h> | ||
#include <app/clusters/network-commissioning/network-commissioning.h> | ||
#include <app/server/Server.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
#include <platform/Linux/NetworkCommissioningDriver.h> | ||
|
||
#if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED | ||
#include <imgui_ui/ui.h> | ||
#include <imgui_ui/windows/boolean_state.h> | ||
#include <imgui_ui/windows/qrcode.h> | ||
|
||
#endif | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters; | ||
|
||
#if CHIP_DEVICE_CONFIG_ENABLE_WPA | ||
namespace { | ||
DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sLinuxWiFiDriver; | ||
Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sLinuxWiFiDriver); | ||
} // namespace | ||
#endif | ||
|
||
/** @brief OnOff Cluster Init | ||
* | ||
* This function is called when a specific cluster is initialized. It gives the | ||
* application an opportunity to take care of cluster initialization procedures. | ||
* It is called exactly once for each endpoint where cluster is present. | ||
* | ||
* @param endpoint Ver.: always | ||
* | ||
* TODO Issue #3841 | ||
* emberAfOnOffClusterInitCallback happens before the stack initialize the cluster | ||
* attributes to the default value. | ||
* The logic here expects something similar to the deprecated Plugins callback | ||
* emberAfPluginOnOffClusterServerPostInitCallback. | ||
* | ||
*/ | ||
void emberAfOnOffClusterInitCallback(EndpointId endpoint) | ||
{ | ||
// TODO: implement any additional Cluster Server init actions | ||
} | ||
|
||
void ApplicationInit() | ||
{ | ||
#if CHIP_DEVICE_CONFIG_ENABLE_WPA | ||
sWiFiNetworkCommissioningInstance.Init(); | ||
#endif | ||
} | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
if (ChipLinuxAppInit(argc, argv) != 0) | ||
{ | ||
return -1; | ||
} | ||
|
||
#if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED | ||
example::Ui::ImguiUi ui; | ||
|
||
ui.AddWindow(std::make_unique<example::Ui::Windows::QRCode>()); | ||
ui.AddWindow(std::make_unique<example::Ui::Windows::BooleanState>(chip::EndpointId(1), "Contact Sensor")); | ||
|
||
ChipLinuxAppMainLoop(&ui); | ||
#else | ||
ChipLinuxAppMainLoop(); | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../.. |
Oops, something went wrong.