chuniio: Add OpeNITHM LED protocol support #26

Merged
Dniel97 merged 3 commits from d4nin3u/segatools:develop into develop 2024-08-06 21:35:52 +00:00
9 changed files with 42 additions and 71 deletions
Showing only changes of commit 960bef65dd - Show all commits

View File

@ -19,7 +19,6 @@ static uint8_t chuni_io_hand_pos;
static HANDLE chuni_io_slider_thread;
static bool chuni_io_slider_stop_flag;
static struct chuni_io_config chuni_io_cfg;
static HANDLE chuni_io_slider_led_port;
uint16_t chuni_io_get_api_version(void)
{
@ -122,38 +121,6 @@ void chuni_io_slider_start(chuni_io_slider_callback_t callback)
callback,
0,
NULL);
chuni_io_slider_led_port = CreateFileW(chuni_io_cfg.led_com,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (chuni_io_slider_led_port == INVALID_HANDLE_VALUE)
dprintf("OpenITHM LEDs: Failed to open COM port (Attempted on %S)\n", chuni_io_cfg.led_com);
else
dprintf("OpenITHM LEDs: COM Port Success!\n");
DCB dcb_serial_params = { 0 };
dcb_serial_params.DCBlength = sizeof(dcb_serial_params);
status = GetCommState(chuni_io_slider_led_port, &dcb_serial_params);
dcb_serial_params.BaudRate = CBR_115200; // Setting BaudRate = 115200
dcb_serial_params.ByteSize = 8; // Setting ByteSize = 8
dcb_serial_params.StopBits = ONESTOPBIT;// Setting StopBits = 1
dcb_serial_params.Parity = NOPARITY; // Setting Parity = None
SetCommState(chuni_io_slider_led_port, &dcb_serial_params);
COMMTIMEOUTS timeouts = { 0 };
timeouts.ReadIntervalTimeout = 50; // in milliseconds
timeouts.ReadTotalTimeoutConstant = 50; // in milliseconds
timeouts.ReadTotalTimeoutMultiplier = 10; // in milliseconds
timeouts.WriteTotalTimeoutConstant = 50; // in milliseconds
timeouts.WriteTotalTimeoutMultiplier = 10; // in milliseconds
SetCommTimeouts(chuni_io_slider_led_port, &timeouts);
}
void chuni_io_slider_stop(void)
Dniel97 marked this conversation as resolved Outdated
Already done here: https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/serialimpl.c#L36
@ -168,34 +135,11 @@ void chuni_io_slider_stop(void)
CloseHandle(chuni_io_slider_thread);
chuni_io_slider_thread = NULL;
chuni_io_slider_stop_flag = false;
dprintf("OpenITHM LEDs: Closing COM port\n");
CloseHandle(chuni_io_slider_led_port);
}
void chuni_io_slider_set_leds(const uint8_t *rgb)
{
led_output_update(2, rgb);
if (chuni_io_slider_led_port != INVALID_HANDLE_VALUE)
{
char led_buffer[100];
DWORD bytes_to_write; // No of bytes to write into the port
DWORD bytes_written = 0; // No of bytes written to the port
bytes_to_write = sizeof(led_buffer);
BOOL status;
led_buffer[0] = 0xAA;
led_buffer[1] = 0xAA;
memcpy(led_buffer+2, rgb, sizeof(uint8_t) * 96);
led_buffer[98] = 0xDD;
led_buffer[99] = 0xDD;
status = WriteFile(chuni_io_slider_led_port, // Handle to the Serial port
led_buffer, // Data to be written to the port
bytes_to_write, //No of bytes to write
&bytes_written, //Bytes written
NULL);
}
}
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx)

View File

@ -57,16 +57,14 @@ void chuni_io_config_load(
filename);
}
GetPrivateProfileStringW(L"slider", L"ledport", L"COM5", port_input, 6, filename);
wcsncpy(cfg->led_com, L"\\\\.\\", 4);
wcsncat_s(cfg->led_com, 11, port_input, 6);
cfg->cab_led_output_pipe = GetPrivateProfileIntW(L"led", L"cabLedOutputPipe", 1, filename);
cfg->cab_led_output_serial = GetPrivateProfileIntW(L"led", L"cabLedOutputSerial", 0, filename);
Dniel97 marked this conversation as resolved Outdated
Already defined here: https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/config.c#L68
cfg->controller_led_output_pipe = GetPrivateProfileIntW(L"led", L"controllerLedOutputPipe", 1, filename);
cfg->controller_led_output_serial = GetPrivateProfileIntW(L"led", L"controllerLedOutputSerial", 0, filename);
cfg->controller_led_output_openithm = GetPrivateProfileIntW(L"led", L"controllerLedOutputOpenITHM", 0, filename);
cfg->led_serial_baud = GetPrivateProfileIntW(L"led", L"serialBaud", 921600, filename);
GetPrivateProfileStringW(

View File

@ -10,7 +10,6 @@ struct chuni_io_config {
uint8_t vk_ir_emu;
uint8_t vk_ir[6];
uint8_t vk_cell[32];
wchar_t led_com[12];
// Which ways to output LED information are enabled
bool cab_led_output_pipe;
@ -19,6 +18,8 @@ struct chuni_io_config {
bool controller_led_output_pipe;
bool controller_led_output_serial;
bool controller_led_output_openithm;
// The name of a COM port to output LED data on, in serial mode
wchar_t led_serial_port[12];
int32_t led_serial_baud;

View File

@ -127,7 +127,11 @@ void led_output_update(uint8_t board, const byte* rgb)
if (config->controller_led_output_serial)
{
led_serial_update(escaped_data);
if (config->controller_led_output_openithm){
led_serial_update_openithm(rgb);
} else {
led_serial_update(escaped_data);
}
}
}
}

View File

@ -4,9 +4,6 @@ chuniio_lib = static_library(
include_directories : inc,
implicit_include_directories : false,
c_pch : '../precompiled.h',
link_with : [
util_lib
],
sources : [
'chu2to3.c',

View File

@ -97,3 +97,29 @@ void led_serial_update(struct _chuni_led_data_buf_t* data)
ReleaseMutex(serial_write_mutex);
}
void led_serial_update_openithm(const byte* rgb)
Dniel97 marked this conversation as resolved
Review

Please remove the nw line here and adjust the comments to either use

/*
*/

or align them properly

Please remove the nw line here and adjust the comments to either use ``` /* */ ``` or align them properly
{
if (serial_port != INVALID_HANDLE_VALUE)
{
char led_buffer[100];
DWORD bytes_to_write; // No of bytes to write into the port
DWORD bytes_written = 0; // No of bytes written to the port
bytes_to_write = sizeof(led_buffer);
BOOL status;
led_buffer[0] = 0xAA;
led_buffer[1] = 0xAA;
memcpy(led_buffer+2, rgb, sizeof(uint8_t) * 96);
led_buffer[98] = 0xDD;
led_buffer[99] = 0xDD;
status = WriteFile(serial_port, // Handle to the Serial port
led_buffer, // Data to be written to the port
bytes_to_write, //No of bytes to write
&bytes_written, //Bytes written
NULL);
}
}

View File

@ -13,3 +13,4 @@
HRESULT led_serial_init(wchar_t led_com[12], DWORD baud);
void led_serial_update(struct _chuni_led_data_buf_t* data);
void led_serial_update_openithm(const byte* rgb);

View File

@ -82,10 +82,12 @@ cabLedOutputSerial=0
controllerLedOutputPipe=1
; Output slider LED data to the serial port
controllerLedOutputSerial=0
; Use the OpenITHM protocol for serial LED output
controllerLedOutputOpenITHM=0

OpeNITHM

lol

OpeNITHM lol
; Serial port to send data to if using serial output. Default is COM5.
;serialPort=COM5
; Baud rate for serial data
; Baud rate for serial data (set to 115200 if using OpenITHM)
;serialBaud=921600
; Data output a sequence of bytes, with JVS-like framing.

View File

@ -108,10 +108,12 @@ cabLedOutputSerial=0
controllerLedOutputPipe=1
; Output slider LED data to the serial port
controllerLedOutputSerial=0
; Use the OpenITHM protocol for serial LED output
controllerLedOutputOpenITHM=0
Dniel97 marked this conversation as resolved Outdated

see above

see above
; Serial port to send data to if using serial output. Default is COM5.
;serialPort=COM5
; Baud rate for serial data
; Baud rate for serial data (set to 115200 if using OpenITHM)
Dniel97 marked this conversation as resolved Outdated

see above

see above
;serialBaud=921600
; Data output a sequence of bytes, with JVS-like framing.
@ -202,7 +204,3 @@ ir=0x20
; ... etc ...
;cell31=0x53
;cell32=0x53
; Enable slider LED serial output. This follows OpeNITHM Serial LED Protocol.
; eg. COM5
;ledport=