Coverage Report

Created: 2024-12-17 06:44

/src/connectedhomeip/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h
Line
Count
Source
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/config.h>
23
#include <cstring>
24
#include <utility>
25
26
namespace chip {
27
namespace app {
28
namespace Clusters {
29
30
namespace RvcRunMode {
31
32
const uint8_t ModeIdle     = 0;
33
const uint8_t ModeCleaning = 1;
34
const uint8_t ModeMapping  = 2;
35
36
/// This is an application level delegate to handle RvcRun commands according to the specific business logic.
37
class RvcRunModeDelegate : public ModeBase::Delegate
38
{
39
private:
40
    using ModeTagStructType               = detail::Structs::ModeTagStruct::Type;
41
    ModeTagStructType ModeTagsIdle[1]     = { { .value = to_underlying(ModeTag::kIdle) } };
42
    ModeTagStructType ModeTagsCleaning[1] = { { .value = to_underlying(ModeTag::kCleaning) } };
43
    ModeTagStructType ModeTagsMapping[1]  = { { .value = to_underlying(ModeTag::kMapping) } };
44
45
    const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
46
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Idle"),
47
                                                 .mode     = ModeIdle,
48
                                                 .modeTags = DataModel::List<const ModeTagStructType>(ModeTagsIdle) },
49
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Cleaning"),
50
                                                 .mode     = ModeCleaning,
51
                                                 .modeTags = DataModel::List<const ModeTagStructType>(ModeTagsCleaning) },
52
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Mapping"),
53
                                                 .mode     = ModeMapping,
54
                                                 .modeTags = DataModel::List<const ModeTagStructType>(ModeTagsMapping) },
55
    };
56
57
    CHIP_ERROR Init() override;
58
    void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;
59
60
    CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
61
    CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
62
    CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;
63
64
public:
65
1
    ~RvcRunModeDelegate() override = default;
66
};
67
68
ModeBase::Instance * Instance();
69
70
void Shutdown();
71
72
} // namespace RvcRunMode
73
74
namespace RvcCleanMode {
75
76
const uint8_t ModeVacuum    = 0;
77
const uint8_t ModeWash      = 1;
78
const uint8_t ModeDeepClean = 2;
79
80
/// This is an application level delegate to handle RvcClean commands according to the specific business logic.
81
class RvcCleanModeDelegate : public ModeBase::Delegate
82
{
83
private:
84
    using ModeTagStructType            = detail::Structs::ModeTagStruct::Type;
85
    ModeTagStructType modeTagsVac[1]   = { { .value = to_underlying(ModeTag::kVacuum) } };
86
    ModeTagStructType modeTagsMop[1]   = { { .value = to_underlying(ModeTag::kMop) } };
87
    ModeTagStructType modeTagsBoost[2] = { { .value = to_underlying(ModeBase::ModeTag::kMax) },
88
                                           { .value = to_underlying(ModeTag::kDeepClean) } };
89
90
    const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
91
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Vacuum"),
92
                                                 .mode     = ModeVacuum,
93
                                                 .modeTags = DataModel::List<const ModeTagStructType>(modeTagsVac) },
94
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Wash"),
95
                                                 .mode     = ModeWash,
96
                                                 .modeTags = DataModel::List<const ModeTagStructType>(modeTagsMop) },
97
        detail::Structs::ModeOptionStruct::Type{ .label    = CharSpan::fromCharString("Deep clean"),
98
                                                 .mode     = ModeDeepClean,
99
                                                 .modeTags = DataModel::List<const ModeTagStructType>(modeTagsBoost) },
100
    };
101
102
    CHIP_ERROR Init() override;
103
    void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;
104
105
    CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
106
    CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
107
    CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;
108
109
public:
110
1
    ~RvcCleanModeDelegate() override = default;
111
};
112
113
ModeBase::Instance * Instance();
114
115
void Shutdown();
116
117
} // namespace RvcCleanMode
118
119
} // namespace Clusters
120
} // namespace app
121
} // namespace chip