From c092e96f66041778da48617bb75756c0cc19a9d7 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 16 Jul 2023 01:04:45 -0500 Subject: [PATCH] Selectable saving (manual save/button) and proper direct mode, code cleanup --- .../RGBController_Seagate.cpp | 19 +++-- .../SeagateController/RGBController_Seagate.h | 2 + .../SeagateController/SeagateController.cpp | 71 ++++++++++++------- .../SeagateController/SeagateController.h | 15 ++-- 4 files changed, 72 insertions(+), 35 deletions(-) diff --git a/Controllers/SeagateController/RGBController_Seagate.cpp b/Controllers/SeagateController/RGBController_Seagate.cpp index 4e113fb3a..095f8be03 100644 --- a/Controllers/SeagateController/RGBController_Seagate.cpp +++ b/Controllers/SeagateController/RGBController_Seagate.cpp @@ -29,9 +29,9 @@ RGBController_Seagate::RGBController_Seagate(SeagateController* controller_ptr) location = controller->GetLocation(); mode Direct; - Direct.name = "Custom"; + Direct.name = "Direct"; Direct.value = 0; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE; Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); @@ -91,10 +91,21 @@ void RGBController_Seagate::UpdateSingleLED(int led) unsigned char grn = RGBGetGValue(colors[led]); unsigned char blu = RGBGetBValue(colors[led]); - controller->SetLED(led, red, grn, blu); + controller->SetLED(led, red, grn, blu, false); } void RGBController_Seagate::DeviceUpdateMode() { - +} + +void RGBController_Seagate::DeviceSaveMode() +{ + for(unsigned int led_idx = 0; led_idx < leds.size(); led_idx++) + { + unsigned char red = RGBGetRValue(colors[led_idx]); + unsigned char grn = RGBGetGValue(colors[led_idx]); + unsigned char blu = RGBGetBValue(colors[led_idx]); + + controller->SetLED(led_idx, red, grn, blu, true); + } } diff --git a/Controllers/SeagateController/RGBController_Seagate.h b/Controllers/SeagateController/RGBController_Seagate.h index 475ef1cda..d946d1f81 100644 --- a/Controllers/SeagateController/RGBController_Seagate.h +++ b/Controllers/SeagateController/RGBController_Seagate.h @@ -26,6 +26,8 @@ public: void DeviceUpdateMode(); + void DeviceSaveMode(); + private: SeagateController* controller; }; diff --git a/Controllers/SeagateController/SeagateController.cpp b/Controllers/SeagateController/SeagateController.cpp index 7f0a6cada..3840b7411 100644 --- a/Controllers/SeagateController/SeagateController.cpp +++ b/Controllers/SeagateController/SeagateController.cpp @@ -31,10 +31,46 @@ std::string SeagateController::GetLocation() void SeagateController::SetLED ( - unsigned char led_id, - unsigned char r, - unsigned char g, - unsigned char b + unsigned char led_id, + unsigned char r, + unsigned char g, + unsigned char b, + bool save + ) +{ + /*-----------------------------------------------------------------------------*\ + | Create buffer to hold RGB control data | + \*-----------------------------------------------------------------------------*/ + unsigned char data[14] = {0}; + data[0] = 0x0E; // size of data packet + data[1] = 0x00; + data[2] = 0x01; + data[3] = 0x09; + data[4] = 0x01; + data[5] = 0x06; + data[6] = led_id; + data[7] = 0x01; + if(save) + { + data[8] = 0x03; // 0x00 for no save, 0x03 for save + } + else + { + data[8] = 0x00; + } + data[9] = r; + data[10] = g; + data[11] = b; + data[12] = 0xFF; + data[13] = 0xFF; + + SendPacket(data, 14); +} + +void SeagateController::SendPacket + ( + void * packet, + unsigned char packet_sz ) { /*-----------------------------------------------------------------------------*\ @@ -44,25 +80,6 @@ void SeagateController::SetLED \*-----------------------------------------------------------------------------*/ unsigned char buffer[80] = {0}; - /*-----------------------------------------------------------------------------*\ - | Create buffer to hold RGB control data | - \*-----------------------------------------------------------------------------*/ - unsigned char data[14] = {0}; - data[0] = 0x0E; - data[1] = 0x00; - data[2] = 0x01; - data[3] = 0x09; - data[4] = 0x01; - data[5] = 0x06; - data[6] = led_id; - data[7] = 0x01; - data[8] = 0x03; - data[9] = r; - data[10] = g; - data[11] = b; - data[12] = 0x00; - data[13] = 0xFF; - /*-----------------------------------------------------------------------------*\ | Create PSCSI_PASS_THROUGH_DIRECT pointer and point it to the buffer | \*-----------------------------------------------------------------------------*/ @@ -79,9 +96,9 @@ void SeagateController::SetLED command->CdbLength = 0x0C; command->SenseInfoLength = 0x20; command->DataIn = SCSI_IOCTL_DATA_OUT; - command->DataTransferLength = 0x0000000E; + command->DataTransferLength = packet_sz; command->TimeOutValue = 0x00000014; - command->DataBuffer = &data; + command->DataBuffer = packet; command->SenseInfoOffset = 0x0000002E; command->Cdb[0] = 0xD2; @@ -94,11 +111,11 @@ void SeagateController::SetLED command->Cdb[7] = 0x00; command->Cdb[8] = 0x00; command->Cdb[9] = 0x30; - command->Cdb[10] = 0x0E; + command->Cdb[10] = packet_sz; command->Cdb[11] = 0x00; /*-----------------------------------------------------------------------------*\ | Send pass through command | \*-----------------------------------------------------------------------------*/ DeviceIoControl(fd, IOCTL_SCSI_PASS_THROUGH_DIRECT, command, 80, command, 80, NULL, NULL); -} +} \ No newline at end of file diff --git a/Controllers/SeagateController/SeagateController.h b/Controllers/SeagateController/SeagateController.h index 9186f717c..1753b329b 100644 --- a/Controllers/SeagateController/SeagateController.h +++ b/Controllers/SeagateController/SeagateController.h @@ -24,13 +24,20 @@ public: void SetLED ( - unsigned char led_id, - unsigned char r, - unsigned char g, - unsigned char b + unsigned char led_id, + unsigned char r, + unsigned char g, + unsigned char b, + bool save ); private: HANDLE fd; std::wstring path; + + void SeagateController::SendPacket + ( + void * packet, + unsigned char packet_sz + ); };