Skip to content

Commit

Permalink
Update DeviceFunctionsApp.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 authored May 26, 2024
1 parent fb67623 commit 67914b4
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions examples/basic-config/src/apps/DeviceFunctionsApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,36 @@ namespace apps
mqttConnWp = addComponent<ksf::comps::ksMqttConnector>();

/* Create LED components. */
wifiLedWp = addComponent<ksf::comps::ksLed>(CFG_STATUS_LED);
connectionStatusLedWp = addComponent<ksf::comps::ksLed>(CFG_STATUS_LED);

/* Bind to MQTT callbacks. */
if (auto mqttConnSp{mqttConnWp.lock()})
if (auto connectionStatusLedSp{connectionStatusLedWp.lock()})
{
mqttConnSp->onConnected->registerEvent(connEventHandleSp, std::bind(&DeviceFunctionsApp::onMqttConnected, this));
mqttConnSp->onDisconnected->registerEvent(disEventHandleSp, std::bind(&DeviceFunctionsApp::onMqttDisconnected, this));
}

/* Start LED blinking on finished init. */
if (auto wifiLedSp{wifiLedWp.lock()})
/* Start LED blinking on finished init. */
wifiLedSp->setBlinking(500);
}

/* Application finished initialization, return true as it succedeed. */
return true;
}

void DeviceFunctionsApp::onMqttDisconnected()
{
if (auto wifiLedSp{wifiLedWp.lock()})
wifiLedSp->setBlinking(500);
if (auto connectionStatusLedSp{connectionStatusLedWp.lock()})
connectionStatusLedSp->setBlinking(500);
}

void DeviceFunctionsApp::onMqttConnected()
{
if (auto wifiLedSp{wifiLedWp.lock()})
wifiLedSp->setBlinking(0);
if (auto connectionStatusLedSp{connectionStatusLedWp.lock()})
connectionStatusLedSp->setBlinking(0);
}

bool DeviceFunctionsApp::loop()
{
/*
Return to superclass application loop.
It handles all our components and whole app logic.
*/
return ksApplication::loop();
}
}

0 comments on commit 67914b4

Please sign in to comment.