VizBlocks
RotaryEncoderBehaviours.h
Go to the documentation of this file.
1 #ifndef ROTARYENCODER_BEHAVIOUR_h
2 #define ROTARYENCODER_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  RotaryEncoderUpdated(VizBlocks* node, String name = "RotaryEncoderUpdated") :
17  Behaviour(name), _node(node){ }
18 
19  char* args() {return "<String rotaryEncoderId> <int position>"; };
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 encoder = "";
25  String position = "";
26 
27  if ( index > 0 ) {
28  encoder = args.substring(0, index);
29  position = args.substring(index+1);
30  } else {
31  return "RotaryEncoderUpdated behaviour args error!";
32  }
33 
34  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"encoder\":\"" + encoder + "\",\"position\":\"" + position + "\"}}";
35  _node->announce(str);
36  return "RotaryEncoderUpdated behaviour " + _name + " with (" + args + ")";
37  }
38 };
39 
40 #endif
RotaryEncoderUpdated::RotaryEncoderUpdated
RotaryEncoderUpdated(VizBlocks *node, String name="RotaryEncoderUpdated")
Definition: RotaryEncoderBehaviours.h:16
Behaviour::name
virtual String name()
Definition: Behaviours.h:28
VizBlocks::getId
char * getId()
Definition: VizBlocks.h:291
RotaryEncoderUpdated::args
char * args()
Definition: RotaryEncoderBehaviours.h:19
Behaviour::_name
String _name
Definition: Behaviours.h:11
Behaviour
Definition: Behaviours.h:4
VizBlocks::announce
void announce(String doc)
Definition: VizBlocks.h:270
Behaviours.h
VizBlocks
Definition: VizBlocks.h:15
RotaryEncoderUpdated
Definition: RotaryEncoderBehaviours.h:7
VizBlocks.h
RotaryEncoderUpdated::start
String start(String args)
Definition: RotaryEncoderBehaviours.h:21