mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-27 09:23:57 -04:00
Adding Elgato Keylight
Code style changes by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
committed by
Adam Honse
parent
a64894445d
commit
0b9825ca19
@@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Driver for Elgato Key Light |
|
||||
| |
|
||||
| Monks (imtherealestmonkey@gmail.com), 11/03/2021 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "ElgatoKeyLightController.h"
|
||||
#include "json.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ElgatoKeyLightController::ElgatoKeyLightController(std::string ip)
|
||||
{
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Fill in location string with device's IP address |
|
||||
\*-----------------------------------------------------------------*/
|
||||
location = "IP: " + ip;
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Open a TCP client sending to the device's IP, port 9123 |
|
||||
\*-----------------------------------------------------------------*/
|
||||
port.tcp_client(ip.c_str(), "9123");
|
||||
}
|
||||
|
||||
ElgatoKeyLightController::~ElgatoKeyLightController()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetLocation()
|
||||
{
|
||||
return(location);
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetName()
|
||||
{
|
||||
return("Elgato KeyLight");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetVersion()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetManufacturer()
|
||||
{
|
||||
return("Elgato");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetUniqueID()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
void ElgatoKeyLightController::SetColor(hsv_t hsv_color)
|
||||
{
|
||||
// Weird elgato color format
|
||||
int k_value = HSVToK(hsv_color.hue);
|
||||
|
||||
port.tcp_client_connect();
|
||||
std::string buf = GetRequest(hsv_color.value, k_value);
|
||||
port.tcp_client_write((char *)buf.c_str(), buf.length() + 1);
|
||||
|
||||
port.tcp_close();
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetRequest(int brightness, int temperature)
|
||||
{
|
||||
json command;
|
||||
|
||||
command["numberOfLights"] = 1;
|
||||
|
||||
auto lights = json::array();
|
||||
lights.push_back(json::object({ {"on", 1}, {"temperature", temperature}, {"brightness", brightness}}));
|
||||
command["lights"] = lights;
|
||||
|
||||
std::string command_str = command.dump();
|
||||
std::string buf = "PUT /elgato/lights HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: " +
|
||||
std::to_string(command_str.length()) +
|
||||
"\r\nConnection: close\r\n\r\n" + command_str + "\r\n\r\n";
|
||||
return(buf);
|
||||
}
|
||||
|
||||
int ElgatoKeyLightController::HSVToK(int hue)
|
||||
{
|
||||
int k_value;
|
||||
|
||||
if(hue <= 60 && hue >= 0)
|
||||
{
|
||||
k_value = 2900;
|
||||
}
|
||||
else if(hue >= 61 && hue <= 120)
|
||||
{
|
||||
k_value = 4000;
|
||||
}
|
||||
else if(hue >= 121 && hue <= 180)
|
||||
{
|
||||
k_value = 5000;
|
||||
}
|
||||
else if(hue >= 181 && hue <= 240)
|
||||
{
|
||||
k_value = 6000;
|
||||
}
|
||||
else
|
||||
{
|
||||
k_value = 7000;
|
||||
}
|
||||
|
||||
return k_value;
|
||||
}
|
||||
Reference in New Issue
Block a user