Initial Philips Wiz controller

This commit is contained in:
Adam Honse 2020-11-03 20:06:14 -06:00
parent 88a96cd0c2
commit 5c5ed6f8bd
6 changed files with 272 additions and 0 deletions

View file

@ -0,0 +1,59 @@
/*---------------------------------------------------------*\
| Driver for Philips Wiz |
| |
| Adam Honse (calcprogrammer1@gmail.com), 9/15/2020 |
\*---------------------------------------------------------*/
#include "PhilipsWizController.h"
PhilipsWizController::PhilipsWizController(std::string ip)
{
location = "IP: " + ip;
port.udp_client(ip.c_str(), "38899");
}
PhilipsWizController::~PhilipsWizController()
{
}
std::string PhilipsWizController::GetLocation()
{
return(location);
}
std::string PhilipsWizController::GetName()
{
return("");
}
std::string PhilipsWizController::GetVersion()
{
return("");
}
std::string PhilipsWizController::GetManufacturer()
{
return("");
}
std::string PhilipsWizController::GetUniqueID()
{
return("");
}
void PhilipsWizController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
if(red == 0 && green == 0 && blue == 0)
{
std::string message = "{\"method\":\"setPilot\",\"params\":{\"r\":" + std::to_string(red) + ",\"g\":" + std::to_string(green) + ",\"b\":" + std::to_string(blue) + ",\"state\":0}}";
port.udp_write((char *)message.c_str(), message.length() + 1);
}
else
{
std::string message = "{\"method\":\"setPilot\",\"params\":{\"r\":" + std::to_string(red) + ",\"g\":" + std::to_string(green) + ",\"b\":" + std::to_string(blue) + ",\"state\":1}}";
port.udp_write((char *)message.c_str(), message.length() + 1);
}
}

View file

@ -0,0 +1,32 @@
/*---------------------------------------------------------*\
| Definitions for Philips Wiz |
| |
| Adam Honse (calcprogrammer1@gmail.com), 11/3/2020 |
\*---------------------------------------------------------*/
#include "RGBController.h"
#include "net_port.h"
#include <string>
#include <vector>
#pragma once
class PhilipsWizController
{
public:
PhilipsWizController(std::string ip);
~PhilipsWizController();
std::string GetLocation();
std::string GetName();
std::string GetVersion();
std::string GetManufacturer();
std::string GetUniqueID();
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
private:
std::string location;
net_port port;
};

View file

@ -0,0 +1,59 @@
#include "Detector.h"
#include "PhilipsWizController.h"
#include "RGBController.h"
#include "RGBController_PhilipsWiz.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
/******************************************************************************************\
* *
* DetectPhilipsWizControllers *
* *
* Detect Philips Wiz devices *
* *
\******************************************************************************************/
void DetectPhilipsWizControllers(std::vector<RGBController*> &rgb_controllers)
{
PhilipsWizController* new_controller;
RGBController_PhilipsWiz* new_rgbcontroller;
std::ifstream infile;
char arg1[64];
//Open settings file
infile.open("wiz.txt");
if (infile.good())
{
for (std::string line; std::getline(infile, line); )
{
if (line == "")
{
continue;
}
else
{
new_controller = new PhilipsWizController(line);
new_rgbcontroller = new RGBController_PhilipsWiz(new_controller);
rgb_controllers.push_back(new_rgbcontroller);
}
}
}
} /* DetectPhilipsWizControllers() */
REGISTER_DETECTOR("Philips Wiz", DetectPhilipsWizControllers);

View file

@ -0,0 +1,85 @@
/*-----------------------------------------*\
| RGBController_PhilipsWiz.cpp |
| |
| Generic RGB Interface for Philips Wiz |
| |
| Adam Honse (CalcProgrammer1) 11/3/2020 |
\*-----------------------------------------*/
#include "RGBController_PhilipsWiz.h"
RGBController_PhilipsWiz::RGBController_PhilipsWiz(PhilipsWizController* light_ptr)
{
light = light_ptr;
name = light->GetManufacturer() + " " + light->GetName();
type = DEVICE_TYPE_UNKNOWN;
version = light->GetVersion();
description = "Philips Wiz Device";
serial = light->GetUniqueID();
location = light->GetLocation();
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_PhilipsWiz::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_PhilipsWiz::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_PhilipsWiz::DeviceUpdateLEDs()
{
unsigned char red = RGBGetRValue(colors[0]);
unsigned char grn = RGBGetGValue(colors[0]);
unsigned char blu = RGBGetBValue(colors[0]);
light->SetColor(red, grn, blu);
}
void RGBController_PhilipsWiz::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsWiz::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsWiz::SetCustomMode()
{
}
void RGBController_PhilipsWiz::DeviceUpdateMode()
{
}

View file

@ -0,0 +1,31 @@
/*-----------------------------------------*\
| RGBController_PhilipsWiz.h |
| |
| Generic RGB Interface for Philips Wiz |
| |
| Adam Honse (CalcProgrammer1) 11/3/2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PhilipsWizController.h"
class RGBController_PhilipsWiz : public RGBController
{
public:
RGBController_PhilipsWiz(PhilipsWizController* light_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:
PhilipsWizController* light;
};

View file

@ -86,6 +86,7 @@ INCLUDEPATH +=
Controllers/NZXTKrakenController/ \
Controllers/OpenRazerController/ \
Controllers/PatriotViperController/ \
Controllers/PhilipsWizController/ \
Controllers/PolychromeController/ \
Controllers/PoseidonZRGBController/ \
Controllers/RedragonController/ \
@ -222,6 +223,8 @@ HEADERS +=
Controllers/OpenRazerController/OpenRazerDevices.h \
Controllers/PatriotViperController/PatriotViperController.h \
Controllers/PatriotViperController/RGBController_PatriotViper.h \
Controllers/PhilipsWizController/PhilipsWizController.h \
Controllers/PhilipsWizController/RGBController_PhilipsWiz.h \
Controllers/PolychromeController/PolychromeController.h \
Controllers/PolychromeController/RGBController_Polychrome.h \
Controllers/PoseidonZRGBController/PoseidonZRGBController.h \
@ -417,6 +420,9 @@ SOURCES +=
Controllers/PatriotViperController/PatriotViperController.cpp \
Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \
Controllers/PatriotViperController/RGBController_PatriotViper.cpp \
Controllers/PhilipsWizController/PhilipsWizController.cpp \
Controllers/PhilipsWizController/PhilipsWizControllerDetect.cpp \
Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp \
Controllers/PolychromeController/PolychromeController.cpp \
Controllers/PolychromeController/PolychromeControllerDetect.cpp \
Controllers/PolychromeController/RGBController_Polychrome.cpp \