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;
|
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,7 +52,8 @@ public:
|
|||||||
|
|
||||||
std::string get (const std::string &aCapability);
|
std::string get (const std::string &aCapability);
|
||||||
int set (const std::string &aCapability, Json::Value anElement);
|
int set (const std::string &aCapability, Json::Value anElement);
|
||||||
|
int set (const std::string &aCapability, int anID, bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mFilePath;
|
std::string mFilePath;
|
||||||
|
|
||||||
|
|||||||
@@ -112,3 +112,14 @@ int ShutterDevice::set (Json::Value anElement)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new Shutter state.
|
||||||
|
*/
|
||||||
|
int ShutterDevice::set (int anID, bool aState)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ public:
|
|||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (bool bDataOnly = false);
|
Json::Value to_json (bool bDataOnly = false);
|
||||||
|
|
||||||
int set (Json::Value anElement);
|
int set (Json::Value anElement);
|
||||||
|
int set (int anID, bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Shutter> mShutter;
|
std::vector <Shutter> mShutter;
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include "devices/Devices.h"
|
||||||
|
|
||||||
#include "timers/Event.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
|
* @fn dump
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
|
|
||||||
|
class Devices;
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
@@ -46,6 +47,9 @@ public:
|
|||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void) const;
|
Json::Value to_json (void) const;
|
||||||
|
|
||||||
|
int start (Devices *aDevices);
|
||||||
|
int stop (Devices *aDevices);
|
||||||
|
|
||||||
void dump (void);
|
void dump (void);
|
||||||
|
|
||||||
|
|||||||
@@ -141,10 +141,10 @@ int Timers::Expire (void)
|
|||||||
|
|
||||||
if ((*timer_evt).isInProgress()) {
|
if ((*timer_evt).isInProgress()) {
|
||||||
if (theClock.isExpired()) {
|
if (theClock.isExpired()) {
|
||||||
//
|
|
||||||
(*timer_evt).setInProgress (false);
|
// Action Stop.
|
||||||
//TODO Action Stop.
|
|
||||||
fprintf (stdout, "Timer Stop\n");
|
fprintf (stdout, "Timer Stop\n");
|
||||||
|
(*timer_evt).stop (mDevices);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf (stdout, "Not expired yet.\n");
|
fprintf (stdout, "Not expired yet.\n");
|
||||||
@@ -154,9 +154,9 @@ int Timers::Expire (void)
|
|||||||
|
|
||||||
if (theClock.isEqualToCurrentTime ()) {
|
if (theClock.isEqualToCurrentTime ()) {
|
||||||
|
|
||||||
(*timer_evt).setInProgress (true);
|
|
||||||
// Action START.
|
// Action START.
|
||||||
fprintf (stdout, "Timer Start\n");
|
fprintf (stdout, "Timer Start\n");
|
||||||
|
(*timer_evt).start (mDevices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user