William | 4eaace4 | 2023-07-21 13:15:35 +0100 | [diff] [blame] | 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 <app/clusters/mode-base-server/mode-base-server.h> |
| 22 | #include <app/util/af.h> |
| 23 | #include <app/util/config.h> |
| 24 | #include <cstring> |
| 25 | #include <utility> |
| 26 | |
| 27 | namespace chip { |
| 28 | namespace app { |
| 29 | namespace Clusters { |
| 30 | |
| 31 | namespace DishwasherMode { |
| 32 | |
| 33 | const uint8_t ModeNormal = 0; |
| 34 | const uint8_t ModeHeavy = 1; |
| 35 | const uint8_t ModeLight = 2; |
| 36 | |
| 37 | /// This is an application level delegate to handle DishwasherMode commands according to the specific business logic. |
| 38 | class DishwasherModeDelegate : public ModeBase::Delegate |
| 39 | { |
| 40 | private: |
| 41 | using ModeTagStructType = detail::Structs::ModeTagStruct::Type; |
| 42 | ModeTagStructType modeTagsNormal[1] = { { .value = to_underlying(ModeTag::kNormal) } }; |
| 43 | ModeTagStructType modeTagsHeavy[2] = { { .value = to_underlying(ModeBase::ModeTag::kMax) }, |
Karsten Sperling | 38d6a48 | 2023-09-29 15:50:08 +1300 | [diff] [blame] | 44 | { .value = to_underlying(ModeTag::kHeavy) } }; |
William | 4eaace4 | 2023-07-21 13:15:35 +0100 | [diff] [blame] | 45 | ModeTagStructType modeTagsLight[3] = { { .value = to_underlying(ModeTag::kLight) }, |
Karsten Sperling | 38d6a48 | 2023-09-29 15:50:08 +1300 | [diff] [blame] | 46 | { .value = to_underlying(ModeBase::ModeTag::kNight) }, |
| 47 | { .value = to_underlying(ModeBase::ModeTag::kQuiet) } }; |
William | 4eaace4 | 2023-07-21 13:15:35 +0100 | [diff] [blame] | 48 | |
| 49 | const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = { |
| 50 | detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Normal"), |
| 51 | .mode = ModeNormal, |
| 52 | .modeTags = DataModel::List<const ModeTagStructType>(modeTagsNormal) }, |
| 53 | detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Heavy"), |
| 54 | .mode = ModeHeavy, |
| 55 | .modeTags = DataModel::List<const ModeTagStructType>(modeTagsHeavy) }, |
| 56 | detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Light"), |
| 57 | .mode = ModeLight, |
| 58 | .modeTags = DataModel::List<const ModeTagStructType>(modeTagsLight) } |
| 59 | }; |
| 60 | |
| 61 | CHIP_ERROR Init() override; |
| 62 | void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override; |
| 63 | |
| 64 | CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override; |
| 65 | CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override; |
| 66 | CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override; |
| 67 | |
| 68 | public: |
| 69 | ~DishwasherModeDelegate() override = default; |
| 70 | }; |
| 71 | |
joonhaengHeo | b8479e1 | 2023-08-25 22:05:59 +0900 | [diff] [blame] | 72 | ModeBase::Instance * Instance(); |
| 73 | |
William | 7b6cbc5 | 2023-07-25 11:07:22 +0100 | [diff] [blame] | 74 | void Shutdown(); |
| 75 | |
William | 4eaace4 | 2023-07-21 13:15:35 +0100 | [diff] [blame] | 76 | } // namespace DishwasherMode |
| 77 | |
| 78 | } // namespace Clusters |
| 79 | } // namespace app |
| 80 | } // namespace chip |