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
5 changed files with 69 additions and 3 deletions
Showing only changes of commit 2f23264068 - Show all commits

View File

@ -19,6 +19,7 @@ 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)
{
@ -121,6 +122,38 @@ 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,
Dniel97 marked this conversation as resolved Outdated
Already done here: https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/serialimpl.c#L36
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)
@ -135,11 +168,34 @@ 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;
Dniel97 marked this conversation as resolved Outdated

This is the only openITHM specific logic which I'm not sure why its needed in the first place but at least move that code to https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/serialimpl.c#L85 and just add a simple config flag to switch to this openITHM code.

This is the only openITHM specific logic which I'm not sure why its needed in the first place but at least move that code to https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/serialimpl.c#L85 and just add a simple config flag to switch to this openITHM code.

from what I understand now OpenITHM doesn't use escaped data but the rgb data directly so it's unfortunately a bit more different than it needed to be

from what I understand now OpenITHM doesn't use escaped data but the rgb data directly so it's unfortunately a bit more different than it needed to be
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

@ -139,9 +139,10 @@ void chuni_io_slider_start(chuni_io_slider_callback_t callback);
void chuni_io_slider_stop(void);
/* Update the RGB lighting on the slider. A pointer to an array of 32 * 3 = 96
bytes is supplied. The illuminated areas on the touch slider are some
combination of rectangular regions and dividing lines between these regions
but the exact mapping of this lighting control buffer is still TBD.
bytes is supplied, organized in BRG format.
The first set of bytes is the right-most slider key, and from there the bytes
alternate between the dividers and the keys until the left-most key.
There are 31 illuminated sections in total.
Minimum API version: 0x0100 */

View File

@ -57,6 +57,10 @@ 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);
Dniel97 marked this conversation as resolved Outdated
Already defined here: https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/develop/chuniio/config.c#L68
cfg->cab_led_output_pipe = GetPrivateProfileIntW(L"led", L"cabLedOutputPipe", 1, filename);
cfg->cab_led_output_serial = GetPrivateProfileIntW(L"led", L"cabLedOutputSerial", 0, filename);

View File

@ -10,6 +10,7 @@ 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;

View File

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