-
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 sensor managers * called cluster apis from delegate * removed dead code * Restyled by whitespace * Restyled by clang-format * Restyled by gn --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
7 changed files
with
544 additions
and
87 deletions.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
...les/air-quality-sensor-app/air-quality-sensor-common/include/air-quality-sensor-manager.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,187 @@ | ||
#include <app-common/zap-generated/ids/Attributes.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app/clusters/air-quality-server/air-quality-server.h> | ||
#include <app/clusters/concentration-measurement-server/concentration-measurement-server.h> | ||
|
||
#include <relative-humidity-sensor-manager.h> | ||
#include <temperature-sensor-manager.h> | ||
|
||
#pragma once | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
class AirQualitySensorManager | ||
{ | ||
public: | ||
// Delete copy constructor and assignment operator. | ||
AirQualitySensorManager(const AirQualitySensorManager &) = delete; | ||
AirQualitySensorManager(const AirQualitySensorManager &&) = delete; | ||
AirQualitySensorManager & operator=(const AirQualitySensorManager &) = delete; | ||
|
||
static void InitInstance(EndpointId aEndpointId = 1) | ||
{ | ||
if (mInstance == nullptr) | ||
{ | ||
mInstance = new AirQualitySensorManager(aEndpointId); | ||
mInstance->Init(); | ||
} | ||
}; | ||
|
||
/** | ||
* @brief Get an Air Quality Manager object - this class acts as a singleton device manager for the air quality device | ||
* @param[in] aEndpointId Endpoint that the air quality is on | ||
* @return mInstance The AirQualitySensorManager instance, note this this could be nullptr if InitInstance has not been | ||
* called | ||
*/ | ||
static AirQualitySensorManager * GetInstance() { return mInstance; }; | ||
|
||
/** | ||
* @brief Handles changes in Carbon Dioxide concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void Init(); | ||
|
||
/** | ||
* @brief Handles changes in Air Quality measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnAirQualityChangeHandler(AirQuality::AirQualityEnum newValue); | ||
|
||
/** | ||
* @brief Handles changes in Carbon Dioxide concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnCarbonDioxideMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Carbon Monoxide concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnCarbonMonoxideMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Nitrogen Dioxide concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnNitrogenDioxideMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in PM1 concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnPm1MeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in PM10 concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnPm10MeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in PM2.5 concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnPm25MeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Radon concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnRadonMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Total Volatile Organic Compounds concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnTotalVolatileOrganicCompoundsMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Ozone concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnOzoneMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Formaldehyde concentration measurement. | ||
* @param[in] newValue The new air value to be applied. | ||
*/ | ||
void OnFormaldehydeMeasurementChangeHandler(float newValue); | ||
|
||
/** | ||
* @brief Handles changes in Temperature measurement. | ||
* @param[in] newValue The new value to be applied. | ||
*/ | ||
void OnTemperatureMeasurementChangeHandler(int16_t newValue); | ||
|
||
/** | ||
* @brief Handles changes in Humidity measurement. | ||
* @param[in] newValue The new value to be applied. | ||
*/ | ||
void OnHumidityMeasurementChangeHandler(uint16_t newValue); | ||
|
||
private: | ||
inline static AirQualitySensorManager * mInstance; | ||
EndpointId mEndpointId; | ||
AirQuality::Instance mAirQualityInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mCarbonDioxideConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mCarbonMonoxideConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mNitrogenDioxideConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mPm1ConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mPm10ConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mPm25ConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mRadonConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> | ||
mTotalVolatileOrganicCompoundsConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mOzoneConcentrationMeasurementInstance; | ||
ConcentrationMeasurement::Instance<true, true, true, true, true, true> mFormaldehydeConcentrationMeasurementInstance; | ||
TemperatureSensorManager mTemperatureSensorManager; | ||
RelativeHumiditySensorManager mHumiditySensorManager; | ||
|
||
/** | ||
* @brief Construct a new Air Quality Manager object - this class acts as a singleton device manager for the air quality device | ||
* @param[in] endpointId Endpoint that the air quality device is on | ||
*/ | ||
AirQualitySensorManager(EndpointId aEndpointId) : | ||
mEndpointId(aEndpointId), | ||
mAirQualityInstance(mEndpointId, | ||
BitMask<AirQuality::Feature, uint32_t>(AirQuality::Feature::kModerate, AirQuality::Feature::kFair, | ||
AirQuality::Feature::kVeryPoor, | ||
AirQuality::Feature::kExtremelyPoor)), | ||
mCarbonDioxideConcentrationMeasurementInstance(mEndpointId, CarbonDioxideConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mCarbonMonoxideConcentrationMeasurementInstance(mEndpointId, CarbonMonoxideConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mNitrogenDioxideConcentrationMeasurementInstance(mEndpointId, NitrogenDioxideConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mPm1ConcentrationMeasurementInstance(mEndpointId, Pm1ConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mPm10ConcentrationMeasurementInstance(mEndpointId, Pm10ConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mPm25ConcentrationMeasurementInstance(mEndpointId, Pm25ConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mRadonConcentrationMeasurementInstance(mEndpointId, RadonConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mTotalVolatileOrganicCompoundsConcentrationMeasurementInstance( | ||
mEndpointId, TotalVolatileOrganicCompoundsConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mOzoneConcentrationMeasurementInstance(mEndpointId, OzoneConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mFormaldehydeConcentrationMeasurementInstance(mEndpointId, FormaldehydeConcentrationMeasurement::Id, | ||
ConcentrationMeasurement::MeasurementMediumEnum::kAir, | ||
ConcentrationMeasurement::MeasurementUnitEnum::kPpm), | ||
mTemperatureSensorManager(mEndpointId), mHumiditySensorManager(mEndpointId){}; | ||
}; | ||
|
||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
37 changes: 37 additions & 0 deletions
37
...r-quality-sensor-app/air-quality-sensor-common/include/relative-humidity-sensor-manager.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,37 @@ | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
|
||
#pragma once | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
class RelativeHumiditySensorManager | ||
{ | ||
public: | ||
RelativeHumiditySensorManager(EndpointId aEndpointId) : mEndpointId(aEndpointId) | ||
{ | ||
EmberAfStatus status = RelativeHumidityMeasurement::Attributes::MinMeasuredValue::Set(mEndpointId, 0); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set RelativeHumidityMeasurement MinMeasuredValue attribute")); | ||
|
||
status = RelativeHumidityMeasurement::Attributes::MaxMeasuredValue::Set(mEndpointId, 100); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set RelativeHumidityMeasurement MaxMeasuredValue attribute")); | ||
}; | ||
|
||
void OnHumidityChangeHandler(uint16_t newValue) | ||
{ | ||
EmberAfStatus status = RelativeHumidityMeasurement::Attributes::MeasuredValue::Set(mEndpointId, newValue); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set RelativeHumidityMeasurement MeasuredValue attribute")); | ||
ChipLogDetail(NotSpecified, "The new RelativeHumidityMeasurement value: %d", newValue); | ||
} | ||
|
||
private: | ||
EndpointId mEndpointId; | ||
}; | ||
|
||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
37 changes: 37 additions & 0 deletions
37
...les/air-quality-sensor-app/air-quality-sensor-common/include/temperature-sensor-manager.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,37 @@ | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
|
||
#pragma once | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
class TemperatureSensorManager | ||
{ | ||
public: | ||
TemperatureSensorManager(EndpointId aEndpointId) : mEndpointId(aEndpointId) | ||
{ | ||
EmberAfStatus status = TemperatureMeasurement::Attributes::MinMeasuredValue::Set(mEndpointId, -5); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set TemperatureMeasurement MinMeasuredValue attribute")); | ||
|
||
status = TemperatureMeasurement::Attributes::MaxMeasuredValue::Set(mEndpointId, 60); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set TemperatureMeasurement MaxMeasuredValue attribute")); | ||
}; | ||
|
||
void OnTemperatureChangeHandler(int16_t newValue) | ||
{ | ||
EmberAfStatus status = TemperatureMeasurement::Attributes::MeasuredValue::Set(mEndpointId, newValue); | ||
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, | ||
ChipLogError(NotSpecified, "Failed to set TemperatureMeasurement MeasuredValue attribute")); | ||
ChipLogDetail(NotSpecified, "The new TemperatureMeasurement value: %d", newValue); | ||
} | ||
|
||
private: | ||
EndpointId mEndpointId; | ||
}; | ||
|
||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
Oops, something went wrong.