Add FanBus support
This commit is contained in:
parent
2a2c0f010c
commit
117500ad04
9 changed files with 399 additions and 0 deletions
45
Controllers/FanBusController/FanBusController.cpp
Normal file
45
Controllers/FanBusController/FanBusController.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| FanBus RGB Controller Interface |
|
||||||
|
| |
|
||||||
|
| Adam Honse (calcprogrammer1@gmail.com), 1/12/2021 |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "FanBusController.h"
|
||||||
|
|
||||||
|
FanBusController::FanBusController(FanBusInterface* bus_ptr, unsigned char dev_addr)
|
||||||
|
{
|
||||||
|
bus = bus_ptr;
|
||||||
|
dev = dev_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FanBusController::~FanBusController()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FanBusController::GetLocation()
|
||||||
|
{
|
||||||
|
std::string location_string;
|
||||||
|
|
||||||
|
location_string = "FanBus: ";
|
||||||
|
location_string.append(bus->GetPort());
|
||||||
|
location_string.append(":");
|
||||||
|
location_string.append(std::to_string(dev));
|
||||||
|
|
||||||
|
return(location_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FanBusController::SetLEDs(std::vector<RGBColor> colors)
|
||||||
|
{
|
||||||
|
for(unsigned int led_idx = 0; led_idx < 4; led_idx++)
|
||||||
|
{
|
||||||
|
unsigned char red = RGBGetRValue(colors[led_idx]);
|
||||||
|
unsigned char grn = RGBGetGValue(colors[led_idx]);
|
||||||
|
unsigned char blu = RGBGetBValue(colors[led_idx]);
|
||||||
|
|
||||||
|
bus->write(dev, 0x10 + (led_idx * 3), red);
|
||||||
|
bus->write(dev, 0x11 + (led_idx * 3), grn);
|
||||||
|
bus->write(dev, 0x12 + (led_idx * 3), blu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bus->write(dev, 0x0C, 0x01);
|
||||||
|
}
|
||||||
28
Controllers/FanBusController/FanBusController.h
Normal file
28
Controllers/FanBusController/FanBusController.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Definitions for FanBus RGB Controller Interface |
|
||||||
|
| |
|
||||||
|
| Adam Honse (calcprogrammer1@gmail.com), 1/12/2021 |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "FanBusInterface.h"
|
||||||
|
#include "RGBController.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class FanBusController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FanBusController(FanBusInterface* bus_ptr, unsigned char dev_addr);
|
||||||
|
~FanBusController();
|
||||||
|
|
||||||
|
std::string GetLocation();
|
||||||
|
|
||||||
|
void SetLEDs(std::vector<RGBColor> colors);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string port_name;
|
||||||
|
FanBusInterface* bus;
|
||||||
|
unsigned char dev;
|
||||||
|
};
|
||||||
45
Controllers/FanBusController/FanBusControllerDetect.cpp
Normal file
45
Controllers/FanBusController/FanBusControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
#include "Detector.h"
|
||||||
|
#include "FanBusController.h"
|
||||||
|
#include "RGBController_FanBus.h"
|
||||||
|
|
||||||
|
void DetectFanBusControllers(std::vector<RGBController*> &rgb_controllers)
|
||||||
|
{
|
||||||
|
FanBusInterface* new_interface;
|
||||||
|
FanBusController* new_controller;
|
||||||
|
RGBController_FanBus* new_rgbcontroller;
|
||||||
|
|
||||||
|
json fanbus_settings;
|
||||||
|
|
||||||
|
/*-------------------------------------------------*\
|
||||||
|
| Get LED Strip settings from settings manager |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
fanbus_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("FanBusDevices");
|
||||||
|
|
||||||
|
/*-------------------------------------------------*\
|
||||||
|
| If the LEDStrip settings contains devices, process|
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
if(fanbus_settings.contains("devices"))
|
||||||
|
{
|
||||||
|
for(unsigned int device_idx = 0; device_idx < fanbus_settings["devices"].size(); device_idx++)
|
||||||
|
{
|
||||||
|
if(fanbus_settings["devices"][device_idx].contains("port"))
|
||||||
|
{
|
||||||
|
std::string port_val = fanbus_settings["devices"][device_idx]["port"];
|
||||||
|
|
||||||
|
new_interface = new FanBusInterface(port_val.c_str());
|
||||||
|
|
||||||
|
std::vector<unsigned char> detected_controllers = new_interface->DetectControllers();
|
||||||
|
|
||||||
|
for(unsigned int controller_idx = 0; controller_idx < detected_controllers.size(); controller_idx++)
|
||||||
|
{
|
||||||
|
new_controller = new FanBusController(new_interface, detected_controllers[controller_idx]);
|
||||||
|
new_rgbcontroller = new RGBController_FanBus(new_controller);
|
||||||
|
|
||||||
|
rgb_controllers.push_back(new_rgbcontroller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_DETECTOR("FanBus", DetectFanBusControllers);
|
||||||
113
Controllers/FanBusController/FanBusInterface.cpp
Normal file
113
Controllers/FanBusController/FanBusInterface.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| FanBus Interface |
|
||||||
|
| |
|
||||||
|
| Adam Honse (calcprogrammer1@gmail.com), 1/12/2021 |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "FanBusInterface.h"
|
||||||
|
|
||||||
|
FanBusInterface::FanBusInterface(const char* portname)
|
||||||
|
{
|
||||||
|
port_name = portname;
|
||||||
|
serialport = new serial_port(portname, 38400);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------*\
|
||||||
|
| Flush any data in the receive queue |
|
||||||
|
\*-----------------------------------------------------*/
|
||||||
|
char read_buf[6];
|
||||||
|
|
||||||
|
while(serialport->serial_read(read_buf, 6) > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
read_buf[0] = 0xFF;
|
||||||
|
|
||||||
|
serialport->serial_write(read_buf, 1);
|
||||||
|
int test = serialport->serial_read(read_buf, 1);
|
||||||
|
|
||||||
|
if(test > 0)
|
||||||
|
{
|
||||||
|
half_duplex = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
half_duplex = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FanBusInterface::~FanBusInterface()
|
||||||
|
{
|
||||||
|
serialport->serial_close();
|
||||||
|
delete serialport;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FanBusInterface::GetPort()
|
||||||
|
{
|
||||||
|
return(port_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FanBusInterface::read
|
||||||
|
(
|
||||||
|
unsigned char dev_addr,
|
||||||
|
unsigned char int_addr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
unsigned char fanbus_msg[] = { 0x01, int_addr, dev_addr, 0x00, 0xFF };
|
||||||
|
|
||||||
|
serialport->serial_write((char *)fanbus_msg, 5);
|
||||||
|
|
||||||
|
usleep(1000);
|
||||||
|
|
||||||
|
char read_buf[6];
|
||||||
|
|
||||||
|
if(half_duplex)
|
||||||
|
{
|
||||||
|
if(serialport->serial_read(read_buf, 6) == 6)
|
||||||
|
{
|
||||||
|
return(read_buf[5]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(serialport->serial_read(read_buf, 1) == 1)
|
||||||
|
{
|
||||||
|
return(read_buf[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FanBusInterface::write
|
||||||
|
(
|
||||||
|
unsigned char dev_addr,
|
||||||
|
unsigned char int_addr,
|
||||||
|
unsigned char val
|
||||||
|
)
|
||||||
|
{
|
||||||
|
unsigned char fanbus_msg[] = { 0x00, int_addr, dev_addr, val, 0xFF };
|
||||||
|
|
||||||
|
return(serialport->serial_write((char *)fanbus_msg, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> FanBusInterface::DetectControllers()
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> detected_controllers;
|
||||||
|
|
||||||
|
for(unsigned int dev_addr = 0x03; dev_addr < 0xFF; dev_addr++)
|
||||||
|
{
|
||||||
|
if(read(dev_addr, 0x00) >= 0)
|
||||||
|
{
|
||||||
|
detected_controllers.push_back(dev_addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(detected_controllers);
|
||||||
|
}
|
||||||
39
Controllers/FanBusController/FanBusInterface.h
Normal file
39
Controllers/FanBusController/FanBusInterface.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| FanBus Interface |
|
||||||
|
| |
|
||||||
|
| Adam Honse (calcprogrammer1@gmail.com), 1/12/2021 |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "serial_port.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class FanBusInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FanBusInterface(const char* portname);
|
||||||
|
~FanBusInterface();
|
||||||
|
|
||||||
|
std::vector<unsigned char> DetectControllers();
|
||||||
|
|
||||||
|
std::string GetPort();
|
||||||
|
|
||||||
|
int read
|
||||||
|
(
|
||||||
|
unsigned char dev_addr,
|
||||||
|
unsigned char int_addr
|
||||||
|
);
|
||||||
|
|
||||||
|
int write
|
||||||
|
(
|
||||||
|
unsigned char dev_addr,
|
||||||
|
unsigned char int_addr,
|
||||||
|
unsigned char val
|
||||||
|
);
|
||||||
|
|
||||||
|
private:
|
||||||
|
serial_port * serialport;
|
||||||
|
std::string port_name;
|
||||||
|
bool half_duplex;
|
||||||
|
};
|
||||||
83
Controllers/FanBusController/RGBController_FanBus.cpp
Normal file
83
Controllers/FanBusController/RGBController_FanBus.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*-----------------------------------------*\
|
||||||
|
| RGBController_FanBus.cpp |
|
||||||
|
| |
|
||||||
|
| Generic RGB Interface for FanBus devices |
|
||||||
|
| |
|
||||||
|
| Adam Honse (CalcProgrammer1) 1/12/2021 |
|
||||||
|
\*-----------------------------------------*/
|
||||||
|
|
||||||
|
#include "RGBController_FanBus.h"
|
||||||
|
|
||||||
|
RGBController_FanBus::RGBController_FanBus(FanBusController* controller_ptr)
|
||||||
|
{
|
||||||
|
controller = controller_ptr;
|
||||||
|
|
||||||
|
name = "FanBus Device";
|
||||||
|
type = DEVICE_TYPE_COOLER;
|
||||||
|
description = "FanBus Device";
|
||||||
|
location = controller->GetLocation();
|
||||||
|
|
||||||
|
mode Direct;
|
||||||
|
Direct.name = "Direct";
|
||||||
|
Direct.value = 0;
|
||||||
|
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||||
|
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||||
|
modes.push_back(Direct);
|
||||||
|
|
||||||
|
SetupZones();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::SetupZones()
|
||||||
|
{
|
||||||
|
zone led_zone;
|
||||||
|
led_zone.name = "Fan LEDs";
|
||||||
|
led_zone.type = ZONE_TYPE_SINGLE;
|
||||||
|
led_zone.leds_min = 4;
|
||||||
|
led_zone.leds_max = 4;
|
||||||
|
led_zone.leds_count = 4;
|
||||||
|
led_zone.matrix_map = NULL;
|
||||||
|
zones.push_back(led_zone);
|
||||||
|
|
||||||
|
for(int led_idx = 0; led_idx < led_zone.leds_count; led_idx++)
|
||||||
|
{
|
||||||
|
led new_led;
|
||||||
|
new_led.name = "LED ";
|
||||||
|
new_led.name.append(std::to_string(led_idx));
|
||||||
|
|
||||||
|
leds.push_back(new_led);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| This device does not support resizing zones |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::DeviceUpdateLEDs()
|
||||||
|
{
|
||||||
|
controller->SetLEDs(colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::UpdateZoneLEDs(int /*zone*/)
|
||||||
|
{
|
||||||
|
controller->SetLEDs(colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::UpdateSingleLED(int /*led*/)
|
||||||
|
{
|
||||||
|
controller->SetLEDs(colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::SetCustomMode()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBController_FanBus::DeviceUpdateMode()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
31
Controllers/FanBusController/RGBController_FanBus.h
Normal file
31
Controllers/FanBusController/RGBController_FanBus.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*-----------------------------------------*\
|
||||||
|
| RGBController_FanBus.h |
|
||||||
|
| |
|
||||||
|
| Generic RGB Interface for FanBus devices |
|
||||||
|
| |
|
||||||
|
| Adam Honse (CalcProgrammer1) 1/12/2021 |
|
||||||
|
\*-----------------------------------------*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "RGBController.h"
|
||||||
|
#include "FanBusController.h"
|
||||||
|
|
||||||
|
class RGBController_FanBus : public RGBController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RGBController_FanBus(FanBusController* controller_ptr);
|
||||||
|
|
||||||
|
void SetupZones();
|
||||||
|
|
||||||
|
void ResizeZone(int zone, int new_size);
|
||||||
|
|
||||||
|
void DeviceUpdateLEDs();
|
||||||
|
void UpdateZoneLEDs(int zone);
|
||||||
|
void UpdateSingleLED(int led);
|
||||||
|
|
||||||
|
void SetCustomMode();
|
||||||
|
void DeviceUpdateMode();
|
||||||
|
|
||||||
|
private:
|
||||||
|
FanBusController* controller;
|
||||||
|
};
|
||||||
|
|
@ -70,6 +70,7 @@ INCLUDEPATH +=
|
||||||
Controllers/EKController/ \
|
Controllers/EKController/ \
|
||||||
Controllers/EspurnaController/ \
|
Controllers/EspurnaController/ \
|
||||||
Controllers/EVGAGPUController/ \
|
Controllers/EVGAGPUController/ \
|
||||||
|
Controllers/FanBusController/ \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/ \
|
Controllers/GigabyteAorusCPUCoolerController/ \
|
||||||
Controllers/GigabyteRGBFusion2DRAMController/ \
|
Controllers/GigabyteRGBFusion2DRAMController/ \
|
||||||
Controllers/GigabyteRGBFusion2SMBusController/ \
|
Controllers/GigabyteRGBFusion2SMBusController/ \
|
||||||
|
|
@ -185,6 +186,9 @@ HEADERS +=
|
||||||
Controllers/EVGAGPUController/EVGAGPUv2Controller.h \
|
Controllers/EVGAGPUController/EVGAGPUv2Controller.h \
|
||||||
Controllers/EVGAGPUController/RGBController_EVGAGPUv1.h \
|
Controllers/EVGAGPUController/RGBController_EVGAGPUv1.h \
|
||||||
Controllers/EVGAGPUController/RGBController_EVGAGPUv2.h \
|
Controllers/EVGAGPUController/RGBController_EVGAGPUv2.h \
|
||||||
|
Controllers/FanBusController/FanBusController.h \
|
||||||
|
Controllers/FanBusController/FanBusInterface.h \
|
||||||
|
Controllers/FanBusController/RGBController_FanBus.h \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.h \
|
Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.h \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/RGBController_AorusATC800.h \
|
Controllers/GigabyteAorusCPUCoolerController/RGBController_AorusATC800.h \
|
||||||
Controllers/GigabyteRGBFusion2DRAMController/GigabyteRGBFusion2DRAMController.h \
|
Controllers/GigabyteRGBFusion2DRAMController/GigabyteRGBFusion2DRAMController.h \
|
||||||
|
|
@ -383,6 +387,10 @@ SOURCES +=
|
||||||
Controllers/EVGAGPUController/EVGAGPUControllerDetect.cpp \
|
Controllers/EVGAGPUController/EVGAGPUControllerDetect.cpp \
|
||||||
Controllers/EVGAGPUController/RGBController_EVGAGPUv1.cpp \
|
Controllers/EVGAGPUController/RGBController_EVGAGPUv1.cpp \
|
||||||
Controllers/EVGAGPUController/RGBController_EVGAGPUv2.cpp \
|
Controllers/EVGAGPUController/RGBController_EVGAGPUv2.cpp \
|
||||||
|
Controllers/FanBusController/FanBusController.cpp \
|
||||||
|
Controllers/FanBusController/FanBusControllerDetect.cpp \
|
||||||
|
Controllers/FanBusController/FanBusInterface.cpp \
|
||||||
|
Controllers/FanBusController/RGBController_FanBus.cpp \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp \
|
Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/GigabyteAorusCPUCoolerControllerDetect.cpp \
|
Controllers/GigabyteAorusCPUCoolerController/GigabyteAorusCPUCoolerControllerDetect.cpp \
|
||||||
Controllers/GigabyteAorusCPUCoolerController/RGBController_AorusATC800.cpp \
|
Controllers/GigabyteAorusCPUCoolerController/RGBController_AorusATC800.cpp \
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,15 @@ bool serial_port::serial_open()
|
||||||
ioctl(file_descriptor, TCGETS2, &options);
|
ioctl(file_descriptor, TCGETS2, &options);
|
||||||
options.c_cflag &= ~CBAUD;
|
options.c_cflag &= ~CBAUD;
|
||||||
options.c_cflag |= BOTHER;
|
options.c_cflag |= BOTHER;
|
||||||
|
options.c_lflag &= ~ICANON;
|
||||||
|
options.c_lflag &= ~ECHO; // Disable echo
|
||||||
|
options.c_lflag &= ~ECHOE; // Disable erasure
|
||||||
|
options.c_lflag &= ~ECHONL; // Disable new-line echo
|
||||||
|
options.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
||||||
|
options.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
||||||
options.c_ispeed = baud_rate;
|
options.c_ispeed = baud_rate;
|
||||||
options.c_ospeed = baud_rate;
|
options.c_ospeed = baud_rate;
|
||||||
|
options.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes
|
||||||
ioctl(file_descriptor, TCSETS2, &options);
|
ioctl(file_descriptor, TCSETS2, &options);
|
||||||
|
|
||||||
//serial_struct ss;
|
//serial_struct ss;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue