|
| 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 "ClosureControlEndpoint.h" |
| 19 | +#include "ClosureDimensionEndpoint.h" |
| 20 | +#include <AppMain.h> |
| 21 | + |
| 22 | +#include <app-common/zap-generated/cluster-objects.h> |
| 23 | +#include <app/util/attribute-storage.h> |
| 24 | +#include <platform/CHIPDeviceLayer.h> |
| 25 | + |
| 26 | +using namespace chip; |
| 27 | +using namespace chip::app; |
| 28 | +using namespace chip::app::Clusters::ClosureControl; |
| 29 | +using namespace chip::app::Clusters::ClosureDimension; |
| 30 | + |
| 31 | +namespace { |
| 32 | + |
| 33 | +// Define the endpoint ID for the Closure |
| 34 | +constexpr chip::EndpointId kClosureEndpoint = 1; |
| 35 | +constexpr chip::EndpointId kClosurePanel1Endpoint = 2; |
| 36 | +constexpr chip::EndpointId kClosurePanel2Endpoint = 3; |
| 37 | + |
| 38 | +// Closure Endpoints |
| 39 | +ClosureControlEndpoint ep1(kClosureEndpoint); |
| 40 | +ClosureDimensionEndpoint ep2(kClosurePanel1Endpoint); |
| 41 | +ClosureDimensionEndpoint ep3(kClosurePanel2Endpoint); |
| 42 | + |
| 43 | +// Define the Namespace and Tag for the endpoint |
| 44 | +// Derived from https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/namespaces/Namespace-Closure.adoc |
| 45 | +constexpr uint8_t kNamespaceClosure = 0x44; |
| 46 | +constexpr uint8_t kTagClosureCovering = 0x00; |
| 47 | +// Derived from |
| 48 | +// https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/namespaces/Namespace-Closure-Covering.adoc |
| 49 | +constexpr uint8_t kNamespaceCovering = 0x46; |
| 50 | +constexpr uint8_t kTagCoveringVenetian = 0x03; |
| 51 | +// Derived from https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/namespaces/Namespace-ClosurePanel.adoc |
| 52 | +constexpr uint8_t kNamespaceClosurePanel = 0x45; |
| 53 | +constexpr uint8_t kTagClosurePanelLift = 0x00; |
| 54 | +constexpr uint8_t kTagClosurePanelTilt = 0x01; |
| 55 | + |
| 56 | +// Define the list of semantic tags for the endpoint |
| 57 | +const Clusters::Descriptor::Structs::SemanticTagStruct::Type gEp1TagList[] = { |
| 58 | + { .namespaceID = kNamespaceClosure, |
| 59 | + .tag = kTagClosureCovering, |
| 60 | + .label = chip::MakeOptional(DataModel::Nullable<chip::CharSpan>("Closure.Covering"_span)) }, |
| 61 | + { .namespaceID = kNamespaceCovering, |
| 62 | + .tag = kTagCoveringVenetian, |
| 63 | + .label = chip::MakeOptional(DataModel::Nullable<chip::CharSpan>("Covering.Venetian"_span)) }, |
| 64 | +}; |
| 65 | + |
| 66 | +const Clusters::Descriptor::Structs::SemanticTagStruct::Type gEp2TagList[] = { |
| 67 | + { .namespaceID = kNamespaceClosurePanel, |
| 68 | + .tag = kTagClosurePanelLift, |
| 69 | + .label = chip::MakeOptional(DataModel::Nullable<chip::CharSpan>("ClosurePanel.Lift"_span)) }, |
| 70 | +}; |
| 71 | + |
| 72 | +const Clusters::Descriptor::Structs::SemanticTagStruct::Type gEp3TagList[] = { |
| 73 | + { .namespaceID = kNamespaceClosurePanel, |
| 74 | + .tag = kTagClosurePanelTilt, |
| 75 | + .label = chip::MakeOptional(DataModel::Nullable<chip::CharSpan>("ClosurePanel.Tilt"_span)) }, |
| 76 | +}; |
| 77 | + |
| 78 | +} // namespace |
| 79 | + |
| 80 | +void ApplicationInit() |
| 81 | +{ |
| 82 | + DeviceLayer::PlatformMgr().LockChipStack(); |
| 83 | + |
| 84 | + // Closure endpoints initilization |
| 85 | + ep1.Init(); |
| 86 | + ep2.Init(); |
| 87 | + ep3.Init(); |
| 88 | + |
| 89 | + // Set Taglist for Closure endpoints |
| 90 | + SetTagList(/* endpoint= */ 1, Span<const Clusters::Descriptor::Structs::SemanticTagStruct::Type>(gEp1TagList)); |
| 91 | + SetTagList(/* endpoint= */ 2, Span<const Clusters::Descriptor::Structs::SemanticTagStruct::Type>(gEp2TagList)); |
| 92 | + SetTagList(/* endpoint= */ 3, Span<const Clusters::Descriptor::Structs::SemanticTagStruct::Type>(gEp3TagList)); |
| 93 | + |
| 94 | + DeviceLayer::PlatformMgr().UnlockChipStack(); |
| 95 | +} |
| 96 | + |
| 97 | +void ApplicationShutdown() |
| 98 | +{ |
| 99 | + ChipLogDetail(NotSpecified, "ApplicationShutdown()"); |
| 100 | +} |
| 101 | + |
| 102 | +int main(int argc, char * argv[]) |
| 103 | +{ |
| 104 | + if (ChipLinuxAppInit(argc, argv) != 0) |
| 105 | + { |
| 106 | + return -1; |
| 107 | + } |
| 108 | + |
| 109 | + ChipLinuxAppMainLoop(); |
| 110 | + return 0; |
| 111 | +} |
0 commit comments