Add controller for Espurna HTTP API
This commit is contained in:
parent
db64cd66a1
commit
312d068021
6 changed files with 313 additions and 2 deletions
71
Controllers/EspurnaController/EspurnaController.cpp
Normal file
71
Controllers/EspurnaController/EspurnaController.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Processing Code for Espurna Interface |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com), 9/11/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "EspurnaController.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
EspurnaController::EspurnaController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EspurnaController::~EspurnaController()
|
||||
{
|
||||
}
|
||||
|
||||
void EspurnaController::Initialize(char* ledstring)
|
||||
{
|
||||
LPSTR apikey = NULL;
|
||||
LPSTR numleds = NULL;
|
||||
LPSTR source = NULL;
|
||||
LPSTR udpport_baud = NULL;
|
||||
LPSTR next = NULL;
|
||||
|
||||
//Assume serial device unless a different protocol is specified
|
||||
bool serial = TRUE;
|
||||
|
||||
source = strtok_s(ledstring, ",", &next);
|
||||
|
||||
//Check for either the UDP port or the serial baud rate
|
||||
if (strlen(next))
|
||||
{
|
||||
udpport_baud = strtok_s(next, ",", &next);
|
||||
}
|
||||
|
||||
//Espurna protocol requires API key
|
||||
if (strlen(next))
|
||||
{
|
||||
apikey = strtok_s(next, ",", &next);
|
||||
}
|
||||
|
||||
InitializeEspurna(source, udpport_baud, apikey);
|
||||
}
|
||||
|
||||
void EspurnaController::InitializeEspurna(char * clientname, char * port, char * apikey)
|
||||
{
|
||||
strcpy(client_name, clientname);
|
||||
strcpy(port_name, port);
|
||||
strcpy(espurna_apikey, apikey);
|
||||
tcpport = new net_port;
|
||||
tcpport->tcp_client(client_name, port_name);
|
||||
}
|
||||
|
||||
void EspurnaController::SetLEDs(std::vector<RGBColor> colors)
|
||||
{
|
||||
if (tcpport != NULL)
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
|
||||
char get_request[1024];
|
||||
snprintf(get_request, 1024, "GET /api/rgb?apikey=%s&value=%%23%02X%02X%02X HTTP/1.1\r\nHost: %s\r\n\r\n", espurna_apikey, RGBGetRValue(color), RGBGetGValue(color), RGBGetBValue(color), client_name);
|
||||
tcpport->tcp_client_connect();
|
||||
tcpport->tcp_client_write(get_request, strlen(get_request));
|
||||
tcpport->tcp_close();
|
||||
}
|
||||
}
|
||||
46
Controllers/EspurnaController/EspurnaController.h
Normal file
46
Controllers/EspurnaController/EspurnaController.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Definitions for Espurna Interface |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com), 9/11/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#ifndef ESPURNA_H
|
||||
#define ESPURNA_H
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "net_port.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE true
|
||||
#define FALSE false
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#define LPSTR char *
|
||||
#define strtok_s strtok_r
|
||||
#endif
|
||||
|
||||
class EspurnaController
|
||||
{
|
||||
public:
|
||||
EspurnaController();
|
||||
~EspurnaController();
|
||||
|
||||
void Initialize(char* ledstring);
|
||||
void InitializeEspurna(char* clientname, char* port, char * apikey);
|
||||
void SetLEDs(std::vector<RGBColor> colors);
|
||||
|
||||
private:
|
||||
int baud_rate;
|
||||
|
||||
char led_string[1024];
|
||||
char port_name[128];
|
||||
char client_name[1024];
|
||||
char espurna_apikey[128];
|
||||
|
||||
net_port *tcpport;
|
||||
};
|
||||
|
||||
#endif
|
||||
77
Controllers/EspurnaController/EspurnaControllerDetect.cpp
Normal file
77
Controllers/EspurnaController/EspurnaControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include "Detector.h"
|
||||
#include "EspurnaController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_Espurna.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectEspurnaControllers *
|
||||
* *
|
||||
* Detect devices supported by the Espurna driver *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectEspurnaControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
EspurnaController* new_espurna;
|
||||
RGBController_Espurna* new_controller;
|
||||
|
||||
std::ifstream infile;
|
||||
char arg1[64];
|
||||
|
||||
//Open settings file
|
||||
infile.open("espurna.txt");
|
||||
|
||||
if (infile.good())
|
||||
{
|
||||
for (std::string line; std::getline(infile, line); )
|
||||
{
|
||||
if (line == "")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
|
||||
{
|
||||
char * argument;
|
||||
char * value;
|
||||
|
||||
value = (char *)line.c_str();
|
||||
|
||||
argument = strtok_s(value, "=", &value);
|
||||
|
||||
//Strip off new line characters if present
|
||||
argument = strtok(argument, "\r\n");
|
||||
value = strtok(value, "\r\n");
|
||||
|
||||
if(argument)
|
||||
{
|
||||
if (strcmp(argument, "espurna") == 0)
|
||||
{
|
||||
new_espurna = new EspurnaController();
|
||||
new_espurna->Initialize(value);
|
||||
|
||||
new_controller = new RGBController_Espurna(new_espurna);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectEspurnaControllers() */
|
||||
|
||||
REGISTER_DETECTOR("Espurna", DetectEspurnaControllers);
|
||||
11
OpenRGB.pro
11
OpenRGB.pro
|
|
@ -61,6 +61,8 @@ INCLUDEPATH += \
|
|||
Controllers/CorsairVengeanceProController/ \
|
||||
Controllers/CrucialController/ \
|
||||
Controllers/DuckyKeyboardController/ \
|
||||
Controllers/EKController/ \
|
||||
Controllers/EspurnaController/ \
|
||||
Controllers/GalaxGPUController/ \
|
||||
Controllers/GloriousModelOController/ \
|
||||
Controllers/HoltekController/ \
|
||||
|
|
@ -135,6 +137,7 @@ HEADERS += \
|
|||
Controllers/CrucialController/CrucialController.h \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardController.h \
|
||||
Controllers/EKController/EKController.h \
|
||||
Controllers/EspurnaController/EspurnaController.h \
|
||||
Controllers/GalaxGPUController/GalaxGPUController.h \
|
||||
Controllers/GloriousModelOController/GloriousModelOController.h \
|
||||
Controllers/HoltekController/HoltekA070Controller.h \
|
||||
|
|
@ -189,8 +192,9 @@ HEADERS += \
|
|||
RGBController/RGBController_Crucial.h \
|
||||
RGBController/RGBController_DuckyKeyboard.h \
|
||||
RGBController/RGBController_Dummy.h \
|
||||
RGBController/RGBController_EKController.h \
|
||||
RGBController/RGBController_E131.h \
|
||||
RGBController/RGBController_EKController.h \
|
||||
RGBController/RGBController_Espurna.h \
|
||||
RGBController/RGBController_GalaxGPU.h \
|
||||
RGBController/RGBController_GloriousModelO.h \
|
||||
RGBController/RGBController_HoltekA070.h \
|
||||
|
|
@ -292,6 +296,8 @@ SOURCES += \
|
|||
Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp \
|
||||
Controllers/EKController/EKControllerDetect.cpp \
|
||||
Controllers/EKController/EKController.cpp \
|
||||
Controllers/EspurnaController/EspurnaController.cpp \
|
||||
Controllers/EspurnaController/EspurnaControllerDetect.cpp \
|
||||
Controllers/GalaxGPUController/GalaxGPUController.cpp \
|
||||
Controllers/GalaxGPUController/GalaxGPUControllerDetect.cpp \
|
||||
Controllers/GloriousModelOController/GloriousModelOController.cpp \
|
||||
|
|
@ -376,7 +382,9 @@ SOURCES += \
|
|||
RGBController/RGBController_Crucial.cpp \
|
||||
RGBController/RGBController_DuckyKeyboard.cpp \
|
||||
RGBController/RGBController_Dummy.cpp \
|
||||
RGBController/RGBController_E131.cpp \
|
||||
RGBController/RGBController_EKController.cpp \
|
||||
RGBController/RGBController_Espurna.cpp \
|
||||
RGBController/RGBController_GalaxGPU.cpp \
|
||||
RGBController/RGBController_GloriousModelO.cpp \
|
||||
RGBController/RGBController_HoltekA070.cpp \
|
||||
|
|
@ -385,7 +393,6 @@ SOURCES += \
|
|||
RGBController/RGBController_HyperXDRAM.cpp \
|
||||
RGBController/RGBController_HyperXKeyboard.cpp \
|
||||
RGBController/RGBController_HyperXPulsefireSurge.cpp \
|
||||
RGBController/RGBController_E131.cpp \
|
||||
RGBController/RGBController_LEDStrip.cpp \
|
||||
RGBController/RGBController_LogitechG203.cpp \
|
||||
RGBController/RGBController_LogitechG203L.cpp \
|
||||
|
|
|
|||
79
RGBController/RGBController_Espurna.cpp
Normal file
79
RGBController/RGBController_Espurna.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_Espurna.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Espurna |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/20/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_Espurna.h"
|
||||
|
||||
|
||||
RGBController_Espurna::RGBController_Espurna(EspurnaController* espurna_ptr)
|
||||
{
|
||||
espurna = espurna_ptr;
|
||||
|
||||
name = "Espurna";
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
description = "Espurna Device";
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_Espurna::SetupZones()
|
||||
{
|
||||
zone led_zone;
|
||||
led_zone.name = "RGB Light";
|
||||
led_zone.type = ZONE_TYPE_SINGLE;
|
||||
led_zone.leds_min = 1;
|
||||
led_zone.leds_max = 1;
|
||||
led_zone.leds_count = 1;
|
||||
led_zone.matrix_map = NULL;
|
||||
zones.push_back(led_zone);
|
||||
|
||||
led new_led;
|
||||
new_led.name = "RGB Light";
|
||||
|
||||
leds.push_back(new_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_Espurna::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Espurna::DeviceUpdateLEDs()
|
||||
{
|
||||
espurna->SetLEDs(colors);
|
||||
}
|
||||
|
||||
void RGBController_Espurna::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
espurna->SetLEDs(colors);
|
||||
}
|
||||
|
||||
void RGBController_Espurna::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
espurna->SetLEDs(colors);
|
||||
}
|
||||
|
||||
void RGBController_Espurna::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Espurna::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
31
RGBController/RGBController_Espurna.h
Normal file
31
RGBController/RGBController_Espurna.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_Espurna.h |
|
||||
| |
|
||||
| Generic RGB Interface for Espurna |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 9/11/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "EspurnaController.h"
|
||||
|
||||
class RGBController_Espurna : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_Espurna(EspurnaController* espurna_ptr);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
EspurnaController* espurna;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue