Skip to content

Commit

Permalink
Use the stored on off attribute state to initialize led state (#17704)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Jan 27, 2024
1 parent fafe456 commit 52be345
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 0 additions & 2 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ CHIP_ERROR AppTask::Init()
sLightLED.Init(LIGHT_LED);
sLightLED.Set(LightMgr().IsLightOn());

chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));

ConfigurationMgr().LogDeviceConfig();

// Print setup info on LCD if available
Expand Down
13 changes: 12 additions & 1 deletion examples/lighting-app/efr32/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include "AppTask.h"
#include <FreeRTOS.h>

#include <app/clusters/on-off-server/on-off-server.h>

using namespace chip;
using namespace ::chip::DeviceLayer;

LightingManager LightingManager::sLight;

TimerHandle_t sLightTimer;
Expand All @@ -43,7 +48,13 @@ CHIP_ERROR LightingManager::Init()
return APP_ERROR_CREATE_TIMER_FAILED;
}

mState = kState_OffCompleted;
bool currentLedState;
// read current on/off value on endpoint one.
chip::DeviceLayer::PlatformMgr().LockChipStack();
OnOffServer::Instance().getOnOffValue(1, &currentLedState);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

mState = currentLedState ? kState_OnCompleted : kState_OffCompleted;
mAutoTurnOffTimerArmed = false;
mAutoTurnOff = false;
mAutoTurnOffDuration = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ bool OnOffServer::HasFeature(chip::EndpointId endpoint, OnOffFeature feature)
return success ? ((featureMap & to_underlying(feature)) != 0) : false;
}

EmberAfStatus OnOffServer::getOnOffValue(chip::EndpointId endpoint, bool * currentOnOffValue)
{
// read current on/off value
EmberAfStatus status = Attributes::OnOff::Get(endpoint, currentOnOffValue);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfOnOffClusterPrintln("ERR: reading on/off %x", status);
}

emberAfOnOffClusterPrintln("On/Off ep%d value: %d", endpoint, *currentOnOffValue);

return status;
}

/** @brief On/off Cluster Set Value
*
* This function is called when the on/off value needs to be set, either through
Expand Down
1 change: 1 addition & 0 deletions src/app/clusters/on-off-server/on-off-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class OnOffServer
bool OnWithTimedOffCommand(const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::OnOff::Commands::OnWithTimedOff::DecodableType & commandData);
void updateOnOffTimeCommand(chip::EndpointId endpoint);
EmberAfStatus getOnOffValue(chip::EndpointId endpoint, bool * currentOnOffValue);
EmberAfStatus setOnOffValue(chip::EndpointId endpoint, uint8_t command, bool initiatedByLevelChange);
EmberAfStatus getOnOffValueForStartUp(chip::EndpointId endpoint, bool & onOffValueForStartUp);

Expand Down

0 comments on commit 52be345

Please sign in to comment.