Big Mouth Billy Bass automation library
Diff: action.hpp
- Revision:
- 2:eaba75af0f0d
- Parent:
- 0:84aaade0de8f
- Child:
- 4:f009306756b3
--- a/action.hpp Tue Jun 18 00:07:47 2013 +0000 +++ b/action.hpp Tue Jun 18 06:12:48 2013 +0000 @@ -9,20 +9,33 @@ #define MAX_ACTION_LINE_LENGTH 30 -struct Action -{ +struct Action { Action(float _time = -1.0, - bool _state = false, - DigitalOut *_out = 0, - char const *_outName = 0) + bool _state = false, + DigitalOut *_out = 0, + char const *_outName = 0) : actionTime(_time), desiredState(_state) - , output(_out), outputName(_outName) - { + , output(_out), outputName(_outName) { + } + + bool operator < (Action const &other) const { + return actionTime < other.actionTime; } - bool operator < (Action const &other) const { return actionTime < other.actionTime; } + bool isValid() const { + return actionTime >= 0.0 && output != 0; + } - bool isValid() const { return actionTime >= 0.0 && output != 0; } + void act() { + output->write(desiredState ? 1 : 0); + } + + bool actIfPast(float _now) { + if (_now >= actionTime) { + act(); + return true; + } else return false; + } float actionTime; bool desiredState;