forked from techniccontroller/wordclock_esp8266
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udplogger.cpp
38 lines (32 loc) · 1.06 KB
/
udplogger.cpp
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
#include "udplogger.h"
UDPLogger::UDPLogger(){
}
UDPLogger::UDPLogger(IPAddress interfaceAddr, IPAddress multicastAddr, int port){
_multicastAddr = multicastAddr;
_port = port;
_interfaceAddr = interfaceAddr;
_name = "Log";
_Udp.beginMulticast(_interfaceAddr, _multicastAddr, _port);
}
void UDPLogger::setName(String name){
_name = name;
}
void UDPLogger::logString(String logmessage){
// wait 5 milliseconds if last send was less than 5 milliseconds before
if(millis() < (_lastSend + 5)){
delay(5);
}
logmessage = _name + ": " + logmessage;
Serial.println(logmessage);
_Udp.beginPacketMulticast(_multicastAddr, _port, _interfaceAddr);
logmessage.toCharArray(_packetBuffer, 100);
_Udp.print(_packetBuffer);
_Udp.endPacket();
_lastSend=millis();
}
void UDPLogger::logColor24bit(uint32_t color){
uint8_t resultRed = color >> 16 & 0xff;
uint8_t resultGreen = color >> 8 & 0xff;
uint8_t resultBlue = color & 0xff;
logString(String(resultRed) + ", " + String(resultGreen) + ", " + String(resultBlue));
}