|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2025 Matter 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/ids/Attributes.h> |
| 19 | +#include <app-common/zap-generated/ids/Clusters.h> |
| 20 | +#include <app/clusters/chime-server/chime-server.h> |
| 21 | +#include <chime-instance.h> |
| 22 | + |
| 23 | +using namespace chip; |
| 24 | +using namespace chip::app; |
| 25 | +using namespace chip::app::DataModel; |
| 26 | +using namespace chip::app::Clusters; |
| 27 | +using namespace chip::app::Clusters::Chime; |
| 28 | +using namespace chip::app::Clusters::Chime::Attributes; |
| 29 | +using chip::Protocols::InteractionModel::Status; |
| 30 | +using ChimeSoundStructType = Structs::ChimeSoundStruct::Type; |
| 31 | + |
| 32 | +ChimeCommandDelegate ChimeCommandDelegate::instance; |
| 33 | + |
| 34 | +ChimeSoundStructType ChimeCommandDelegate::supportedChimes[] = { |
| 35 | + { .chimeID = 5, .name = chip::CharSpan("Chime 5"_span) }, |
| 36 | + { .chimeID = 10, .name = chip::CharSpan("Chime 10"_span) }, |
| 37 | +}; |
| 38 | + |
| 39 | +CHIP_ERROR ChimeCommandDelegate::GetChimeSoundByIndex(uint8_t chimeIndex, uint8_t & chimeID, MutableCharSpan & name) |
| 40 | +{ |
| 41 | + if (chimeIndex >= MATTER_ARRAY_SIZE(supportedChimes)) |
| 42 | + { |
| 43 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 44 | + } |
| 45 | + auto & selectedChime = supportedChimes[chimeIndex]; |
| 46 | + chip::CopyCharSpanToMutableCharSpan(selectedChime.name, name); |
| 47 | + chimeID = selectedChime.chimeID; |
| 48 | + return CHIP_NO_ERROR; |
| 49 | +} |
| 50 | + |
| 51 | +CHIP_ERROR ChimeCommandDelegate::GetChimeIDByIndex(uint8_t chimeIndex, uint8_t & chimeID) |
| 52 | +{ |
| 53 | + if (chimeIndex >= MATTER_ARRAY_SIZE(supportedChimes)) |
| 54 | + { |
| 55 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 56 | + } |
| 57 | + auto & selectedChime = supportedChimes[chimeIndex]; |
| 58 | + chimeID = selectedChime.chimeID; |
| 59 | + return CHIP_NO_ERROR; |
| 60 | +} |
| 61 | + |
| 62 | +Status ChimeCommandDelegate::PlayChimeSound() |
| 63 | +{ |
| 64 | + return Status::Success; |
| 65 | +} |
| 66 | + |
| 67 | +static ChimeServer gChimeClusterServerInstance = ChimeServer(EndpointId(1), ChimeCommandDelegate::getInstance()); |
| 68 | + |
| 69 | +void emberAfChimeClusterInitCallback(EndpointId endpoint) |
| 70 | +{ |
| 71 | + gChimeClusterServerInstance.Init(); |
| 72 | +} |
0 commit comments