VizBlocks
PotentiometerBehaviours.h
Go to the documentation of this file.
1 #ifndef POTENTIOMETER_BEHAVIOUR_h
2 #define POTENTIOMETER_BEHAVIOUR_h
3 #include "Arduino.h"
4 #include "Behaviours.h"
5 #include <VizBlocks.h>
6 
8  /*
9  * Class that defines a behaviour that publishes a
10  * ButtonPressed message to the input topic of the
11  * MQQT broker
12  */
13  VizBlocks* _node;
14 
15 public:
16  PotentiometerUpdated(VizBlocks* node, String name = "PotentiometerUpdated") :
17  Behaviour(name), _node(node){ }
18 
19  char* args() {return "<String potentiometerId> <int value>"; };
20 
21  String start(String args) {
22  //This is where you do your stuff for a simple behaviour
23  int index = args.indexOf(" ");
24  String pot = "";
25  String value = "";
26 
27  if ( index > 0 ) {
28  pot = args.substring(0, index);
29  value = args.substring(index+1);
30  } else {
31  return "PotentiometerUpdated behaviour args error!";
32  }
33  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"pot\":\"" + pot + "\",\"value\":\"" + value + "\"}}";
34  _node->announce(str);
35  return "PotentiometerUpdated behaviour " + _name + " with (" + args + ")";
36  }
37 };
38 
39 #endif
Behaviour::name
virtual String name()
Definition: Behaviours.h:28
VizBlocks::getId
char * getId()
Definition: VizBlocks.h:291
Behaviour::_name
String _name
Definition: Behaviours.h:11
Behaviour
Definition: Behaviours.h:4
VizBlocks::announce
void announce(String doc)
Definition: VizBlocks.h:270
PotentiometerUpdated::args
char * args()
Definition: PotentiometerBehaviours.h:19
PotentiometerUpdated
Definition: PotentiometerBehaviours.h:7
PotentiometerUpdated::PotentiometerUpdated
PotentiometerUpdated(VizBlocks *node, String name="PotentiometerUpdated")
Definition: PotentiometerBehaviours.h:16
Behaviours.h
VizBlocks
Definition: VizBlocks.h:15
PotentiometerUpdated::start
String start(String args)
Definition: PotentiometerBehaviours.h:21
VizBlocks.h