Timer Event now could change the devices state.
This commit is contained in:
@@ -166,3 +166,32 @@ int Devices::set (const std::string &aCapability, Json::Value anElement)
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief get the device of a specific capabilities, with the ID.
|
||||
*/
|
||||
int Devices::set (const std::string &aCapability, int anID, bool aState)
|
||||
{
|
||||
int theResult = -1;
|
||||
|
||||
if (aCapability == "Lights") {
|
||||
|
||||
theResult = mLights.set (anID, aState);
|
||||
}
|
||||
else if (aCapability == "Shutters") {
|
||||
|
||||
theResult = mShutters.set (anID, aState);
|
||||
}
|
||||
else if (aCapability == "Sprinklers") {
|
||||
|
||||
theResult = mSprinklers.set (anID, aState);
|
||||
}
|
||||
|
||||
if (theResult == 0)
|
||||
save ();
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
|
||||
std::string get (const std::string &aCapability);
|
||||
int set (const std::string &aCapability, Json::Value anElement);
|
||||
int set (const std::string &aCapability, int anID, bool aState);
|
||||
|
||||
private:
|
||||
std::string mFilePath;
|
||||
|
||||
@@ -112,3 +112,14 @@ int ShutterDevice::set (Json::Value anElement)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief set the new Shutter state.
|
||||
*/
|
||||
int ShutterDevice::set (int anID, bool aState)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
Json::Value to_json (bool bDataOnly = false);
|
||||
|
||||
int set (Json::Value anElement);
|
||||
int set (int anID, bool aState);
|
||||
|
||||
private:
|
||||
std::vector <Shutter> mShutter;
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "devices/Devices.h"
|
||||
|
||||
#include "timers/Event.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -111,6 +113,32 @@ Json::Value Event::to_json (void) const
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn start
|
||||
*
|
||||
* @brief Stop the Event.
|
||||
*/
|
||||
int Event::start (Devices *aDevices)
|
||||
{
|
||||
setInProgress (true);
|
||||
|
||||
return aDevices->set (mCapability.c_str(), mID, true);
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn stop
|
||||
*
|
||||
* @brief Stop the Event.
|
||||
*/
|
||||
int Event::stop (Devices *aDevices)
|
||||
{
|
||||
setInProgress (false);
|
||||
|
||||
return aDevices->set (mCapability.c_str(), mID, false);
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn dump
|
||||
*
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
@@ -47,6 +48,9 @@ public:
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (void) const;
|
||||
|
||||
int start (Devices *aDevices);
|
||||
int stop (Devices *aDevices);
|
||||
|
||||
void dump (void);
|
||||
|
||||
/* Getter */
|
||||
|
||||
@@ -141,10 +141,10 @@ int Timers::Expire (void)
|
||||
|
||||
if ((*timer_evt).isInProgress()) {
|
||||
if (theClock.isExpired()) {
|
||||
//
|
||||
(*timer_evt).setInProgress (false);
|
||||
//TODO Action Stop.
|
||||
|
||||
// Action Stop.
|
||||
fprintf (stdout, "Timer Stop\n");
|
||||
(*timer_evt).stop (mDevices);
|
||||
}
|
||||
else {
|
||||
fprintf (stdout, "Not expired yet.\n");
|
||||
@@ -154,9 +154,9 @@ int Timers::Expire (void)
|
||||
|
||||
if (theClock.isEqualToCurrentTime ()) {
|
||||
|
||||
(*timer_evt).setInProgress (true);
|
||||
// Action START.
|
||||
fprintf (stdout, "Timer Start\n");
|
||||
(*timer_evt).start (mDevices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user