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

[portinglayer] laundrywasher implementation #153

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions component/common/application/matter/core/matter_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ struct AppEvent
kEventType_Uplink = 0,
kEventType_Downlink_OnOff,
kEventType_Downlink_Identify,
kEventType_Downlink_Opstate_State,
kEventType_Downlink_Opstate_Error_State,
kEventType_Downlink_LW_SpinSpeed,
kEventType_Downlink_LW_NumberOfRinses,
kEventType_Downlink_LW_Mode,
};

uint16_t Type;
Expand Down
168 changes: 168 additions & 0 deletions component/common/application/matter/driver/opstate_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
*
* 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 <opstate_driver.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OperationalState;
using namespace chip::app::Clusters::RvcOperationalState;

CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_t index, GenericOperationalState &operationalState)
{
if (index >= mOperationalStateList.size())
{
return CHIP_ERROR_NOT_FOUND;
}
operationalState = mOperationalStateList[index];
return CHIP_NO_ERROR;
}

CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase &operationalPhase)
{
if (index >= mOperationalPhaseList.size())
{
return CHIP_ERROR_NOT_FOUND;
}
operationalPhase = mOperationalPhaseList[index];
return CHIP_NO_ERROR;
}

void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError &err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError &err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError &err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError &err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kStopped));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

// Init Operational State cluster

static OperationalState::Instance *gOperationalStateInstance = nullptr;
static OperationalStateDelegate *gOperationalStateDelegate = nullptr;

void OperationalState::Shutdown()
{
if (gOperationalStateInstance != nullptr)
{
delete gOperationalStateInstance;
gOperationalStateInstance = nullptr;
}
if (gOperationalStateDelegate != nullptr)
{
delete gOperationalStateDelegate;
gOperationalStateDelegate = nullptr;
}
}

OperationalState::Instance *OperationalState::GetOperationalStateInstance()
{
return gOperationalStateInstance;
}

void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gOperationalStateInstance == nullptr && gOperationalStateDelegate == nullptr);

gOperationalStateDelegate = new OperationalStateDelegate;
EndpointId operationalStateEndpoint = 0x01;
gOperationalStateInstance = new Instance(gOperationalStateDelegate, operationalStateEndpoint, Clusters::OperationalState::Id);

gOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gOperationalStateInstance->Init();
}

// Init RVC Operational State cluster

static OperationalState::Instance *gRvcOperationalStateInstance = nullptr;
static RvcOperationalStateDelegate *gRvcOperationalStateDelegate = nullptr;

void RvcOperationalState::Shutdown()
{
if (gRvcOperationalStateInstance != nullptr)
{
delete gRvcOperationalStateInstance;
gRvcOperationalStateInstance = nullptr;
}
if (gRvcOperationalStateDelegate != nullptr)
{
delete gRvcOperationalStateDelegate;
gRvcOperationalStateDelegate = nullptr;
}
}

void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr);

gRvcOperationalStateDelegate = new RvcOperationalStateDelegate;
EndpointId operationalStateEndpoint = 0x01;
gRvcOperationalStateInstance =
new Instance(gRvcOperationalStateDelegate, operationalStateEndpoint, Clusters::RvcOperationalState::Id);

gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gRvcOperationalStateInstance->Init();
}
161 changes: 161 additions & 0 deletions component/common/application/matter/driver/opstate_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
*
* 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-common/zap-generated/cluster-objects.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>

void getOperationalStateSet(u8 state);

namespace chip {
namespace app {
namespace Clusters {

namespace OperationalState {

Instance *GetOperationalStateInstance();

// This is an application level delegate to handle operational state commands according to the specific business logic.
class GenericOperationalStateDelegateImpl : public Delegate
{
public:
/**
* Get the countdown time. This attribute is not used in this application.
* @return The current countdown time.
*/
app::DataModel::Nullable<uint32_t> GetCountdownTime() override { return {}; };

/**
* Fills in the provided GenericOperationalState with the state at index `index` if there is one,
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of states.
* Note: This is used by the SDK to populate the operational state list attribute. If the contents of this list changes,
* the device SHALL call the Instance's ReportOperationalStateListChange method to report that this attribute has changed.
* @param index The index of the state, with 0 representing the first state.
* @param operationalState The GenericOperationalState is filled.
*/
CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState &operationalState) override;

/**
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
* @param index The index of the phase, with 0 representing the first phase.
* @param operationalPhase The GenericOperationalPhase is filled.
*/
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase &operationalPhase) override;

// command callback
/**
* Handle Command Callback in application: Pause
* @param[out] get operational error after callback.
*/
void HandlePauseStateCallback(GenericOperationalError &err) override;

/**
* Handle Command Callback in application: Resume
* @param[out] get operational error after callback.
*/
void HandleResumeStateCallback(GenericOperationalError &err) override;

/**
* Handle Command Callback in application: Start
* @param[out] get operational error after callback.
*/
void HandleStartStateCallback(GenericOperationalError &err) override;

/**
* Handle Command Callback in application: Stop
* @param[out] get operational error after callback.
*/
void HandleStopStateCallback(GenericOperationalError &err) override;

protected:
Span<const GenericOperationalState> mOperationalStateList;
Span<const GenericOperationalPhase> mOperationalPhaseList;
};

// This is an application level delegate to handle operational state commands according to the specific business logic.
class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
{
private:
const GenericOperationalState opStateList[4] = {
GenericOperationalState(to_underlying(OperationalStateEnum::kStopped)),
GenericOperationalState(to_underlying(OperationalStateEnum::kRunning)),
GenericOperationalState(to_underlying(OperationalStateEnum::kPaused)),
GenericOperationalState(to_underlying(OperationalStateEnum::kError)),
};

const GenericOperationalPhase opPhaseList[1] = {
// Phase List is null
GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
};

public:
OperationalStateDelegate()
{
GenericOperationalStateDelegateImpl::mOperationalStateList = Span<const GenericOperationalState>(opStateList);
GenericOperationalStateDelegateImpl::mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);
}
};

void Shutdown();

} // namespace OperationalState

namespace RvcOperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
class RvcOperationalStateDelegate : public OperationalState::GenericOperationalStateDelegateImpl
{
private:
const OperationalState::GenericOperationalState rvcOpStateList[7] = {
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
OperationalState::GenericOperationalState(
to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kSeekingCharger)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
};

const OperationalState::GenericOperationalPhase rvcOpPhaseList[1] = {
// Phase List is null
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
};

public:
RvcOperationalStateDelegate()
{
GenericOperationalStateDelegateImpl::mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
GenericOperationalStateDelegateImpl::mOperationalPhaseList =
Span<const OperationalState::GenericOperationalPhase>(rvcOpPhaseList);
}
};

void Shutdown();

} // namespace RvcOperationalState
} // namespace Clusters
} // namespace app
} // namespace chip
18 changes: 18 additions & 0 deletions component/common/application/matter/driver/washer_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <washer_driver.h>
#include <support/logging/CHIPLogging.h>

void MatterWasher::Init(PinName pin)
{
mPwm_obj = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t));
pwmout_init(mPwm_obj, pin);
}

void MatterWasher::deInit(void)
{
vPortFree(mPwm_obj);
}

void MatterWasher::Do(void)
{

}
15 changes: 15 additions & 0 deletions component/common/application/matter/driver/washer_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <platform_stdlib.h>
#include "pwmout_api.h"

class MatterWasher
{
public:
void Init(PinName pin);
void deInit(void);
void Do(void);

private:
pwmout_t *mPwm_obj = NULL;
};
Loading