From b8519487f8cfd049bed5d01d2dc72410b5de4a17 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 15 Jul 2023 23:39:16 -0500 Subject: [PATCH] Custom mode implemented (saves to hardware) --- .../RGBController_Seagate.cpp | 38 +++++----- .../SeagateController/SeagateController.cpp | 69 ++++++++++++------- .../SeagateController/SeagateController.h | 11 ++- 3 files changed, 74 insertions(+), 44 deletions(-) diff --git a/Controllers/SeagateController/RGBController_Seagate.cpp b/Controllers/SeagateController/RGBController_Seagate.cpp index 6040b9551..4e113fb3a 100644 --- a/Controllers/SeagateController/RGBController_Seagate.cpp +++ b/Controllers/SeagateController/RGBController_Seagate.cpp @@ -29,7 +29,7 @@ RGBController_Seagate::RGBController_Seagate(SeagateController* controller_ptr) location = controller->GetLocation(); mode Direct; - Direct.name = "Direct"; + Direct.name = "Custom"; Direct.value = 0; Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; Direct.color_mode = MODE_COLORS_PER_LED; @@ -46,18 +46,21 @@ RGBController_Seagate::~RGBController_Seagate() void RGBController_Seagate::SetupZones() { zone led_zone; - led_zone.name = "RGB Light"; + led_zone.name = "LED Strip"; led_zone.type = ZONE_TYPE_SINGLE; - led_zone.leds_min = 1; - led_zone.leds_max = 1; - led_zone.leds_count = 1; + led_zone.leds_min = 6; + led_zone.leds_max = 6; + led_zone.leds_count = 6; led_zone.matrix_map = NULL; zones.push_back(led_zone); - led new_led; - new_led.name = "RGB Light"; + for(unsigned int led_idx = 0; led_idx < zones[0].leds_count; led_idx++) + { + led new_led; + new_led.name = "LED Strip LED"; - leds.push_back(new_led); + leds.push_back(new_led); + } SetupColors(); } @@ -71,11 +74,10 @@ void RGBController_Seagate::ResizeZone(int /*zone*/, int /*new_size*/) void RGBController_Seagate::DeviceUpdateLEDs() { - unsigned char red = RGBGetRValue(colors[0]); - unsigned char grn = RGBGetGValue(colors[0]); - unsigned char blu = RGBGetBValue(colors[0]); - - //controller->SetRGB(red, grn, blu); + for(unsigned int led_idx = 0; led_idx < leds.size(); led_idx++) + { + UpdateSingleLED(led_idx); + } } void RGBController_Seagate::UpdateZoneLEDs(int /*zone*/) @@ -83,12 +85,16 @@ void RGBController_Seagate::UpdateZoneLEDs(int /*zone*/) DeviceUpdateLEDs(); } -void RGBController_Seagate::UpdateSingleLED(int /*led*/) +void RGBController_Seagate::UpdateSingleLED(int led) { - DeviceUpdateLEDs(); + unsigned char red = RGBGetRValue(colors[led]); + unsigned char grn = RGBGetGValue(colors[led]); + unsigned char blu = RGBGetBValue(colors[led]); + + controller->SetLED(led, red, grn, blu); } void RGBController_Seagate::DeviceUpdateMode() { - + } diff --git a/Controllers/SeagateController/SeagateController.cpp b/Controllers/SeagateController/SeagateController.cpp index 5a368dbf3..7f0a6cada 100644 --- a/Controllers/SeagateController/SeagateController.cpp +++ b/Controllers/SeagateController/SeagateController.cpp @@ -14,38 +14,63 @@ SeagateController::SeagateController(HANDLE fd, wchar_t* path) { - this->nvme_fd = fd; - this->path = path; + this->fd = fd; + this->path = path; +} + +SeagateController::~SeagateController() +{ + +} + +std::string SeagateController::GetLocation() +{ + std::string str(path.begin(), path.end()); + return("SCSI: " + str); +} + +void SeagateController::SetLED + ( + unsigned char led_id, + unsigned char r, + unsigned char g, + unsigned char b + ) +{ + /*-----------------------------------------------------------------------------*\ + | Create buffer to hold SCSI_PASS_THROUGH_DIRECT | + | Size must be enough for the SCSI_PASS_THROUGH_DIRECT struct plus the sense | + | data. Size of 80 bytes taken from captured data | + \*-----------------------------------------------------------------------------*/ + unsigned char buffer[80] = {0}; /*-----------------------------------------------------------------------------*\ - | Create buffer to hold STORAGE_PROTOCOL_COMMAND | - | Size must be enough for the STORAGE_PROTOCOL_COMMAND struct plus the command | - | data. Subtract sizeof(DWORD) as the Command field in the structure overlaps | - | the actual command data. | + | Create buffer to hold RGB control data | \*-----------------------------------------------------------------------------*/ - unsigned char data[14] = {0}; - unsigned char buffer[80] = {0}; - + 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] = 0x00; + data[6] = led_id; data[7] = 0x01; data[8] = 0x03; - data[9] = 0x00; - data[10] = 0x15; - data[11] = 0xFF; + data[9] = r; + data[10] = g; + data[11] = b; data[12] = 0x00; data[13] = 0xFF; /*-----------------------------------------------------------------------------*\ - | Create STORAGE_PROTOCOL_COMMAND pointer and point it to the buffer | + | Create PSCSI_PASS_THROUGH_DIRECT pointer and point it to the buffer | \*-----------------------------------------------------------------------------*/ PSCSI_PASS_THROUGH_DIRECT command = (PSCSI_PASS_THROUGH_DIRECT)buffer; + /*-----------------------------------------------------------------------------*\ + | Set up pass through command | + \*-----------------------------------------------------------------------------*/ command->Length = sizeof(SCSI_PASS_THROUGH_DIRECT); command->ScsiStatus = 0x00; command->PathId = 0x00; @@ -72,16 +97,8 @@ SeagateController::SeagateController(HANDLE fd, wchar_t* path) command->Cdb[10] = 0x0E; command->Cdb[11] = 0x00; - DeviceIoControl(nvme_fd, IOCTL_SCSI_PASS_THROUGH_DIRECT, command, 80, command, 80, NULL, NULL); -} - -SeagateController::~SeagateController() -{ - -} - -std::string SeagateController::GetLocation() -{ - std::string str(path.begin(), path.end()); - return("SCSI: " + str); + /*-----------------------------------------------------------------------------*\ + | Send pass through command | + \*-----------------------------------------------------------------------------*/ + DeviceIoControl(fd, IOCTL_SCSI_PASS_THROUGH_DIRECT, command, 80, command, 80, NULL, NULL); } diff --git a/Controllers/SeagateController/SeagateController.h b/Controllers/SeagateController/SeagateController.h index 9d7d93a23..9186f717c 100644 --- a/Controllers/SeagateController/SeagateController.h +++ b/Controllers/SeagateController/SeagateController.h @@ -22,8 +22,15 @@ public: std::string GetLocation(); + void SetLED + ( + unsigned char led_id, + unsigned char r, + unsigned char g, + unsigned char b + ); + private: - HANDLE nvme_fd; + HANDLE fd; std::wstring path; - int a; };