Skip to content

Commit

Permalink
Added support for the Dygma Raise
Browse files Browse the repository at this point in the history
Commit amended for code style by Adam Honse <calcprogrammer1@gmail.com>
  • Loading branch information
eispalast authored and CalcProgrammer1 committed Dec 19, 2021
1 parent 4b9fa42 commit aea555c
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 0 deletions.
97 changes: 97 additions & 0 deletions Controllers/DygmaRaiseController/DygmaRaiseController.cpp
Original file line number Diff line number Diff line change
@@ -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::vector<RGBColor>colors, 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);
}
36 changes: 36 additions & 0 deletions Controllers/DygmaRaiseController/DygmaRaiseController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*-----------------------------------------*\
| DygmaRaiseController.h |
| |
| Driver for Dygma Raise keyboard |
| |
| Timo Schlegel (@eispalast) 12/12/2021 |
\*-----------------------------------------*/

#pragma once
#include "RGBController.h"
#include <string>
#include <vector>
#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::vector<RGBColor>colors, size_t led_num);
private:
std::string location;
std::string port_name;
serial_port * serialport = nullptr;
};
39 changes: 39 additions & 0 deletions Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Detector.h"
#include "DygmaRaiseController.h"
#include "RGBController.h"
#include "RGBController_DygmaRaise.h"
#include "find_usb_serial_port.h"
#include <vector>
#include <stdio.h>


#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<RGBController*> &rgb_controllers)
{
std::vector<std::string *> 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);

0 comments on commit aea555c

Please sign in to comment.