Skip to content

Commit c415c55

Browse files
committed
Adds changes for refrigerator modes and callbacks
1 parent a58a8c3 commit c415c55

5 files changed

+177
-42
lines changed

examples/refrigerator-app/silabs/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ silabs_executable("refrigerator_app") {
140140
"src/AppTask.cpp",
141141
"src/RefrigeratorManager.cpp",
142142
"src/ZclCallbacks.cpp",
143+
"src/refrigerator-and-temperature-controlled-cabinet-mode.cpp",
143144
]
144145

145146
if (use_temp_sensor) {

examples/refrigerator-app/silabs/include/RefrigeratorManager.h

-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ using namespace chip::app::Clusters::RefrigeratorAndTemperatureControlledCabinet
3939
using namespace chip::DeviceLayer;
4040
using chip::Protocols::InteractionModel::Status;
4141

42-
// AppCluster Spec Table 85.
43-
enum SUPPORTED_MODES
44-
{
45-
NORMAL = 0x0000,
46-
ENERGY_SAVE = 0x0004,
47-
RAPID_COOL = 0x4000,
48-
RAPID_FREEZE = 0x4001,
49-
};
50-
5142
class RefrigeratorManager
5243
{
5344
public:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
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 RefrigeratorAndTemperatureControlledCabinetMode {
31+
32+
const uint8_t ModeRapidCool = 0;
33+
const uint8_t ModeRapidFreeze = 1;
34+
35+
/// This is an application level delegate to handle LaundryWasherMode commands according to the specific business logic.
36+
class RefrigeratorAndTemperatureControlledCabinetModeDelegate : public ModeBase::Delegate
37+
{
38+
private:
39+
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
40+
ModeTagStructType modeTagsRapidCool[1] = { { .value = to_underlying(ModeTag::kRapidCool) } };
41+
ModeTagStructType modeTagsRapidFreeze[2] = { { .value = to_underlying(ModeBase::ModeTag::kMax) },
42+
{ .value = to_underlying(ModeTag::kRapidFreeze) } };
43+
44+
const detail::Structs::ModeOptionStruct::Type kModeOptions[2] = {
45+
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Rapid Cool"),
46+
.mode = ModeRapidCool,
47+
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsRapidCool) },
48+
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Rapid Freeze"),
49+
.mode = ModeRapidFreeze,
50+
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsRapidFreeze) },
51+
};
52+
53+
CHIP_ERROR Init() override;
54+
void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;
55+
CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
56+
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
57+
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;
58+
59+
public:
60+
~RefrigeratorAndTemperatureControlledCabinetModeDelegate() override = default;
61+
};
62+
63+
ModeBase::Instance * Instance();
64+
65+
void Shutdown();
66+
67+
} // namespace LaundryWasherMode
68+
69+
} // namespace Clusters
70+
} // namespace app
71+
} // namespace chip

examples/refrigerator-app/silabs/src/ZclCallbacks.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
7070
}
7171
}
7272

73-
/** @brief Refrigerator And TemperatureControlled Cabinet Mode Cluster Init
74-
*
75-
* This function is called when a specific cluster is initialized. It gives the
76-
* application an opportunity to take care of cluster initialization procedures.
77-
* It is called exactly once for each endpoint where cluster is present.
78-
*
79-
* @param endpoint Ver.: always
80-
*
81-
*/
82-
void emberAfRefrigeratorAndTemperatureControlledCabinetModeClusterInitCallback(EndpointId endpoint) {}
83-
8473
/** @brief Refrigerator Alarm Cluster Init
8574
*
8675
* This function is called when a specific cluster is initialized. It gives the
@@ -102,25 +91,3 @@ void emberAfRefrigeratorAlarmClusterInitCallback(EndpointId endpoint) {}
10291
*
10392
*/
10493
void emberAfTemperatureControlClusterInitCallback(EndpointId endpoint) {}
105-
106-
// /**
107-
// * @brief Handles the SetTemperature command for the Temperature Control Cluster.
108-
// *
109-
// * This function is called when the SetTemperature command is received from a client.
110-
// * It is responsible for setting the temperature for the cabinet as per the command data.
111-
// *
112-
// * @param CommandHandler commandObj Pointer to the command handler object.
113-
// * @param const ConcreteCommandPath commandPath The path of the command received.
114-
// * @param const DecodableType & commandData
115-
// * The data decoded from the SetTemperature command, which includes the desired temperature.
116-
// *
117-
// * @return bool Returns true if the command was handled successfully, false otherwise.
118-
// *
119-
// * @note The actual implementation to set the temperature is yet to be added.
120-
// */
121-
// bool emberAfTemperatureControlClusterSetTemperatureCallback(
122-
// chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
123-
// const chip::app::Clusters::TemperatureControl::Commands::SetTemperature::DecodableType & commandData) {
124-
// // TODO: Add implementation to set the temperature for the cabinet
125-
// return true;
126-
// }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 <app-common/zap-generated/attributes/Accessors.h>
19+
#include <refrigerator-and-temperature-controlled-cabinet-mode.h>
20+
21+
using namespace chip::app::Clusters;
22+
using namespace chip::app::Clusters::RefrigeratorAndTemperatureControlledCabinetMode;
23+
using chip::Protocols::InteractionModel::Status;
24+
template <typename T>
25+
using List = chip::app::DataModel::List<T>;
26+
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;
27+
28+
static RefrigeratorAndTemperatureControlledCabinetModeDelegate * gRefrigeratorAndTemperatureControlledCabinetModeDelegate = nullptr;
29+
static ModeBase::Instance * gRefrigeratorAndTemperatureControlledCabinetModeInstance = nullptr;
30+
31+
CHIP_ERROR RefrigeratorAndTemperatureControlledCabinetModeDelegate::Init()
32+
{
33+
return CHIP_NO_ERROR;
34+
}
35+
36+
void RefrigeratorAndTemperatureControlledCabinetModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands::ChangeToModeResponse::Type & response)
37+
{
38+
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
39+
}
40+
41+
CHIP_ERROR RefrigeratorAndTemperatureControlledCabinetModeDelegate::GetModeLabelByIndex(uint8_t modeIndex, chip::MutableCharSpan & label)
42+
{
43+
if (modeIndex >= ArraySize(kModeOptions))
44+
{
45+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
46+
}
47+
return chip::CopyCharSpanToMutableCharSpan(kModeOptions[modeIndex].label, label);
48+
}
49+
50+
CHIP_ERROR RefrigeratorAndTemperatureControlledCabinetModeDelegate::GetModeValueByIndex(uint8_t modeIndex, uint8_t & value)
51+
{
52+
if (modeIndex >= ArraySize(kModeOptions))
53+
{
54+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
55+
}
56+
value = kModeOptions[modeIndex].mode;
57+
return CHIP_NO_ERROR;
58+
}
59+
60+
CHIP_ERROR RefrigeratorAndTemperatureControlledCabinetModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTagStructType> & tags)
61+
{
62+
if (modeIndex >= ArraySize(kModeOptions))
63+
{
64+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
65+
}
66+
67+
if (tags.size() < kModeOptions[modeIndex].modeTags.size())
68+
{
69+
return CHIP_ERROR_INVALID_ARGUMENT;
70+
}
71+
72+
std::copy(kModeOptions[modeIndex].modeTags.begin(), kModeOptions[modeIndex].modeTags.end(), tags.begin());
73+
tags.reduce_size(kModeOptions[modeIndex].modeTags.size());
74+
75+
return CHIP_NO_ERROR;
76+
}
77+
78+
ModeBase::Instance * RefrigeratorAndTemperatureControlledCabinetMode::Instance()
79+
{
80+
return gRefrigeratorAndTemperatureControlledCabinetModeInstance;
81+
}
82+
83+
void RefrigeratorAndTemperatureControlledCabinetMode::Shutdown()
84+
{
85+
if (gRefrigeratorAndTemperatureControlledCabinetModeInstance != nullptr)
86+
{
87+
delete gRefrigeratorAndTemperatureControlledCabinetModeInstance;
88+
gRefrigeratorAndTemperatureControlledCabinetModeInstance = nullptr;
89+
}
90+
if (gRefrigeratorAndTemperatureControlledCabinetModeDelegate != nullptr)
91+
{
92+
delete gRefrigeratorAndTemperatureControlledCabinetModeDelegate;
93+
gRefrigeratorAndTemperatureControlledCabinetModeDelegate = nullptr;
94+
}
95+
}
96+
97+
void emberAfRefrigeratorAndTemperatureControlledCabinetModeClusterInitCallback(chip::EndpointId endpointId)
98+
{
99+
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
100+
VerifyOrDie(gRefrigeratorAndTemperatureControlledCabinetModeDelegate == nullptr && gRefrigeratorAndTemperatureControlledCabinetModeInstance == nullptr);
101+
gRefrigeratorAndTemperatureControlledCabinetModeDelegate = new RefrigeratorAndTemperatureControlledCabinetMode::RefrigeratorAndTemperatureControlledCabinetModeDelegate;
102+
gRefrigeratorAndTemperatureControlledCabinetModeInstance =
103+
new ModeBase::Instance(gRefrigeratorAndTemperatureControlledCabinetModeDelegate, 0x1, RefrigeratorAndTemperatureControlledCabinetMode::Id, chip::to_underlying(Feature::kOnOff));
104+
gRefrigeratorAndTemperatureControlledCabinetModeInstance->Init();
105+
}

0 commit comments

Comments
 (0)