-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit amended for code style by Adam Honse <[email protected]>
- Loading branch information
1 parent
4b9fa42
commit aea555c
Showing
6 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
Controllers/DygmaRaiseController/DygmaRaiseControllerDetect.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.