Skip to content

Commit

Permalink
updated App code after reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
liangpy4 committed Nov 22, 2023
1 parent 20f9d35 commit 91ec757
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>
#include <functional>


namespace chip {
namespace app {
namespace Clusters {

class MicrowaveOvenDevice;

typedef Protocols::InteractionModel::Status (MicrowaveOvenDevice::*HandleSetCookingParametersCommand)(uint8_t cookMode,
uint32_t cookTime,
uint8_t powerSetting);
typedef Protocols::InteractionModel::Status (MicrowaveOvenDevice::*HandleAddMoreTimeCommand)(uint32_t addedCookTime);

namespace MicrowaveOvenControl {

// This is an application level delegate to handle microwave oven control commands according to the specific
Expand All @@ -42,10 +36,8 @@ class ExampleMicrowaveOvenControlDelegate : public MicrowaveOvenControl::Delegat
{

private:
MicrowaveOvenDevice * mSetCookingParametersInstance;
HandleSetCookingParametersCommand mSetCookingParametersCommandCallback;
MicrowaveOvenDevice * mAddMoreTimeInstance;
HandleAddMoreTimeCommand mAddMoreTimeCommandCallback;
std::function<Protocols::InteractionModel::Status(uint8_t,uint32_t,uint8_t)> mHandleSetCookingParametersCallback;
std::function<Protocols::InteractionModel::Status(uint32_t)> mHandleAddMoreTimeCallback;

public:
/**
Expand Down Expand Up @@ -77,13 +69,12 @@ class ExampleMicrowaveOvenControlDelegate : public MicrowaveOvenControl::Delegat
/**
* Set callback function for set cooking parameters
*/
void SetMicrowaveOvenControlSetCookingParametersCallback(HandleSetCookingParametersCommand aCallback,
MicrowaveOvenDevice * aInstance);
void SetMicrowaveOvenControlSetCookingParametersCallback(std::function<Protocols::InteractionModel::Status(uint8_t,uint32_t,uint8_t)> aCallback);

/**
* Set callback function for add more time
*/
void SetMicrowaveOvenControlAddMoreTimeCallback(HandleAddMoreTimeCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetMicrowaveOvenControlAddMoreTimeCallback(std::function<Protocols::InteractionModel::Status(uint32_t)> aCallback);
};

} // namespace MicrowaveOvenControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ class MicrowaveOvenDevice
mMicrowaveOvenControlInstance(&mMicrowaveOvenControlDelegate, aClustersEndpoint, MicrowaveOvenControl::Id),
mOperationalStateDelegate(), mOperationalStateInstance(&mOperationalStateDelegate, aClustersEndpoint, OperationalState::Id)
{
// set callback functions
// set callback functions
mMicrowaveOvenControlDelegate.SetMicrowaveOvenControlSetCookingParametersCallback(
&MicrowaveOvenDevice::HandleMicrowaveOvenSetCookingParametersCallback, this);
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenSetCookingParametersCallback, this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3));
mMicrowaveOvenControlDelegate.SetMicrowaveOvenControlAddMoreTimeCallback(
&MicrowaveOvenDevice::HandleMicrowaveOvenAddMoreTimeCallback, this);
mOperationalStateDelegate.SetOpStatePauseCallback(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStatePauseCallback, this);
mOperationalStateDelegate.SetOpStateResumeCallback(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateResumeCallback, this);
mOperationalStateDelegate.SetOpStateStartCallback(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateStartCallback, this);
mOperationalStateDelegate.SetOpStateStopCallback(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateStopCallback, this);
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenAddMoreTimeCallback, this, std::placeholders::_1));
mOperationalStateDelegate.SetOpStatePauseCallback(
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStatePauseCallback, this, std::placeholders::_1));
mOperationalStateDelegate.SetOpStateResumeCallback(
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateResumeCallback, this, std::placeholders::_1));
mOperationalStateDelegate.SetOpStateStartCallback(
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateStartCallback, this, std::placeholders::_1));
mOperationalStateDelegate.SetOpStateStopCallback(
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateStopCallback, this, std::placeholders::_1));
mOperationalStateDelegate.SetOpStateGetCountdownTimeCallback(
&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateGetCountdownTime, this);
std::bind(&MicrowaveOvenDevice::HandleMicrowaveOvenOpStateGetCountdownTime, this));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>
#include <functional>

namespace chip {
namespace app {
namespace Clusters {

class MicrowaveOvenDevice;

typedef void (MicrowaveOvenDevice::*HandleOpStateCommand)(Clusters::OperationalState::GenericOperationalError & err);
typedef app::DataModel::Nullable<uint32_t> (MicrowaveOvenDevice::*HandleGetCountdownTimeCommand)(void);

namespace OperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
Expand All @@ -54,17 +49,13 @@ class OperationalStateDelegate : public OperationalState::Delegate

Span<const GenericOperationalPhase> mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);

MicrowaveOvenDevice * mPauseMicrowaveOvenInstance;
HandleOpStateCommand mPauseCallback;
MicrowaveOvenDevice * mResumeMicrowaveOvenInstance;
HandleOpStateCommand mResumeCallback;
MicrowaveOvenDevice * mStartMicrowaveOvenInstance;
HandleOpStateCommand mStartCallback;
MicrowaveOvenDevice * mStopMicrowaveOvenInstance;
HandleOpStateCommand mStopCallback;
MicrowaveOvenDevice * mGetCountdownTimeMicrowaveOvenInstance;
HandleGetCountdownTimeCommand mGetCountdownTimeCallback;
std::function<void(Clusters::OperationalState::GenericOperationalError & err)> mPauseCallback;
std::function<void(Clusters::OperationalState::GenericOperationalError & err)> mResumeCallback;
std::function<void(Clusters::OperationalState::GenericOperationalError & err)> mStartCallback;
std::function<void(Clusters::OperationalState::GenericOperationalError & err)> mStopCallback;
std::function<app::DataModel::Nullable<uint32_t>(void)> mGetCountdownTimeCallback;


public:
/**
* Get the countdown time.
Expand Down Expand Up @@ -120,27 +111,27 @@ class OperationalStateDelegate : public OperationalState::Delegate
/**
* Set callback function for pause
*/
void SetOpStatePauseCallback(HandleOpStateCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetOpStatePauseCallback(std::function<void(Clusters::OperationalState::GenericOperationalError & err)> aCallback);

/**
* Set callback function for resume
*/
void SetOpStateResumeCallback(HandleOpStateCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetOpStateResumeCallback(std::function<void(Clusters::OperationalState::GenericOperationalError & err)> aCallback);

/**
* Set callback function for start
*/
void SetOpStateStartCallback(HandleOpStateCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetOpStateStartCallback(std::function<void(Clusters::OperationalState::GenericOperationalError & err)> aCallback);

/**
* Set callback function for stop
*/
void SetOpStateStopCallback(HandleOpStateCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetOpStateStopCallback(std::function<void(Clusters::OperationalState::GenericOperationalError & err)> aCallback);

/**
* Set callback function for get count down time
*/
void SetOpStateGetCountdownTimeCallback(HandleGetCountdownTimeCommand aCallback, MicrowaveOvenDevice * aInstance);
void SetOpStateGetCountdownTimeCallback(std::function<app::DataModel::Nullable<uint32_t>(void)> aCallback);
};

} // namespace OperationalState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,38 @@ server cluster GroupKeyManagement = 63 {
fabric command access(invoke: administer) KeySetReadAllIndices(): KeySetReadAllIndicesResponse = 4;
}

/** Attributes and commands for selecting a mode from a list of supported options. */
provisional server cluster MicrowaveOvenMode = 94 {
enum ModeTag : enum16 {
kNormal = 16384;
kDefrost = 16385;
}

bitmap Feature : bitmap32 {
kOnOff = 0x1;
}

struct ModeTagStruct {
optional vendor_id mfgCode = 0;
enum16 value = 1;
}

struct ModeOptionStruct {
char_string<64> label = 0;
int8u mode = 1;
ModeTagStruct modeTags[] = 2;
}

readonly attribute ModeOptionStruct supportedModes[] = 0;
readonly attribute int8u currentMode = 1;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;
}

/** Attributes and commands for configuring the microwave oven control, and reporting cooking stats. */
provisional server cluster MicrowaveOvenControl = 95 {
readonly attribute elapsed_s cookTime = 1;
Expand Down Expand Up @@ -1331,6 +1363,17 @@ endpoint 1 {
callback attribute clusterRevision default = 1;
}

server cluster MicrowaveOvenMode {
callback attribute supportedModes;
callback attribute currentMode;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
callback attribute featureMap default = 0;
ram attribute clusterRevision default = 1;
}

server cluster MicrowaveOvenControl {
callback attribute cookTime default = 30;
callback attribute powerSetting default = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3335,6 +3335,145 @@
}
]
},
{
"name": "Microwave Oven Mode",
"code": 94,
"mfgCode": null,
"define": "MICROWAVE_OVEN_MODE_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"attributes": [
{
"name": "SupportedModes",
"code": 0,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "CurrentMode",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
]
},
{
"name": "Microwave Oven Control",
"code": 95,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ using namespace chip::app::Clusters::MicrowaveOvenControl;
Protocols::InteractionModel::Status
ExampleMicrowaveOvenControlDelegate::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, uint8_t powerSetting)
{
return (mSetCookingParametersInstance->*mSetCookingParametersCommandCallback)(cookMode, cookTime, powerSetting);
return mHandleSetCookingParametersCallback(cookMode, cookTime, powerSetting);
}

Protocols::InteractionModel::Status ExampleMicrowaveOvenControlDelegate::HandleAddMoreTimeCallback(uint32_t finalCookTime)
{
return (mAddMoreTimeInstance->*mAddMoreTimeCommandCallback)(finalCookTime);
return mHandleAddMoreTimeCallback(finalCookTime);
}


void ExampleMicrowaveOvenControlDelegate::SetMicrowaveOvenControlSetCookingParametersCallback(
HandleSetCookingParametersCommand aCallback, MicrowaveOvenDevice * aInstance)
std::function<Protocols::InteractionModel::Status(uint8_t,uint32_t,uint8_t)> aCallback)
{
mSetCookingParametersCommandCallback = aCallback;
mSetCookingParametersInstance = aInstance;
mHandleSetCookingParametersCallback = aCallback;
}

void ExampleMicrowaveOvenControlDelegate::SetMicrowaveOvenControlAddMoreTimeCallback(HandleAddMoreTimeCommand aCallback,
MicrowaveOvenDevice * aInstance)
void ExampleMicrowaveOvenControlDelegate::SetMicrowaveOvenControlAddMoreTimeCallback(std::function<Protocols::InteractionModel::Status(uint32_t)> aCallback)
{
mAddMoreTimeCommandCallback = aCallback;
mAddMoreTimeInstance = aInstance;
mHandleAddMoreTimeCallback = aCallback;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Protocols::InteractionModel::Status
MicrowaveOvenDevice::HandleMicrowaveOvenSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, uint8_t powerSetting)
{
// placeholder implementation
// TODO: set Microwave Oven cooking mode by cookMode.Value().
// TODO(#30609): set Microwave Oven cooking mode by cookMode.Value().
mMicrowaveOvenControlInstance.SetCookTime(cookTime);
mMicrowaveOvenControlInstance.SetPowerSetting(powerSetting);
return Status::Success;
Expand Down
Loading

0 comments on commit 91ec757

Please sign in to comment.