forked from Jorgen-VikingGod/ESP8266-WiFi-Relay-Async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.h
64 lines (59 loc) · 1.71 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
/*
* helper.h
* ----------------------------------------------------------------------------
* helper methods and defines
* ----------------------------------------------------------------------------
* Source: https://github.com/Jorgen-VikingGod/ESP8266-WiFi-Relay-Async
* Copyright: Copyright (c) 2017 Juergen Skrotzky
* Author: Juergen Skrotzky <[email protected]>
* License: MIT License
* Created on: 11.Sep. 2017
* ----------------------------------------------------------------------------
*/
#ifndef _HELPER_H
#define _HELPER_H
/*
* Debug mode
*/
#define _debug 1
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);
}
}
void parseBytes(const char* str, char sep, byte* bytes, int maxBytes, int base) {
for (int i = 0; i < maxBytes; i++) {
bytes[i] = strtoul(str, NULL, base); // Convert byte
str = strchr(str, sep); // Find next separator
if (str == NULL || *str == '\0') {
break; // No more separators, exit
}
str++; // Point to next character after separator
}
}
#endif // _HELPER_H