Skip to content

Commit 2162ff2

Browse files
eispalastCalcProgrammer1
authored andcommitted
Added support for the Dygma Raise
Commit amended for code style by Adam Honse <calcprogrammer1@gmail.com>
1 parent 4b9fa42 commit 2162ff2

6 files changed

+458
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*-----------------------------------------*\
2+
| DygmaRaiseController.cpp |
3+
| |
4+
| Driver for Dygma Raise keyboard |
5+
| |
6+
| Timo Schlegel (@eispalast) 12/12/2021 |
7+
\*-----------------------------------------*/
8+
9+
#include "DygmaRaiseController.h"
10+
11+
using namespace std::chrono_literals;
12+
13+
static int val_char_len(int number)
14+
{
15+
if(number < 10)
16+
{
17+
return 1;
18+
}
19+
else if
20+
(number < 100)
21+
{
22+
return 2;
23+
}
24+
else
25+
{
26+
return 3;
27+
}
28+
}
29+
30+
DygmaRaiseController::DygmaRaiseController()
31+
{
32+
33+
}
34+
35+
DygmaRaiseController::~DygmaRaiseController()
36+
{
37+
serialport->serial_close();
38+
delete serialport;
39+
}
40+
41+
void DygmaRaiseController::Initialize(char* port)
42+
{
43+
port_name = port;
44+
45+
serialport = new serial_port(port_name.c_str(), DYGMA_RAISE_BAUD);
46+
}
47+
48+
std::string DygmaRaiseController::GetDeviceLocation()
49+
{
50+
return("COM: " + port_name);
51+
}
52+
53+
void DygmaRaiseController::SendDirect(std::vector<RGBColor>colors, size_t led_num)
54+
{
55+
char serial_buf[MAX_LEN];
56+
57+
/*-----------------------------------------------------*\
58+
| Zero out buffer |
59+
\*-----------------------------------------------------*/
60+
memset(serial_buf,0x00,sizeof(serial_buf));
61+
62+
/*-----------------------------------------------------*\
63+
| Set up led theme packet |
64+
\*-----------------------------------------------------*/
65+
sprintf(serial_buf,"led.theme");
66+
int actual_length=9;
67+
68+
/*-----------------------------------------------------*\
69+
| Fill packet with color values |
70+
\*-----------------------------------------------------*/
71+
for(std::size_t led_idx = 0; led_idx < led_num; led_idx++)
72+
{
73+
int r = RGBGetRValue(colors[led_idx]);
74+
int g = RGBGetGValue(colors[led_idx]);
75+
int b = RGBGetBValue(colors[led_idx]);
76+
77+
sprintf(serial_buf+actual_length," %d",r);
78+
actual_length += val_char_len(r) + 1;
79+
80+
sprintf(serial_buf+actual_length," %d",g);
81+
actual_length += val_char_len(g) + 1;
82+
83+
sprintf(serial_buf+actual_length," %d",b);
84+
actual_length += val_char_len(b) + 1;
85+
}
86+
87+
/*-----------------------------------------------------*\
88+
| Add the final newline |
89+
\*-----------------------------------------------------*/
90+
sprintf(serial_buf+actual_length,"\n");
91+
actual_length++;
92+
93+
/*-----------------------------------------------------*\
94+
| Send packet |
95+
\*-----------------------------------------------------*/
96+
serialport->serial_write(serial_buf, actual_length);
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*-----------------------------------------*\
2+
| DygmaRaiseController.h |
3+
| |
4+
| Driver for Dygma Raise keyboard |
5+
| |
6+
| Timo Schlegel (@eispalast) 12/12/2021 |
7+
\*-----------------------------------------*/
8+
9+
#pragma once
10+
#include "RGBController.h"
11+
#include <string>
12+
#include <vector>
13+
#include "serial_port.h"
14+
15+
#pragma once
16+
17+
#define DYGMA_RAISE_VID 0x1209
18+
#define DYGMA_RAISE_PID 0x2201
19+
20+
#define DYGMA_RAISE_BAUD 115200
21+
#define MAX_LEN (4*3*132+9) //max. 4 Bytes per led channel * 3 channels * 132 leds + codeword led.theme
22+
23+
class DygmaRaiseController
24+
{
25+
public:
26+
DygmaRaiseController();
27+
~DygmaRaiseController();
28+
29+
void Initialize(char* port);
30+
std::string GetDeviceLocation();
31+
void SendDirect(std::vector<RGBColor>colors, size_t led_num);
32+
private:
33+
std::string location;
34+
std::string port_name;
35+
serial_port * serialport = nullptr;
36+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "Detector.h"
2+
#include "DygmaRaiseController.h"
3+
#include "RGBController.h"
4+
#include "RGBController_DygmaRaise.h"
5+
#include "find_usb_serial_port.h"
6+
#include <vector>
7+
#include <stdio.h>
8+
9+
10+
#define DYGMA_RAISE_VID 0x1209
11+
#define DYGMA_RAISE_PID 0x2201
12+
13+
/******************************************************************************************\
14+
* *
15+
* DetectDygmaRaiseControllers *
16+
* *
17+
* Tests the USB address to see if a DygmaRaise keyboard exists there. *
18+
* Then opens a serial port to communicate with the KB *
19+
* *
20+
\******************************************************************************************/
21+
22+
void DetectDygmaRaiseControllers(std::vector<RGBController*> &rgb_controllers)
23+
{
24+
std::vector<std::string *> ports = find_usb_serial_port(DYGMA_RAISE_VID, DYGMA_RAISE_PID);
25+
26+
for(std::size_t i = 0; i < ports.size(); i++)
27+
{
28+
if(*ports[i] != "")
29+
{
30+
DygmaRaiseController* controller = new DygmaRaiseController();
31+
controller->Initialize((char *)ports[i]->c_str());
32+
33+
RGBController_DygmaRaise* rgb_controller = new RGBController_DygmaRaise(controller);
34+
rgb_controllers.push_back(rgb_controller);
35+
}
36+
}
37+
}
38+
39+
REGISTER_DETECTOR("Dygma Raise", DetectDygmaRaiseControllers);

0 commit comments

Comments
 (0)