Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

Revision:
4:f009306756b3
Parent:
2:eaba75af0f0d
Child:
6:ea8136eb6976
--- a/action.hpp	Tue Jun 18 13:11:07 2013 +0000
+++ b/action.hpp	Tue Jun 18 14:10:34 2013 +0000
@@ -15,12 +15,17 @@
            DigitalOut *_out = 0,
            char const *_outName = 0)
         : actionTime(_time), desiredState(_state)
-        , output(_out), outputName(_outName) {
+        , output(_out) {
     }
 
     bool operator < (Action const &other) const {
         return actionTime < other.actionTime;
     }
+    
+    // return <0 if *p1 is before *p2
+    static int compare(const void* p1, const void* p2) {
+        return static_cast<Action const *>(p1)->actionTime - static_cast<Action const *>(p2)->actionTime;
+    }
 
     bool isValid() const {
         return actionTime >= 0.0 && output != 0;
@@ -29,18 +34,22 @@
     void act() {
         output->write(desiredState ? 1 : 0);
     }
-    
+
     bool actIfPast(float _now) {
         if (_now >= actionTime) {
             act();
             return true;
         } else return false;
     }
+    void set(float _time, int _state, DigitalOut* _out) {
+        actionTime = _time;
+        desiredState = _state;
+        output = _out;
+    }
 
     float actionTime;
-    bool desiredState;
+    int desiredState;
     DigitalOut *output;
-    char const *outputName;
 };
 
 #endif