VizBlocks
ButtonBehaviours.h
Go to the documentation of this file.
1 #ifndef BUTTON_BEHAVIOUR_h
2 #define BUTTON_BEHAVIOUR_h
3 #include "Arduino.h"
4 #include "Behaviours.h"
5 #include <VizBlocks.h>
6 
7 class ButtonPressed : public Behaviour {
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  ButtonPressed(VizBlocks* node, String name = "ButtonPressed") :
17  Behaviour(name), _node(node){ }
18 
19  char* args() {return "<String buttonId>"; };
20 
21  String start(String args) {
22  //This is where you do your stuff for a simple behaviour
23  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"button\":\"" + args + "\"}}";
24  _node->announce(str);
25  return "ButtonPressed behaviour " + _name + " with (" + args + ")";
26  }
27 };
28 
29 class ButtonReleased : public Behaviour {
30  /*
31  * Class that defines a behaviour that publishes a
32  * ButtonReleased message to the input topic of the
33  * MQQT broker
34  */
35  VizBlocks* _node;
36 
37 public:
38  ButtonReleased(VizBlocks* node, String name = "ButtonReleased") :
39  Behaviour(name), _node(node){ }
40 
41  char* args() {return "<String buttonId>"; };
42 
43  String start(String args) {
44  //This is where you do your stuff for a simple behaviour
45  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"button\":\"" + args + "\"}}";
46  _node->announce(str);
47  return "ButtonReleased behaviour " + _name + " with (" + args + ")";
48  }
49 };
50 
51 class ButtonClicked : public Behaviour {
52  /*
53  * Class that defines a behaviour that publishes a
54  * ButtonClicked message to the input topic of the
55  * MQQT broker
56  */
57  VizBlocks* _node;
58 
59 public:
60  ButtonClicked(VizBlocks* node, String name = "ButtonClicked") :
61  Behaviour(name), _node(node){ }
62 
63  char* args() {return "<String buttonId>"; };
64 
65  String start(String args) {
66  //This is where you do your stuff for a simple behaviour
67  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"button\":\"" + args + "\"}}";
68  _node->announce(str);
69  return "ButtonClicked behaviour " + _name + " with (" + args + ")";
70  }
71 };
72 
73 class ButtonHeld : public Behaviour {
74  /*
75  * Class that defines a behaviour that publishes a
76  * ButtonLongPressed message to the input topic of the
77  * MQQT broker
78  */
79  VizBlocks* _node;
80 
81 public:
82  ButtonHeld(VizBlocks* node, String name = "ButtonHeld") :
83  Behaviour(name), _node(node){ }
84 
85  char* args() {return "<String buttonId>"; };
86 
87  String start(String args) {
88  //This is where you do your stuff for a simple behaviour
89  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"button\":\"" + args + "\"}}";
90  _node->announce(str);
91  return "ButtonHeld behaviour " + _name + " with (" + args + ")";
92  }
93 };
94 
95 class ButtonTick : public Behaviour {
96  /*
97  * Class that defines a behaviour that publishes a
98  * ButtonRepeatPressed message to the input topic of the
99  * MQQT broker
100  */
101  VizBlocks* _node;
102 
103 public:
104  ButtonTick(VizBlocks* node, String name = "ButtonTick") :
105  Behaviour(name), _node(node){ }
106 
107  char* args() {return "<String buttonId>"; };
108 
109  String start(String args) {
110  //This is where you do your stuff for a simple behaviour
111  String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Input\":{\"type\":\"" + String(name()) + "\",\"button\":\"" + args + "\"}}";
112  _node->announce(str);
113  return "ButtonTick behaviour " + _name + " with (" + args + ")";
114  }
115 };
116 
117 #endif
ButtonTick::ButtonTick
ButtonTick(VizBlocks *node, String name="ButtonTick")
Definition: ButtonBehaviours.h:104
ButtonTick::start
String start(String args)
Definition: ButtonBehaviours.h:109
Behaviour::name
virtual String name()
Definition: Behaviours.h:28
VizBlocks::getId
char * getId()
Definition: VizBlocks.h:291
ButtonHeld::args
char * args()
Definition: ButtonBehaviours.h:85
ButtonHeld::ButtonHeld
ButtonHeld(VizBlocks *node, String name="ButtonHeld")
Definition: ButtonBehaviours.h:82
Behaviour::_name
String _name
Definition: Behaviours.h:11
Behaviour
Definition: Behaviours.h:4
ButtonPressed::args
char * args()
Definition: ButtonBehaviours.h:19
ButtonPressed::ButtonPressed
ButtonPressed(VizBlocks *node, String name="ButtonPressed")
Definition: ButtonBehaviours.h:16
ButtonClicked::ButtonClicked
ButtonClicked(VizBlocks *node, String name="ButtonClicked")
Definition: ButtonBehaviours.h:60
ButtonPressed
Definition: ButtonBehaviours.h:7
ButtonReleased::start
String start(String args)
Definition: ButtonBehaviours.h:43
ButtonTick::args
char * args()
Definition: ButtonBehaviours.h:107
ButtonHeld::start
String start(String args)
Definition: ButtonBehaviours.h:87
VizBlocks::announce
void announce(String doc)
Definition: VizBlocks.h:270
ButtonReleased
Definition: ButtonBehaviours.h:29
ButtonClicked::args
char * args()
Definition: ButtonBehaviours.h:63
ButtonClicked::start
String start(String args)
Definition: ButtonBehaviours.h:65
ButtonClicked
Definition: ButtonBehaviours.h:51
Behaviours.h
VizBlocks
Definition: VizBlocks.h:15
ButtonTick
Definition: ButtonBehaviours.h:95
ButtonPressed::start
String start(String args)
Definition: ButtonBehaviours.h:21
ButtonHeld
Definition: ButtonBehaviours.h:73
VizBlocks.h
ButtonReleased::args
char * args()
Definition: ButtonBehaviours.h:41
ButtonReleased::ButtonReleased
ButtonReleased(VizBlocks *node, String name="ButtonReleased")
Definition: ButtonBehaviours.h:38