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

[SL-UP] Restyling the light switch app #274

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
2 changes: 2 additions & 0 deletions examples/light-switch-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#pragma once

#include <cstdint>

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand Down
1 change: 0 additions & 1 deletion examples/light-switch-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ class AppTask : public BaseApplication
* @return CHIP_ERROR
*/
CHIP_ERROR Init();

};
8 changes: 3 additions & 5 deletions examples/light-switch-app/silabs/include/BindingHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "app-common/zap-generated/ids/Clusters.h"
#include "app-common/zap-generated/ids/Commands.h"
#include "lib/core/CHIPError.h"
#include <platform/CHIPDeviceLayer.h>
#include <app/clusters/bindings/bindings.h>
#include <platform/CHIPDeviceLayer.h>
#include <variant>

using namespace chip;
Expand All @@ -31,15 +31,13 @@ CHIP_ERROR InitBindingHandler();
void SwitchWorkerFunction(intptr_t context);
void BindingWorkerFunction(intptr_t context);


struct CommandBase
{
chip::BitMask<OptionsBitmap> optionsMask;
chip::BitMask<OptionsBitmap> optionsOverride;

// Constructor to initialize the BitMask
CommandBase()
: optionsMask(0), optionsOverride(0) {}
CommandBase() : optionsMask(0), optionsOverride(0) {}
};

struct BindingCommandData
Expand Down Expand Up @@ -71,4 +69,4 @@ struct BindingCommandData
};
// Use std::variant to hold different command types
std::variant<MoveToLevel, Move, Step, Stop> commandData;
};
};
29 changes: 13 additions & 16 deletions examples/light-switch-app/silabs/include/LightSwitchMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

#pragma once

#include "AppEvent.h"
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/clusters/bindings/bindings.h>
#include <app/util/basic-types.h>
#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CodeUtils.h>
#include <app/clusters/bindings/bindings.h>
#include <platform/CHIPDeviceLayer.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include "AppEvent.h"
#include <cmsis_os2.h>
#include <string>

using namespace chip;
Expand All @@ -49,10 +49,7 @@ class LightSwitchMgr
};

static constexpr Clusters::LevelControl::Commands::Step::Type stepCommand = {
.stepSize = 1,
.transitionTime = 0,
.optionsMask = 0,
.optionsOverride = 0
.stepSize = 1, .transitionTime = 0, .optionsMask = 0, .optionsOverride = 0
};

struct Timer
Expand Down Expand Up @@ -106,19 +103,19 @@ class LightSwitchMgr
static LightSwitchMgr sSwitch;

Timer * mLongPressTimer = nullptr;
bool mFunctionButtonPressed = false; // True when button0 is pressed, used to trigger factory reset
bool mActionButtonPressed = false; // True when button1 is pressed, used to initiate toggle or level-up/down
bool mActionButtonSuppressed = false; // True when both button0 and button1 are pressed, used to switch step direction
bool mFunctionButtonPressed = false; // True when button0 is pressed, used to trigger factory reset
bool mActionButtonPressed = false; // True when button1 is pressed, used to initiate toggle or level-up/down
bool mActionButtonSuppressed = false; // True when both button0 and button1 are pressed, used to switch step direction
bool mResetWarning = false;

// Default Step direction for Level control
StepModeEnum stepDirection = StepModeEnum::kUp;
StepModeEnum stepDirection = StepModeEnum::kUp;

static void OnLongPressTimeout(Timer & timer);
LightSwitchMgr() = default;

/**
* @brief This function will be called when PB0 is
/**
* @brief This function will be called when PB0 is
* long-pressed to trigger the factory-reset
*/
void HandleLongPress();
Expand All @@ -127,8 +124,8 @@ class LightSwitchMgr

chip::EndpointId mLightSwitchEndpoint = chip::kInvalidEndpointId;
chip::EndpointId mGenericSwitchEndpoint = chip::kInvalidEndpointId;
/**

/**
* @brief Button event processing function
* Function triggers a switch action sent to the CHIP task
*
Expand Down
80 changes: 32 additions & 48 deletions examples/light-switch-app/silabs/src/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,35 @@ void ProcessLevelControlUnicastBindingCommand(BindingCommandData * data, const E

switch (data->commandId)
{
case Clusters::LevelControl::Commands::MoveToLevel::Id:
{
case Clusters::LevelControl::Commands::MoveToLevel::Id: {
Clusters::LevelControl::Commands::MoveToLevel::Type moveToLevelCommand;
if (auto moveToLevel = std::get_if<BindingCommandData::MoveToLevel>(&data->commandData))
{
moveToLevelCommand.level = moveToLevel->level;
moveToLevelCommand.transitionTime = moveToLevel->transitionTime;
moveToLevelCommand.optionsMask = moveToLevel->optionsMask;
moveToLevelCommand.optionsOverride = moveToLevel->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
moveToLevelCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, moveToLevelCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::Move::Id:
{
case Clusters::LevelControl::Commands::Move::Id: {
Clusters::LevelControl::Commands::Move::Type moveCommand;
if (auto move = std::get_if<BindingCommandData::Move>(&data->commandData))
{
moveCommand.moveMode = move->moveMode;
moveCommand.rate = move->rate;
moveCommand.optionsMask = move->optionsMask;
moveCommand.optionsOverride = move->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
moveCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, moveCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::Step::Id:
{
case Clusters::LevelControl::Commands::Step::Id: {
Clusters::LevelControl::Commands::Step::Type stepCommand;
if (auto step = std::get_if<BindingCommandData::Step>(&data->commandData))
{
Expand All @@ -141,57 +138,53 @@ void ProcessLevelControlUnicastBindingCommand(BindingCommandData * data, const E
stepCommand.transitionTime = step->transitionTime;
stepCommand.optionsMask = step->optionsMask;
stepCommand.optionsOverride = step->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
stepCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, stepCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::Stop::Id:
{
case Clusters::LevelControl::Commands::Stop::Id: {
Clusters::LevelControl::Commands::Stop::Type stopCommand;
if (auto stop = std::get_if<BindingCommandData::Stop>(&data->commandData))
{
stopCommand.optionsMask = stop->optionsMask;
stopCommand.optionsOverride = stop->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
stopCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, stopCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id:
{
case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id: {
Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Type moveToLevelWithOnOffCommand;
if (auto moveToLevel = std::get_if<BindingCommandData::MoveToLevel>(&data->commandData))
{
moveToLevelWithOnOffCommand.level = moveToLevel->level;
moveToLevelWithOnOffCommand.transitionTime = moveToLevel->transitionTime;
moveToLevelWithOnOffCommand.optionsMask = moveToLevel->optionsMask;
moveToLevelWithOnOffCommand.optionsOverride = moveToLevel->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
moveToLevelWithOnOffCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, moveToLevelWithOnOffCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::MoveWithOnOff::Id:
{
case Clusters::LevelControl::Commands::MoveWithOnOff::Id: {
Clusters::LevelControl::Commands::MoveWithOnOff::Type moveWithOnOffCommand;
if (auto move = std::get_if<BindingCommandData::Move>(&data->commandData))
{
moveWithOnOffCommand.moveMode = move->moveMode;
moveWithOnOffCommand.rate = move->rate;
moveWithOnOffCommand.optionsMask = move->optionsMask;
moveWithOnOffCommand.optionsOverride = move->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
moveWithOnOffCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, moveWithOnOffCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::StepWithOnOff::Id:
{
case Clusters::LevelControl::Commands::StepWithOnOff::Id: {
Clusters::LevelControl::Commands::StepWithOnOff::Type stepWithOnOffCommand;
if (auto step = std::get_if<BindingCommandData::Step>(&data->commandData))
{
Expand All @@ -200,21 +193,20 @@ void ProcessLevelControlUnicastBindingCommand(BindingCommandData * data, const E
stepWithOnOffCommand.transitionTime = step->transitionTime;
stepWithOnOffCommand.optionsMask = step->optionsMask;
stepWithOnOffCommand.optionsOverride = step->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
stepWithOnOffCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, stepWithOnOffCommand, onSuccess, onFailure);
}
break;
}

case Clusters::LevelControl::Commands::StopWithOnOff::Id:
{
case Clusters::LevelControl::Commands::StopWithOnOff::Id: {
Clusters::LevelControl::Commands::StopWithOnOff::Type stopWithOnOffCommand;
if (auto stop = std::get_if<BindingCommandData::Stop>(&data->commandData))
{
stopWithOnOffCommand.optionsMask = stop->optionsMask;
stopWithOnOffCommand.optionsOverride = stop->optionsOverride;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
stopWithOnOffCommand, onSuccess, onFailure);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding.remote, stopWithOnOffCommand, onSuccess, onFailure);
}
break;
}
Expand All @@ -229,8 +221,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb

switch (data->commandId)
{
case Clusters::LevelControl::Commands::MoveToLevel::Id:
{
case Clusters::LevelControl::Commands::MoveToLevel::Id: {
Clusters::LevelControl::Commands::MoveToLevel::Type moveToLevelCommand;
if (auto moveToLevel = std::get_if<BindingCommandData::MoveToLevel>(&data->commandData))
{
Expand All @@ -243,8 +234,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::Move::Id:
{
case Clusters::LevelControl::Commands::Move::Id: {
Clusters::LevelControl::Commands::Move::Type moveCommand;
if (auto move = std::get_if<BindingCommandData::Move>(&data->commandData))
{
Expand All @@ -257,8 +247,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::Step::Id:
{
case Clusters::LevelControl::Commands::Step::Id: {
Clusters::LevelControl::Commands::Step::Type stepCommand;
if (auto step = std::get_if<BindingCommandData::Step>(&data->commandData))
{
Expand All @@ -272,8 +261,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::Stop::Id:
{
case Clusters::LevelControl::Commands::Stop::Id: {
Clusters::LevelControl::Commands::Stop::Type stopCommand;
if (auto stop = std::get_if<BindingCommandData::Stop>(&data->commandData))
{
Expand All @@ -284,8 +272,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id:
{
case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id: {
Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Type moveToLevelWithOnOffCommand;
if (auto moveToLevel = std::get_if<BindingCommandData::MoveToLevel>(&data->commandData))
{
Expand All @@ -298,8 +285,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::MoveWithOnOff::Id:
{
case Clusters::LevelControl::Commands::MoveWithOnOff::Id: {
Clusters::LevelControl::Commands::MoveWithOnOff::Type moveWithOnOffCommand;
if (auto move = std::get_if<BindingCommandData::Move>(&data->commandData))
{
Expand All @@ -312,8 +298,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::StepWithOnOff::Id:
{
case Clusters::LevelControl::Commands::StepWithOnOff::Id: {
Clusters::LevelControl::Commands::StepWithOnOff::Type stepWithOnOffCommand;
if (auto step = std::get_if<BindingCommandData::Step>(&data->commandData))
{
Expand All @@ -327,8 +312,7 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
break;
}

case Clusters::LevelControl::Commands::StopWithOnOff::Id:
{
case Clusters::LevelControl::Commands::StopWithOnOff::Id: {
Clusters::LevelControl::Commands::StopWithOnOff::Type stopWithOnOffCommand;
if (auto stop = std::get_if<BindingCommandData::Stop>(&data->commandData))
{
Expand Down
Loading
Loading