New device: Obinslab Anne Pro 2
* Renamed "Obins Lab" to "Obinslab" as that is the name that I saw used most frequently in store listings. Commit amended for code style and to update the name by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
0755959741
commit
bf99a5f250
7 changed files with 467 additions and 0 deletions
122
Controllers/AnnePro2Controller/AnnePro2Controller.cpp
Normal file
122
Controllers/AnnePro2Controller/AnnePro2Controller.cpp
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*-----------------------------------------*\
|
||||
| AnnePro2Controller.cpp |
|
||||
| |
|
||||
| Driver for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06/06/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AnnePro2Controller.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("");
|
||||
}
|
||||
|
||||
std::wstring return_wstring = serial_string;
|
||||
std::string return_string(return_wstring.begin(), return_wstring.end());
|
||||
|
||||
return(return_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);
|
||||
}
|
||||
}
|
||||
36
Controllers/AnnePro2Controller/AnnePro2Controller.h
Normal file
36
Controllers/AnnePro2Controller/AnnePro2Controller.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*-----------------------------------------*\
|
||||
| AnnePro2Controller.h |
|
||||
| |
|
||||
| Driver for Obins Lab AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06/06/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
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;
|
||||
};
|
||||
36
Controllers/AnnePro2Controller/AnnePro2ControllerDetect.cpp
Normal file
36
Controllers/AnnePro2Controller/AnnePro2ControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include "Detector.h"
|
||||
#include "AnnePro2Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AnnePro2.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define ANNE_PRO_2_VID 0x04D9
|
||||
#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
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* 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);
|
||||
// Constructor sets the name
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID, ANNE_PRO_2_PID_1, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID, ANNE_PRO_2_PID_2, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID, ANNE_PRO_2_PID_3, 1);
|
||||
REGISTER_HID_DETECTOR_I("Anne Pro 2", DetectAnnePro2Controllers, ANNE_PRO_2_VID, ANNE_PRO_2_PID_4, 1);
|
||||
235
Controllers/AnnePro2Controller/RGBController_AnnePro2.cpp
Normal file
235
Controllers/AnnePro2Controller/RGBController_AnnePro2.cpp
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_AnnePro2.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Obins Lab |
|
||||
| AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06/06/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#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[] =
|
||||
{
|
||||
"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;
|
||||
} led_type;
|
||||
|
||||
static const led_type led_names[] =
|
||||
{
|
||||
/* Key Label Index */
|
||||
{ "Key: Escape", 0 },
|
||||
{ "Key: 1", 1 },
|
||||
{ "Key: 2", 2 },
|
||||
{ "Key: 3", 3 },
|
||||
{ "Key: 4", 4 },
|
||||
{ "Key: 5", 5 },
|
||||
{ "Key: 6", 6 },
|
||||
{ "Key: 7", 7 },
|
||||
{ "Key: 8", 8 },
|
||||
{ "Key: 9", 9 },
|
||||
{ "Key: 0", 10 },
|
||||
{ "Key: -", 11 },
|
||||
{ "Key: =", 12 },
|
||||
{ "Key: Backspace", 13 },
|
||||
{ "Key: Tab", 14 },
|
||||
{ "Key: Q", 15 },
|
||||
{ "Key: W", 16 },
|
||||
{ "Key: E", 17 },
|
||||
{ "Key: R", 18 },
|
||||
{ "Key: T", 19 },
|
||||
{ "Key: Y", 20 },
|
||||
{ "Key: U", 21 },
|
||||
{ "Key: I", 22 },
|
||||
{ "Key: O", 23 },
|
||||
{ "Key: P", 24 },
|
||||
{ "Key: [", 25 },
|
||||
{ "Key: ]", 26 },
|
||||
{ "Key: \\ (ANSI)", 27 },
|
||||
{ "Key: Caps Lock", 28 },
|
||||
{ "Key: A", 29 },
|
||||
{ "Key: S", 30 },
|
||||
{ "Key: D", 31 },
|
||||
{ "Key: F", 32 },
|
||||
{ "Key: G", 33 },
|
||||
{ "Key: H", 34 },
|
||||
{ "Key: J", 35 },
|
||||
{ "Key: K", 36 },
|
||||
{ "Key: L", 37 },
|
||||
{ "Key: ;", 38 },
|
||||
{ "Key: '", 39 },
|
||||
{ "Key: Enter", 40 },
|
||||
{ "Key: Left Shift", 41 },
|
||||
{ "Key: Z", 42 },
|
||||
{ "Key: X", 43 },
|
||||
{ "Key: C", 44 },
|
||||
{ "Key: V", 45 },
|
||||
{ "Key: B", 46 },
|
||||
{ "Key: N", 47 },
|
||||
{ "Key: M", 48 },
|
||||
{ "Key: ,", 49 },
|
||||
{ "Key: .", 50 },
|
||||
{ "Key: /", 51 },
|
||||
{ "Key: Right Shift", 52 },
|
||||
{ "Key: Left Control", 53 },
|
||||
{ "Key: Left Windows", 54 },
|
||||
{ "Key: Left Alt", 55 },
|
||||
{ "Key: Space", 56 },
|
||||
{ "Key: Right Alt", 57 },
|
||||
{ "Key: Right Fn", 58 },
|
||||
{ "Key: Menu", 59 },
|
||||
{ "Key: Right Control", 60 },
|
||||
};
|
||||
|
||||
RGBController_AnnePro2::RGBController_AnnePro2(AnnePro2Controller* annepro2_ptr)
|
||||
{
|
||||
annepro2 = annepro2_ptr;
|
||||
|
||||
name = "Anne Pro 2";
|
||||
vendor = "Obinslab";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Obinslab Anne Pro 2 Device";
|
||||
location = annepro2->GetDeviceLocation();
|
||||
serial = annepro2->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 annepro2;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
annepro2->SendDirect(frame_buf_length, frame_buf);
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_AnnePro2::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
32
Controllers/AnnePro2Controller/RGBController_AnnePro2.h
Normal file
32
Controllers/AnnePro2Controller/RGBController_AnnePro2.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_AnnePro2.h |
|
||||
| |
|
||||
| Generic RGB Interface for Obins Lab |
|
||||
| AnnePro2 keyboard |
|
||||
| |
|
||||
| Sergey Gavrilov (DrZlo13) 06/06/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "AnnePro2Controller.h"
|
||||
|
||||
class RGBController_AnnePro2 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_AnnePro2(AnnePro2Controller* annepro2_ptr);
|
||||
~RGBController_AnnePro2();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
AnnePro2Controller* annepro2;
|
||||
};
|
||||
|
|
@ -173,6 +173,8 @@ HEADERS +=
|
|||
super_io/super_io.h \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismController.h \
|
||||
Controllers/AMDWraithPrismController/RGBController_AMDWraithPrism.h \
|
||||
Controllers/AnnePro2Controller/AnnePro2Controller.h \
|
||||
Controllers/AnnePro2Controller/RGBController_AnnePro2.h \
|
||||
Controllers/ASRockPolychromeSMBusController/ASRockPolychromeSMBusController.h \
|
||||
Controllers/ASRockPolychromeSMBusController/RGBController_ASRockPolychromeSMBus.h \
|
||||
Controllers/ASRockPolychromeUSBController/ASRockPolychromeUSBController.h \
|
||||
|
|
@ -448,6 +450,9 @@ SOURCES +=
|
|||
Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismControllerDetect.cpp \
|
||||
Controllers/AMDWraithPrismController/RGBController_AMDWraithPrism.cpp \
|
||||
Controllers/AnnePro2Controller/AnnePro2Controller.cpp \
|
||||
Controllers/AnnePro2Controller/AnnePro2ControllerDetect.cpp \
|
||||
Controllers/AnnePro2Controller/RGBController_AnnePro2.cpp \
|
||||
Controllers/ASRockPolychromeSMBusController/ASRockPolychromeSMBusController.cpp \
|
||||
Controllers/ASRockPolychromeSMBusController/ASRockPolychromeSMBusControllerDetect.cpp \
|
||||
Controllers/ASRockPolychromeSMBusController/RGBController_ASRockPolychromeSMBus.cpp \
|
||||
|
|
|
|||
|
|
@ -218,3 +218,4 @@ While no code from these projects directly made its way into OpenRGB, these proj
|
|||
* VRMTool: https://github.com/rbrune/VRMtool
|
||||
* g810-led: https://github.com/MatMoul/g810-led
|
||||
* liquidctl: https://github.com/jonasmalacofilho/liquidctl
|
||||
* Annemone: https://github.com/manualmanul/Annemone
|
||||
Loading…
Add table
Add a link
Reference in a new issue