-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTesterComponent.h
More file actions
83 lines (58 loc) · 1.91 KB
/
TesterComponent.h
File metadata and controls
83 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Author: Claudiu Matei
*/
#ifndef TesterComponent_h
#define TesterComponent_h
#include <FlowerPlatformArduinoRuntime.h>
#include <HardwareSerial.h>
class TesterComponent;
class TesterEvent {
public:
TesterComponent* tester;
};
class TesterComponent {
protected:
void logEvent(const char* event, const char* eventProperties);
// unsigned long deadline;
public:
const char* name;
// unsigned long delay;
TesterComponent(const char* name);
Callback<TesterEvent>* onTesterEvent = NULL;
void setup();
void loop();
};
TesterComponent::TesterComponent(const char* name) {
this->name = name;
// delay = 500;
// deadline = millis() + delay;
}
void TesterComponent::loop() {
Serial.print("{\"eventType\":\"functionCall\",\"functionName\":\"loop\",\"objectClass\":\"TesterComponent\"");
Serial.print(",\"objectProperties\":{\"name\":\""); Serial.print(name); Serial.print("\"}");
Serial.println("}");
// unsigned long currentTime = millis();
// if (onTesterEvent && (currentTime > deadline)) {
TesterEvent event;
event.tester = this;
(*onTesterEvent)(&event);
// deadline = currentTime + delay;
// }
}
void TesterComponent::setup() {
Serial.print("{\"eventType\":\"functionCall\",\"functionName\":\"setup\",\"objectClass\":\"TesterComponent\"");
Serial.print(",\"objectProperties\":{\"name\":\""); Serial.print(name); Serial.print("\"}");
Serial.println("}");
}
void logFunctionCallEvent(const char* functionName, const char* objectClass = NULL, const char* customProperties = NULL) {
Serial.print("{\"eventType\":\"functionCall\",\"functionName\":\""); Serial.print(functionName); Serial.print("\"");
if (objectClass) {
Serial.print(",\"objectClass\":\""); Serial.print(objectClass); Serial.print("\"");
}
if (customProperties) {
Serial.print(",");
Serial.print(customProperties);
}
Serial.println("}");
}
#endif