Skip to content

Commit 993bfda

Browse files
restruncturing
1 parent df0099d commit 993bfda

18 files changed

+314
-662
lines changed

examples/rangehood-app/rangehood-app-common/include/ExtractorHoodEndpoint.h

Lines changed: 28 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -28,75 +28,28 @@
2828
#include <lib/core/CHIPError.h>
2929
#include <lib/core/DataModelTypes.h>
3030

31-
using namespace chip;
32-
using namespace chip::app;
33-
using namespace chip::app::Clusters::FanControl;
34-
using Protocols::InteractionModel::Status;
35-
36-
namespace chip {
37-
namespace app {
38-
namespace Clusters {
39-
namespace ExtractorHood {
40-
41-
class FanDelegate : public FanControl::Delegate
42-
{
43-
public:
44-
/**
45-
* @brief
46-
* This method handles the step command. This will happen as fast as possible.
47-
* The step command logic is implemented directly here for better encapsulation.
48-
* Since this is called from the CHIP stack thread, we can update attributes directly.
49-
*
50-
* @param[in] aDirection the direction in which the speed should step
51-
* @param[in] aWrap whether the speed should wrap or not
52-
* @param[in] aLowestOff whether the device should consider the lowest setting as off
53-
*
54-
* @return Success On success.
55-
* @return Other Value indicating it failed to execute the command.
56-
*/
57-
Status HandleStep(StepDirectionEnum aDirection, bool aWrap, bool aLowestOff) override;
58-
59-
FanDelegate(EndpointId aEndpoint)
60-
: FanControl::Delegate(aEndpoint), mEndpoint(aEndpoint) {}
61-
62-
protected:
63-
EndpointId mEndpoint = kInvalidEndpointId;
64-
};
65-
6631
class ExtractorHoodEndpoint
6732
{
6833
public:
69-
ExtractorHoodEndpoint(EndpointId endpointId) : mEndpointId(endpointId), mFanDelegate(mEndpointId) {}
34+
ExtractorHoodEndpoint(chip::EndpointId endpointId) : mEndpointId(endpointId) {}
7035

7136
/**
7237
* @brief Initialize the ExtractorHood endpoint.
38+
* @param offPercent Percent value for Off mode (typically 0)
39+
* @param lowPercent Percent value for Low mode (typically 30)
40+
* @param mediumPercent Percent value for Medium mode (typically 60)
41+
* @param highPercent Percent value for High/On mode (typically 100)
7342
*/
74-
CHIP_ERROR Init();
43+
CHIP_ERROR Init(chip::Percent offPercent, chip::Percent lowPercent,
44+
chip::Percent mediumPercent, chip::Percent highPercent);
7545

76-
// Accessor for registering the fan control delegate
77-
FanDelegate * GetFanDelegate() { return &mFanDelegate; }
78-
79-
80-
/**
81-
* @brief Get the endpoint ID
82-
*/
83-
EndpointId GetEndpointId() const { return mEndpointId; }
46+
chip::EndpointId GetEndpointId() const { return mEndpointId; }
8447

85-
/**
86-
* @brief Get current percent setting from the attribute
87-
*/
88-
DataModel::Nullable<Percent> GetPercentSetting() const;
48+
chip::app::DataModel::Nullable<chip::Percent> GetPercentSetting() const;
8949

90-
/**
91-
* @brief Get current fan mode from the attribute
92-
*/
93-
Status GetFanMode(FanModeEnum & fanMode) const;
50+
chip::Protocols::InteractionModel::Status GetFanMode(chip::app::Clusters::FanControl::FanModeEnum & fanMode) const;
9451

95-
/**
96-
* @brief Set percent current (actual fan speed)
97-
* This updates the PercentCurrent attribute which represents the actual fan speed
98-
*/
99-
Status SetPercentCurrent(Percent aNewPercentSetting);
52+
chip::Protocols::InteractionModel::Status SetPercentCurrent(chip::Percent aNewPercentSetting);
10053

10154
/**
10255
* @brief Handle percent setting change and update percent current accordingly
@@ -106,7 +59,7 @@ class ExtractorHoodEndpoint
10659
* @param aNewPercentSetting The new percent setting value
10760
* @return Status Success on success, error code otherwise
10861
*/
109-
Status HandlePercentSettingChange(Percent aNewPercentSetting);
62+
chip::Protocols::InteractionModel::Status HandlePercentSettingChange(chip::Percent aNewPercentSetting);
11063

11164
/**
11265
* @brief Handle fan mode change and update percent current accordingly
@@ -115,30 +68,26 @@ class ExtractorHoodEndpoint
11568
* @param aNewFanMode The new fan mode to apply
11669
* @return Status Success on success, error code otherwise
11770
*/
118-
Status HandleFanModeChange(FanModeEnum aNewFanMode);
71+
chip::Protocols::InteractionModel::Status HandleFanModeChange(chip::app::Clusters::FanControl::FanModeEnum aNewFanMode);
11972

12073
/**
12174
* @brief Update the FanMode attribute
122-
* This is used for modes like Auto/Smart that don't have fixed percent values
12375
*/
124-
Status UpdateFanModeAttribute(FanModeEnum aFanMode);
76+
chip::Protocols::InteractionModel::Status UpdateFanModeAttribute(chip::app::Clusters::FanControl::FanModeEnum aFanMode);
12577

126-
// Step command configuration constants
127-
static constexpr uint8_t kStepSizePercent = 10; // Step by 10% increments
128-
static constexpr uint8_t kaLowestOffTrue = 0; // Can step down to 0% (off)
129-
static constexpr uint8_t kaLowestOffFalse = 1; // Can only step down to 1% (minimum on)
130-
131-
// Fan Mode Percent Mappings (since SPEED features are not enabled)
132-
static constexpr uint8_t kFanModeOffPercent = 0; // Off: 0%
133-
static constexpr uint8_t kFanModeLowPercent = 30; // Low: 30%
134-
static constexpr uint8_t kFanModeMediumPercent = 60; // Medium: 60%
135-
static constexpr uint8_t kFanModeHighPercent = 100; // High: 100%
78+
/**
79+
* @brief Toggle fan mode between Off and High
80+
* This is typically used for button press toggles
81+
* @return Status Success on success, error code otherwise
82+
*/
83+
chip::Protocols::InteractionModel::Status ToggleFanMode();
13684

13785
private:
138-
EndpointId mEndpointId = kInvalidEndpointId;
139-
FanDelegate mFanDelegate;
140-
141-
} // namespace ExtractorHood
142-
} // namespace Clusters
143-
} // namespace app
144-
} // namespace chip
86+
chip::EndpointId mEndpointId = chip::kInvalidEndpointId;
87+
88+
// Fan Mode Percent Mappings (set during initialization)
89+
chip::Percent mFanModeOffPercent = 0; // Off: 0%
90+
chip::Percent mFanModeLowPercent = 30; // Low: 30%
91+
chip::Percent mFanModeMediumPercent = 60; // Medium: 60%
92+
chip::Percent mFanModeHighPercent = 100; // High: 100%
93+
};

examples/rangehood-app/rangehood-app-common/include/LightEndpoint.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020

2121
#include <app/clusters/on-off-server/on-off-server.h>
2222
#include <lib/core/CHIPError.h>
23-
24-
namespace chip {
25-
namespace app {
26-
namespace Clusters {
27-
namespace Light {
23+
#include <lib/core/DataModelTypes.h>
2824

2925
class LightEndpoint
3026
{
3127
public:
32-
LightEndpoint(EndpointId endpointId) : mEndpointId(endpointId) {}
28+
LightEndpoint(chip::EndpointId endpointId) : mEndpointId(endpointId) {}
3329

3430
/**
3531
* @brief Initialize the Light endpoint.
@@ -79,12 +75,7 @@ class LightEndpoint
7975
uint32_t GetAutoTurnOffDuration() const { return mAutoTurnOffDuration; }
8076

8177
private:
82-
EndpointId mEndpointId = kInvalidEndpointId;
78+
chip::EndpointId mEndpointId = chip::kInvalidEndpointId;
8379
bool mAutoTurnOff = false;
8480
uint32_t mAutoTurnOffDuration = 0;
85-
};
86-
87-
} // namespace Light
88-
} // namespace Clusters
89-
} // namespace app
90-
} // namespace chip
81+
};

0 commit comments

Comments
 (0)