Initial fan controller API and Thermaltake Riing controller implementation

This commit is contained in:
Adam Honse
2020-06-05 16:59:32 -05:00
parent b171906162
commit f995eb8021
15 changed files with 498 additions and 9 deletions

View File

@@ -0,0 +1,61 @@
/*-----------------------------------------*\
| FanController_ThermaltakeRiing.cpp |
| |
| Generic Fan Interface for Thermaltake |
| Riing controller |
| |
| Adam Honse (CalcProgrammer1) 6/5/2020 |
\*-----------------------------------------*/
#include "FanController_ThermaltakeRiing.h"
FanController_ThermaltakeRiing::FanController_ThermaltakeRiing(ThermaltakeRiingController* riing_ptr)
{
riing = riing_ptr;
name = "Thermaltake Riing";
description = "Thermaltake Riing Device";
version = riing->GetFirmwareVersion();
for(std::size_t fan_index = 0; fan_index < THERMALTAKE_NUM_CHANNELS; fan_index++)
{
fan new_fan;
unsigned char speed;
unsigned short rpm;
riing->GetFanData(fan_index + 1, &speed, &rpm);
new_fan.name = "Thermaltake Riing Fan ";
new_fan.name.append(std::to_string(fan_index + 1));
new_fan.speed_min = THERMALTAKE_FAN_SPEED_MIN;
new_fan.speed_max = THERMALTAKE_FAN_SPEED_MAX;
new_fan.speed_cmd = speed;
new_fan.rpm_rdg = rpm;
fans.push_back(new_fan);
}
UpdateControl();
}
void FanController_ThermaltakeRiing::UpdateControl()
{
for(std::size_t fan_index = 0; fan_index < fans.size(); fan_index++)
{
riing->SendFan(fan_index + 1, THERMALTAKE_FAN_MODE_FIXED, fans[fan_index].speed_cmd);
}
}
void FanController_ThermaltakeRiing::UpdateReading()
{
for(std::size_t fan_index = 0; fan_index < fans.size(); fan_index++)
{
unsigned char speed;
unsigned short rpm;
riing->GetFanData(fan_index + 1, &speed, &rpm);
fans[fan_index].rpm_rdg = rpm;
}
}

View File

@@ -0,0 +1,24 @@
/*-----------------------------------------*\
| FanController_ThermaltakeRiing.h |
| |
| Generic Fan Interface for Thermaltake |
| Riing controller |
| |
| Adam Honse (CalcProgrammer1) 6/5/2020 |
\*-----------------------------------------*/
#pragma once
#include "FanController.h"
#include "ThermaltakeRiingController.h"
class FanController_ThermaltakeRiing : public FanController
{
public:
FanController_ThermaltakeRiing(ThermaltakeRiingController* riing_ptr);
void UpdateControl();
void UpdateReading();
private:
ThermaltakeRiingController* riing;
};

View File

@@ -44,6 +44,37 @@ std::string ThermaltakeRiingController::GetSerialString()
return(StringUtils::wstring_to_string(serial_string));
}
void ThermaltakeRiingController::GetFanData
(
unsigned char port,
unsigned char * speed,
unsigned short * rpm
)
{
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Get Fan Data packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x33;
usb_buf[0x01] = 0x51;
usb_buf[0x02] = port;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 64);
hid_read(dev, usb_buf, 64);
*speed = usb_buf[0x04];
*rpm = (usb_buf[0x06] << 8) + usb_buf[0x05];
}
std::string ThermaltakeRiingController::GetFirmwareVersion()
{
unsigned char usb_buf[64];
@@ -120,6 +151,36 @@ void ThermaltakeRiingController::SendInit()
hid_read(dev, usb_buf, 65);
}
void ThermaltakeRiingController::SendFan
(
unsigned char port,
unsigned char mode,
unsigned char speed
)
{
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up RGB packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x32;
usb_buf[0x01] = 0x51;
usb_buf[0x02] = port;
usb_buf[0x03] = mode;
usb_buf[0x04] = speed;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 64);
hid_read(dev, usb_buf, 64);
}
void ThermaltakeRiingController::SendRGB
(
unsigned char port,

View File

@@ -44,6 +44,18 @@ enum
THERMALTAKE_SPEED_EXTREME = 0x00
};
enum
{
THERMALTAKE_FAN_MODE_FIXED = 0x01,
THERMALTAKE_FAN_MODE_PWM = 0x02
};
enum
{
THERMALTAKE_FAN_SPEED_MIN = 20,
THERMALTAKE_FAN_SPEED_MAX = 100
};
#define THERMALTAKE_NUM_CHANNELS 5
class ThermaltakeRiingController
@@ -56,9 +68,23 @@ public:
std::string GetSerialString();
std::string GetFirmwareVersion();
void GetFanData
(
unsigned char port,
unsigned char * speed,
unsigned short * rpm
);
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
void SetMode(unsigned char mode, unsigned char speed);
void SendFan
(
unsigned char port,
unsigned char mode,
unsigned char speed
);
private:
hid_device* dev;
@@ -68,15 +94,14 @@ private:
void SendInit();
void SendRGB
(
unsigned char port,
unsigned char mode,
unsigned char speed,
unsigned char num_colors,
unsigned char* color_data
);
void SendRGB
(
unsigned char port,
unsigned char mode,
unsigned char speed,
unsigned char num_colors,
unsigned char* color_data
);
void SendFan();
void SendSave();
};

View File

@@ -15,6 +15,8 @@
#include "Detector.h"
#include "ThermaltakeRiingController.h"
#include "ThermaltakeRiingQuadController.h"
#include "FanController.h"
#include "FanController_ThermaltakeRiing.h"
#include "RGBController.h"
#include "RGBController_ThermaltakeRiing.h"
#include "RGBController_ThermaltakeRiingQuad.h"
@@ -40,6 +42,10 @@ void DetectThermaltakeRiingControllers(hid_device_info* info, const std::string&
RGBController_ThermaltakeRiing* rgb_controller = new RGBController_ThermaltakeRiing(controller);
// Constructor sets the name
ResourceManager::get()->RegisterRGBController(rgb_controller);
FanController_ThermaltakeRiing* fan_controller = new FanController_ThermaltakeRiing(controller);
ResourceManager::get()->RegisterFanController(fan_controller);
}
} /* DetectThermaltakeRiingControllers() */

View File

@@ -0,0 +1,51 @@
/*-----------------------------------------*\
| FanController.h |
| |
| Definitions and types for generic fan |
| and pump controller interface |
| |
| Adam Honse (CalcProgrammer1) 6/5/2020 |
\*-----------------------------------------*/
#pragma once
#include <vector>
#include <string>
/*------------------------------------------------------------------*\
| Fan Type |
\*------------------------------------------------------------------*/
typedef struct
{
/*--------------------------------------------------------------*\
| Fan Information |
\*--------------------------------------------------------------*/
std::string name; /* Fan name */
unsigned int speed_cmd; /* Speed command */
unsigned int speed_min; /* Minimum speed command */
unsigned int speed_max; /* Maximum speed command */
unsigned int rpm_rdg; /* RPM reading */
} fan;
class FanController
{
public:
std::string name; /* controller name */
std::string description; /* controller description */
std::string version; /* controller version */
std::string serial; /* controller serial number */
std::string location; /* controller location */
std::vector<fan> fans; /* Fans */
/*---------------------------------------------------------*\
| FanController base class constructor |
\*---------------------------------------------------------*/
//FanController();
//~FanController();
/*---------------------------------------------------------*\
| Functions to be implemented in device implementation |
\*---------------------------------------------------------*/
virtual void UpdateControl() = 0;
virtual void UpdateReading() = 0;
};

View File

@@ -122,6 +122,7 @@ INCLUDEPATH +=
super_io/ \
AutoStart/ \
KeyboardLayoutManager/ \
FanController/ \
RGBController/ \
qt/
@@ -159,6 +160,7 @@ HEADERS +=
super_io/super_io.h \
AutoStart/AutoStart.h \
KeyboardLayoutManager/KeyboardLayoutManager.h \
FanController/FanController.h \
RGBController/RGBController.h \
RGBController/RGBController_Dummy.h \
RGBController/RGBControllerKeyNames.h \

View File

@@ -191,6 +191,11 @@ std::vector<i2c_smbus_interface*> & ResourceManager::GetI2CBusses()
return busses;
}
void ResourceManager::RegisterFanController(FanController *fan_controller)
{
fan_controllers.push_back(fan_controller);
}
void ResourceManager::RegisterRGBController(RGBController *rgb_controller)
{
LOG_INFO("[%s] Registering RGB controller", rgb_controller->name.c_str());
@@ -254,6 +259,11 @@ void ResourceManager::UnregisterRGBController(RGBController* rgb_controller)
UpdateDeviceList();
}
std::vector<FanController*> & ResourceManager::GetFanControllers()
{
return fan_controllers;
}
std::vector<RGBController*> & ResourceManager::GetRGBControllers()
{
return rgb_controllers;

View File

@@ -29,6 +29,7 @@
#define CONTROLLER_LIST_HID 0
struct hid_device_info;
class FanController;
class NetworkClient;
class NetworkServer;
class ProfileManager;
@@ -136,9 +137,11 @@ public:
void RegisterI2CBus(i2c_smbus_interface *);
std::vector<i2c_smbus_interface*> & GetI2CBusses();
void RegisterFanController(FanController *fan_controller);
void RegisterRGBController(RGBController *rgb_controller);
void UnregisterRGBController(RGBController *rgb_controller);
std::vector<FanController*> & GetFanControllers();
std::vector<RGBController*> & GetRGBControllers();
void RegisterI2CBusDetector (I2CBusDetectorFunction detector);
@@ -264,6 +267,11 @@ private:
\*-------------------------------------------------------------------------------------*/
std::vector<i2c_smbus_interface*> busses;
/*-------------------------------------------------------------------------------------*\
| FanControllers |
\*-------------------------------------------------------------------------------------*/
std::vector<FanController*> fan_controllers;
/*-------------------------------------------------------------------------------------*\
| RGBControllers |
\*-------------------------------------------------------------------------------------*/

View File

@@ -13,6 +13,7 @@
#include "PluginManager.h"
#include "OpenRGBDevicePage.h"
#include "OpenRGBDeviceInfoPage.h"
#include "OpenRGBFanPage.h"
#include "OpenRGBServerInfoPage.h"
#include "OpenRGBConsolePage.h"
#include "OpenRGBPluginContainer.h"
@@ -1167,6 +1168,7 @@ void OpenRGBDialog2::ClearDevicesList()
void OpenRGBDialog2::UpdateDevicesList()
{
std::vector<FanController *> fan_controllers = ResourceManager::get()->GetFanControllers();
std::vector<RGBController *> controllers = ResourceManager::get()->GetRGBControllers();
/*-----------------------------------------------------*\
@@ -1332,6 +1334,31 @@ void OpenRGBDialog2::UpdateDevicesList()
base_tab += 1;
}
}
/*-----------------------------------------------------*\
| Set up list of fan devices |
\*-----------------------------------------------------*/
QTabBar *FanTabBar = ui->FanTabBar->tabBar();
for(std::size_t fan_idx = 0; fan_idx < fan_controllers.size(); fan_idx++)
{
OpenRGBFanPage *NewPage = new OpenRGBFanPage(fan_controllers[fan_idx]);
ui->FanTabBar->addTab(NewPage, "");
/*-----------------------------------------------------*\
| Use Qt's HTML capabilities to display both icon and |
| text in the tab label. Choose icon based on device |
| type and append device name string. |
\*-----------------------------------------------------*/
QString NewLabelString = QString::fromStdString(fan_controllers[fan_idx]->name);
QLabel *NewTabLabel = new QLabel();
NewTabLabel->setText(NewLabelString);
NewTabLabel->setIndent(20);
NewTabLabel->setGeometry(0, 0, 200, 20);
FanTabBar->setTabButton(fan_idx, QTabBar::LeftSide, NewTabLabel);
}
}
void OpenRGBDialog2::SetDialogMessage(PLogMessage msg)

View File

@@ -39,6 +39,7 @@
#include "PluginManager.h"
#include "i2c_smbus.h"
#include "FanController.h"
#include "LogManager.h"
#include "RGBController.h"
#include "ProfileManager.h"

View File

@@ -60,6 +60,23 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="TabFans">
<attribute name="title">
<string>Fans</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QTabWidget" name="FanTabBar">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="TabSettings">
<attribute name="title">
<string>Settings</string>

81
qt/OpenRGBFanPage.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include "OpenRGBFanPage.h"
#include <QTimer>
using namespace Ui;
OpenRGBFanPage::OpenRGBFanPage(FanController *dev, QWidget *parent) :
QFrame(parent),
ui(new Ui::OpenRGBFanPageUi)
{
ui->setupUi(this);
/*-----------------------------------------------------*\
| Store device pointer |
\*-----------------------------------------------------*/
device = dev;
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, QOverload<>::of(&OpenRGBFanPage::UpdateRPM));
timer->start(1000);
/*-----------------------------------------------------*\
| Fill in the fan box |
\*-----------------------------------------------------*/
for (std::size_t i = 0; i < device->fans.size(); i++)
{
ui->FanBox->addItem(device->fans[i].name.c_str());
ui->SpeedSlider->setMinimum(device->fans[i].speed_min);
ui->SpeedSlider->setMaximum(device->fans[i].speed_max);
ui->SpeedSlider->setValue(device->fans[i].speed_cmd);
ui->RPMValue->setText(QString::number(device->fans[i].rpm_rdg));
}
}
OpenRGBFanPage::~OpenRGBFanPage()
{
delete ui;
}
void OpenRGBFanPage::UpdateRPM()
{
/*-----------------------------------------------------*\
| Read selected fan |
\*-----------------------------------------------------*/
unsigned int selected_fan = (unsigned int)ui->FanBox->currentIndex();
device->UpdateReading();
ui->RPMValue->setText(QString::number(device->fans[selected_fan].rpm_rdg));
}
void OpenRGBFanPage::on_FanBox_currentIndexChanged(int /*index*/)
{
/*-----------------------------------------------------*\
| Read selected fan |
\*-----------------------------------------------------*/
unsigned int selected_fan = (unsigned int)ui->FanBox->currentIndex();
ui->SpeedSlider->setMinimum(device->fans[selected_fan].speed_min);
ui->SpeedSlider->setMaximum(device->fans[selected_fan].speed_max);
ui->SpeedSlider->setValue(device->fans[selected_fan].speed_cmd);
UpdateRPM();
}
void OpenRGBFanPage::on_ModeBox_currentIndexChanged(int /*index*/)
{
}
void OpenRGBFanPage::on_SpeedSlider_valueChanged(int /* value */)
{
/*-----------------------------------------------------*\
| Read selected fan |
\*-----------------------------------------------------*/
unsigned int selected_fan = (unsigned int)ui->FanBox->currentIndex();
unsigned int speed_cmd = ui->SpeedSlider->value();
device->fans[selected_fan].speed_cmd = speed_cmd;
device->UpdateControl();
}

40
qt/OpenRGBFanPage.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef OPENRGBFANPAGE_H
#define OPENRGBFANPAGE_H
#include "ui_OpenRGBFanPage.h"
#include "FanController.h"
#include <QFrame>
namespace Ui {
class OpenRGBFanPage;
}
class Ui::OpenRGBFanPage : public QFrame
{
Q_OBJECT
public:
explicit OpenRGBFanPage(FanController *dev, QWidget *parent = nullptr);
~OpenRGBFanPage();
void SetDevice(unsigned char red, unsigned char green, unsigned char blue);
void SetCustomMode();
void UpdateDevice();
void UpdateMode();
void UpdateModeUi();
private slots:
void UpdateRPM();
void on_FanBox_currentIndexChanged(int index);
void on_ModeBox_currentIndexChanged(int index);
void on_SpeedSlider_valueChanged(int value);
private:
Ui::OpenRGBFanPageUi *ui;
FanController *device;
signals:
};
#endif // OPENRGBDEVICEPAGE_H

75
qt/OpenRGBFanPage.ui Normal file
View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OpenRGBFanPageUi</class>
<widget class="QFrame" name="OpenRGBFanPageUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1" colspan="3">
<widget class="QSlider" name="SpeedSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="FanBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="FanLabel">
<property name="text">
<string>Fan:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QComboBox" name="ModeBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="SpeedLabel">
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="RPMLabel">
<property name="text">
<string>RPM:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="ModeLabel">
<property name="text">
<string>Mode:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QLabel" name="RPMValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>RPM Value</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>