From 3d2d86d129cfe235a867e852f58219d5ed4dd752 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Mon, 4 Jan 2021 23:44:23 -0600 Subject: [PATCH] Finalize plugin interface and rework into a template for plugin development --- Dependencies/ResourceManager.h | 147 -------- ORGBExamplePlugin.cpp | 50 --- ORGBExamplePlugin.h | 33 -- ORGBExamplePlugin.pro | 34 -- ORGBExamplePlugin.pro.user | 357 ------------------ ORGBPluginInterface.h | 35 -- {Dependencies => OpenRGB}/NetworkClient.h | 0 {Dependencies => OpenRGB}/NetworkProtocol.h | 0 {Dependencies => OpenRGB}/NetworkServer.h | 0 OpenRGB/OpenRGBPluginInterface.h | 43 +++ OpenRGB/ProfileManager.h | 70 ++++ .../RGBController}/RGBController.h | 0 OpenRGB/ResourceManager.h | 117 ++++++ {Dependencies => OpenRGB}/SettingsManager.h | 24 +- .../dependencies/json}/json.hpp | 0 OpenRGB/i2c_smbus/i2c_smbus.h | 129 +++++++ {Dependencies => OpenRGB/net_port}/net_port.h | 0 OpenRGBPlugin.cpp | 114 ++++++ OpenRGBPlugin.h | 40 ++ OpenRGBPlugin.pro | 65 ++++ 20 files changed, 596 insertions(+), 662 deletions(-) delete mode 100644 Dependencies/ResourceManager.h delete mode 100644 ORGBExamplePlugin.cpp delete mode 100644 ORGBExamplePlugin.h delete mode 100644 ORGBExamplePlugin.pro delete mode 100644 ORGBExamplePlugin.pro.user delete mode 100644 ORGBPluginInterface.h rename {Dependencies => OpenRGB}/NetworkClient.h (100%) rename {Dependencies => OpenRGB}/NetworkProtocol.h (100%) rename {Dependencies => OpenRGB}/NetworkServer.h (100%) create mode 100644 OpenRGB/OpenRGBPluginInterface.h create mode 100644 OpenRGB/ProfileManager.h rename {Dependencies => OpenRGB/RGBController}/RGBController.h (100%) create mode 100644 OpenRGB/ResourceManager.h rename {Dependencies => OpenRGB}/SettingsManager.h (53%) rename {Dependencies => OpenRGB/dependencies/json}/json.hpp (100%) create mode 100644 OpenRGB/i2c_smbus/i2c_smbus.h rename {Dependencies => OpenRGB/net_port}/net_port.h (100%) create mode 100644 OpenRGBPlugin.cpp create mode 100644 OpenRGBPlugin.h create mode 100644 OpenRGBPlugin.pro diff --git a/Dependencies/ResourceManager.h b/Dependencies/ResourceManager.h deleted file mode 100644 index 2239004..0000000 --- a/Dependencies/ResourceManager.h +++ /dev/null @@ -1,147 +0,0 @@ -/*-----------------------------------------*\ -| ResourceManager.h | -| | -| OpenRGB Resource Manager controls access | -| to application components including | -| RGBControllers, I2C interfaces, and | -| network SDK components | -| | -| Adam Honse (CalcProgrammer1) 9/27/2020 | -\*-----------------------------------------*/ - -#pragma once - -#include -#include -#include -#include -#include - -#include "NetworkClient.h" -#include "NetworkServer.h" -#include "RGBController.h" -#include "SettingsManager.h" - -#define HID_INTERFACE_ANY -1 -#define HID_USAGE_ANY -1 -#define HID_USAGE_PAGE_ANY -1L - -#define CONTROLLER_LIST_HID 0 - -struct hid_device_info; - -typedef std::function&)> DeviceDetectorFunction; - -typedef void (*DeviceListChangeCallback)(void *); -typedef void (*DetectionProgressCallback)(void *); -typedef void (*I2CBusListChangeCallback)(void *); - -class ResourceManager -{ -public: - static ResourceManager *get(); - - ResourceManager(); - ~ResourceManager(); - - void RegisterRGBController(RGBController *rgb_controller); - - std::vector & GetRGBControllers(); - - unsigned int GetDetectionPercent(); - const char* GetDetectionString(); - - std::string GetConfigurationDirectory(); - - std::vector& GetClients(); - NetworkServer* GetServer(); - - SettingsManager* GetSettingsManager(); - - void SetConfigurationDirectory(std::string directory); - - void DeviceListChanged(); - void DetectionProgressChanged(); - void I2CBusListChanged(); - - void Cleanup(); - - void DetectDevices(); - - void DisableDetection(); - - void StopDeviceDetection(); - - void WaitForDeviceDetection(); - -private: - void DetectDevicesThreadFunction(); - - static std::unique_ptr instance; - - /*-------------------------------------------------------------------------------------*\ - | Detection enabled flag | - \*-------------------------------------------------------------------------------------*/ - bool detection_enabled; - - /*-------------------------------------------------------------------------------------*\ - | Settings Manager | - \*-------------------------------------------------------------------------------------*/ - SettingsManager* settings_manager; - - /*-------------------------------------------------------------------------------------*\ - | RGBControllers | - \*-------------------------------------------------------------------------------------*/ - std::vector rgb_controllers_sizes; - std::vector rgb_controllers_hw; - std::vector rgb_controllers; - - /*-------------------------------------------------------------------------------------*\ - | Network Server | - \*-------------------------------------------------------------------------------------*/ - NetworkServer* server; - - /*-------------------------------------------------------------------------------------*\ - | Network Clients | - \*-------------------------------------------------------------------------------------*/ - std::vector clients; - - /*-------------------------------------------------------------------------------------*\ - | Detectors | - \*-------------------------------------------------------------------------------------*/ - std::vector device_detectors; - std::vector device_detector_strings; - std::vector i2c_device_detector_strings; - std::vector hid_device_detector_strings; - - /*-------------------------------------------------------------------------------------*\ - | Detection Thread and Detection State | - \*-------------------------------------------------------------------------------------*/ - std::thread * DetectDevicesThread; - std::mutex DetectDeviceMutex; - - std::atomic detection_is_required; - std::atomic detection_percent; - const char* detection_string; - - /*-------------------------------------------------------------------------------------*\ - | Device List Changed Callback | - \*-------------------------------------------------------------------------------------*/ - std::mutex DeviceListChangeMutex; - std::vector DeviceListChangeCallbacks; - std::vector DeviceListChangeCallbackArgs; - - /*-------------------------------------------------------------------------------------*\ - | Detection Progress Callback | - \*-------------------------------------------------------------------------------------*/ - std::mutex DetectionProgressMutex; - std::vector DetectionProgressCallbacks; - std::vector DetectionProgressCallbackArgs; - - /*-------------------------------------------------------------------------------------*\ - | I2C/SMBus Adapter List Changed Callback | - \*-------------------------------------------------------------------------------------*/ - std::mutex I2CBusListChangeMutex; - std::vector I2CBusListChangeCallbacks; - std::vector I2CBusListChangeCallbackArgs; -}; diff --git a/ORGBExamplePlugin.cpp b/ORGBExamplePlugin.cpp deleted file mode 100644 index 2763f72..0000000 --- a/ORGBExamplePlugin.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "ORGBExamplePlugin.h" -#include "Dependencies/ResourceManager.h" - -PluginInfo ORGBPlugin::DefineNeeded() -{ - ORGBPlugin::PInfo.PluginName = "Example"; - ORGBPlugin::PInfo.PluginDesc = "An example Plugin for OpenRGB"; - ORGBPlugin::PInfo.PluginLoca = "InfoTab"; - - ORGBPlugin::PInfo.HasCustom = false; - ORGBPlugin::PInfo.SettingName = ""; - - return ORGBPlugin::PInfo; -} - -QLabel* TabLabel() -{ - QLabel *TLabel = new QLabel(); - TLabel->setText("Example"); - return TLabel; -} - -PluginInfo ORGBPlugin::init(json Settings, bool DarkTheme) -{ - ORGBPlugin::PInfo.PluginLabel = TabLabel(); - - return ORGBPlugin::PInfo; -} - -QWidget* ORGBPlugin::CreateGUI(QWidget *Parent) -{ - QWidget *ORGBExamplePage = new QWidget(Parent); - QLabel *ORGBExampleLabel = new QLabel(ORGBExamplePage); - - QPushButton *ORGBExamplePushButton = new QPushButton(ORGBExamplePage); - qDebug() << ORGBExamplePushButton->objectName(); - connect(ORGBExamplePushButton,SIGNAL(clicked()) ,this , SLOT(on_ExampleButton_clicked())); - - ORGBExampleLabel->setText("This is an example page added by plugins"); - return ORGBExamplePage; -} - -void ORGBPlugin::on_ExampleButton_clicked() -{ - QDialog *ButtonDialog = new QDialog(); - ButtonDialog->setModal(true); - QLabel *DialogText = new QLabel(ButtonDialog); - DialogText->setText("This is the result of the button being clicked"); - ButtonDialog->show(); -} diff --git a/ORGBExamplePlugin.h b/ORGBExamplePlugin.h deleted file mode 100644 index 2cf4527..0000000 --- a/ORGBExamplePlugin.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "ORGBPluginInterface.h" -#include "Dependencies/ResourceManager.h" - -#include -#include -#include -#include "QWidget" -#include "QLabel" -#include "QPushButton" -#include "QDialog" -#include "QAction" - -class ORGBPlugin : public QObject, public ORGBPluginInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID ORGBPluginInterface_IID) - Q_INTERFACES(ORGBPluginInterface) - -public: - virtual ~ORGBPlugin() {}; - - PluginInfo PInfo; - - virtual PluginInfo DefineNeeded() override; - - virtual PluginInfo init(json Settings , bool DarkTheme) override; - - virtual QWidget *CreateGUI(QWidget *Parent) override; -private slots: - void on_ExampleButton_clicked(); -}; diff --git a/ORGBExamplePlugin.pro b/ORGBExamplePlugin.pro deleted file mode 100644 index 358b396..0000000 --- a/ORGBExamplePlugin.pro +++ /dev/null @@ -1,34 +0,0 @@ -QT += \ - gui \ - widgets \ - core \ - -TEMPLATE = lib -DEFINES += ORGBEXAMPLEPLUGIN_LIBRARY - -CONFIG += c++11 - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - ORGBExamplePlugin.cpp - -HEADERS += \ - ORGBExamplePlugin.h \ - Dependencies/ResourceManager.h \ - Dependencies/RGBController.h \ - Dependencies/NetworkClient.h \ - Dependencies/NetworkServer.h \ - Dependencies/SettingsManager.h \ - Dependencies/NetworkProtocol.h \ - Dependencies/net_port.h \ - Dependencies/json.hpp \ - ORGBPluginInterface.h - -# Default rules for deployment. -unix { - target.path = /usr/lib -} -!isEmpty(target.path): INSTALLS += target diff --git a/ORGBExamplePlugin.pro.user b/ORGBExamplePlugin.pro.user deleted file mode 100644 index 67a21bf..0000000 --- a/ORGBExamplePlugin.pro.user +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - EnvironmentId - {a9f886a9-a27f-40ea-90f1-a5ecc7e77297} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - true - true - true - true - - - 0 - true - - -fno-delayed-template-parsing - - true - Builtin.Questionable - - true - Builtin.DefaultTidyAndClazy - 6 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 5.15.1 MSVC2019 64bit - Desktop Qt 5.15.1 MSVC2019 64bit - qt.qt5.5151.win64_msvc2019_64_kit - 1 - 0 - 0 - - true - 0 - C:\Users\heros\OneDrive\Documents\Code\OpenRGB related\Plugin\build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug - C:/Users/heros/OneDrive/Documents/Code/OpenRGB related/Plugin/build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - - true - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 2 - 2 - - - true - 2 - C:\Users\heros\OneDrive\Documents\Code\OpenRGB related\Plugin\build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Release - C:/Users/heros/OneDrive/Documents/Code/OpenRGB related/Plugin/build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 2 - - - true - 0 - C:\Users\heros\OneDrive\Documents\Code\OpenRGB related\Plugin\build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Profile - C:/Users/heros/OneDrive/Documents/Code/OpenRGB related/Plugin/build-ORGBExamplePlugin-Desktop_Qt_5_15_1_MSVC2019_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - - true - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - - ProjectExplorer.CustomExecutableRunConfiguration - - - false - - false - true - false - false - true - - - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/ORGBPluginInterface.h b/ORGBPluginInterface.h deleted file mode 100644 index f68f28f..0000000 --- a/ORGBPluginInterface.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include -#include "Dependencies/ResourceManager.h" - -#define ORGBPluginInterface_IID "com.ORGBPluginInterface" - -struct PluginInfo -{ - std::string PluginName; - std::string PluginDesc; - std::string PluginLoca; - - bool HasCustom; - QLabel *PluginLabel; - - std::string SettingName; -}; - -class ORGBPluginInterface -{ -public: - virtual ~ORGBPluginInterface() {} - - PluginInfo PInfo; - - virtual PluginInfo DefineNeeded() = 0; - - virtual PluginInfo init(json Settings , bool DarkTheme) = 0; - - virtual QWidget *CreateGUI(QWidget *Parent) = 0; -}; - -Q_DECLARE_INTERFACE(ORGBPluginInterface, ORGBPluginInterface_IID) diff --git a/Dependencies/NetworkClient.h b/OpenRGB/NetworkClient.h similarity index 100% rename from Dependencies/NetworkClient.h rename to OpenRGB/NetworkClient.h diff --git a/Dependencies/NetworkProtocol.h b/OpenRGB/NetworkProtocol.h similarity index 100% rename from Dependencies/NetworkProtocol.h rename to OpenRGB/NetworkProtocol.h diff --git a/Dependencies/NetworkServer.h b/OpenRGB/NetworkServer.h similarity index 100% rename from Dependencies/NetworkServer.h rename to OpenRGB/NetworkServer.h diff --git a/OpenRGB/OpenRGBPluginInterface.h b/OpenRGB/OpenRGBPluginInterface.h new file mode 100644 index 0000000..9ee829f --- /dev/null +++ b/OpenRGB/OpenRGBPluginInterface.h @@ -0,0 +1,43 @@ +/*-----------------------------------------*\ +| OpenRGBPluginInterface.h | +| | +| OpenRGB Plugin Interface Class | +| | +| herosilas12 (CoffeeIsLife) 12/11/2020 | +| Adam Honse (CalcProgrammer1) 1/5/2021 | +\*-----------------------------------------*/ + +#pragma once + +#include "ResourceManager.h" + +#include +#include + +#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface" + +struct OpenRGBPluginInfo +{ + std::string PluginName; + std::string PluginDescription; + std::string PluginLocation; + + bool HasCustom; + QLabel *PluginLabel; + + std::string SettingName; +}; + +class OpenRGBPluginInterface +{ +public: + virtual ~OpenRGBPluginInterface() {} + + virtual OpenRGBPluginInfo Initialize(bool dark_theme, ResourceManager* resource_manager_ptr) = 0; + + virtual QWidget *CreateGUI(QWidget* parent) = 0; + + OpenRGBPluginInfo info; +}; + +Q_DECLARE_INTERFACE(OpenRGBPluginInterface, OpenRGBPluginInterface_IID) diff --git a/OpenRGB/ProfileManager.h b/OpenRGB/ProfileManager.h new file mode 100644 index 0000000..3769698 --- /dev/null +++ b/OpenRGB/ProfileManager.h @@ -0,0 +1,70 @@ +#include "RGBController.h" + +#pragma once + +class ProfileManagerInterface +{ +public: + virtual bool SaveProfile(std::string profile_name) = 0; + virtual bool LoadProfile(std::string profile_name) = 0; + virtual bool LoadSizeFromProfile(std::string profile_name) = 0; + virtual void DeleteProfile(std::string profile_name) = 0; + + std::vector profile_list; + + virtual bool LoadDeviceFromListWithOptions + ( + std::vector& temp_controllers, + std::vector& temp_controller_used, + RGBController* load_controller, + bool load_size, + bool load_settings + ) = 0; + + virtual std::vector LoadProfileToList (std::string profile_name) = 0; + + virtual void SetConfigurationDirectory(std::string directory) = 0; +protected: + virtual ~ProfileManagerInterface() {}; +}; + +class ProfileManager: public ProfileManagerInterface +{ +public: + ProfileManager(std::string config_dir); + ~ProfileManager(); + + bool SaveProfile(std::string profile_name); + bool LoadProfile(std::string profile_name); + bool LoadSizeFromProfile(std::string profile_name); + void DeleteProfile(std::string profile_name); + + std::vector profile_list; + + bool LoadDeviceFromListWithOptions + ( + std::vector& temp_controllers, + std::vector& temp_controller_used, + RGBController* load_controller, + bool load_size, + bool load_settings + ); + + std::vector LoadProfileToList + ( + std::string profile_name + ); + + void SetConfigurationDirectory(std::string directory); + +private: + std::string configuration_directory; + + void UpdateProfileList(); + bool LoadProfileWithOptions + ( + std::string profile_name, + bool load_size, + bool load_settings + ); +}; diff --git a/Dependencies/RGBController.h b/OpenRGB/RGBController/RGBController.h similarity index 100% rename from Dependencies/RGBController.h rename to OpenRGB/RGBController/RGBController.h diff --git a/OpenRGB/ResourceManager.h b/OpenRGB/ResourceManager.h new file mode 100644 index 0000000..cf450dd --- /dev/null +++ b/OpenRGB/ResourceManager.h @@ -0,0 +1,117 @@ +/*-----------------------------------------*\ +| ResourceManager.h | +| | +| OpenRGB Resource Manager controls access | +| to application components including | +| RGBControllers, I2C interfaces, and | +| network SDK components | +| | +| Adam Honse (CalcProgrammer1) 9/27/2020 | +\*-----------------------------------------*/ + +#pragma once + +#include +#include +#include +#include +#include + +#include "i2c_smbus.h" +#include "NetworkClient.h" +#include "NetworkServer.h" +#include "ProfileManager.h" +#include "RGBController.h" +#include "SettingsManager.h" + +#define HID_INTERFACE_ANY -1 +#define HID_USAGE_ANY -1 +#define HID_USAGE_PAGE_ANY -1L + +#define CONTROLLER_LIST_HID 0 + +typedef std::function&)> I2CBusDetectorFunction; +typedef std::function&)> DeviceDetectorFunction; +typedef std::function&, std::vector&)> I2CDeviceDetectorFunction; + +typedef void (*DeviceListChangeCallback)(void *); +typedef void (*DetectionProgressCallback)(void *); +typedef void (*I2CBusListChangeCallback)(void *); + +class ResourceManagerInterface +{ +public: + virtual std::vector & GetI2CBusses() = 0; + + virtual void RegisterRGBController(RGBController *rgb_controller) = 0; + + virtual void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg) = 0; + virtual void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg) = 0; + virtual void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg) = 0; + + virtual std::vector & GetRGBControllers() = 0; + + virtual std::string GetConfigurationDirectory() = 0; + + virtual std::vector& GetClients() = 0; + virtual NetworkServer* GetServer() = 0; + + virtual ProfileManager* GetProfileManager() = 0; + virtual SettingsManager* GetSettingsManager() = 0; + + virtual void DeviceListChanged() = 0; + +protected: + virtual ~ResourceManagerInterface() {}; +}; + +class ResourceManager: public ResourceManagerInterface +{ +public: + static ResourceManager *get(); + + ResourceManager(); + ~ResourceManager(); + + void RegisterI2CBus(i2c_smbus_interface *); + std::vector & GetI2CBusses(); + + void RegisterRGBController(RGBController *rgb_controller); + + std::vector & GetRGBControllers(); + + void RegisterI2CBusDetector (I2CBusDetectorFunction detector); + void RegisterDeviceDetector (std::string name, DeviceDetectorFunction detector); + void RegisterI2CDeviceDetector (std::string name, I2CDeviceDetectorFunction detector); + + void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg); + void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg); + void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg); + + unsigned int GetDetectionPercent(); + const char* GetDetectionString(); + + std::string GetConfigurationDirectory(); + + std::vector& GetClients(); + NetworkServer* GetServer(); + + ProfileManager* GetProfileManager(); + SettingsManager* GetSettingsManager(); + + void SetConfigurationDirectory(std::string directory); + + void DeviceListChanged(); + void DetectionProgressChanged(); + void I2CBusListChanged(); + + void Cleanup(); + + void DetectDevices(); + + void DisableDetection(); + + void StopDeviceDetection(); + + void WaitForDeviceDetection(); +}; diff --git a/Dependencies/SettingsManager.h b/OpenRGB/SettingsManager.h similarity index 53% rename from Dependencies/SettingsManager.h rename to OpenRGB/SettingsManager.h index 48a3dbd..350e72c 100644 --- a/Dependencies/SettingsManager.h +++ b/OpenRGB/SettingsManager.h @@ -15,19 +15,31 @@ using json = nlohmann::json; -class SettingsManager +class SettingsManagerInterface +{ +public: + virtual json GetSettings(std::string settings_key) = 0; + virtual void SetSettings(std::string settings_key, json new_settings) = 0; + + virtual void LoadSettings(std::string filename) = 0; + virtual void SaveSettings() = 0; + +protected: + virtual ~SettingsManagerInterface() {}; +}; + +class SettingsManager: public SettingsManagerInterface { public: SettingsManager(); ~SettingsManager(); - json GetSettings(std::string settings_key); - void SetSettings(std::string settings_key, json new_settings); + json GetSettings(std::string settings_key) override; + void SetSettings(std::string settings_key, json new_settings) override; - void LoadSettings(std::string filename); - void SaveSettings(); + void LoadSettings(std::string filename) override; + void SaveSettings() override; - private: json settings_data; json settings_prototype; diff --git a/Dependencies/json.hpp b/OpenRGB/dependencies/json/json.hpp similarity index 100% rename from Dependencies/json.hpp rename to OpenRGB/dependencies/json/json.hpp diff --git a/OpenRGB/i2c_smbus/i2c_smbus.h b/OpenRGB/i2c_smbus/i2c_smbus.h new file mode 100644 index 0000000..0fecc95 --- /dev/null +++ b/OpenRGB/i2c_smbus/i2c_smbus.h @@ -0,0 +1,129 @@ +/*-----------------------------------------*\ +| i2c_smbus.h | +| | +| Definitions and types for SMBUS drivers | +| | +| Adam Honse (CalcProgrammer1) 8/8/2018 | +| Portions based on Linux source code | +| GNU GPL v2 | +\*-----------------------------------------*/ + +#ifndef I2C_SMBUS_H +#define I2C_SMBUS_H + +#include +#include +#include +#include + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef int s32; + +#ifdef _WIN32 + +//Data for SMBus Messages +#define I2C_SMBUS_BLOCK_MAX 32 + +union i2c_smbus_data +{ + u8 byte; + u16 word; + u8 block[I2C_SMBUS_BLOCK_MAX + 2]; +}; + +#endif /* _WIN32 */ + +#ifdef __linux__ + +#include + +#endif /* __linux__ */ + +#ifdef __APPLE__ + +//Data for SMBus Messages +#define I2C_SMBUS_BLOCK_MAX 32 + +union i2c_smbus_data +{ + u8 byte; + u16 word; + u8 block[I2C_SMBUS_BLOCK_MAX + 2]; +}; + +#endif /* __APPLE__ */ + +// i2c_smbus_xfer read or write markers +#define I2C_SMBUS_READ 1 +#define I2C_SMBUS_WRITE 0 + +// SMBus transaction types (size parameter in the above functions) +#define I2C_SMBUS_QUICK 0 +#define I2C_SMBUS_BYTE 1 +#define I2C_SMBUS_BYTE_DATA 2 +#define I2C_SMBUS_WORD_DATA 3 +#define I2C_SMBUS_PROC_CALL 4 +#define I2C_SMBUS_BLOCK_DATA 5 +#define I2C_SMBUS_I2C_BLOCK_BROKEN 6 +#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */ +#define I2C_SMBUS_I2C_BLOCK_DATA 8 + +class i2c_smbus_interface +{ +public: + char device_name[512]; + + int port_id; + int pci_device; + int pci_vendor; + int pci_subsystem_device; + int pci_subsystem_vendor; + + i2c_smbus_interface(); + virtual ~i2c_smbus_interface(); + + void i2c_smbus_thread_function(); + + //Functions derived from i2c-core.c + s32 i2c_smbus_write_quick(u8 addr, u8 value); + s32 i2c_smbus_read_byte(u8 addr); + s32 i2c_smbus_write_byte(u8 addr, u8 value); + s32 i2c_smbus_read_byte_data(u8 addr, u8 command); + s32 i2c_smbus_write_byte_data(u8 addr, u8 command, u8 value); + s32 i2c_smbus_read_word_data(u8 addr, u8 command); + s32 i2c_smbus_write_word_data(u8 addr, u8 command, u16 value); + s32 i2c_smbus_read_block_data(u8 addr, u8 command, u8 *values); + s32 i2c_smbus_write_block_data(u8 addr, u8 command, u8 length, const u8 *values); + s32 i2c_smbus_read_i2c_block_data(u8 addr, u8 command, u8 length, u8 *values); + s32 i2c_smbus_write_i2c_block_data(u8 addr, u8 command, u8 length, const u8 *values); + + s32 i2c_smbus_xfer_call(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data); + + //Virtual function to be implemented by the driver + virtual s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data) = 0; + +private: + std::thread * i2c_smbus_thread; + std::atomic i2c_smbus_thread_running; + + std::atomic i2c_smbus_start; + std::condition_variable i2c_smbus_start_cv; + std::mutex i2c_smbus_start_mutex; + + std::atomic i2c_smbus_done; + std::condition_variable i2c_smbus_done_cv; + std::mutex i2c_smbus_done_mutex; + + std::mutex i2c_smbus_xfer_mutex; + + u8 i2c_addr; + char i2c_read_write; + u16 i2c_command; + int i2c_size; + i2c_smbus_data* i2c_data; + s32 i2c_ret; +}; + +#endif /* I2C_SMBUS_H */ diff --git a/Dependencies/net_port.h b/OpenRGB/net_port/net_port.h similarity index 100% rename from Dependencies/net_port.h rename to OpenRGB/net_port/net_port.h diff --git a/OpenRGBPlugin.cpp b/OpenRGBPlugin.cpp new file mode 100644 index 0000000..3b438fc --- /dev/null +++ b/OpenRGBPlugin.cpp @@ -0,0 +1,114 @@ +/*-----------------------------------------*\ +| OpenRGBPlugin.cpp | +| | +| OpenRGB Plugin template with example | +| | +| herosilas12 (CoffeeIsLife) 12/11/2020 | +| Adam Honse (CalcProgrammer1) 1/5/2021 | +\*-----------------------------------------*/ + +#include "OpenRGBPlugin.h" + +/*-----------------------------------------*\ +| Initialize | +| | +| This function must be present in all | +| OpenRGB plugins. It defines the plugin | +| name, description, location, and other | +| plugin information. It creates the tab | +| label and is the entry point for plugin | +| code | +\*-----------------------------------------*/ +OpenRGBPluginInfo OpenRGBPlugin::Initialize(bool dark_theme, ResourceManager* resource_manager_ptr) +{ + info.PluginName = "OpenRGB Plugin Template"; + info.PluginDescription = "An example plugin for OpenRGB"; + info.PluginLocation = "InformationTab"; + info.HasCustom = false; + info.SettingName = ""; + info.PluginLabel = new QLabel(); + + /*-----------------------------------------------------*\ + | Set the label text | + \*-----------------------------------------------------*/ + info.PluginLabel->setText("OpenRGB Example Plugin"); + + /*-----------------------------------------------------*\ + | Save the arguments to Initialize based on what you | + | need for this plugin's functionality. In this example| + | we will need the Resource Manager to access the device| + | list, so save the Resource Manager pointer locally. | + \*-----------------------------------------------------*/ + resource_manager = resource_manager_ptr; + + return info; +} + +/*-----------------------------------------*\ +| CreateGUI | +| | +| This function must be present in all | +| OpenRGB plugins. It creates the QWidget | +| that represents the plugin tab's content | +\*-----------------------------------------*/ +QWidget* OpenRGBPlugin::CreateGUI(QWidget* parent) +{ + /*-----------------------------------------------------*\ + | Create the main widget for this plugin tab | + \*-----------------------------------------------------*/ + QWidget* plugin_widget = new QWidget(parent); + + /*-----------------------------------------------------*\ + | In this example, we will create a label showing the | + | number of RGBController devices. This will be shown | + | in a QLabel, updated at 1Hz by a background thread. | + \*-----------------------------------------------------*/ + plugin_label = new QLabel(plugin_widget); + + /*-----------------------------------------------------*\ + | With the label created, start the worker thread | + \*-----------------------------------------------------*/ + TimerThread = new std::thread(&OpenRGBPlugin::TimerThreadFunction, this); + + /*-----------------------------------------------------*\ + | The CreateGUI function must return the main widget | + \*-----------------------------------------------------*/ + return plugin_widget; +} + +/*-----------------------------------------*\ +| TimerThreadFunction | +| | +| This function is part of the example code| +| and is not a required part of an OpenRGB | +| plugin. This function is an example of | +| how a plugin can run a background thread | +| and interact with the Resource Manager | +\*-----------------------------------------*/ +void OpenRGBPlugin::TimerThreadFunction() +{ + /*-----------------------------------------------------*\ + | Begin infinite loop | + \*-----------------------------------------------------*/ + while(1) + { + /*-------------------------------------------------*\ + | Print the number of devices to a string | + \*-------------------------------------------------*/ + std::string text; + + text.append("Number of devices detected: "); + text.append(std::to_string(resource_manager->GetRGBControllers().size())); + text.append("\r\n"); + + /*-------------------------------------------------*\ + | Update the label | + \*-------------------------------------------------*/ + plugin_label->setText(QString::fromStdString(text)); + + /*-------------------------------------------------*\ + | Sleep for 1 second | + \*-------------------------------------------------*/ + Sleep(1000); + } +} diff --git a/OpenRGBPlugin.h b/OpenRGBPlugin.h new file mode 100644 index 0000000..d0748a4 --- /dev/null +++ b/OpenRGBPlugin.h @@ -0,0 +1,40 @@ +/*-----------------------------------------*\ +| OpenRGBPlugin.h | +| | +| OpenRGB Plugin template with example | +| | +| herosilas12 (CoffeeIsLife) 12/11/2020 | +| Adam Honse (CalcProgrammer1) 1/5/2021 | +\*-----------------------------------------*/ + +#pragma once + +#include "OpenRGBPluginInterface.h" + +#include +#include +#include +#include +#include + +class OpenRGBPlugin : public QObject, public OpenRGBPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID OpenRGBPluginInterface_IID) + Q_INTERFACES(OpenRGBPluginInterface) + +public: + virtual ~OpenRGBPlugin() {}; + + virtual OpenRGBPluginInfo Initialize(bool dark_theme, ResourceManager* resource_manager_ptr) override; + + virtual QWidget *CreateGUI(QWidget* parent) override; + + void TimerThreadFunction(); + +private: + ResourceManager* resource_manager; + QLabel* plugin_label; + + std::thread* TimerThread; +}; diff --git a/OpenRGBPlugin.pro b/OpenRGBPlugin.pro new file mode 100644 index 0000000..5e17fe2 --- /dev/null +++ b/OpenRGBPlugin.pro @@ -0,0 +1,65 @@ +#-----------------------------------------------------------------------------------------------# +# OpenRGB Plugin Template QMake Project # +# # +# herosilas12 (CoffeeIsLife) 12/11/2020 # +# Adam Honse (CalcProgrammer1) 1/5/2021 # +#-----------------------------------------------------------------------------------------------# + +#-----------------------------------------------------------------------------------------------# +# Qt Configuration # +#-----------------------------------------------------------------------------------------------# +QT += \ + core \ + gui \ + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +#-----------------------------------------------------------------------------------------------# +# Application Configuration # +#-----------------------------------------------------------------------------------------------# + +TEMPLATE = lib +DEFINES += ORGBEXAMPLEPLUGIN_LIBRARY + +CONFIG += c++11 + +#-----------------------------------------------------------------------------------------------# +# Plugin Project Files # +#-----------------------------------------------------------------------------------------------# +SOURCES += \ + OpenRGBPlugin.cpp \ + +HEADERS += \ + OpenRGBPlugin.h \ + +#-----------------------------------------------------------------------------------------------# +# OpenRGB Plugin SDK # +#-----------------------------------------------------------------------------------------------# +INCLUDEPATH += \ + OpenRGB/ \ + OpenRGB/dependencies/json \ + OpenRGB/i2c_smbus \ + OpenRGB/net_port \ + OpenRGB/RGBController \ + +HEADERS += \ + OpenRGB/NetworkClient.h \ + OpenRGB/NetworkProtocol.h \ + OpenRGB/NetworkServer.h \ + OpenRGB/OpenRGBPluginInterface.h \ + OpenRGB/ProfileManager.h \ + OpenRGB/ResourceManager.h \ + OpenRGB/SettingsManager.h \ + OpenRGB/dependencies/json/json.hpp \ + OpenRGB/i2c_smbus/i2c_smbus.h \ + OpenRGB/net_port/net_port.h \ + OpenRGB/RGBController/RGBController.h \ + +#-----------------------------------------------------------------------------------------------# +# Default rules for deployment. # +#-----------------------------------------------------------------------------------------------# +unix { + target.path = /usr/lib +} + +!isEmpty(target.path): INSTALLS += target