-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added an air quality cluster instance class that manages the attributes via the AttributeAccessInterface. Marke these attributes as being manage via the AttributeAccessInterface. * Regenerated auto gen code * Added the instantiation of the Air Quality cluter in the all-clusters-app. * Added method to get the current setting of the AirQuality attribute. * Restyled by whitespace * Restyled by clang-format * Restyled by prettier-json --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
925914d
commit cbc3865
Showing
15 changed files
with
254 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
examples/all-clusters-app/all-clusters-common/include/air-quality-instance.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <app/clusters/air-quality-server/air-quality-server.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace AirQuality { | ||
|
||
void Shutdown(); | ||
|
||
} // namespace AirQuality | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
25 changes: 25 additions & 0 deletions
25
examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <air-quality-instance.h> | ||
|
||
using namespace chip::app::Clusters; | ||
using namespace chip::app::Clusters::AirQuality; | ||
|
||
Instance * gAirQualityCluster = nullptr; | ||
|
||
void AirQuality::Shutdown() | ||
{ | ||
if (gAirQualityCluster != nullptr) | ||
{ | ||
delete gAirQualityCluster; | ||
gAirQualityCluster = nullptr; | ||
} | ||
} | ||
|
||
void emberAfAirQualityClusterInitCallback(chip::EndpointId endpointId) | ||
{ | ||
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. | ||
VerifyOrDie(gAirQualityCluster == nullptr); | ||
chip::BitMask<Feature, uint32_t> airQualityFeatures(Feature::kModerate, Feature::kFair, Feature::kVeryPoor, | ||
Feature::kExtremelyPoor); | ||
gAirQualityCluster = new Instance(1, airQualityFeatures.Raw()); | ||
gAirQualityCluster->Init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/app/clusters/air-quality-server/air-quality-server.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 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-common/zap-generated/ids/Clusters.h" | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <app/clusters/air-quality-server/air-quality-server.h> | ||
#include <app/reporting/reporting.h> | ||
#include <app/util/attribute-storage.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters; | ||
using chip::Protocols::InteractionModel::Status; | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace AirQuality { | ||
|
||
Instance::Instance(EndpointId aEndpointId, uint32_t aFeature) : | ||
AttributeAccessInterface(Optional<EndpointId>(aEndpointId), Id), mEndpointId(aEndpointId), mFeature(aFeature) | ||
{} | ||
|
||
Instance::~Instance() | ||
{ | ||
unregisterAttributeAccessOverride(this); | ||
} | ||
|
||
CHIP_ERROR Instance::Init() | ||
{ | ||
// Check if the cluster has been selected in zap | ||
VerifyOrDie(emberAfContainsServer(mEndpointId, Id) == true); | ||
|
||
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
bool Instance::HasFeature(AirQualityEnum aFeature) const | ||
{ | ||
return mFeature & to_underlying(aFeature); | ||
} | ||
|
||
Protocols::InteractionModel::Status Instance::UpdateAirQuality(AirQualityEnum aNewAirQuality) | ||
{ | ||
// Check that the value in is valid according to the enabled features. | ||
switch (aNewAirQuality) | ||
{ | ||
case AirQualityEnum::kFair: { | ||
if (!HasFeature(AirQualityEnum::kFair)) | ||
{ | ||
return Protocols::InteractionModel::Status::ConstraintError; | ||
} | ||
} | ||
break; | ||
case AirQualityEnum::kModerate: { | ||
if (!HasFeature(AirQualityEnum::kModerate)) | ||
{ | ||
return Protocols::InteractionModel::Status::ConstraintError; | ||
} | ||
} | ||
break; | ||
case AirQualityEnum::kPoor: { | ||
if (!HasFeature(AirQualityEnum::kPoor)) | ||
{ | ||
return Protocols::InteractionModel::Status::ConstraintError; | ||
} | ||
} | ||
break; | ||
case AirQualityEnum::kExtremelyPoor: { | ||
if (!HasFeature(AirQualityEnum::kExtremelyPoor)) | ||
{ | ||
return Protocols::InteractionModel::Status::ConstraintError; | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
mAirQuality = aNewAirQuality; | ||
MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, Id, Attributes::AirQuality::Id)); | ||
return Protocols::InteractionModel::Status::Success; | ||
} | ||
|
||
AirQualityEnum Instance::GetAirQuality() | ||
{ | ||
return mAirQuality; | ||
} | ||
|
||
CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) | ||
{ | ||
switch (aPath.mAttributeId) | ||
{ | ||
case Attributes::AirQuality::Id: | ||
ReturnErrorOnFailure(aEncoder.Encode(mAirQuality)); | ||
break; | ||
} | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
} // namespace AirQuality | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 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/AttributeAccessInterface.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace AirQuality { | ||
|
||
class Instance : public AttributeAccessInterface | ||
{ | ||
public: | ||
/** | ||
* Creates an air quality cluster instance. The Init() function needs to be called for this instance to be registered and | ||
* called by the interaction model at the appropriate times. | ||
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. | ||
* @param aFeature The bitmask value that identifies which features are supported by this instance. | ||
*/ | ||
Instance(EndpointId aEndpointId, uint32_t eFeature); | ||
|
||
~Instance() override; | ||
|
||
/** | ||
* Initialises the air quality cluster instance | ||
* @return Returns an error if an air quality cluster has not been enabled in zap for the given endpoint ID or | ||
* if the AttributeHandler registration fails. | ||
*/ | ||
CHIP_ERROR Init(); | ||
|
||
/** | ||
* Returns true if the feature is supported. | ||
* @param feature the feature to check. | ||
*/ | ||
bool HasFeature(AirQualityEnum) const; | ||
|
||
/** | ||
* Sets the AirQuality attribute. | ||
* @param aNewAirQuality The value to which the AirQuality attribute is to be set. | ||
* @return Returns a ConstraintError if the aNewAirQuality value is not valid. Returns Success otherwise. | ||
*/ | ||
Protocols::InteractionModel::Status UpdateAirQuality(AirQualityEnum aNewAirQuality); | ||
|
||
/** | ||
* @return The current AirQuality enum. | ||
*/ | ||
AirQualityEnum GetAirQuality(); | ||
|
||
private: | ||
EndpointId mEndpointId; | ||
AirQualityEnum mAirQuality = AirQualityEnum::kUnknown; | ||
uint32_t mFeature; | ||
|
||
// AttributeAccessInterface | ||
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; | ||
}; | ||
|
||
} // namespace AirQuality | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.