-
Notifications
You must be signed in to change notification settings - Fork 10
/
helper.h
80 lines (74 loc) · 1.93 KB
/
helper.h
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
/*
* helper.h
* ----------------------------------------------------------------------------
* helper methods and defines
* ----------------------------------------------------------------------------
* Source: https://github.com/Jorgen-VikingGod/ESP8266-WiFi-Relay
* Copyright: Copyright (c) 2017 Juergen Skrotzky
* Author: Juergen Skrotzky <[email protected]>
* License: MIT License
* Created on: 23.Nov. 2017
* ----------------------------------------------------------------------------
*/
#ifndef _HELPER_H
#define _HELPER_H
/*
* Debug mode
*/
#define _debug 1
/*
* relay container
* ----------------------------------------------------------------------------
*/
struct sRelay {
uint8_t pin;
uint8_t type;
uint8_t state;
sRelay(uint8_t relayPin, uint8_t relayType = HIGH, uint8_t relayState = LOW) {
pin = relayPin;
type = relayType;
state = relayState;
}
};
/*
* format ip address as String
* ----------------------------------------------------------------------------
*/
String printIP(IPAddress adress) {
return (String)adress[0] + "." + (String)adress[1] + "." + (String)adress[2] + "." + (String)adress[3];
}
/*
* debug messages
* ----------------------------------------------------------------------------
*/
template <typename... Args>
void DEBUG_PRINTF(const char *format, Args &&...args) {
if (_debug) {
Serial.printf(format, args...);
}
}
template <typename Generic>
void DEBUG_PRINT(Generic text) {
if (_debug) {
Serial.print(text);
}
}
template <typename Generic, typename Format>
void DEBUG_PRINT(Generic text, Format format) {
if (_debug) {
Serial.print(text, format);
}
}
template <typename Generic>
void DEBUG_PRINTLN(Generic text) {
if (_debug) {
Serial.println(text);
}
}
template <typename Generic, typename Format>
void DEBUG_PRINTLN(Generic text, Format format) {
if (_debug) {
Serial.println(text, format);
}
}
#endif // _HELPER_H