Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temperature control cluster impl for laundry washer #36105

Merged
merged 21 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions examples/chef/common/chef-laundry-washer-mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ template <typename T>
using List = chip::app::DataModel::List<T>;
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;

#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
static LaundryWasherModeDelegate * gLaundryWasherModeDelegate = nullptr;
static ModeBase::Instance * gLaundryWasherModeInstance = nullptr;

Expand Down Expand Up @@ -94,6 +95,61 @@ void LaundryWasherMode::Shutdown()
}
}

chip::Protocols::InteractionModel::Status chefLaundryWasherModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrDie(gLaundryWasherModeInstance != nullptr);
stingchang marked this conversation as resolved.
Show resolved Hide resolved
chip::Protocols::InteractionModel::Status ret;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
case chip::app::Clusters::LaundryWasherMode::Attributes::CurrentMode::Id: {
uint8_t m = buffer[0];
ret = gLaundryWasherModeInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success != ret)
{
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
}
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
break;
}

return ret;
}

chip::Protocols::InteractionModel::Status chefLaundryWasherModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted);
buffer[0] = gLaundryWasherModeInstance->GetCurrentMode();
stingchang marked this conversation as resolved.
Show resolved Hide resolved

chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
case chip::app::Clusters::LaundryWasherMode::Attributes::CurrentMode::Id: {
*buffer = gLaundryWasherModeInstance->GetCurrentMode();
ChipLogDetail(DeviceLayer, "Reading LaundryWasherMode CurrentMode : %d", static_cast<int>(attributeId));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcCleanMode", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfLaundryWasherModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
Expand All @@ -103,3 +159,4 @@ void emberAfLaundryWasherModeClusterInitCallback(chip::EndpointId endpointId)
new ModeBase::Instance(gLaundryWasherModeDelegate, 0x1, LaundryWasherMode::Id, chip::to_underlying(Feature::kOnOff));
gLaundryWasherModeInstance->Init();
}
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
9 changes: 9 additions & 0 deletions examples/chef/common/chef-laundry-washer-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ void Shutdown();
} // namespace Clusters
} // namespace app
} // namespace chip

#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
chip::Protocols::InteractionModel::Status chefLaundryWasherModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
chip::Protocols::InteractionModel::Status chefLaundryWasherModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength);
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <app/util/config.h>

#ifdef MATTER_DM_PLUGIN_TEMPERATURE_CONTROL_SERVER
#include "static-supported-temperature-levels.h"
#include <app/clusters/temperature-control-server/supported-temperature-levels-manager.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::TemperatureControl;
using chip::Protocols::InteractionModel::Status;

app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;

CharSpan AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions[] = { "Low"_span, "Medium"_span, "High"_span };
// uint8_t kLevelCount = ArraySize(AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions);
stingchang marked this conversation as resolved.
Show resolved Hide resolved

const AppSupportedTemperatureLevelsDelegate::EndpointPair AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints
[MATTER_DM_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT] = {
stingchang marked this conversation as resolved.
Show resolved Hide resolved
EndpointPair(
1, AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions,
stingchang marked this conversation as resolved.
Show resolved Hide resolved
ArraySize(AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions)) // Supported level options for endPoint 1
};

uint8_t AppSupportedTemperatureLevelsDelegate::Size()
{
for (auto & endpointPair : AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints)
{
if (endpointPair.mEndpointId == mEndpoint)
{
return endpointPair.mSize;
}
}
return 0;
}

CHIP_ERROR AppSupportedTemperatureLevelsDelegate::Next(MutableCharSpan & item)
{
for (auto & endpointPair : AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints)
{
if (endpointPair.mEndpointId == mEndpoint)
{
if (endpointPair.mSize > mIndex)
{
CHIP_ERROR err = CopyCharSpanToMutableCharSpan(endpointPair.mTemperatureLevels[mIndex], item);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Error copying char span to mutable char span %s", ErrorStr(err));
return err;
}
mIndex++;
return CHIP_NO_ERROR;
}
}
}
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
void emberAfTemperatureControlClusterInitCallback(EndpointId endpoint)
{
VerifyOrDie(endpoint == 1); // this cluster is only enabled for endpoint 1.
chip::app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
}
#endif // MATTER_DM_PLUGIN_TEMPERATURE_CONTROL_SERVER
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/clusters/temperature-control-server/supported-temperature-levels-manager.h>
#include <app/util/config.h>

namespace chip {
namespace app {
namespace Clusters {
namespace TemperatureControl {

class AppSupportedTemperatureLevelsDelegate : public SupportedTemperatureLevelsIteratorDelegate
{
struct EndpointPair
{
EndpointId mEndpointId;
CharSpan * mTemperatureLevels;
uint8_t mSize;

EndpointPair(EndpointId aEndpointId, CharSpan * aTemperatureLevels, uint8_t aSize) :
mEndpointId(aEndpointId), mTemperatureLevels(aTemperatureLevels), mSize(aSize)
stingchang marked this conversation as resolved.
Show resolved Hide resolved
{}
};

static CharSpan temperatureLevelOptions[3];

public:
static const EndpointPair supportedOptionsByEndpoints[MATTER_DM_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT];
stingchang marked this conversation as resolved.
Show resolved Hide resolved

uint8_t Size() override;

CHIP_ERROR Next(MutableCharSpan & item) override;

~AppSupportedTemperatureLevelsDelegate() {}
};

} // namespace TemperatureControl
} // namespace Clusters
} // namespace app
} // namespace chip
20 changes: 20 additions & 0 deletions examples/chef/common/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@ const Clusters::Descriptor::Structs::SemanticTagStruct::Type freezerTagList[]
#include "chef-dishwasher-mode-delegate-impl.h"
#endif // MATTER_DM_PLUGIN_DISHWASHER_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
#include "chef-laundry-washer-mode.h"
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_CONTROLS_SERVER
#include "chef-laundry-washer-controls-delegate-impl.h"
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_CONTROLS_SERVER

#ifdef MATTER_DM_PLUGIN_OPERATIONAL_STATE_SERVER
#include "chef-operational-state-delegate-impl.h"
#endif // MATTER_DM_PLUGIN_OPERATIONAL_STATE_SERVER

#ifdef MATTER_DM_PLUGIN_TEMPERATURE_CONTROL_SERVER
#include "temperature-control/static-supported-temperature-levels.h"
#endif // MATTER_DM_PLUGIN_TEMPERATURE_CONTROL_SERVER

Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
Expand Down Expand Up @@ -124,6 +136,10 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
case chip::app::Clusters::DishwasherMode::Id:
return chefDishwasherModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength);
#endif // MATTER_DM_PLUGIN_DISHWASHER_MODE_SERVER
#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
case chip::app::Clusters::LaundryWasherMode::Id:
return chefLaundryWasherModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength);
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
#ifdef MATTER_DM_PLUGIN_OPERATIONAL_STATE_SERVER
case chip::app::Clusters::OperationalState::Id:
return chefOperationalStateReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength);
Expand Down Expand Up @@ -202,6 +218,10 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
case chip::app::Clusters::DishwasherMode::Id:
return chefDishwasherModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
#endif // MATTER_DM_PLUGIN_DISHWASHER_MODE_SERVER
#ifdef MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
case chip::app::Clusters::LaundryWasherMode::Id:
return chefLaundryWasherModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
#endif // MATTER_DM_PLUGIN_LAUNDRY_WASHER_MODE_SERVER
#ifdef MATTER_DM_PLUGIN_OPERATIONAL_STATE_SERVER
case chip::app::Clusters::OperationalState::Id:
return chefOperationalStateWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
Expand Down
Loading
Loading