|
| 1 | +/* |
| 2 | + * Copyright 2017-, Rohan Budhiraja, CNRS |
| 3 | + * |
| 4 | + * This file is part of sot-core. |
| 5 | + * sot-core is free software: you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public License |
| 7 | + * as published by the Free Software Foundation, either version 3 of |
| 8 | + * the License, or (at your option) any later version. |
| 9 | + * sot-core is distributed in the hope that it will be |
| 10 | + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 11 | + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. You should |
| 13 | + * have received a copy of the GNU Lesser General Public License along |
| 14 | + * with sot-core. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef __SOT_SWITCH_H__ |
| 18 | +#define __SOT_SWITCH_H__ |
| 19 | + |
| 20 | +/* --------------------------------------------------------------------- */ |
| 21 | +/* --- INCLUDE --------------------------------------------------------- */ |
| 22 | +/* --------------------------------------------------------------------- */ |
| 23 | + |
| 24 | +/* SOT */ |
| 25 | +#include <dynamic-graph/command-bind.h> |
| 26 | +#include <sot/core/pool.hh> |
| 27 | +#include <dynamic-graph/entity.h> |
| 28 | +#include <dynamic-graph/all-signals.h> |
| 29 | + |
| 30 | +/* STD */ |
| 31 | +#include <string> |
| 32 | + |
| 33 | +namespace dynamicgraph { |
| 34 | + namespace sot { |
| 35 | + |
| 36 | + /* --------------------------------------------------------------------- */ |
| 37 | + /* --- CLASS ----------------------------------------------------------- */ |
| 38 | + /* --------------------------------------------------------------------- */ |
| 39 | + using dynamicgraph::Entity; |
| 40 | + using dynamicgraph::command::makeCommandVoid0; |
| 41 | + using dynamicgraph::command::docCommandVoid0; |
| 42 | + |
| 43 | + class Switch : public Entity |
| 44 | + { |
| 45 | + |
| 46 | + public: /* --- SIGNAL --- */ |
| 47 | + DYNAMIC_GRAPH_ENTITY_DECL(); |
| 48 | + dynamicgraph::SignalTimeDependent<bool,int> outSOUT; |
| 49 | + |
| 50 | + protected: |
| 51 | + bool signalOutput; |
| 52 | + void turnOn(){ signalOutput = true; } |
| 53 | + |
| 54 | + void turnOff(){ signalOutput = false; } |
| 55 | + |
| 56 | + bool& switchOutput(bool& res, int){ res = signalOutput; return res; } |
| 57 | + |
| 58 | + public: |
| 59 | + Switch( const std::string& name ) |
| 60 | + : Entity(name) |
| 61 | + ,outSOUT( boost::bind(&Switch::switchOutput,this,_1,_2), |
| 62 | + sotNOSIGNAL,"Switch("+name+")::output(bool)::out") |
| 63 | + { |
| 64 | + signalOutput = false; |
| 65 | + signalRegistration (outSOUT ); |
| 66 | + addCommand ("turnOn", |
| 67 | + makeCommandVoid0 (*this, &Switch::turnOn, |
| 68 | + docCommandVoid0 ("Turn on the switch"))); |
| 69 | + addCommand ("turnOff", |
| 70 | + makeCommandVoid0 (*this, &Switch::turnOff, |
| 71 | + docCommandVoid0 ("Turn off the switch"))); |
| 72 | + } |
| 73 | + |
| 74 | + virtual ~Switch( void ) {}; |
| 75 | + |
| 76 | +}; |
| 77 | +} /* namespace sot */ |
| 78 | +} /* namespace dynamicgraph */ |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +#endif // #ifndef __SOT_SWITCH_H__ |
0 commit comments