Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| AnnePro2Controller.cpp |
|
||||
| |
|
||||
| Driver for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06 Jun 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "AnnePro2Controller.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
AnnePro2Controller::AnnePro2Controller(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
AnnePro2Controller::~AnnePro2Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string AnnePro2Controller::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string AnnePro2Controller::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
void AnnePro2Controller::SendDirect(unsigned char frame_count, unsigned char * frame_data)
|
||||
{
|
||||
/*-------------------------------------------------------------*\
|
||||
| Reverse engineered by https://github.com/manualmanul/Annemone |
|
||||
\*-------------------------------------------------------------*/
|
||||
|
||||
const unsigned char hid_cmd_service_data_length = 4;
|
||||
const unsigned char hid_cmd_service_data[hid_cmd_service_data_length] = {0, 123, 16, 65};
|
||||
|
||||
const unsigned char hid_cmd_static_message_length = 3;
|
||||
const unsigned char hid_cmd_static_message[hid_cmd_static_message_length] = {0, 0, 125};
|
||||
|
||||
const unsigned char hid_cmd_command_info_length = 3;
|
||||
const unsigned char hid_cmd_command_info[hid_cmd_command_info_length] = {32, 3, 255};
|
||||
|
||||
const unsigned char real_command_info_length = hid_cmd_command_info_length + 1;
|
||||
const unsigned char max_hid_length = 64;
|
||||
|
||||
const unsigned char max_command_length = max_hid_length - hid_cmd_service_data_length - 2 - hid_cmd_static_message_length;
|
||||
const unsigned char max_message_length = max_command_length - real_command_info_length;
|
||||
const unsigned char messages_to_send_amount = frame_count / max_message_length + 1;
|
||||
const unsigned char val_1 = frame_count % max_message_length;
|
||||
const unsigned char val_2 = (0 == val_1) ? max_message_length : val_1;
|
||||
|
||||
unsigned char hid_command[max_hid_length];
|
||||
|
||||
unsigned char led_data = 0;
|
||||
|
||||
for(unsigned char p = 0; p < messages_to_send_amount; p++)
|
||||
{
|
||||
const unsigned char e = (messages_to_send_amount << 4) + p;
|
||||
const unsigned char a = ((messages_to_send_amount - 1) == p) ? val_2 + real_command_info_length : max_message_length + real_command_info_length;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Service data |
|
||||
\*---------------------------------------------------------*/
|
||||
hid_command[0] = hid_cmd_service_data[0];
|
||||
hid_command[1] = hid_cmd_service_data[1];
|
||||
hid_command[2] = hid_cmd_service_data[2];
|
||||
hid_command[3] = hid_cmd_service_data[3];
|
||||
|
||||
hid_command[4] = e;
|
||||
hid_command[5] = a;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Static message |
|
||||
\*---------------------------------------------------------*/
|
||||
hid_command[6] = hid_cmd_static_message[0];
|
||||
hid_command[7] = hid_cmd_static_message[1];
|
||||
hid_command[8] = hid_cmd_static_message[2];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Command info |
|
||||
\*---------------------------------------------------------*/
|
||||
hid_command[9] = hid_cmd_command_info[0];
|
||||
hid_command[10] = hid_cmd_command_info[1];
|
||||
hid_command[11] = hid_cmd_command_info[2];
|
||||
|
||||
hid_command[12] = 2;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| LED data |
|
||||
\*---------------------------------------------------------*/
|
||||
for(uint8_t i = 0; i < max_message_length; i++)
|
||||
{
|
||||
hid_command[13 + i] = frame_data[led_data];
|
||||
led_data++;
|
||||
}
|
||||
|
||||
hid_write(dev, hid_command, max_hid_length);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Needed due to Anne Pro 2 ignoring commands when they're |
|
||||
| sent faster than 50ms apart from each other. |
|
||||
\*---------------------------------------------------------*/
|
||||
std::this_thread::sleep_for(50ms);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| AnnePro2Controller.h |
|
||||
| |
|
||||
| Driver for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06 Jun 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
class AnnePro2Controller
|
||||
{
|
||||
public:
|
||||
AnnePro2Controller(hid_device* dev_handle, const char* path);
|
||||
~AnnePro2Controller();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char frame_count,
|
||||
unsigned char * frame_data
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| AnnePro2ControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06 Jun 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "Detector.h"
|
||||
#include "AnnePro2Controller.h"
|
||||
#include "RGBController_AnnePro2.h"
|
||||
#include <hidapi.h>
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Anne Pro 2 vendor IDs |
|
||||
\*---------------------------------------------------------*/
|
||||
#define ANNE_PRO_2_VID_1 0x04D9
|
||||
#define ANNE_PRO_2_VID_2 0x3311
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Anne Pro 2 product IDs |
|
||||
\*---------------------------------------------------------*/
|
||||
#define ANNE_PRO_2_PID_1 0x8008
|
||||
#define ANNE_PRO_2_PID_2 0x8009
|
||||
#define ANNE_PRO_2_PID_3 0xA292
|
||||
#define ANNE_PRO_2_PID_4 0xA293
|
||||
#define ANNE_PRO_2_PID_5 0xA297
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAnnePro2Controllers *
|
||||
* *
|
||||
* Tests the USB address to see if an Obins Lab AnnePro2 keyboard exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAnnePro2Controllers(hid_device_info* info, const std::string&)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
AnnePro2Controller* controller = new AnnePro2Controller(dev, info->path);
|
||||
RGBController_AnnePro2* rgb_controller = new RGBController_AnnePro2(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID_1, ANNE_PRO_2_PID_1, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID_1, ANNE_PRO_2_PID_2, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID_1, ANNE_PRO_2_PID_3, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID_1, ANNE_PRO_2_PID_4, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID_2, ANNE_PRO_2_PID_5, 1);
|
||||
@@ -0,0 +1,244 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_AnnePro2.cpp |
|
||||
| |
|
||||
| RGBController for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06 Jun 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBControllerKeyNames.h"
|
||||
#include "RGBController_AnnePro2.h"
|
||||
|
||||
#define NA 0xFFFFFFFF
|
||||
#define LED_REAL_COUNT (5*14)
|
||||
#define LED_COUNT (LED_REAL_COUNT - 9)
|
||||
|
||||
static unsigned int matrix_map[5][14] =
|
||||
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
|
||||
{ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 },
|
||||
{ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, NA },
|
||||
{ 41, NA, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, NA },
|
||||
{ 53, NA, 54, 55, NA, NA, 56, NA, NA, 57, 58, 59, 60, NA } };
|
||||
|
||||
static const char* zone_names[] =
|
||||
{
|
||||
ZONE_EN_KEYBOARD,
|
||||
};
|
||||
|
||||
static zone_type zone_types[] =
|
||||
{
|
||||
ZONE_TYPE_MATRIX
|
||||
};
|
||||
|
||||
static const unsigned int zone_sizes[] =
|
||||
{
|
||||
LED_COUNT,
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char * name;
|
||||
const unsigned char idx;
|
||||
} annepro2_led_type;
|
||||
|
||||
static const annepro2_led_type led_names[] =
|
||||
{
|
||||
/* Key Label Index */
|
||||
{ KEY_EN_ESCAPE, 0 },
|
||||
{ KEY_EN_1, 1 },
|
||||
{ KEY_EN_2, 2 },
|
||||
{ KEY_EN_3, 3 },
|
||||
{ KEY_EN_4, 4 },
|
||||
{ KEY_EN_5, 5 },
|
||||
{ KEY_EN_6, 6 },
|
||||
{ KEY_EN_7, 7 },
|
||||
{ KEY_EN_8, 8 },
|
||||
{ KEY_EN_9, 9 },
|
||||
{ KEY_EN_0, 10 },
|
||||
{ KEY_EN_MINUS, 11 },
|
||||
{ KEY_EN_EQUALS, 12 },
|
||||
{ KEY_EN_BACKSPACE, 13 },
|
||||
{ KEY_EN_TAB, 14 },
|
||||
{ KEY_EN_Q, 15 },
|
||||
{ KEY_EN_W, 16 },
|
||||
{ KEY_EN_E, 17 },
|
||||
{ KEY_EN_R, 18 },
|
||||
{ KEY_EN_T, 19 },
|
||||
{ KEY_EN_Y, 20 },
|
||||
{ KEY_EN_U, 21 },
|
||||
{ KEY_EN_I, 22 },
|
||||
{ KEY_EN_O, 23 },
|
||||
{ KEY_EN_P, 24 },
|
||||
{ KEY_EN_LEFT_BRACKET, 25 },
|
||||
{ KEY_EN_RIGHT_BRACKET, 26 },
|
||||
{ KEY_EN_ANSI_BACK_SLASH, 27 },
|
||||
{ KEY_EN_CAPS_LOCK, 28 },
|
||||
{ KEY_EN_A, 29 },
|
||||
{ KEY_EN_S, 30 },
|
||||
{ KEY_EN_D, 31 },
|
||||
{ KEY_EN_F, 32 },
|
||||
{ KEY_EN_G, 33 },
|
||||
{ KEY_EN_H, 34 },
|
||||
{ KEY_EN_J, 35 },
|
||||
{ KEY_EN_K, 36 },
|
||||
{ KEY_EN_L, 37 },
|
||||
{ KEY_EN_SEMICOLON, 38 },
|
||||
{ KEY_EN_QUOTE, 39 },
|
||||
{ KEY_EN_ANSI_ENTER, 40 },
|
||||
{ KEY_EN_LEFT_SHIFT, 41 },
|
||||
{ KEY_EN_Z, 42 },
|
||||
{ KEY_EN_X, 43 },
|
||||
{ KEY_EN_C, 44 },
|
||||
{ KEY_EN_V, 45 },
|
||||
{ KEY_EN_B, 46 },
|
||||
{ KEY_EN_N, 47 },
|
||||
{ KEY_EN_M, 48 },
|
||||
{ KEY_EN_COMMA, 49 },
|
||||
{ KEY_EN_PERIOD, 50 },
|
||||
{ KEY_EN_FORWARD_SLASH, 51 },
|
||||
{ KEY_EN_RIGHT_SHIFT, 52 },
|
||||
{ KEY_EN_LEFT_CONTROL, 53 },
|
||||
{ KEY_EN_LEFT_WINDOWS, 54 },
|
||||
{ KEY_EN_LEFT_ALT, 55 },
|
||||
{ KEY_EN_SPACE, 56 },
|
||||
{ KEY_EN_RIGHT_ALT, 57 },
|
||||
{ KEY_EN_RIGHT_FUNCTION, 58 },
|
||||
{ KEY_EN_MENU, 59 },
|
||||
{ KEY_EN_RIGHT_CONTROL, 60 },
|
||||
};
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Anne Pro 2
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectAnnePro2Controllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_AnnePro2::RGBController_AnnePro2(AnnePro2Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = "Anne Pro 2";
|
||||
vendor = "Obinslab";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Obinslab Anne Pro 2 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_AnnePro2::~RGBController_AnnePro2()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up zones |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int total_led_count = 0;
|
||||
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
|
||||
{
|
||||
zone new_zone;
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.type = zone_types[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
|
||||
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
new_zone.matrix_map = new matrix_map_type;
|
||||
new_zone.matrix_map->height = 5;
|
||||
new_zone.matrix_map->width = 14;
|
||||
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
total_led_count += zone_sizes[zone_idx];
|
||||
}
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = led_names[led_idx].name;
|
||||
new_led.value = led_names[led_idx].idx;
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::DeviceUpdateLEDs()
|
||||
{
|
||||
const unsigned char frame_buf_length = LED_REAL_COUNT * 3;
|
||||
unsigned char frame_buf[frame_buf_length];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| TODO: Send packets with multiple LED frames |
|
||||
\*---------------------------------------------------------*/
|
||||
std::size_t led_real_idx = 0;
|
||||
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
frame_buf[(led_real_idx * 3) + 0] = RGBGetRValue(colors[led_idx]);
|
||||
frame_buf[(led_real_idx * 3) + 1] = RGBGetGValue(colors[led_idx]);
|
||||
frame_buf[(led_real_idx * 3) + 2] = RGBGetBValue(colors[led_idx]);
|
||||
|
||||
if(led_idx == 40 || led_idx == 41 || led_idx == 52 || led_idx == 53 || led_idx == 60)
|
||||
{
|
||||
led_real_idx++;
|
||||
}
|
||||
else if(led_idx == 55 || led_idx == 56)
|
||||
{
|
||||
led_real_idx++;
|
||||
led_real_idx++;
|
||||
}
|
||||
|
||||
led_real_idx++;
|
||||
}
|
||||
|
||||
controller->SendDirect(frame_buf_length, frame_buf);
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_AnnePro2.h |
|
||||
| |
|
||||
| RGBController for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06 Jun 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "AnnePro2Controller.h"
|
||||
|
||||
class RGBController_AnnePro2 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_AnnePro2(AnnePro2Controller* controller_ptr);
|
||||
~RGBController_AnnePro2();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
AnnePro2Controller* controller;
|
||||
};
|
||||
Reference in New Issue
Block a user