Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ICE-Application/src/ConfigurationHandler/Controls/TimerControl.h
- Committer:
- jmarkel44
- Date:
- 2017-01-24
- Revision:
- 1:b2e90cda7a5a
- Parent:
- 0:61364762ee0e
File content as of revision 1:b2e90cda7a5a:
/******************************************************************************
*
* File: TimerControl.h
* Desciption: ICE Timer Control Class
*
*****************************************************************************/
#ifndef TIMERCONTROL_H
#define TIMERCONTROL_H
//#include "ConfigurationHandler.h"
#include <string>
#include <stdio.h>
#include <vector>
typedef enum {
TIMER_CONTROL_OK,
TIMER_CONTROL_UNK_STATE,
TIMER_CONTROL_ERROR,
TIMER_CONTROL_DESTROY
} TimerControlError_t;
//! Timer Control - implements a timer control.
/// @code
/// #include "TimerControl.h"
///
/// int main(void)
/// {
/// TimerControl *t = new TimerControl();
/// bool rc = t->load(controlFile);
/// if ( rc != true ) {
/// logError("%s: failed to load the manual control\n");
/// delete t;
/// exit(-1);
/// }
///
/// t->start();
/// for ( ;; ) {
/// t->update();
/// }
/// }
/// @endcode
class TimerControl
{
private:
std::string controlFile; // file containing control data
std::string id; // timer identifier
std::string output; // output to control
unsigned int priority; // control priority
unsigned int day;
unsigned int startHour; // start hour (0-23)
unsigned int startMin; // start minute (0-59)
unsigned int startSec; // start second (0-59)
unsigned int duration; // duration in seconds
unsigned int week; // every week, first week, ...
enum State {
STATE_INIT,
STATE_OFF,
STATE_RUNNING,
STATE_FINISHED,
STATE_DISABLED
};
State currentState;
unsigned long nextScheduledStartTime;
unsigned long startTime;
bool isVirtualOutput;
// validate control file data
bool validateControlData(const char *buf);
// copy control file data to object
void copyControlData(const char *buf);
// start a feed
void startFeed(void);
// stop a feed
void stopFeed(void);
// calculate time until start
unsigned long calcStartTime() const;
const char *displayTime(void);
public:
TimerControl() {
currentState = STATE_INIT;
}
~TimerControl() {
printf("\r%s invoked\n", __func__);
}
/// load control data from a JSON configuration file
bool load(std::string filename);
/// start a timer control instance
void start(void);
/// update a timer control instance
TimerControlError_t update(void);
/// unregister a timer control instance from the output thread
void unregisterControl(void);
/// display pertinent data of a timer control instance
void display(void);
std::string getControlFile(void) const {
return controlFile;
}
std::string getId(void) const {
return id;
}
std::string getOutput(void) const {
return output;
}
unsigned int getPriority(void) const {
return priority;
}
unsigned int getDuration(void) const {
return duration;
}
State getCurrentState(void) const {
return currentState;
}
};
#endif