Add keepalive option for E1.31 output
This commit is contained in:
parent
ed01850926
commit
4f5cf83e47
3 changed files with 49 additions and 0 deletions
|
|
@ -56,6 +56,9 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
|
|||
|
||||
bool new_device = false;
|
||||
|
||||
//Clear E131 device data
|
||||
memset(&dev, 0, sizeof(E131Device));
|
||||
|
||||
//Open settings file
|
||||
infile.open(filename);
|
||||
|
||||
|
|
@ -105,6 +108,10 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
|
|||
{
|
||||
dev.start_channel = atoi(value);
|
||||
}
|
||||
else if(strcmp(argument, "keepalive_time") == 0)
|
||||
{
|
||||
dev.keepalive_time = atoi(value);
|
||||
}
|
||||
else if(strcmp(argument, "rgb_order") == 0)
|
||||
{
|
||||
if(strcmp(value, "RGB") == 0)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
#include <e131.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
RGBController_E131::RGBController_E131(std::vector<E131Device> device_list)
|
||||
{
|
||||
name = "E1.31 Streaming ACN Device";
|
||||
|
|
@ -28,10 +30,23 @@ RGBController_E131::RGBController_E131(std::vector<E131Device> device_list)
|
|||
|
||||
sockfd = e131_socket();
|
||||
|
||||
keepalive_delay = 0ms;
|
||||
|
||||
SetupZones();
|
||||
|
||||
for (std::size_t device_idx = 0; device_idx < devices.size(); device_idx++)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Update keepalive delay |
|
||||
\*-----------------------------------------*/
|
||||
if(devices[device_idx].keepalive_time > 0)
|
||||
{
|
||||
if(keepalive_delay.count() == 0 || keepalive_delay.count() > devices[device_idx].keepalive_time)
|
||||
{
|
||||
keepalive_delay = std::chrono::milliseconds(devices[device_idx].keepalive_time);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Add Universes |
|
||||
\*-----------------------------------------*/
|
||||
|
|
@ -162,6 +177,11 @@ RGBController_E131::RGBController_E131(std::vector<E131Device> device_list)
|
|||
zones[device_idx].matrix_map = new_map;
|
||||
}
|
||||
}
|
||||
|
||||
if(keepalive_delay.count() > 0)
|
||||
{
|
||||
KeepaliveThread = new std::thread(&RGBController_E131::KeepaliveThreadFunction, this);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_E131::SetupZones()
|
||||
|
|
@ -212,6 +232,8 @@ void RGBController_E131::DeviceUpdateLEDs()
|
|||
{
|
||||
int color_idx = 0;
|
||||
|
||||
last_update_time = std::chrono::steady_clock::now();
|
||||
|
||||
for(std::size_t device_idx = 0; device_idx < devices.size(); device_idx++)
|
||||
{
|
||||
unsigned int total_universes = ceil( ( ( devices[device_idx].num_leds * 3 ) + devices[device_idx].start_channel ) / 512.0f );
|
||||
|
|
@ -288,3 +310,15 @@ void RGBController_E131::DeviceUpdateMode()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_E131::KeepaliveThreadFunction()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_update_time) > ( keepalive_delay * 0.95f ) )
|
||||
{
|
||||
UpdateLEDs();
|
||||
}
|
||||
std::this_thread::sleep_for(keepalive_delay / 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include <e131.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
typedef unsigned int e131_rgb_order;
|
||||
|
||||
|
|
@ -43,6 +45,7 @@ struct E131Device
|
|||
unsigned int num_leds;
|
||||
unsigned int start_universe;
|
||||
unsigned int start_channel;
|
||||
unsigned int keepalive_time;
|
||||
e131_rgb_order rgb_order;
|
||||
zone_type type;
|
||||
unsigned int matrix_width;
|
||||
|
|
@ -66,10 +69,15 @@ public:
|
|||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
void KeepaliveThreadFunction();
|
||||
|
||||
private:
|
||||
std::vector<E131Device> devices;
|
||||
std::vector<e131_packet_t> packets;
|
||||
std::vector<e131_addr_t> dest_addrs;
|
||||
std::vector<unsigned int> universes;
|
||||
int sockfd;
|
||||
std::thread * KeepaliveThread;
|
||||
std::chrono::milliseconds keepalive_delay;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue