alarm wip
This commit is contained in:
@@ -155,8 +155,6 @@ int main(int argc, char *argv[])
|
||||
CapabilitiesShuttersModel the_cap_shutters(&the_devices_manager);
|
||||
CapabilitiesSprinklersModel the_cap_sprinklers(&the_devices_manager);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Setup the Ubus context. */
|
||||
the_ctx = setup_ubus();
|
||||
if (the_ctx == NULL)
|
||||
|
||||
@@ -48,39 +48,38 @@ Clock::~Clock(void)
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn isEqual
|
||||
* @fn set
|
||||
*
|
||||
* @brief Set an Event to the Clock.
|
||||
* @brief Set a time (hour/minute) to the Clock.
|
||||
*/
|
||||
#if 0
|
||||
int Clock::set(const Event &an_event)
|
||||
int Clock::set(void)
|
||||
{
|
||||
m_event = an_event;
|
||||
|
||||
m_now = time(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn is_equal_to_current_time
|
||||
* @fn is_equal_to_timer
|
||||
*
|
||||
* @brief return true if the clock is equal to current time.
|
||||
*/
|
||||
bool Clock::is_equal_to_current_time(void)
|
||||
bool Clock::is_equal_to_timer(const Timer &a_timer)
|
||||
{
|
||||
struct tm the_compared_time;
|
||||
double the_diff;
|
||||
|
||||
the_compared_time = *localtime(&m_now);
|
||||
|
||||
#if 0
|
||||
the_compared_time.tm_hour = m_event.get_hour();
|
||||
the_compared_time.tm_min = m_event.get_minute();
|
||||
#endif
|
||||
printf ("=>Hour: %.2d h %.2d\n", the_compared_time.tm_hour, the_compared_time.tm_min);
|
||||
|
||||
the_compared_time.tm_hour = a_timer.get_hour();
|
||||
the_compared_time.tm_min = a_timer.get_minute();
|
||||
|
||||
the_diff = difftime(m_now, mktime(&the_compared_time));
|
||||
|
||||
//printf ("%.f seconds of diff between current time and Timer time.\n", theDiff);
|
||||
printf ("=>Timer: %.2d h %.2d\n", a_timer.get_hour(),a_timer.get_minute());
|
||||
printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
|
||||
|
||||
if (the_diff == 0)
|
||||
return true;
|
||||
@@ -93,19 +92,19 @@ bool Clock::is_equal_to_current_time(void)
|
||||
*
|
||||
* @brief Return true if the curent time has expired.
|
||||
*/
|
||||
bool Clock::is_expired(void)
|
||||
bool Clock::is_expired(uint16_t a_duration)
|
||||
{
|
||||
time_t the_expired;
|
||||
struct tm the_compared_time;
|
||||
double the_diff;
|
||||
|
||||
the_compared_time = *localtime(&m_now);
|
||||
#if 0
|
||||
the_compared_time.tm_hour = m_event.get_hour();
|
||||
the_compared_time.tm_min = m_event.get_minute();
|
||||
|
||||
the_expired = mktime(&the_compared_time) + (m_event.get_duration() * 60);
|
||||
#endif
|
||||
// the_compared_time.tm_hour = m_hour;
|
||||
// the_compared_time.tm_min = m_minute;
|
||||
|
||||
the_expired = mktime(&the_compared_time) + (a_duration * 60);
|
||||
|
||||
the_diff = difftime(m_now, the_expired);
|
||||
|
||||
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);
|
||||
|
||||
@@ -28,9 +28,11 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
//#include "timers/event.h"
|
||||
#include "timer.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
@@ -42,12 +44,12 @@ class Clock
|
||||
Clock(void);
|
||||
~Clock(void);
|
||||
|
||||
//int set(const Event &an_event);
|
||||
bool is_equal_to_current_time(void);
|
||||
bool is_expired(void);
|
||||
int set(void);
|
||||
|
||||
bool is_equal_to_timer(const Timer &a_timer);
|
||||
bool is_expired(uint16_t a_duration);
|
||||
|
||||
private:
|
||||
//Event m_event;
|
||||
time_t m_now;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
*
|
||||
* @brief Constructor of the Sequence Object.
|
||||
*/
|
||||
Sequence::Sequence(void) : m_id(0)
|
||||
Sequence::Sequence(void) : m_is_in_progress(false),
|
||||
m_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -148,3 +149,34 @@ const std::string &Sequence::get_name(void) const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get_timer
|
||||
*
|
||||
* @brief return the timer of the Sequence.
|
||||
*/
|
||||
const Timer &Sequence::get_timer(void) const
|
||||
{
|
||||
return m_timer;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn is_active
|
||||
*
|
||||
* @brief return true if the sequence has an active timer. false otherwise.
|
||||
*/
|
||||
bool Sequence::is_active(void)
|
||||
{
|
||||
return m_timer.is_active();
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn is_in_progress
|
||||
*
|
||||
* @brief return true if the sequence has been started..
|
||||
*/
|
||||
bool Sequence::is_in_progress(void)
|
||||
{
|
||||
return m_is_in_progress;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,13 @@ public:
|
||||
|
||||
uint16_t get_id(void) const;
|
||||
const std::string &get_name(void) const;
|
||||
const Timer &get_timer(void) const;
|
||||
|
||||
bool is_active(void);
|
||||
bool is_in_progress(void);
|
||||
|
||||
private:
|
||||
bool m_is_in_progress;
|
||||
uint16_t m_id;
|
||||
std::string m_name;
|
||||
Timer m_timer;
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
//#define k60s 60000
|
||||
#define k60s 2000
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn SequencesManager
|
||||
*
|
||||
@@ -96,6 +95,8 @@ int SequencesManager::load(void)
|
||||
/* Clean the json object. */
|
||||
json_object_put(the_root_node);
|
||||
|
||||
tzset ();
|
||||
|
||||
start(k60s, true);
|
||||
|
||||
return 0;
|
||||
@@ -198,6 +199,26 @@ int SequencesManager::expire(void)
|
||||
Clock the_clock;
|
||||
fprintf(stderr, "**** >> Manage timers....\n");
|
||||
|
||||
for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++)
|
||||
{
|
||||
if ((*the_seq_it).is_active())
|
||||
{
|
||||
printf("sequence %d active.\n", (*the_seq_it).get_id());
|
||||
if (!(*the_seq_it).is_in_progress())
|
||||
{
|
||||
if (the_clock.is_equal_to_timer((*the_seq_it).get_timer()))
|
||||
{
|
||||
// Action START.
|
||||
fprintf(stdout, "Sequence Start\n");
|
||||
//(*the_seq_it).start(m_devices_manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++)
|
||||
{
|
||||
@@ -231,6 +252,6 @@ int SequencesManager::expire(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user