Commit 9b167ae2 authored by Adam Honse's avatar Adam Honse

Remove files that are no longer needed after switching to OpenRGB SDK

parent c8b6191c
......@@ -13,16 +13,6 @@ TEMPLATE = app
LIBS += -lopenal
packagesExist(hidapi-libusb) {
unix:LIBS += -lhidapi-libusb
} else {
packagesExist(hidapi) {
unix:LIBS += -lhidapi
} else {
unix:LIBS += -lhidapi-libusb
}
}
DISTFILES +=
INCLUDEPATH += \
......@@ -49,7 +39,6 @@ SOURCES += \
HEADERS += \
KeyboardVisualizerCommon/chuck_fft.h \
KeyboardVisualizerCommon/hsv.h \
KeyboardVisualizerCommon/net_port.h \
KeyboardVisualizerCommon/Visualizer.h \
KeyboardVisualizerCommon/VisualizerDefines.h \
KeyboardVisualizerQT/KeyboardVisDlg.h \
......
#include "UsbDevice.h"
//Helper functions for native Windows USB
//These functions courtesy of http://www.reddit.com/user/chrisgzy
#if defined(WIN32) && !defined(HIDAPI)
#pragma comment(lib, "hid.lib")
#pragma comment(lib, "setupapi.lib")
bool IsMatchingDevice(wchar_t *pDeviceID, unsigned int uiVID, unsigned int uiPID, unsigned int uiMI)
{
unsigned int uiLocalVID = 0, uiLocalPID = 0, uiLocalMI = 0;
LPWSTR pszNextToken = 0;
LPWSTR pszToken = wcstok(pDeviceID, L"\\#&");
while (pszToken)
{
std::wstring tokenStr(pszToken);
if (tokenStr.find(L"VID_", 0, 4) != std::wstring::npos)
{
std::wistringstream iss(tokenStr.substr(4));
iss >> std::hex >> uiLocalVID;
}
else if (tokenStr.find(L"PID_", 0, 4) != std::wstring::npos)
{
std::wistringstream iss(tokenStr.substr(4));
iss >> std::hex >> uiLocalPID;
}
else if (tokenStr.find(L"MI_", 0, 3) != std::wstring::npos)
{
std::wistringstream iss(tokenStr.substr(3));
iss >> std::hex >> uiLocalMI;
}
pszToken = wcstok(0, L"\\#&");
}
if (uiVID != uiLocalVID || uiPID != uiLocalPID || uiMI != uiLocalMI)
return false;
return true;
}
HANDLE GetDeviceHandle(unsigned int uiVID, unsigned int uiPID, unsigned int uiMI)
{
const GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 };
HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_HID, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE)
return 0;
HANDLE hReturn = 0;
SP_DEVINFO_DATA deviceData = { 0 };
deviceData.cbSize = sizeof(SP_DEVINFO_DATA);
for (unsigned int i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &deviceData); ++i)
{
wchar_t wszDeviceID[MAX_DEVICE_ID_LEN];
if (CM_Get_Device_IDW(deviceData.DevInst, wszDeviceID, MAX_DEVICE_ID_LEN, 0))
continue;
if (!IsMatchingDevice(wszDeviceID, uiVID, uiPID, uiMI))
continue;
SP_INTERFACE_DEVICE_DATA interfaceData = { 0 };
interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
if (!SetupDiEnumDeviceInterfaces(hDevInfo, &deviceData, &GUID_DEVINTERFACE_HID, 0, &interfaceData))
break;
DWORD dwRequiredSize = 0;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &interfaceData, 0, 0, &dwRequiredSize, 0);
SP_INTERFACE_DEVICE_DETAIL_DATA *pData = (SP_INTERFACE_DEVICE_DETAIL_DATA *)new unsigned char[dwRequiredSize];
pData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &interfaceData, pData, dwRequiredSize, 0, 0))
{
delete pData;
break;
}
HANDLE hDevice = CreateFile(pData->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (hDevice == INVALID_HANDLE_VALUE)
{
delete pData;
break;
}
hReturn = hDevice;
break;
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return hReturn;
}
#endif
UsbDevice::UsbDevice()
{
}
bool UsbDevice::OpenDevice(unsigned short vendor, unsigned short product, unsigned int MI)
{
#ifdef HIDAPI
device = hid_open(vendor, product, 0);
if (device == NULL)
{
return false;
}
return true;
#elif defined(WIN32)
handle = GetDeviceHandle(vendor, product, MI);
if (handle == NULL)
{
return false;
}
return true;
#endif
}
bool UsbDevice::SendToDevice(unsigned char* data, unsigned int length)
{
#ifdef HIDAPI
hid_send_feature_report(device, data, length);
return true;
#elif defined(WIN32)
return(HidD_SetFeature(handle, data, length));
#endif
}
#ifndef USB_DEVICE_H
#define USB_DEVICE_H
#ifndef WIN32
#define HIDAPI
#endif
#include <cstdio>
#ifdef HIDAPI
#include <hidapi/hidapi.h>
#elif defined(WIN32)
#include <sstream>
#include <wchar.h>
#include <string.h>
#include <Windows.h>
#include <hidsdi.h>
#include <SetupAPI.h>
#include <cfgmgr32.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#endif
class UsbDevice
{
public:
UsbDevice();
bool OpenDevice(unsigned short vendor, unsigned short product, unsigned int MI);
bool SendToDevice(unsigned char* data, unsigned int length);
private:
#ifdef HIDAPI
hid_device* device;
#elif defined(WIN32)
HANDLE handle;
#endif
};
#endif
......@@ -28,8 +28,6 @@
#define FALSE 0
#endif
std::vector<char *> device_properties;
char * net_string;
int ledstrip_sections_size = 1;
int matrix_setup_pos;
......@@ -84,14 +82,6 @@ Visualizer::Visualizer()
}
void Visualizer::SetDeviceProperty(char * devprop, char * argument)
{
//Save device property to list of device properties
char * buf = new char[strlen(devprop) + 1];
strcpy(buf, devprop);
device_properties.push_back(buf);
}
void Visualizer::InitAudioDeviceList()
{
#ifdef WIN32
......@@ -473,14 +463,6 @@ void Visualizer::SaveSettings()
break;
}
//Save Device Properties
for (int i = 0; i < device_properties.size(); i++)
{
//Save Device Property
snprintf(out_str, 1024, "%s\r\n", device_properties[i]);
outfile.write(out_str, strlen(out_str));
}
//Close Output File
outfile.close();
}
......
......@@ -112,9 +112,6 @@ public:
//Shut Down
void Shutdown();
//Function to set custom properties for devices
void SetDeviceProperty(char * devprop, char * argument);
//Save Settings File
void SaveSettings();
......
/*---------------------------------------------------------*\
| Cross Platform Network Library for Windows and Linux |
| This library provides access to TCP and UDP ports with |
| a common API for both Windows and Linux systems. It |
| features read and write |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/15/2016 |
\*---------------------------------------------------------*/
#include "net_port.h"
#ifndef WIN32
#include <sys/ioctl.h>
#include <netinet/tcp.h>
#include <sys/types.h>
#endif
#include <memory.h>
#include <errno.h>
#include <stdlib.h>
#include <iostream>
const char yes = 1;
net_port::net_port()
{
}
//net_port (constructor)
// When created with port information, the constructor
// will automatically open client address <client_name> on port <port>
net_port::net_port(const char * client_name, const char * port)
{
udp_client(client_name, port);
}
net_port::~net_port()
{
}
bool net_port::udp_client(const char * client_name, const char * port)
{
sockaddr_in myAddress;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return(false);
}
#endif
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == INVALID_SOCKET)
{
WSACleanup();
return(false);
}
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
myAddress.sin_port = htons(0);
if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
{
WSACleanup();
return false;
}
result_list = NULL;
addrinfo hints = {};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
if(getaddrinfo(client_name, port, &hints, &result_list) == 0)
{
memcpy(&addrDest, result_list->ai_addr, result_list->ai_addrlen);
freeaddrinfo(result_list);
return(true);
}
else
{
WSACleanup();
return(false);
}
}
int net_port::udp_listen(char * recv_data, int length)
{
return(recvfrom(sock, recv_data, length, 0, NULL, NULL));
}
int net_port::udp_write(char * buffer, int length)
{
return(sendto(sock, buffer, length, 0, (sockaddr *)&addrDest, sizeof(addrDest)));
}
bool net_port::tcp_client(const char * client_name, const char * port)
{
addrinfo hints = {};
connected = false;
result_list = NULL;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return(false);
}
#endif
port = strtok((char *)port, "\r");
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo(client_name, port, &hints, &result_list);
if(result_list == NULL)
{
WSACleanup();
return(false);
}
return(true);
}
bool net_port::tcp_client_connect()
{
if (!connected)
{
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
{
WSACleanup();
return(false);
}
u_long arg = 1;
fd_set fdset;
timeval tv;
ioctlsocket(sock, FIONBIO, &arg);
if(result_list == NULL)
{
connected = false;
return(false);
}
connect(sock, result_list->ai_addr, result_list->ai_addrlen);
FD_ZERO(&fdset);
FD_SET(sock, &fdset);
tv.tv_sec = 4;
tv.tv_usec = 0;
if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
{
char so_error;
socklen_t len = sizeof(so_error);
getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
if (so_error == 0)
{
connected = true;
arg = 0;
ioctlsocket(sock, FIONBIO, &arg);
}
else
{
connected = false;
closesocket(sock);
}
}
else
{
connected = false;
closesocket(sock);
}
}
return(true);
}
bool net_port::tcp_server(const char * port)
{
sockaddr_in myAddress;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return false;
}
#endif
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
{
WSACleanup();
return false;
}
port = strtok((char *)port, "\r");
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
myAddress.sin_port = htons(atoi(port));
if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
{
WSACleanup();
return false;
}
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
return(true);
}
void net_port::tcp_server_listen()
{
SOCKET * client = new SOCKET();
listen(sock, 10);
*client = accept(sock, NULL, NULL);
u_long arg = 0;
ioctlsocket(*client, FIONBIO, &arg);
setsockopt(*client, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
clients.push_back(client);
}
void net_port::tcp_close()
{
closesocket(sock);
connected = false;
}
int net_port::tcp_listen(char * recv_data, int length)
{
int ret = 0;
int len = 0;
int tot = 0;
timeval waitd;
fd_set readfd;
FD_ZERO(&readfd);
FD_SET(sock, &readfd);
if (connected)
{
while(ret != sizeof(len))
{
waitd.tv_sec = 10;
waitd.tv_usec = 0;
if (select(sock + 1, &readfd, NULL, NULL, &waitd))
{
ret = recv(sock, (char *)&len, sizeof(len), 0);
if (ret == -1 || ret == 0)
{
closesocket(sock);
connected = false;
return(0);
}
}
else
{
closesocket(sock);
connected = false;
return(0);
}
}
ret = 0;
while(tot != len)
{
waitd.tv_sec = 10;
waitd.tv_usec = 0;
if (select(sock + 1, &readfd, NULL, NULL, &waitd))
{
ret = recv(sock, recv_data + ret, len - ret, 0);
if (ret == -1 || ret == 0)
{
closesocket(sock);
connected = false;
return(0);
}
tot += ret;
}
else
{
closesocket(sock);
connected = false;
return(0);
}
}
}
return(ret);
}
int net_port::tcp_client_write(char * buffer, int length)
{
return(send(sock, buffer, length, 0));
}
int net_port::tcp_write(char * buffer, int length)
{