Initial commit for scsiapi and Seagate FireCuda Gaming External HDD controller

This commit is contained in:
Adam Honse 2023-07-30 06:12:21 +00:00
parent f6e0996250
commit 9cf453008d
10 changed files with 1170 additions and 0 deletions

View file

@ -0,0 +1,168 @@
/*-----------------------------------------*\
| RGBController_Seagate.cpp |
| |
| Generic RGB Interface for Seagate |
| |
| Adam Honse (CalcProgrammer1) 11/8/2022 |
\*-----------------------------------------*/
#include "RGBController_Seagate.h"
/**------------------------------------------------------------------*\
@name Seagate
@category Storage
@type SCSI
@save :white_check_mark:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectSeagateControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_Seagate::RGBController_Seagate(SeagateController* controller_ptr)
{
controller = controller_ptr;
name = "Seagate Device";
vendor = "Seagate";
type = DEVICE_TYPE_STORAGE;
description = "Seagate Device";
location = controller->GetLocation();
mode Direct;
Direct.name = "Direct";
Direct.value = SEAGATE_MODE_STATIC;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Blink;
Blink.name = "Flashing";
Blink.value = SEAGATE_MODE_BLINK;
Blink.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Blink.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Blink);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = SEAGATE_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Breathing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Breathing);
mode Spectrum;
Spectrum.name = "Spectrum Cycle";
Spectrum.value = SEAGATE_MODE_SPECTRUM;
Spectrum.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_MANUAL_SAVE;
Spectrum.color_mode = MODE_COLORS_RANDOM;
modes.push_back(Spectrum);
SetupZones();
}
RGBController_Seagate::~RGBController_Seagate()
{
delete controller;
}
void RGBController_Seagate::SetupZones()
{
zone led_zone;
led_zone.name = "LED Strip";
led_zone.type = ZONE_TYPE_LINEAR;
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);
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);
}
SetupColors();
}
void RGBController_Seagate::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_Seagate::DeviceUpdateLEDs()
{
for(unsigned int led_idx = 0; led_idx < leds.size(); led_idx++)
{
UpdateSingleLED(led_idx);
}
}
void RGBController_Seagate::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_Seagate::UpdateSingleLED(int led)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
switch(modes[active_mode].value)
{
case SEAGATE_MODE_STATIC:
controller->SetLEDStatic(led, red, grn, blu, false);
break;
case SEAGATE_MODE_BLINK:
controller->SetLEDBlink(led, red, grn, blu, false);
break;
case SEAGATE_MODE_BREATHING:
controller->SetLEDBreathing(led, red, grn, blu, false);
break;
case SEAGATE_MODE_SPECTRUM:
controller->SetLEDsSpectrum(led, false);
break;
}
}
void RGBController_Seagate::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
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]);
switch(modes[active_mode].value)
{
case SEAGATE_MODE_STATIC:
controller->SetLEDStatic(led_idx, red, grn, blu, true);
break;
case SEAGATE_MODE_BLINK:
controller->SetLEDBlink(led_idx, red, grn, blu, true);
break;
case SEAGATE_MODE_BREATHING:
controller->SetLEDBreathing(led_idx, red, grn, blu, true);
break;
case SEAGATE_MODE_SPECTRUM:
controller->SetLEDsSpectrum(led_idx, true);
break;
}
}
}

View file

@ -0,0 +1,33 @@
/*-----------------------------------------*\
| RGBController_Seagate.h |
| |
| Generic RGB Interface for Seagate |
| |
| Adam Honse (CalcProgrammer1) 11/8/2022 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "SeagateController.h"
class RGBController_Seagate : public RGBController
{
public:
RGBController_Seagate(SeagateController* controller_ptr);
~RGBController_Seagate();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void DeviceSaveMode();
private:
SeagateController* controller;
};

View file

@ -0,0 +1,222 @@
/*-----------------------------------------*\
| SeagateController.cpp |
| |
| Code for Seagate Firecuda External HDD |
| RGB controller |
| |
| Adam Honse (CalcProgrammer1) 6/15/2023 |
\*-----------------------------------------*/
#include "SeagateController.h"
SeagateController::SeagateController(scsi_device* dev_handle, char* path)
{
this->dev = dev_handle;
this->path = path;
}
SeagateController::~SeagateController()
{
scsi_close(dev);
}
std::string SeagateController::GetLocation()
{
std::string str(path.begin(), path.end());
return("SCSI: " + str);
}
void SeagateController::SetLEDBlink
(
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[0x10] = {0};
data[0] = 0x10; /* 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] = SEAGATE_MODE_BLINK;
if(save)
{
data[8] = 0x03; /* 0x00 for no save, 0x03 for */
/* save */
}
else
{
data[8] = 0x00;
}
data[9] = 0x10;
data[10] = 0x10;
data[11] = r;
data[12] = g;
data[13] = b;
data[14] = 0xFF;
data[15] = 0xFF;
/*-----------------------------------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------------------------------*/
SendPacket(data, 0x10);
}
void SeagateController::SetLEDBreathing
(
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[0x14] = {0};
data[0] = 0x14; /* 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] = SEAGATE_MODE_BREATHING;
if(save)
{
data[8] = 0x03; /* 0x00 for no save, 0x03 for */
/* save */
}
else
{
data[8] = 0x00;
}
data[9] = 0x0F;
data[10] = 0x0F;
data[11] = 0x0F;
data[12] = 0x0F;
data[13] = r;
data[14] = g;
data[15] = b;
data[16] = 0xFF;
data[17] = 0xFF;
data[18] = 0xFF;
data[19] = 0x00;
/*-----------------------------------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------------------------------*/
SendPacket(data, 0x14);
}
void SeagateController::SetLEDsSpectrum
(
unsigned char led_id,
bool save
)
{
/*-----------------------------------------------------------------------------*\
| Create buffer to hold RGB control data |
\*-----------------------------------------------------------------------------*/
unsigned char data[0x0A] = {0};
data[0] = 0x0A; /* 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] = SEAGATE_MODE_SPECTRUM;
data[8] = 0x02;
data[9] = 0xB4;
/*-----------------------------------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------------------------------*/
SendPacket(data, 0x0A);
}
void SeagateController::SetLEDStatic
(
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[0x0E] = {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] = SEAGATE_MODE_STATIC;
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;
/*-----------------------------------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------------------------------*/
SendPacket(data, 0x0E);
}
void SeagateController::SendPacket
(
unsigned char * packet,
unsigned char packet_sz
)
{
/*-----------------------------------------------------------------------------*\
| Create buffer to hold CDB |
\*-----------------------------------------------------------------------------*/
unsigned char cdb[12] = {0};
cdb[0] = 0xD2;
cdb[1] = 0x53; /* S */
cdb[2] = 0x65; /* e */
cdb[3] = 0x74; /* t */
cdb[4] = 0x4C; /* L */
cdb[5] = 0x65; /* e */
cdb[6] = 0x64; /* d */
cdb[7] = 0x00;
cdb[8] = 0x00;
cdb[9] = 0x30;
cdb[10] = packet_sz;
cdb[11] = 0x00;
/*-----------------------------------------------------------------------------*\
| Create buffer to hold sense data |
\*-----------------------------------------------------------------------------*/
unsigned char sense[32] = {0};
/*-----------------------------------------------------------------------------*\
| Write SCSI packet |
\*-----------------------------------------------------------------------------*/
scsi_write(dev, packet, packet_sz, cdb, 12, sense, 32);
}

View file

@ -0,0 +1,73 @@
/*-----------------------------------------*\
| SeagateController.h |
| |
| Definitions for Seagate Firecuda |
| External HDD RGB controller |
| |
| Adam Honse (CalcProgrammer1) 6/15/2023 |
\*-----------------------------------------*/
#pragma once
#include <string>
#include "scsiapi.h"
enum
{
SEAGATE_MODE_STATIC = 0x01, /* Static mode */
SEAGATE_MODE_BLINK = 0x02, /* Blink mode */
SEAGATE_MODE_BREATHING = 0x03, /* Breathing mode */
SEAGATE_MODE_SPECTRUM = 0x05, /* Spectrum mode */
};
class SeagateController
{
public:
SeagateController(scsi_device* dev_handle, char* path);
~SeagateController();
std::string GetLocation();
void SetLEDBlink
(
unsigned char led_id,
unsigned char r,
unsigned char g,
unsigned char b,
bool save
);
void SetLEDBreathing
(
unsigned char led_id,
unsigned char r,
unsigned char g,
unsigned char b,
bool save
);
void SetLEDsSpectrum
(
unsigned char led_id,
bool save
);
void SetLEDStatic
(
unsigned char led_id,
unsigned char r,
unsigned char g,
unsigned char b,
bool save
);
private:
scsi_device* dev;
std::string path;
void SendPacket
(
unsigned char * packet,
unsigned char packet_sz
);
};

View file

@ -0,0 +1,43 @@
#include "Detector.h"
#include "LogManager.h"
#include "SeagateController.h"
#include "RGBController.h"
#include "RGBController_Seagate.h"
#include <vector>
#include "scsiapi.h"
/******************************************************************************************\
* *
* DetectSeagateControllers *
* *
* Detects Seagate FireCuda HDD devices *
* *
\******************************************************************************************/
void DetectSeagateControllers()
{
scsi_device_info * info = scsi_enumerate(NULL, NULL);
while(info)
{
if(strncmp(info->vendor, "Seagate", 7) == 0 && strncmp(info->product, "FireCuda HDD", 12) == 0)
{
scsi_device * dev = scsi_open_path(info->path);
if(dev)
{
SeagateController* controller = new SeagateController(dev, info->path);
RGBController_Seagate* rgb_controller = new RGBController_Seagate(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
info = info->next;
}
scsi_free_enumeration(info);
} /* DetectSeagateControllers() */
REGISTER_DETECTOR("Seagate Firecuda HDD", DetectSeagateControllers);