From aea555c3c9781ea52ce5cab3c6544619305c05c5 Mon Sep 17 00:00:00 2001 From: eispalast Date: Sun, 19 Dec 2021 21:42:30 +0000 Subject: [PATCH] Added support for the Dygma Raise Commit amended for code style by Adam Honse --- .../DygmaRaiseController.cpp | 97 +++++++ .../DygmaRaiseController.h | 36 +++ .../DygmaRaiseControllerDetect.cpp | 39 +++ .../RGBController_DygmaRaise.cpp | 249 ++++++++++++++++++ .../RGBController_DygmaRaise.h | 31 +++ OpenRGB.pro | 6 + 6 files changed, 458 insertions(+) create mode 100644 Controllers/DygmaRaiseController/DygmaRaiseController.cpp create mode 100644 Controllers/DygmaRaiseController/DygmaRaiseController.h create mode 100644 Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp create mode 100644 Controllers/DygmaRaiseController/RGBController_DygmaRaise.cpp create mode 100644 Controllers/DygmaRaiseController/RGBController_DygmaRaise.h diff --git a/Controllers/DygmaRaiseController/DygmaRaiseController.cpp b/Controllers/DygmaRaiseController/DygmaRaiseController.cpp new file mode 100644 index 000000000..38292801a --- /dev/null +++ b/Controllers/DygmaRaiseController/DygmaRaiseController.cpp @@ -0,0 +1,97 @@ +/*-----------------------------------------*\ +| DygmaRaiseController.cpp | +| | +| Driver for Dygma Raise keyboard | +| | +| Timo Schlegel (@eispalast) 12/12/2021 | +\*-----------------------------------------*/ + +#include "DygmaRaiseController.h" + +using namespace std::chrono_literals; + +static int val_char_len(int number) +{ + if(number < 10) + { + return 1; + } + else if + (number < 100) + { + return 2; + } + else + { + return 3; + } +} + +DygmaRaiseController::DygmaRaiseController() +{ + +} + +DygmaRaiseController::~DygmaRaiseController() +{ + serialport->serial_close(); + delete serialport; +} + +void DygmaRaiseController::Initialize(char* port) +{ + port_name = port; + + serialport = new serial_port(port_name.c_str(), DYGMA_RAISE_BAUD); +} + +std::string DygmaRaiseController::GetDeviceLocation() +{ + return("COM: " + port_name); +} + +void DygmaRaiseController::SendDirect(std::vectorcolors, size_t led_num) +{ + char serial_buf[MAX_LEN]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(serial_buf,0x00,sizeof(serial_buf)); + + /*-----------------------------------------------------*\ + | Set up led theme packet | + \*-----------------------------------------------------*/ + sprintf(serial_buf,"led.theme"); + int actual_length=9; + + /*-----------------------------------------------------*\ + | Fill packet with color values | + \*-----------------------------------------------------*/ + for(std::size_t led_idx = 0; led_idx < led_num; led_idx++) + { + int r = RGBGetRValue(colors[led_idx]); + int g = RGBGetGValue(colors[led_idx]); + int b = RGBGetBValue(colors[led_idx]); + + sprintf(serial_buf+actual_length," %d",r); + actual_length += val_char_len(r) + 1; + + sprintf(serial_buf+actual_length," %d",g); + actual_length += val_char_len(g) + 1; + + sprintf(serial_buf+actual_length," %d",b); + actual_length += val_char_len(b) + 1; + } + + /*-----------------------------------------------------*\ + | Add the final newline | + \*-----------------------------------------------------*/ + sprintf(serial_buf+actual_length,"\n"); + actual_length++; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + serialport->serial_write(serial_buf, actual_length); +} diff --git a/Controllers/DygmaRaiseController/DygmaRaiseController.h b/Controllers/DygmaRaiseController/DygmaRaiseController.h new file mode 100644 index 000000000..d0348cead --- /dev/null +++ b/Controllers/DygmaRaiseController/DygmaRaiseController.h @@ -0,0 +1,36 @@ +/*-----------------------------------------*\ +| DygmaRaiseController.h | +| | +| Driver for Dygma Raise keyboard | +| | +| Timo Schlegel (@eispalast) 12/12/2021 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include +#include +#include "serial_port.h" + +#pragma once + +#define DYGMA_RAISE_VID 0x1209 +#define DYGMA_RAISE_PID 0x2201 + +#define DYGMA_RAISE_BAUD 115200 +#define MAX_LEN (4*3*132+9) //max. 4 Bytes per led channel * 3 channels * 132 leds + codeword led.theme + +class DygmaRaiseController +{ +public: + DygmaRaiseController(); + ~DygmaRaiseController(); + + void Initialize(char* port); + std::string GetDeviceLocation(); + void SendDirect(std::vectorcolors, size_t led_num); +private: + std::string location; + std::string port_name; + serial_port * serialport = nullptr; +}; \ No newline at end of file diff --git a/Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp b/Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp new file mode 100644 index 000000000..109a9c15b --- /dev/null +++ b/Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp @@ -0,0 +1,39 @@ +#include "Detector.h" +#include "DygmaRaiseController.h" +#include "RGBController.h" +#include "RGBController_DygmaRaise.h" +#include "find_usb_serial_port.h" +#include +#include + + +#define DYGMA_RAISE_VID 0x1209 +#define DYGMA_RAISE_PID 0x2201 + +/******************************************************************************************\ +* * +* DetectDygmaRaiseControllers * +* * +* Tests the USB address to see if a DygmaRaise keyboard exists there. * +* Then opens a serial port to communicate with the KB * +* * +\******************************************************************************************/ + +void DetectDygmaRaiseControllers(std::vector &rgb_controllers) +{ + std::vector ports = find_usb_serial_port(DYGMA_RAISE_VID, DYGMA_RAISE_PID); + + for(std::size_t i = 0; i < ports.size(); i++) + { + if(*ports[i] != "") + { + DygmaRaiseController* controller = new DygmaRaiseController(); + new_dygmaraise->Initialize((char *)ports[i]->c_str()); + + RGBController_DygmaRaise* rgb_controller = new RGBController_DygmaRaise(new_dygmaraise); + rgb_controllers.push_back(new_controller); + } + } +} + +REGISTER_DETECTOR("Dygma Raise", DetectDygmaRaiseControllers); diff --git a/Controllers/DygmaRaiseController/RGBController_DygmaRaise.cpp b/Controllers/DygmaRaiseController/RGBController_DygmaRaise.cpp new file mode 100644 index 000000000..5e7b8f3bb --- /dev/null +++ b/Controllers/DygmaRaiseController/RGBController_DygmaRaise.cpp @@ -0,0 +1,249 @@ +/*-----------------------------------------*\ +| RGBController_DygmaRaise.cpp | +| | +| RGB Interface DygmaRaise keyboard | +| | +| Timo Schlegel (@eispalast) 12/12/2021 | +\*-----------------------------------------*/ + +#include "RGBController_DygmaRaise.h" + +#define NA 0xFFFFFFFF +#define LED_REAL_COUNT ((6*14)+(12*14)) +#define LED_COUNT (LED_REAL_COUNT - 121) + +static unsigned int kb_matrix_map_ISO[6][14] = + { { 0, 1, 2, 3, 4, 5, 6, 39, 38, 37, 36, 35, 34, 33 }, + { 7, 8, 9, 10, 11, 12, 47, 46, 45, 44, 43, 42, 41, 40 }, + { 13, 14, 15, 16, 17, 18, 54, 53, 52, 51, 50, 49, 48, NA }, + { 19, 20, 21, 22, 23, 24, 25, 60, 59, 58, 57, 56, 55, NA }, + { 26, 27, 28, NA, 29, 30, NA, 66, 65, NA, 64, 63, 62, 61 }, + { NA, NA, NA, NA, 31, 32, NA, 68, 67, NA, NA, NA, NA, NA } }; + +static unsigned int underglow_matrix[11][14] = + { { 2, 3 , 4, 5 , 6 , 7, NA, 38, 37, 36, 35, 34, 33, 32}, + { 1, NA, NA, NA, NA, 8, NA, 39, NA, NA, NA, NA, NA, 31 }, + { 0, NA, NA, NA, NA, 9, NA, 40, NA, NA, NA, NA, NA, 30 }, + { 29, NA, NA, NA, NA, 10,NA, 41, NA, NA, NA, NA, NA, 61 }, + { 28, NA, NA, NA, NA, 11,NA, 42, NA, NA, NA, NA, NA, 60 }, + { 27, NA, NA, NA, NA, 12,NA, 43, NA, NA, NA, NA, NA, 59 }, + { 26, NA, NA, NA, NA, 13,NA, 44, NA, NA, NA, NA, NA, 58 }, + { 25, NA, NA, NA, NA, 14,NA, 45, NA, NA, NA, NA, NA, 57 }, + { 24, NA, NA, NA, NA, 15,NA, 46, NA, NA, NA, NA, NA, 56 }, + { 23, NA, NA, NA, NA, 16,NA, 47, NA, NA, NA, NA, NA, 55 }, + { 22, 21, 20, 19, 18, 17,NA, 48,49,50,51,52,53, 54, }}; + + +static const char* zone_names[] = +{ + "Keyboard", + "Underglow", + "Neuron", +}; + +static zone_type zone_types[] = +{ + ZONE_TYPE_MATRIX, + ZONE_TYPE_MATRIX, + ZONE_TYPE_SINGLE, +}; + +static const unsigned int zone_sizes[] = +{ + 69, + 62, + 1, +}; + +static const char* led_names[] = +{ + "Key: Escape", + "Key: 1", + "Key: 2", + "Key: 3", + "Key: 4", + "Key: 5", + "Key: 6", + "Key: Tab", + "Key: Q", + "Key: W", + "Key: E", + "Key: R", + "Key: T", + "Key: Caps Lock", + "Key: A", + "Key: S", + "Key: D", + "Key: F", + "Key: G", + "Key: Left Shift", + "Key: \\ (ISO)", + "Key: Z", + "Key: X", + "Key: C", + "Key: V", + "Key: B", + "Key: Left Control", + "Key: Left Windows", + "Key: Left Alt", + "Key: T1", + "Key: T2", + "Key: T3", + "Key: T4", + "Key: Backspace", + "Key: =", + "Key: -", + "Key: 0", + "Key: 9", + "Key: 8", + "Key: 7", + "Key: Enter", + "Key: ]", + "Key: [", + "Key: P", + "Key: O", + "Key: I", + "Key: U", + "Key: Y", + "Key: #", + "Key: '", + "Key: ;", + "Key: L", + "Key: K", + "Key: J", + "Key: H", + "Key: Right Shift", + "Key: /", + "Key: .", + "Key: ,", + "Key: M", + "Key: N", + "Key: Right Control", + "Key: Right Windows", + "Key: Right Fn", + "Key: Right Alt", + "Key: T6", + "Key: T5", + "Key: T8", + "Key: T7", +}; + +RGBController_DygmaRaise::RGBController_DygmaRaise(DygmaRaiseController* controller_ptr) +{ + controller = controller_ptr; + + name = "Raise"; + vendor = "Dygma"; + type = DEVICE_TYPE_KEYBOARD; + description = "Dygma Raise Split Mech KB"; + location = controller->GetDeviceLocation(); + + 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_DygmaRaise::~RGBController_DygmaRaise() +{ + delete controller; +} + +void RGBController_DygmaRaise::SetupZones() +{ + /*---------------------------------------------------------*\ + | Set up zones | + \*---------------------------------------------------------*/ + for(size_t i=0; i<3; i++) + { + zone new_zone; + new_zone.name = zone_names[i]; + new_zone.type = zone_types[i]; + new_zone.leds_min = zone_sizes[i]; + new_zone.leds_max = zone_sizes[i]; + new_zone.leds_count = zone_sizes[i]; + + if(i==0) + { + new_zone.matrix_map = new matrix_map_type; + new_zone.matrix_map->height = 6; + new_zone.matrix_map->width = 14; + new_zone.matrix_map->map = (unsigned int *)&kb_matrix_map_ISO; + } + else if(i==1) + { + new_zone.matrix_map = new matrix_map_type; + new_zone.matrix_map->height = 11; + new_zone.matrix_map->width = 14; + new_zone.matrix_map->map = (unsigned int *)&underglow_matrix; + } + + zones.push_back(new_zone); + } + + /*---------------------------------------------------------*\ + | Set up keyboard LEDs | + \*---------------------------------------------------------*/ + for(unsigned int led_idx = 0; led_idx < zone_sizes[0]; led_idx++) + { + led new_led; + new_led.name = led_names[led_idx]; + leds.push_back(new_led); + } + + /*---------------------------------------------------------*\ + | Set up underglow LEDs | + \*---------------------------------------------------------*/ + for(unsigned int led_idx = 0; led_idx < zone_sizes[1]; led_idx++) + { + led new_led; + new_led.name = "Underglow"; + leds.push_back(new_led); + } + + /*---------------------------------------------------------*\ + | Set up Neuron LED | + \*---------------------------------------------------------*/ + led new_led; + new_led.name = "Neuron"; + leds.push_back(new_led); + + SetupColors(); +} + +void RGBController_DygmaRaise::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + + +void RGBController_DygmaRaise::DeviceUpdateLEDs() +{ + controller->SendDirect(colors,leds.size()); +} + +void RGBController_DygmaRaise::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_DygmaRaise::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_DygmaRaise::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_DygmaRaise::DeviceUpdateMode() +{ + +} diff --git a/Controllers/DygmaRaiseController/RGBController_DygmaRaise.h b/Controllers/DygmaRaiseController/RGBController_DygmaRaise.h new file mode 100644 index 000000000..9f14a1bdc --- /dev/null +++ b/Controllers/DygmaRaiseController/RGBController_DygmaRaise.h @@ -0,0 +1,31 @@ +/*-----------------------------------------*\ +| RGBController_DygmaRaise.h | +| | +| RGB Interface for DygmaRaise keyboard | +| | +| Timo Schlegel (@eispalast) 12/12/2021 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "DygmaRaiseController.h" + +class RGBController_DygmaRaise : public RGBController +{ +public: + RGBController_DygmaRaise(DygmaRaiseController* controller_ptr); + ~RGBController_DygmaRaise(); + + void SetupZones(); + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + DygmaRaiseController* controller; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index 88d57fd3e..858d0449c 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -94,6 +94,7 @@ INCLUDEPATH += Controllers/DasKeyboardController/ \ Controllers/DebugController/ \ Controllers/DuckyKeyboardController/ \ + Controllers/DygmaRaiseController/ \ Controllers/E131Controller/ \ Controllers/EKController/ \ Controllers/ENESMBusController/ \ @@ -284,6 +285,8 @@ HEADERS += Controllers/DasKeyboardController/RGBController_DasKeyboard.h \ Controllers/DuckyKeyboardController/DuckyKeyboardController.h \ Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.h \ + Controllers/DygmaRaiseController/DygmaRaiseController.h \ + Controllers/DygmaRaiseController/RGBController_DygmaRaise.h \ Controllers/DebugController/RGBController_Debug.h \ Controllers/E131Controller/RGBController_E131.h \ Controllers/EKController/EKController.h \ @@ -668,6 +671,9 @@ SOURCES += Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp \ Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.cpp \ Controllers/DebugController/RGBController_Debug.cpp \ + Controllers/DygmaRaiseController/DygmaRaiseController.cpp \ + Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp \ + Controllers/DygmaRaiseController/RGBController_DygmaRaise.cpp \ Controllers/E131Controller/E131ControllerDetect.cpp \ Controllers/E131Controller/RGBController_E131.cpp \ Controllers/EKController/EKControllerDetect.cpp \