Merge pull request #148 from RedWolf-369/main

添加RGB支持
main
稚晖 2 years ago committed by GitHub
commit 59fba533bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePresetLoader"><![CDATA[{
"useNewFormat": true
}]]></component>
<component name="CMakeReloadState">
<option name="reloaded" value="true" />
</component>
@ -18,10 +21,6 @@
<component name="ChangeListManager">
<list default="true" id="064cb8dd-c74c-418a-a862-af96d67ded4c" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BSP/u8g2/cpp/U8g2lib.hpp" beforeDir="false" afterPath="$PROJECT_DIR$/BSP/u8g2/cpp/U8g2lib.hpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Ctrl/Motor/knob.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Ctrl/Motor/knob.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Ctrl/Motor/knob.h" beforeDir="false" afterPath="$PROJECT_DIR$/Ctrl/Motor/knob.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/UserApp/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/UserApp/main.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -59,15 +58,18 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "true",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"cmake.loaded.for.project": "true",
"last_opened_file_path": "E:/OnWorking/HelloWord-Keyboard/2.Firmware/HelloWord-Dynamic-fw/Ctrl/Motor",
"last_opened_file_path": "D:/DEV_TOOLS/Projets/HelloWord-Keyboard/2.Firmware/HelloWord-Keyboard-fw",
"settings.editor.selected.configurable": "CMakeSettings",
"structure.view.defaults.are.configured": "true"
"structure.view.defaults.are.configured": "true",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RecentsManager">
@ -87,9 +89,19 @@
</key>
</component>
<component name="RunManager">
<configuration default="true" type="CLionExternalRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true">
<configuration default="true" type="lua.app" factoryName="Lua Application">
<option name="program" value="lua.exe" />
<option name="file" value="" />
<option name="workingDir" value="$PROJECT_DIR$/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h" />
<option name="debuggerType" value="1" />
<option name="params" value="" />
<option name="charset" value="UTF-8" />
<option name="showConsole" value="true" />
<method v="2" />
</configuration>
<configuration default="true" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true">
<method v="2">
<option name="CLION.EXTERNAL.BUILD" enabled="true" />
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration default="true" type="PythonConfigurationType" factoryName="Python">
@ -132,16 +144,6 @@
<option name="CLION.COMPOUND.BUILD" enabled="true" />
</method>
</configuration>
<configuration default="true" type="lua.app" factoryName="Lua Application">
<option name="program" value="lua.exe" />
<option name="file" value="" />
<option name="workingDir" value="$PROJECT_DIR$/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h" />
<option name="debuggerType" value="1" />
<option name="params" value="" />
<option name="charset" value="UTF-8" />
<option name="showConsole" value="true" />
<method v="2" />
</configuration>
<configuration default="true" type="tests" factoryName="Autodetect">
<module name="HelloWord-Dynamic-fw" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -279,6 +281,7 @@
<workItem from="1658479549618" duration="6478000" />
<workItem from="1658499259416" duration="4546000" />
<workItem from="1659172165877" duration="1356000" />
<workItem from="1676859689038" duration="190000" />
</task>
<servers />
</component>

@ -44,7 +44,7 @@ extern "C" {
#define CUSTOM_HID_EPIN_ADDR 0x81U
#define CUSTOM_HID_EPIN_SIZE 64U
#define CUSTOM_HID_EPOUT_ADDR 0x01U
#define CUSTOM_HID_EPOUT_ADDR 0x02U
#define CUSTOM_HID_EPOUT_SIZE 64U
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U

@ -632,7 +632,7 @@ static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev,
* @param epnum: endpoint index
* @retval status
*/
void HID_RxCpltCallback(uint8_t* _data);
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev,
uint8_t epnum)
@ -640,9 +640,9 @@ static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev,
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
// ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
// hhid->Report_buf[1]);
HID_RxCpltCallback( hhid->Report_buf);
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
hhid->Report_buf[1]);
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);

@ -32,7 +32,7 @@
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
void HID_RxCpltCallback(uint8_t* _data);
/* USER CODE END PV */
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY

@ -7,7 +7,8 @@
KeyboardConfig_t config;
HWKeyboard keyboard(&hspi1);
static bool isSoftWareControlColor = false;
static bool isReceiveSuccess = false;
/* Main Entry ----------------------------------------------------------------*/
void Main()
{
@ -39,12 +40,19 @@ void Main()
if (t > 250) fadeDir = false;
else if (t < 1) fadeDir = true;
for (uint8_t i = 0; i < HWKeyboard::LED_NUMBER; i++)
keyboard.SetRgbBufferByID(i, HWKeyboard::Color_t{(uint8_t) t, 50, 0});
/*-----------------------------------*/
// Send RGB buffers to LEDs
keyboard.SyncLights();
if(isReceiveSuccess){
keyboard.SyncLights();
isReceiveSuccess = false;
}
if(!isSoftWareControlColor)
{
/*---- This is a demo RGB effect ----*/
for (uint8_t i = 0; i < HWKeyboard::LED_NUMBER; i++)
keyboard.SetRgbBufferByID(i, HWKeyboard::Color_t{(uint8_t)t, 50, 20});
/*-----------------------------------*/
keyboard.SyncLights();
}
}
}
@ -80,5 +88,17 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi)
extern "C"
void HID_RxCpltCallback(uint8_t* _data)
{
if(_data[1] == 0xbd) isSoftWareControlColor= false;
if(_data[1] == 0xac) {
isSoftWareControlColor = true;
uint8_t pageIndex = _data[2];
for (uint8_t i = 0; i < 10; i++) {
if(i+pageIndex*10>=HWKeyboard::LED_NUMBER) {
isReceiveSuccess = true;
break;
}
keyboard.SetRgbBufferByID(i+pageIndex*10,
HWKeyboard::Color_t{_data[3+i*3], _data[4+i*3], _data[5+i*3]});
}
}
}

@ -0,0 +1,146 @@
export function Name() { return "HellowWord Keyboard"; }
export function VendorId() { return 0x1001; }
export function ProductId() { return 0xF103; }
export function Publisher() { return "HellowWord"; }
export function Size() { return [17, 8]; }
export function DefaultPosition(){return [75, 55]; }
export function DefaultScale(){return 18.8}
export function ControllableParameters() {
return [
{"property":"shutdownColor", "group":"lighting", "label":"Shutdown Color", "min":"0", "max":"360", "type":"color", "default":"009bde"},
{"property":"LightingMode", "group":"lighting", "label":"Lighting Mode", "type":"combobox", "values":["Canvas", "Forced"], "default":"Canvas"},
{"property":"forcedColor", "group":"lighting", "label":"Forced Color", "min":"0", "max":"360", "type":"color", "default":"009bde"},
];
}
export function Initialize() {
device.log("初始化")
}
const vKeys =
[
13,12,11,10,9,8,7,6,5,4,3,2,1,0, // 14
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,26, 27, 28,
43,42,41,40,39,38,37,36,35,34,33,32,31,30,29, // 15
//29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,40, 41, 42, 43, // 14
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,55, 56, 57,
71,70,69,68,67,66,65,64,63,62,61,60,59,58, // 14
//58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, // 14
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, //10
82, 83, 84,
//100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85 //背部16个灯
];
//LED对应Key的位置共82还有19个为背景灯和三个指示灯
var vLedNames = [
//"Pasue","f12","f11","f10","f9","f8","f7","f6","f5","f4","f3","f2","f1","esc",
"Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Pasue",
"~","1","2","3","4","5","6","7","8","9","0","-","=","backspace","Insert",
"TAB", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "LEFT_U_BRACE", "RIGHT_U_BRACE", "BACKSLASH", "DELETE",
"CAP_LOCK", "A","S","D","F","G","H","J","K","L","SEMI_COLON", "QUOTE", "ENTER", "PAGE_UP",
"LEFT_SHIFT", "Z","X","C","V","B","N","M","COMMA", "PERIOD", "SLASH", "RIGHT_SHIFT", "UP_ARROW", "PAGE_DOWN",
"LEFT_CTRL", "LEFT_GUI", "LEFT_ALT", "SPACE", "RIGHT_ALT", "FN", "RIGHT_CTRL", "LEFT_ARROW", "DOWN_ARROW", "RIGHT_ARROW",
"Front1","Front2","Front3",
//"back1","back2","back3","back4","back5","back6","back7","back8","back9","back10","back11","back12","back13","back14","back15","back16",
]
//上位机矩阵LED对应坐标点
var vLedPositions = [
//键盘的82个灯
[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0], [12,0], [13,0], //14
//[13,0],[12,0],[11,0],[10,0],[9,0],[8,0],[7,0],[6,0],[5,0],[4,0],[3,0],[2,0], [1,0], [0,0], //14
[0,1],[1,1],[2,1],[3,1],[4,1],[5,1],[6,1],[7,1],[8,1],[9,1],[10,1],[11,1], [12,1], [13,1], [14,1], //15
[0,2],[1,2],[2,2],[3,2],[4,2],[5,2],[6,2],[7,2],[8,2],[9,2],[10,2],[11,2], [12,2], [13,2], [14,2] ,//15
[0,3],[1,3],[2,3],[3,3],[4,3],[5,3],[6,3],[7,3],[8,3],[9,3],[10,3],[11,3], [12,3], [13,3], //14
[0,4],[1,4],[2,4],[3,4],[4,4],[5,4],[6,4],[7,4],[8,4],[9,4],[10,4],[11,4], [12,4], [13,4], //14
[0,5],[1,5],[2,5],[3,5],[4,5],[5,5],[6,5],[7,5],[8,5],[9,5], [10,5],[11,5],[12,5], //13 指示灯 3个
//背部16个灯
//[0,6],[1,6],[2,6],[3,6],[4,6],[5,6],[6,6],[7,6],[8,6],[8,6],[10,6],[11,6], [12,6], [13,6], [14,6] ,[15,6],//16
]
export function LedNames() {
return vLedNames;
}
export function LedPositions() {
return vLedPositions;
}
export function Render() {
sendColors();
}
export function Shutdown() {
let packet = [];
packet[0x00] = 0x02;//reportid
packet[0x01] = 0xBD;//控制命令:关闭软件控制
packet[0x02] = 0;//第几包数据共6包120个灯
packet[0x03] = 1;//保留字节
device.write(packet,32);
}
/**
The three above examples are each suitable for a different packet structure.
The sendZone function is good for devices that use a separate packet for each LED.
The sendPacket function is more suitable for devices that send multiple LEDs in a row within a single packet.
The sendColors function is suitable for devices that have multiple LEDs in a packet,
but they are not one directly after the other. In our case, we are going to use the sendColors function.
* @param {*} zone
* @param {*} shutdown
*/
function sendColors(shutdown = false){
const RGBData = new Array(110*3).fill(0);
for(let led_idx = 0; led_idx < vKeys.length; led_idx++) {
let iX = vLedPositions[led_idx][0];
let iY = vLedPositions[led_idx][1];
var col;
if(shutdown){
col = hexToRgb(shutdownColor);
}else if (LightingMode === "Forced") {
col = hexToRgb(forcedColor);
device.log("Forced"+col)
}else{
col = device.color(iX, iY);
}
let iLedIdx = vKeys[led_idx] * 3;
RGBData[iLedIdx] = col[0];
RGBData[iLedIdx + 1] = col[1];
RGBData[iLedIdx + 2] = col[2];
}
//总共110灯珠每次传输10个
for(let ledPage = 0; ledPage < 12; ledPage++)
{
let packet = [];
packet[0x00] = 0x02;//reportid不占用实际字节由于是多id设备必须占用
packet[0x01] = 0xac;//控制命令
packet[0x02] = ledPage;//包页码
//3个字节对应一个rgb灯一个包传10个占用30字节
packet = packet.concat(RGBData.splice(0, 30));
device.write(packet,33);
}
}
function hexToRgb(hex) {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
let colors = [];
colors[0] = parseInt(result[1], 16);
colors[1] = parseInt(result[2], 16);
colors[2] = parseInt(result[3], 16);
return colors;
}
export function Validate(endpoint) {
return endpoint.interface === -1 && endpoint.usage === 0xc00 && endpoint.usage_page === 0xffc0;
}
export function Image() {
return "";
}

@ -27,6 +27,13 @@
## 1. 项目说明
### 1.0 更新说明:
**23.2.20更新**
* 修改`CUSTOM_HID_EPOUT_ADDR = 2`HID_RxCpltCallback位置变更到CUSTOM_HID_OutEvent_FS中原来的位置可能导致while循环内无法发送report
> * main里面增加了RGB控制相关代码可以通过HID协议发送数据包来控制键盘RGB效果
> * 已对接SignalRGBSoftware中添加SignalRGB插件
> * report包大小33字节前三个字节依次为reportid(本项目为2)、控制命令0xAC上位机控制0xBD关闭上位机控制report包次序一个包最多传10个RGB值需要多个包拼接从0计算后30字节为RGB值。
**22.8.31更新:**

Loading…
Cancel
Save