Initial implementation of Zalman Z Sync controller

This commit is contained in:
Adam Honse 2021-01-31 00:33:51 -06:00
parent a00c259b96
commit 578157f44d
6 changed files with 287 additions and 0 deletions

View file

@ -0,0 +1,95 @@
/*-----------------------------------------*\
| RGBController_ZalmanZSync.cpp |
| |
| Generic RGB Interface for Zalman Z Sync |
| lighting devices |
| |
| Adam Honse (CalcProgrammer1) 1/30/2021 |
\*-----------------------------------------*/
#include "RGBController_ZalmanZSync.h"
RGBController_ZalmanZSync::RGBController_ZalmanZSync(ZalmanZSyncController* controller_ptr)
{
controller = controller_ptr;
type = DEVICE_TYPE_LEDSTRIP;
name = "Zalman Z Sync Device";
description = "Zalman Z Sync Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
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();
}
RGBController_ZalmanZSync::~RGBController_ZalmanZSync()
{
}
void RGBController_ZalmanZSync::SetupZones()
{
for(unsigned int zone_idx = 0; zone_idx < 8; zone_idx++)
{
zone new_zone;
new_zone.name = "Channel " + std::to_string(zone_idx + 1);
new_zone.type = ZONE_TYPE_LINEAR;
new_zone.leds_min = 24;
new_zone.leds_max = 24;
new_zone.leds_count = 24;
new_zone.matrix_map = NULL;
zones.push_back(new_zone);
for(unsigned int led_idx = 0; led_idx < 24; led_idx++)
{
led new_led;
new_led.name = "LED " + std::to_string(led_idx + 1);
leds.push_back(new_led);
}
}
SetupColors();
}
void RGBController_ZalmanZSync::ResizeZone(int zone, int new_size)
{
}
void RGBController_ZalmanZSync::DeviceUpdateLEDs()
{
for(unsigned int zone_idx = 0; zone_idx < 8; zone_idx++)
{
controller->SetLEDs(zone_idx, zones[zone_idx].colors);
}
}
void RGBController_ZalmanZSync::UpdateZoneLEDs(int zone)
{
controller->SetLEDs(zone, zones[zone].colors);
}
void RGBController_ZalmanZSync::UpdateSingleLED(int led)
{
DeviceUpdateLEDs();
}
void RGBController_ZalmanZSync::SetCustomMode()
{
}
void RGBController_ZalmanZSync::DeviceUpdateMode()
{
}

View file

@ -0,0 +1,33 @@
/*-----------------------------------------*\
| RGBController_ZalmanZSync.h |
| |
| Generic RGB Interface for Zalman Z Sync |
| lighting devices |
| |
| Adam Honse (CalcProgrammer1) 1/30/2021 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "ZalmanZSyncController.h"
class RGBController_ZalmanZSync : public RGBController
{
public:
RGBController_ZalmanZSync(ZalmanZSyncController* controller_ptr);
~RGBController_ZalmanZSync();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
ZalmanZSyncController* controller;
};

View file

@ -0,0 +1,80 @@
#include "ZalmanZSyncController.h"
ZalmanZSyncController::ZalmanZSyncController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
}
ZalmanZSyncController::~ZalmanZSyncController()
{
}
std::string ZalmanZSyncController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string ZalmanZSyncController::GetSerialString()
{
return("");
}
void ZalmanZSyncController::SetLEDs(unsigned char channel, RGBColor* colors)
{
SendDirectFrame(channel, ZALMAN_Z_SYNC_COLOR_CHANNEL_RED, colors);
SendDirectFrame(channel, ZALMAN_Z_SYNC_COLOR_CHANNEL_GREEN, colors);
SendDirectFrame(channel, ZALMAN_Z_SYNC_COLOR_CHANNEL_BLUE, colors);
SendApply();
}
void ZalmanZSyncController::SendApply()
{
unsigned char usb_buf[65];
usb_buf[0] = 0x00;
usb_buf[1] = 0x33;
usb_buf[2] = 0xFF;
hid_write(dev, usb_buf, 65);
}
void ZalmanZSyncController::SendDirectFrame(unsigned char channel, unsigned char color_channel, RGBColor* colors)
{
unsigned char usb_buf[65];
usb_buf[0] = 0x00;
usb_buf[1] = 0x32;
usb_buf[2] = channel;
usb_buf[3] = 0x00;
usb_buf[4] = 0x18;
usb_buf[5] = color_channel;
switch(color_channel)
{
case ZALMAN_Z_SYNC_COLOR_CHANNEL_RED:
for(unsigned int color_idx = 0; color_idx < 24; color_idx++)
{
usb_buf[6 + color_idx] = RGBGetRValue(colors[color_idx]);
}
break;
case ZALMAN_Z_SYNC_COLOR_CHANNEL_GREEN:
for(unsigned int color_idx = 0; color_idx < 24; color_idx++)
{
usb_buf[6 + color_idx] = RGBGetGValue(colors[color_idx]);
}
break;
case ZALMAN_Z_SYNC_COLOR_CHANNEL_BLUE:
for(unsigned int color_idx = 0; color_idx < 24; color_idx++)
{
usb_buf[6 + color_idx] = RGBGetBValue(colors[color_idx]);
}
break;
}
hid_write(dev, usb_buf, 65);
}

View file

@ -0,0 +1,41 @@
/*-----------------------------------------*\
| ZalmanZSyncController.h |
| |
| Definitions and types for Zalman Z Sync |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 1/30/2021 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
ZALMAN_Z_SYNC_COLOR_CHANNEL_RED = 0x00,
ZALMAN_Z_SYNC_COLOR_CHANNEL_GREEN = 0x01,
ZALMAN_Z_SYNC_COLOR_CHANNEL_BLUE = 0x02,
};
class ZalmanZSyncController
{
public:
ZalmanZSyncController(hid_device* dev_handle, const char* path);
~ZalmanZSyncController();
std::string GetDeviceLocation();
std::string GetSerialString();
void SetLEDs(unsigned char channel, RGBColor* colors);
private:
hid_device* dev;
std::string location;
void SendApply();
void SendDirectFrame(unsigned char channel, unsigned char color_channel, RGBColor* colors);
};

View file

@ -0,0 +1,32 @@
#include "Detector.h"
#include "ZalmanZSyncController.h"
#include "RGBController.h"
#include "RGBController_ZalmanZSync.h"
#include <vector>
#include <hidapi/hidapi.h>
#define ZALMAN_VID 0x1C57
#define ZALMAN_Z_SYNC_PID 0x7ED0
/******************************************************************************************\
* *
* DetectZalmanZSyncControllers *
* *
* Detect devices supported by the Zalman Z Sync driver *
* *
\******************************************************************************************/
void DetectZalmanZSyncControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if( dev )
{
ZalmanZSyncController* controller = new ZalmanZSyncController(dev, info->path);
RGBController_ZalmanZSync* rgb_controller = new RGBController_ZalmanZSync(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectZalmanZSyncControllers() */
REGISTER_HID_DETECTOR("Zalman Z Sync", DetectZalmanZSyncControllers, ZALMAN_VID, ZALMAN_Z_SYNC_PID);