Gokit2代RGB灯单个功能体现
1、串口协议2、智能宠物屋_Gokit_2_STM源码的修改内容
文件Protocol.h:
(1)修改productkey
(2)在修改是否设置标志设置位
typedef enum
{
SetLED_R =0x01,
SetLED_G =0x02,
SetLED_B =0x04,
}Attr_FlagsTypeDef;
(3)查看可写设置列表是否已经有Led_Cmd选项
__packed typedef struct
{
uint8_t LED_Cmd;
uint8_t LED_R;
uint8_t LED_G;
uint8_t LED_B;
uint16_t Motor;
}Device_WirteTypeDef;
(4)数据值的填写
typedef enum
{
LED_OnOff =0x00,
LED_R =0x01,
LED_G =0x02,
LED_B =0x04,
}LED_ColorTypeDef;
3、更改功能,
文件Protocol:更改Pro_W2D_Control_DevceHandle函数
void Pro_W2D_Control_DevceHandle(void)
{
Pro_P0_ControlTypeDef Pro_P0_ControlStruct;
Pro_W2D_CommonCmdHandle();
memcpy(&Pro_P0_ControlStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_P0_ControlStruct));
switch (Pro_P0_ControlStruct.Attr_Flags)
{
case SetLED_R:
Device_WirteStruct.LED_Cmd = Pro_P0_ControlStruct.Device_Wirte.LED_Cmd ;
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_OnOff )
{
LED_RGB_Control(0,0,0);
printf("SetLED_Off \r\n");
}
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_R )
{
LED_RGB_Control(254,0,0);
printf("SetLED_Off \r\n");
}
break;
case SetLED_G:
Device_WirteStruct.LED_Cmd = Pro_P0_ControlStruct.Device_Wirte.LED_Cmd ;
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_OnOff )
{
LED_RGB_Control(0,0,0);
printf("SetLED_Off \r\n");
}
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_G )
{
LED_RGB_Control(0,254,0);
printf("SetLED_Off \r\n");
}
break;
case SetLED_B:
Device_WirteStruct.LED_Cmd = Pro_P0_ControlStruct.Device_Wirte.LED_Cmd ;
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_OnOff )
{
LED_RGB_Control(0,0,0);
printf("SetLED_Off \r\n");
}
if(Pro_P0_ControlStruct.Device_Wirte.LED_Cmd==LED_B )
{
LED_RGB_Control(0,0,254);
printf("SetLED_Off \r\n");
}
break;
在数据点可写数据不大于8个时,是可行的。但是数据点可写数据大于8时,字节序第一框为:byte0,byte1,bit序:bit0-bit15
数据内容为:16为bit位而不是8位。这时候这种方法就不可行了。求技术解决该如何修改。 字节序第一框:填写的定义为bool型和enum型,其它定义为数值类型都为一个字节
页:
[1]