From 74b543cd65952564a50bc6794e6757d8800fdc47 Mon Sep 17 00:00:00 2001 From: Rabit Date: Sun, 22 Jul 2018 00:10:29 -0700 Subject: [PATCH] Bugfix for intel chipsets and couple improvements * Changed min & max input & output levels * Added read response from hid request: fixes #1 * Added headphone init to the defaults --- README.md | 14 ++++++++---- maya22-control.c | 59 +++++++++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 62a1d5d..50691ed 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,15 @@ $ maya22-control -h Usage: ./maya22-control [options] -e - Enumerate available devices + -i - Enable headphone -d - Set default values -c - Set input channel ('mic', 'hiz', 'line', 'mic_hiz', 'mute') -M - Input monitoring on -m - Input monitoring off - -l <0-255> - Input left volume - -r <0-255> - Input right volume - -L <0-255> - Output left volume - -R <0-255> - Output right volume + -l <0-127> - Input left volume + -r <0-127> - Input right volume + -L <0-145> - Output left volume (seems 127 without gain and > with gain) + -R <0-145> - Output right volume (seems 127 without gain and > with gain) ``` Udev permissions & autoset defaults @@ -37,3 +38,8 @@ Just create udev rule for hidraw device with autorun set defaults (/etc/udev/rul ``` KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2573", ATTRS{idProduct}=="0017", GROUP="plugdev", MODE="0660", RUN+="/usr/local/bin/maya22-control -d" ``` + +GUI application +--------------- +You can find GUI more useful for your needs, so please check the following project: +* https://gitlab.com/Psy-Kai/ESI-Maya22USBControl diff --git a/maya22-control.c b/maya22-control.c index 8d4a1c5..257e561 100644 --- a/maya22-control.c +++ b/maya22-control.c @@ -43,29 +43,32 @@ void enumerate_hid() int send(hid_device *dev, unsigned char op, unsigned char byte) { - unsigned char buf[] = {0x00, - 0x12, 0x34, op, 0x00, 0x01, - byte, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00 - }; + unsigned char buf[33]; // +1 byte for report id + memset(buf, 0, sizeof(buf)); + buf[1] = 0x12; + buf[2] = 0x34; + buf[3] = op; + buf[5] = 1; + buf[6] = byte; + buf[22] = 0x80; int res = hid_write(dev, buf, sizeof(buf)); - if( res < 0 ) + if( res < 0 ) { wprintf(L"ERROR: Operation failed: %d\n", res); + return res; + } - return res; + // Waiting response + return hid_read(dev, buf, sizeof(buf)); } int main(int argc, char *argv[]) { // Options values - long input_l = 190, input_r = 190, output_l = 255, output_r = 255; + long input_l = 86, input_r = 86, output_l = 145, output_r = 145; bool monitor = false, input_mute = false; - unsigned char input_channel = 0x8; // MIC: 0x1, HIZ: 0x2, LINE: 0x4, MIC_HIZ: 0x8, MUTE: 0xc2 + unsigned char input_channel = 0x8; // MIC: 0x1, HIZ: 0x2, LINE: 0x4, MIC_HIZ: 0x8, MUTE: 0xc1 (depends on selected channel, (0xc0 || channel)) bool do_e = false, do_i = false, do_c = false, do_m = false, do_l = false, do_r = false, do_L = false, do_R = false; @@ -81,7 +84,7 @@ int main(int argc, char *argv[]) do_i = true; break; case 'd': - do_c = true; do_m = true; do_l = true; do_r = true; do_L = true; do_R = true; + do_i = true; do_c = true; do_m = true; do_l = true; do_r = true; do_L = true; do_R = true; break; case 'c': do_c = true; @@ -89,7 +92,7 @@ int main(int argc, char *argv[]) if( optarg[strlen(optarg)-1] == 'z' ) input_channel = 0x8; else if( optarg[strlen(optarg)-1] == 'e' ) - input_channel = 0xc2; + input_channel = 0xc1; // Only one channel here due to the app interface else input_channel = 0x1; } @@ -108,35 +111,35 @@ int main(int argc, char *argv[]) case 'l': do_l = true; input_l = atoi(optarg); - input_l = max(min(input_l, 255), 0); + input_l = max(min(input_l, 127), 0); break; case 'r': do_r = true; input_r = atoi(optarg); - input_r = max(min(input_r, 255), 0); + input_r = max(min(input_r, 127), 0); break; case 'L': do_L = true; output_l = atoi(optarg); - output_l = max(min(output_l, 255), 0); + output_l = max(min(output_l, 145), 0); break; case 'R': do_R = true; output_r = atoi(optarg); - output_r = max(min(output_r, 255), 0); + output_r = max(min(output_r, 145), 0); break; default: wprintf(L"Usage: %s [options]\n\n", argv[0]); wprintf(L" -e - Enumerate available devices\n"); - wprintf(L" -i - Init device\n"); + wprintf(L" -i - Enable headphone\n"); wprintf(L" -d - Set default values\n"); wprintf(L" -c - Set input channel ('mic', 'hiz', 'line', 'mic_hiz', 'mute')\n"); wprintf(L" -M - Input monitoring on\n"); wprintf(L" -m - Input monitoring off\n"); - wprintf(L" -l <0-255> - Input left volume\n"); - wprintf(L" -r <0-255> - Input right volume\n"); - wprintf(L" -L <0-255> - Output left volume\n"); - wprintf(L" -R <0-255> - Output right volume\n"); + wprintf(L" -l <0-127> - Input left volume\n"); + wprintf(L" -r <0-127> - Input right volume\n"); + wprintf(L" -L <0-145> - Output left volume\n"); + wprintf(L" -R <0-145> - Output right volume\n"); exit(0); } } @@ -154,7 +157,7 @@ int main(int argc, char *argv[]) hiddev = hid_open(VENDOR_ID, PRODUCT_ID, NULL); if( hiddev != NULL ) { if( do_i ) { - wprintf(L" Init device\n"); + wprintf(L" Enable headphone\n"); send(hiddev, 0x1a, 0x00); } if( do_c ) { @@ -167,19 +170,19 @@ int main(int argc, char *argv[]) } if( do_l ) { wprintf(L" Set input left volume: %d\n", input_l); - send(hiddev, 0x1c, input_l); + send(hiddev, 0x1c, input_l + 104); // 104 - min value } if( do_r ) { wprintf(L" Set input right volume: %d\n", input_r); - send(hiddev, 0x1e, input_r); + send(hiddev, 0x1e, input_r + 104); // 104 - min value } if( do_L ) { wprintf(L" Set output left volume: %d\n", output_l); - send(hiddev, 0x07, output_l); + send(hiddev, 0x07, output_l + 110); // 110 - min value } if( do_R ) { wprintf(L" Set output right volume: %d\n", output_r); - send(hiddev, 0x09, output_r); + send(hiddev, 0x09, output_r + 110); // 110 - min value } hid_close(hiddev); } else