Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

Committer:
bikeNomad
Date:
Tue Jun 18 06:12:48 2013 +0000
Revision:
2:eaba75af0f0d
Parent:
0:84aaade0de8f
Child:
4:f009306756b3
Still not doing actions but loading OK;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 0:84aaade0de8f 1 #ifndef __included_action_hpp
bikeNomad 0:84aaade0de8f 2 #define __included_action_hpp
bikeNomad 0:84aaade0de8f 3
bikeNomad 0:84aaade0de8f 4 #include "billybass.hpp"
bikeNomad 0:84aaade0de8f 5
bikeNomad 0:84aaade0de8f 6 // 0.000000\t5.646050\thead
bikeNomad 0:84aaade0de8f 7 // 0.064498\t1.069177\ttail
bikeNomad 0:84aaade0de8f 8 // 0.357219\t0.580481\tmouth
bikeNomad 0:84aaade0de8f 9
bikeNomad 0:84aaade0de8f 10 #define MAX_ACTION_LINE_LENGTH 30
bikeNomad 0:84aaade0de8f 11
bikeNomad 2:eaba75af0f0d 12 struct Action {
bikeNomad 0:84aaade0de8f 13 Action(float _time = -1.0,
bikeNomad 2:eaba75af0f0d 14 bool _state = false,
bikeNomad 2:eaba75af0f0d 15 DigitalOut *_out = 0,
bikeNomad 2:eaba75af0f0d 16 char const *_outName = 0)
bikeNomad 0:84aaade0de8f 17 : actionTime(_time), desiredState(_state)
bikeNomad 2:eaba75af0f0d 18 , output(_out), outputName(_outName) {
bikeNomad 2:eaba75af0f0d 19 }
bikeNomad 2:eaba75af0f0d 20
bikeNomad 2:eaba75af0f0d 21 bool operator < (Action const &other) const {
bikeNomad 2:eaba75af0f0d 22 return actionTime < other.actionTime;
bikeNomad 0:84aaade0de8f 23 }
bikeNomad 0:84aaade0de8f 24
bikeNomad 2:eaba75af0f0d 25 bool isValid() const {
bikeNomad 2:eaba75af0f0d 26 return actionTime >= 0.0 && output != 0;
bikeNomad 2:eaba75af0f0d 27 }
bikeNomad 0:84aaade0de8f 28
bikeNomad 2:eaba75af0f0d 29 void act() {
bikeNomad 2:eaba75af0f0d 30 output->write(desiredState ? 1 : 0);
bikeNomad 2:eaba75af0f0d 31 }
bikeNomad 2:eaba75af0f0d 32
bikeNomad 2:eaba75af0f0d 33 bool actIfPast(float _now) {
bikeNomad 2:eaba75af0f0d 34 if (_now >= actionTime) {
bikeNomad 2:eaba75af0f0d 35 act();
bikeNomad 2:eaba75af0f0d 36 return true;
bikeNomad 2:eaba75af0f0d 37 } else return false;
bikeNomad 2:eaba75af0f0d 38 }
bikeNomad 0:84aaade0de8f 39
bikeNomad 0:84aaade0de8f 40 float actionTime;
bikeNomad 0:84aaade0de8f 41 bool desiredState;
bikeNomad 0:84aaade0de8f 42 DigitalOut *output;
bikeNomad 0:84aaade0de8f 43 char const *outputName;
bikeNomad 0:84aaade0de8f 44 };
bikeNomad 0:84aaade0de8f 45
bikeNomad 0:84aaade0de8f 46 #endif