Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Lenovo4ZoneUSBController.cpp |
|
||||
| |
|
||||
| Driver for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
#include "Lenovo4ZoneUSBController.h"
|
||||
#include "LogManager.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
Lenovo4ZoneUSBController::Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
pid = in_pid;
|
||||
name = dev_name;
|
||||
}
|
||||
|
||||
Lenovo4ZoneUSBController::~Lenovo4ZoneUSBController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
void Lenovo4ZoneUSBController::setMode(const KeyboardState &in_mode)
|
||||
{
|
||||
uint8_t buffer[LENOVO_4_ZONE_HID_PACKET_SIZE] =
|
||||
{
|
||||
in_mode.header[0], in_mode.header[1],
|
||||
in_mode.effect,
|
||||
in_mode.speed,
|
||||
in_mode.brightness,
|
||||
in_mode.zone0_rgb[0], in_mode.zone0_rgb[1], in_mode.zone0_rgb[2],
|
||||
in_mode.zone1_rgb[0], in_mode.zone1_rgb[1], in_mode.zone1_rgb[2],
|
||||
in_mode.zone2_rgb[0], in_mode.zone2_rgb[1], in_mode.zone2_rgb[2],
|
||||
in_mode.zone3_rgb[0], in_mode.zone3_rgb[1], in_mode.zone3_rgb[2],
|
||||
0x00,
|
||||
in_mode.wave_ltr, in_mode.wave_rtl
|
||||
};
|
||||
hid_send_feature_report(dev, buffer, LENOVO_4_ZONE_HID_PACKET_SIZE);
|
||||
}
|
||||
|
||||
uint16_t Lenovo4ZoneUSBController::getPid()
|
||||
{
|
||||
return pid;
|
||||
}
|
||||
|
||||
std::string Lenovo4ZoneUSBController::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string Lenovo4ZoneUSBController::getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Lenovo4ZoneUSBController.h |
|
||||
| |
|
||||
| Driver for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
#include "LogManager.h"
|
||||
#include "LenovoDevices4Zone.h"
|
||||
|
||||
#ifndef HID_MAX_STR
|
||||
#define HID_MAX_STR 255
|
||||
#endif
|
||||
|
||||
#define LENOVO_4_ZONE_HID_PACKET_SIZE 33
|
||||
|
||||
class Lenovo4ZoneUSBController
|
||||
{
|
||||
public:
|
||||
/*--------------*\
|
||||
|ctor(s) and dtor|
|
||||
\*--------------*/
|
||||
Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name);
|
||||
~Lenovo4ZoneUSBController();
|
||||
|
||||
void setMode(const KeyboardState &in_mode);
|
||||
|
||||
/*--------------*\
|
||||
|device functions|
|
||||
\*--------------*/
|
||||
uint16_t getPid();
|
||||
std::string getName();
|
||||
std::string getLocation();
|
||||
|
||||
private:
|
||||
/*--------------*\
|
||||
|data members |
|
||||
\*--------------*/
|
||||
std::string name;
|
||||
hid_device *dev;
|
||||
std::string location;
|
||||
uint16_t pid;
|
||||
KeyboardState mode;
|
||||
|
||||
/*--------------*\
|
||||
|device functions|
|
||||
\*--------------*/
|
||||
void sendBasicInstruction(uint8_t instruction);
|
||||
};
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Lenovo4ZoneUSBControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <hidapi.h>
|
||||
#include "Detector.h"
|
||||
#include "Lenovo4ZoneUSBController.h"
|
||||
#include "LenovoDevices4Zone.h"
|
||||
#include "RGBController_Lenovo4ZoneUSB.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| vendor IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
#define ITE_VID 0x048D
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Interface, Usage, and Usage Page |
|
||||
\*-----------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
LENOVO_PAGE = 0xFF89,
|
||||
LENOVO_USAGE = 0xCC
|
||||
};
|
||||
|
||||
void DetectLenovo4ZoneUSBControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
Lenovo4ZoneUSBController* controller = new Lenovo4ZoneUSBController(dev, info->path, info->product_id, name);
|
||||
RGBController_Lenovo4ZoneUSB* rgb_controller = new RGBController_Lenovo4ZoneUSB(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo Ideapad 3-15ach6", DetectLenovo4ZoneUSBControllers, ITE_VID, IDEAPAD_315ACH6, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2023", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2023_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2023 Ideapad", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2023_IDEAPAD_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2022", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2022_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2022 Ideapad", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2022_IDEAPAD_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2021", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2021_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2021 Ideapad", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2021_IDEAPAD_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
REGISTER_HID_DETECTOR_PU("Lenovo 5 2020", DetectLenovo4ZoneUSBControllers, ITE_VID, LEGION_5_2020_PID, LENOVO_PAGE, LENOVO_USAGE);
|
||||
@@ -0,0 +1,107 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LenovoDevices4Zone.h |
|
||||
| |
|
||||
| Device list for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "RGBControllerKeyNames.h"
|
||||
#include "RGBController.h"
|
||||
#include "LenovoDevices.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Keyboard product IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
#define IDEAPAD_315ACH6 0xC963
|
||||
#define LEGION_5_2023_PID 0xC985
|
||||
#define LEGION_5_2023_IDEAPAD_PID 0xC984
|
||||
#define LEGION_5_2022_PID 0xC975
|
||||
#define LEGION_5_2022_IDEAPAD_PID 0xC973
|
||||
#define LEGION_5_2021_PID 0xC965
|
||||
#define LEGION_5_2021_IDEAPAD_PID 0xC963
|
||||
#define LEGION_5_2020_PID 0xC955
|
||||
|
||||
enum LENOVO_4_ZONE_EFFECT
|
||||
{
|
||||
LENOVO_4_ZONE_EFFECT_STATIC = 1,
|
||||
LENOVO_4_ZONE_EFFECT_BREATH = 3,
|
||||
LENOVO_4_ZONE_EFFECT_WAVE = 4,
|
||||
LENOVO_4_ZONE_EFFECT_SMOOTH = 6,
|
||||
};
|
||||
|
||||
enum LENOVO_4_ZONE_BRIGHTNESS
|
||||
{
|
||||
LENOVO_4_ZONE_BRIGHTNESS_LOW = 1,
|
||||
LENOVO_4_ZONE_BRIGHTNESS_HIGH = 2,
|
||||
};
|
||||
|
||||
enum LENOVO_4_ZONE_SPEED
|
||||
{
|
||||
LENOVO_4_ZONE_SPEED_SLOWEST = 1,
|
||||
LENOVO_4_ZONE_SPEED_SLOW = 2,
|
||||
LENOVO_4_ZONE_SPEED_FAST = 3,
|
||||
LENOVO_4_ZONE_SPEED_FASTEST = 4,
|
||||
};
|
||||
|
||||
/// struct a USB packet for set the keyboard LEDs
|
||||
class KeyboardState
|
||||
{
|
||||
public:
|
||||
uint8_t header[2] = {0xCC, 0x16};
|
||||
uint8_t effect = LENOVO_4_ZONE_EFFECT_STATIC;
|
||||
uint8_t speed = LENOVO_4_ZONE_SPEED_SLOWEST;
|
||||
uint8_t brightness = LENOVO_4_ZONE_BRIGHTNESS_LOW;
|
||||
uint8_t zone0_rgb[3] = {0xFF, 0xFF, 0xFF};
|
||||
uint8_t zone1_rgb[3] = {0xFF, 0xFF, 0xFF};
|
||||
uint8_t zone2_rgb[3] = {0xFF, 0xFF, 0xFF};
|
||||
uint8_t zone3_rgb[3] = {0xFF, 0xFF, 0xFF};
|
||||
uint8_t wave_ltr = 0;
|
||||
uint8_t wave_rtl = 0;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
header[0] = 0xCC, header[1] = 0x16;
|
||||
effect = LENOVO_4_ZONE_EFFECT_STATIC;
|
||||
speed = LENOVO_4_ZONE_SPEED_SLOWEST;
|
||||
brightness = LENOVO_4_ZONE_BRIGHTNESS_LOW;
|
||||
zone0_rgb[0] = 0xFF, zone0_rgb[1] = 0xFF, zone0_rgb[2] = 0xFF;
|
||||
zone1_rgb[0] = 0xFF, zone1_rgb[1] = 0xFF, zone1_rgb[2] = 0xFF;
|
||||
zone2_rgb[0] = 0xFF, zone2_rgb[1] = 0xFF, zone2_rgb[2] = 0xFF;
|
||||
zone3_rgb[0] = 0xFF, zone3_rgb[1] = 0xFF, zone3_rgb[2] = 0xFF;
|
||||
wave_ltr = 0;
|
||||
wave_rtl = 0;
|
||||
}
|
||||
|
||||
void SetColors(std::vector<RGBColor> group_colors)
|
||||
{
|
||||
zone0_rgb[0] = RGBGetRValue(group_colors[0]);
|
||||
zone0_rgb[1] = RGBGetGValue(group_colors[0]);
|
||||
zone0_rgb[2] = RGBGetBValue(group_colors[0]);
|
||||
zone1_rgb[0] = RGBGetRValue(group_colors[1]);
|
||||
zone1_rgb[1] = RGBGetGValue(group_colors[1]);
|
||||
zone1_rgb[2] = RGBGetBValue(group_colors[1]);
|
||||
zone2_rgb[0] = RGBGetRValue(group_colors[2]);
|
||||
zone2_rgb[1] = RGBGetGValue(group_colors[2]);
|
||||
zone2_rgb[2] = RGBGetBValue(group_colors[2]);
|
||||
zone3_rgb[0] = RGBGetRValue(group_colors[3]);
|
||||
zone3_rgb[1] = RGBGetGValue(group_colors[3]);
|
||||
zone3_rgb[2] = RGBGetBValue(group_colors[3]);
|
||||
}
|
||||
};
|
||||
|
||||
/*-------------------------*\
|
||||
| 4-Zone keyboard |
|
||||
\*-------------------------*/
|
||||
|
||||
static const lenovo_led lenovo_4_zone_leds[]
|
||||
{
|
||||
{0x00, "Left side"},
|
||||
{0x01, "Left center"},
|
||||
{0x02, "Right center"},
|
||||
{0x03, "Right side"},
|
||||
};
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_Lenovo4ZoneUSB.cpp |
|
||||
| |
|
||||
| Device list for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "Lenovo4ZoneUSBController.h"
|
||||
#include "LenovoDevices4Zone.h"
|
||||
#include "RGBController_Lenovo4ZoneUSB.h"
|
||||
#include "LogManager.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Lenovo 4 Zone USB
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectLenovo4ZoneUSBControllers
|
||||
@comment Tested on Lenovo Legion 5 2021
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#define LENOVO_4_ZONE_NUM_LEDS 4
|
||||
|
||||
RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->getName();
|
||||
type = DEVICE_TYPE_LAPTOP;
|
||||
vendor = "Lenovo";
|
||||
description = "Lenovo 4-Zone device";
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
Direct.brightness_min = 1;
|
||||
Direct.brightness_max = 2;
|
||||
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Breath;
|
||||
Breath.name = "Breathing";
|
||||
Breath.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
|
||||
Breath.color_mode = MODE_COLORS_PER_LED;
|
||||
Breath.brightness_min = 1;
|
||||
Breath.brightness_max = 2;
|
||||
Breath.speed_min = 1;
|
||||
Breath.speed_max = 4;
|
||||
|
||||
modes.push_back(Breath);
|
||||
|
||||
mode Wave;
|
||||
Wave.name = "Rainbow Wave";
|
||||
Wave.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR;
|
||||
Wave.color_mode = MODE_COLORS_RANDOM;
|
||||
Wave.brightness_min = 1;
|
||||
Wave.brightness_max = 2;
|
||||
Wave.speed_min = 1;
|
||||
Wave.speed_max = 4;
|
||||
Wave.direction = MODE_DIRECTION_LEFT | MODE_DIRECTION_RIGHT;
|
||||
modes.push_back(Wave);
|
||||
|
||||
mode Smooth;
|
||||
Smooth.name = "Spectrum Cycle";
|
||||
Smooth.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
|
||||
Smooth.color_mode = MODE_COLORS_RANDOM;
|
||||
Smooth.brightness_min = 1;
|
||||
Smooth.brightness_max = 2;
|
||||
Smooth.speed_min = 1;
|
||||
Smooth.speed_max = 4;
|
||||
modes.push_back(Smooth);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_Lenovo4ZoneUSB::~RGBController_Lenovo4ZoneUSB()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::SetupZones()
|
||||
{
|
||||
zone new_zone;
|
||||
new_zone.name = ZONE_EN_KEYBOARD;
|
||||
new_zone.type = ZONE_TYPE_LINEAR;
|
||||
new_zone.leds_count = LENOVO_4_ZONE_NUM_LEDS;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
|
||||
new_zone.matrix_map = NULL;
|
||||
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < LENOVO_4_ZONE_NUM_LEDS; led_idx++ )
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = lenovo_4_zone_leds[led_idx].name;
|
||||
new_led.value = lenovo_4_zone_leds[led_idx].led_num;
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::DeviceUpdateLEDs()
|
||||
{
|
||||
state.SetColors(colors);
|
||||
controller->setMode(state);
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::DeviceUpdateMode()
|
||||
{
|
||||
state.Reset();
|
||||
state.SetColors(colors);
|
||||
|
||||
switch (active_mode)
|
||||
{
|
||||
case 0:
|
||||
state.effect = LENOVO_4_ZONE_EFFECT_STATIC;
|
||||
break;
|
||||
case 1:
|
||||
state.effect = LENOVO_4_ZONE_EFFECT_BREATH;
|
||||
break;
|
||||
case 2:
|
||||
state.effect = LENOVO_4_ZONE_EFFECT_WAVE;
|
||||
state.wave_ltr = modes[active_mode].direction?0:1;
|
||||
state.wave_rtl = modes[active_mode].direction?1:0;
|
||||
break;
|
||||
case 3:
|
||||
state.effect = LENOVO_4_ZONE_EFFECT_SMOOTH;
|
||||
break;
|
||||
}
|
||||
|
||||
if(active_mode != (LENOVO_4_ZONE_EFFECT_STATIC - 1)) // mode number from 0, but in mode from 1
|
||||
{
|
||||
state.speed = modes[active_mode].speed;
|
||||
}
|
||||
state.brightness = modes[active_mode].brightness;
|
||||
|
||||
controller->setMode(state);
|
||||
}
|
||||
|
||||
void RGBController_Lenovo4ZoneUSB::DeviceSaveMode()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support saving or multiple modes |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_Lenovo4ZoneUSB.h |
|
||||
| |
|
||||
| RGBController for Lenovo 4-Zone devices |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "LenovoDevices.h"
|
||||
#include "Lenovo4ZoneUSBController.h"
|
||||
#include "RGBController.h"
|
||||
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
class RGBController_Lenovo4ZoneUSB : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBController* controller_ptr);
|
||||
~RGBController_Lenovo4ZoneUSB();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
void DeviceSaveMode();
|
||||
|
||||
private:
|
||||
KeyboardState state;
|
||||
|
||||
Lenovo4ZoneUSBController *controller;
|
||||
};
|
||||
Reference in New Issue
Block a user