Skip to content

Commit 83d5b79

Browse files
committed
Valve: Disco ball - add example app
1 parent 2e4f0ff commit 83d5b79

File tree

11 files changed

+7227
-1
lines changed

11 files changed

+7227
-1
lines changed

examples/valve-app/linux/.gn

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
17+
# The location of the build configuration file.
18+
buildconfig = "${build_root}/config/BUILDCONFIG.gn"
19+
20+
# CHIP uses angle bracket includes.
21+
check_system_includes = true
22+
23+
default_args = {
24+
import("//args.gni")
25+
}

examples/valve-app/linux/BUILD.gn

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/build/chip/tools.gni")
18+
import("${chip_root}/src/app/common_flags.gni")
19+
20+
assert(chip_build_tools)
21+
22+
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
23+
24+
config("includes") {
25+
include_dirs = [
26+
".",
27+
"include",
28+
]
29+
}
30+
31+
executable("valve-app") {
32+
sources = [
33+
"include/CHIPProjectAppConfig.h",
34+
"main.cpp",
35+
]
36+
37+
deps = [
38+
"${chip_root}/examples/platform/linux:app-main",
39+
"${chip_root}/examples/valve-app/valve-common",
40+
"${chip_root}/src/lib",
41+
]
42+
43+
cflags = [ "-Wconversion" ]
44+
45+
include_dirs = [ "include" ]
46+
output_dir = root_out_dir
47+
}
48+
49+
group("linux") {
50+
deps = [ ":valve-app" ]
51+
}
52+
53+
group("default") {
54+
deps = [ ":linux" ]
55+
}

examples/valve-app/linux/args.gni

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/config/standalone/args.gni")
18+
19+
chip_device_project_config_include = "<CHIPProjectAppConfig.h>"
20+
chip_project_config_include = "<CHIPProjectAppConfig.h>"
21+
chip_system_project_config_include = "<SystemProjectConfig.h>"
22+
23+
chip_project_config_include_dirs =
24+
[ "${chip_root}/examples/air-purifier-app/linux/include" ]
25+
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../build_overrides
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
// include the CHIPProjectConfig from config/standalone
22+
#include <CHIPProjectConfig.h>
23+
24+
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0
25+
26+
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT 0
27+
28+
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
29+
30+
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1
31+
32+
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 0x0042 // Water valve
33+
34+
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1
35+
36+
#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1
37+
38+
#define CHIP_DEVICE_CONFIG_DEVICE_NAME "DISCO Drinks"

examples/valve-app/linux/main.cpp

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#include <AppMain.h>
19+
#include <app-common/zap-generated/ids/Clusters.h>
20+
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h>
21+
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h>
22+
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.h>
23+
#include <lib/support/logging/CHIPLogging.h>
24+
#include <platform/KvsPersistentStorageDelegate.h>
25+
26+
using namespace chip;
27+
using namespace chip::app;
28+
using namespace chip::app::Clusters;
29+
using namespace chip::app::Clusters::ValveConfigurationAndControl;
30+
namespace {
31+
class PrintOnlyDelegate : public NonLevelControlDelegate
32+
{
33+
public:
34+
PrintOnlyDelegate(EndpointId endpoint) : mEndpoint(endpoint) {}
35+
CHIP_ERROR HandleOpenValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & valveFault) override
36+
{
37+
ChipLogProgress(NotSpecified, "VALVE IS OPENING!!!!!");
38+
state = ValveStateEnum::kOpen;
39+
currentState = state;
40+
return CHIP_NO_ERROR;
41+
}
42+
ValveStateEnum GetCurrentValveState() override { return state; }
43+
CHIP_ERROR HandleCloseValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & valveFault) override
44+
{
45+
ChipLogProgress(NotSpecified, "VALVE IS CLOSING!!!!!");
46+
state = ValveStateEnum::kClosed;
47+
currentState = state;
48+
return CHIP_NO_ERROR;
49+
}
50+
51+
private:
52+
ValveStateEnum state = ValveStateEnum::kClosed;
53+
EndpointId mEndpoint;
54+
};
55+
56+
class NonLevelValveEndpoint
57+
{
58+
public:
59+
NonLevelValveEndpoint(EndpointId endpoint) :
60+
mEndpoint(endpoint), mContext(mEndpoint, storage), mDelegate(mEndpoint), mLogic(mDelegate, mContext),
61+
mInterface(mEndpoint, mLogic)
62+
{}
63+
CHIP_ERROR Init()
64+
{
65+
ReturnErrorOnFailure(mLogic.Init(kConformance, kInitParams));
66+
ReturnErrorOnFailure(mInterface.Init());
67+
return CHIP_NO_ERROR;
68+
}
69+
70+
private:
71+
const ClusterConformance kConformance = {
72+
.featureMap = 0, .supportsDefaultOpenLevel = false, .supportsValveFault = false, .supportsLevelStep = false
73+
};
74+
const ClusterInitParameters kInitParams = { .currentState = DataModel::MakeNullable(ValveStateEnum::kClosed),
75+
.currentLevel = DataModel::NullNullable,
76+
.valveFault = 0,
77+
.levelStep = 1 };
78+
EndpointId mEndpoint;
79+
KvsPersistentStorageDelegate storage;
80+
MatterContext mContext;
81+
PrintOnlyDelegate mDelegate;
82+
ClusterLogic mLogic;
83+
Interface mInterface;
84+
};
85+
86+
NonLevelValveEndpoint ep1(1);
87+
NonLevelValveEndpoint ep2(2);
88+
NonLevelValveEndpoint ep3(3);
89+
NonLevelValveEndpoint ep4(4);
90+
NonLevelValveEndpoint ep5(5);
91+
NonLevelValveEndpoint ep6(6);
92+
} // namespace
93+
94+
void ApplicationInit()
95+
{
96+
ChipLogError(NotSpecified, "App init!!!");
97+
ep1.Init();
98+
ep2.Init();
99+
ep3.Init();
100+
ep4.Init();
101+
ep5.Init();
102+
ep6.Init();
103+
}
104+
105+
void ApplicationShutdown()
106+
{
107+
ChipLogDetail(NotSpecified, "ApplicationShutdown()");
108+
}
109+
110+
int main(int argc, char * argv[])
111+
{
112+
if (ChipLinuxAppInit(argc, argv) != 0)
113+
{
114+
return -1;
115+
}
116+
117+
ChipLinuxAppMainLoop();
118+
return 0;
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("${chip_root}/src/app/chip_data_model.gni")
17+
18+
chip_data_model("valve-common") {
19+
zap_file = "valve-app.zap"
20+
is_server = true
21+
}

0 commit comments

Comments
 (0)