优化这段代码 if(i > num - 1) break; isDraw = (not == 2 && (draw == i+1)); if (DBData[i] != RT1064_YS_YYDD && DBData[i] != RT1064KZZ_FC_CHZ ) LCD_DisString((i%LISTOFFSET)+1, 0, gRunPara.gap_ActionDZInfo[gapid][DBData[i]].szName); if (DBData[i] == RT1064KZZ_FC_CHZ) LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"大电流闭锁重合闸"); if (DBData[i] == RT1064_YS_YYDD) LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"重合闸检有压时间"); val = get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i]); if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) ); } else if(DBData[i] == RT1064KZZ_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) ); } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) ); } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , val); LCD_DisString((i%LISTOFFSET)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); if (isDraw == 1) len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); }
时间: 2024-03-01 22:50:53 浏览: 113
基于mediapipe的简单手势识别-python源码.zip
这段代码可以进行如下优化:
1. 将多个 if 判断语句合并成一个 switch 语句,增加代码的可读性和可维护性;
2. 将重复的代码提取出来,封装成函数,减少代码的冗余度;
3. 使用三目运算符代替 if-else 语句,使代码更简洁。
下面是优化后的代码:
```c
for (int i = 0; i < num; i++) {
if (i > num - 1) break;
isDraw = (not == 2 && (draw == i+1));
int data = DBData[i];
switch (data) {
case RT1064_YS_YYDD:
LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"重合闸检有压时间");
break;
case RT1064KZZ_FC_CHZ:
LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"大电流闭锁重合闸");
break;
case RT1064KZZ_MODE:
(isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)]));
break;
case RT1064KZZ_FBS:
case RT1064KZZ_FBS_MODE:
(isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)]));
break;
case RT1064KZZ_UAB_CH:
case RT1064KZZ_UBC_CH:
case RT1064_DZ_CHZCS:
sprintf(szVal, "%0.f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data));
LCD_DisString((i%LISTOFFSET)+1, 19 , szVal);
if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次");
if (isDraw == 1) len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit);
break;
default:
if (data >= RT1064KZZ_GL1_ALM && data <= RT1064KZZ_KZHL && data != RT1064KZZ_UAB_CH && data != RT1064KZZ_UBC_CH && data != RT1064KZZ_FBS && data != RT1064KZZ_FBS_MODE) {
(isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,data)] ));
} else {
LCD_DisString((i%LISTOFFSET)+1, 0, gRunPara.gap_ActionDZInfo[gapid][data].szName);
}
break;
}
}
```
希望这些优化能够对你有所帮助!
阅读全文