display.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. #include <rtthread.h>
  2. #include "main.h"
  3. #include "flash.h"
  4. #include "display.h"
  5. #include "buffer.h"
  6. #include "button.h"
  7. #include "usart.h"
  8. #include <stdlib.h>
  9. #include "weight.h"
  10. #include "plan.h"
  11. #include "daScreen.h"
  12. #include "xBeeAppEscapingMode.h"
  13. rt_sem_t display_lock = RT_NULL;
  14. struct rt_event display_event;
  15. uint8_t MenuItem=0; //当前菜单
  16. uint8_t WeightConst_Feed_display[40]; //显示标题
  17. uint8_t WeightConst_Weight_display[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量
  18. uint8_t WeightConst_WeightCur_display[5] = {0x20,0x20,0x20,0x20,0x20}; //显示重量
  19. uint8_t WeightConst_Weight_display_old[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量
  20. static signed long WeightConst_Weight_displayW; //显示重量
  21. static signed long WeightConst_Weight_displayCurW; //显示重量
  22. unsigned char WeightConst_displayTotal = 0; //0差重,1实重
  23. unsigned char WeightConst_remoteDisplay = 0;
  24. unsigned char RemoteSendDisplay = 1;
  25. extern unsigned char iscowweight;
  26. extern unsigned char remote_sumweight;
  27. const uint8_t MenuItemList[12][8] = {{0xC9,0xE8,0xB1,0xB8,0xB5,0xD8,0xD6,0xB7}, //设备地址
  28. {0xCC,0xE1,0xC8,0xA1,0xB7,0xBD,0xCA,0xBD}, //提取方式
  29. {0xCD,0xF8,0xC2,0xE7,0xB1,0xE0,0xBA,0xC5}, //网络编号
  30. {0xC9,0xE8,0xB1,0xB8,0xC0,0xE0,0xD0,0xCD}, //设备类型
  31. {0x54,0x4D,0x52,0xCA,0xFD,0xC1,0xBF,0x20}, //铲车数量
  32. {0x41,0x50,0x49,0x20,0x20,0x20,0x20,0x20}, //API
  33. {0xD0,0xA3,0xD5,0xFD,0xD6,0xD8,0xC1,0xBF}, //校正重量
  34. {0xD7,0xEE,0xB4,0xF3,0xB3,0xC6,0xC1,0xBF}, //最大称量
  35. {0xC2,0xCB,0xB2,0xA8,0xC9,0xEE,0xB6,0xC8}, //滤波深度
  36. {0xD0,0xA1,0xCA,0xFD,0xB5,0xE3,0x20,0x20}, //小数点
  37. {0xB7,0xD6,0xB6,0xC8,0xD6,0xB5,0x20,0x20}, //分度值
  38. {0xB8,0xF4,0xC0,0xEB,0xD6,0xD8,0xC1,0xBF} //重量隔离
  39. };
  40. const uint8_t MenuTQTypeList[15][8] = {
  41. {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
  42. {0x4E,0x45,0x57,0x4C,0x61,0x62,0x65,0x6C}, //NewLabel
  43. {0x5A,0x4D,0x33,0x30,0x33,0x20,0x20,0x20}, //AWT_ZM303
  44. {0x58,0x4B,0x33,0x31,0x39,0x30,0x20,0x20}, //XK3190_A27E()
  45. {0x54,0x4D,0x52,0x20,0x32,0x20,0x20,0x20}, //TMR2
  46. {0x54,0x4D,0x52,0x20,0x33,0x20,0x20,0x20}, //TMR3
  47. {0x45,0x5A,0x33,0x34,0x30,0x30,0x20,0x20}, //EZ3400
  48. {0x41,0x44,0x32,0x35,0x30,0x20,0x20,0x20}, //AD250 TQ
  49. {0x50,0x54,0x4D,0x20,0x20,0x20,0x20,0x20}, //PTM
  50. {0x54,0x2D,0x32,0x30,0x30,0x30,0x20,0x20}, //T_2000
  51. {0x53,0x4C,0x31,0x30,0x30,0x30,0x30,0x20}, //XL10000
  52. {0x58,0x4B,0x33,0x31,0x39,0x30,0x43,0x38}, //P_XK3190_C8();
  53. {0x54,0x44,0x49,0x32,0x30,0x30,0x49,0x20}, //TDI200I
  54. {0x49,0x44,0x35,0x31,0x31,0x20,0x20,0x20}, //ID511;
  55. {0xD7,0xD4,0xB6,0xAF,0x20,0x20,0x20,0x20} //自动
  56. };
  57. const uint8_t MenuSBTypeList[5][8] = {
  58. {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
  59. {0xBF,0xD8,0xD6,0xC6,0xC6,0xF7,0x20,0x20}, //控制器
  60. {0xD4,0xB6,0xB3,0xCC,0xCF,0xD4,0xCA,0xBE}, //远程显示
  61. {0xB4,0xF3,0xC6,0xC1,0x20,0x20,0x20,0x20}, //大屏
  62. {0xB4,0xF3,0xC6,0xC1,0x31,0x20,0x20,0x20} //LED大屏
  63. };
  64. static uint8_t TDisplay = 1;
  65. // CRC 高位字节值表
  66. const unsigned char auchCRCHi[] = {
  67. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
  68. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
  69. 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
  70. 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
  71. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
  72. 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
  73. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
  74. 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
  75. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
  76. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
  77. 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
  78. 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
  79. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
  80. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
  81. 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
  82. 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
  83. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
  84. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
  85. 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
  86. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
  87. 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
  88. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
  89. 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
  90. 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
  91. 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
  92. 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
  93. } ;
  94. // CRC 低位字节值表
  95. const unsigned char auchCRCLo[] = {
  96. 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
  97. 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
  98. 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
  99. 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
  100. 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
  101. 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
  102. 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
  103. 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
  104. 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
  105. 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
  106. 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
  107. 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
  108. 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
  109. 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
  110. 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
  111. 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
  112. 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
  113. 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
  114. 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
  115. 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
  116. 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
  117. 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
  118. 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
  119. 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
  120. 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
  121. 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
  122. };
  123. static void MenuDisplay_entry(void *parameter) {
  124. extern IWDG_HandleTypeDef hiwdg;
  125. while(1)
  126. {
  127. if (MenuItem<11)
  128. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量
  129. WeightConst_Weight_display[SendDisplay_i]=0x20;
  130. if (MenuItem==0)
  131. {
  132. if (XbeeConst_DeviceAddress>9) {
  133. WeightConst_Weight_display[6] = (XbeeConst_DeviceAddress/10)%10 + 0x30;
  134. WeightConst_Weight_display[5] = XbeeConst_DeviceAddress%10 + 0x30;
  135. }
  136. else WeightConst_Weight_display[6] = XbeeConst_DeviceAddress + 0x30;
  137. }
  138. else if (MenuItem==1)
  139. {
  140. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
  141. WeightConst_Weight_display[SendDisplay_i] = MenuTQTypeList[WeightConst_TQ][7-SendDisplay_i];
  142. }
  143. else if (MenuItem==2)
  144. {
  145. if (XbeeConst_NetAddress>99) WeightConst_Weight_display[7] = XbeeConst_NetAddress/100 + 0x30;
  146. if (XbeeConst_NetAddress>9) WeightConst_Weight_display[6] = (XbeeConst_NetAddress/10)%10 + 0x30;
  147. WeightConst_Weight_display[5] = XbeeConst_NetAddress%10 + 0x30;
  148. }
  149. else if (MenuItem==3)
  150. {
  151. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
  152. WeightConst_Weight_display[SendDisplay_i] = MenuSBTypeList[WeightConst_SBType][7-SendDisplay_i];
  153. }
  154. else if (MenuItem==4)
  155. {
  156. if (WeightConst_ChanCheShu>9) {
  157. WeightConst_Weight_display[6] = (WeightConst_ChanCheShu/10)%10 + 0x30;
  158. WeightConst_Weight_display[5] = WeightConst_ChanCheShu%10 + 0x30;
  159. }
  160. else WeightConst_Weight_display[6] = WeightConst_ChanCheShu + 0x30;
  161. }
  162. else if (MenuItem==5)
  163. {
  164. WeightConst_Weight_display[6] = XbeeConst_UseAPI + 0x30;
  165. }
  166. else if (MenuItem==6)
  167. { TDisplay++;
  168. WeightConst_Weight_display[4] = (WeightConst_JZZ_==4 && TDisplay%2? 0x20:(WeightConst_JZZ>9999 ? (WeightConst_JZZ/10000)%10 : 0x00) + 0x30);
  169. WeightConst_Weight_display[3] = (WeightConst_JZZ_==3 && TDisplay%2? 0x20:(WeightConst_JZZ>999 ? (WeightConst_JZZ/1000)%10 : 0x00) + 0x30);
  170. WeightConst_Weight_display[2] = (WeightConst_JZZ_==2 && TDisplay%2? 0x20:(WeightConst_JZZ>99 ? (WeightConst_JZZ/100)%10 : 0x00) + 0x30);
  171. WeightConst_Weight_display[1] = (WeightConst_JZZ_==1 && TDisplay%2? 0x20:(WeightConst_JZZ>9 ? (WeightConst_JZZ/10)%10 : 0x00) + 0x30);
  172. WeightConst_Weight_display[0] = (WeightConst_JZZ_==0 && TDisplay%2? 0x20:(WeightConst_JZZ%10 + 0x30));
  173. }
  174. else if (MenuItem==7)
  175. { TDisplay++;
  176. WeightConst_Weight_display[4] = (WeightConst_ZD_==4 && TDisplay%2? 0x20:(Maxval>9999 ? (Maxval/10000)%10 : 0x00) + 0x30);
  177. WeightConst_Weight_display[3] = (WeightConst_ZD_==3 && TDisplay%2? 0x20:(Maxval>999 ? (Maxval/1000)%10 : 0x00) + 0x30);
  178. WeightConst_Weight_display[2] = (WeightConst_ZD_==2 && TDisplay%2? 0x20:(Maxval>99 ? (Maxval/100)%10 : 0x00) + 0x30);
  179. WeightConst_Weight_display[1] = (WeightConst_ZD_==1 && TDisplay%2? 0x20:(Maxval>9 ? (Maxval/10)%10 : 0x00) + 0x30);
  180. WeightConst_Weight_display[0] = (WeightConst_ZD_==0 && TDisplay%2? 0x20:(Maxval%10 + 0x30));
  181. }
  182. else if (MenuItem==8)
  183. {
  184. WeightConst_Weight_display[6] = ad_FS + 0x30;
  185. }
  186. else if (MenuItem==9)
  187. {
  188. WeightConst_Weight_display[6] = ad_Point + 0x30;
  189. }
  190. else if (MenuItem==10)
  191. {
  192. WeightConst_Weight_display[6] = ad_Inteval + 0x30;
  193. }
  194. else if (MenuItem==11)
  195. {
  196. WeightConst_Weight_display[6] = WeightConst_BLE + 0x30;
  197. }
  198. if (WeightConst_SBType<3 || WeightConst_SBType==6) {
  199. uart4_send_data[0] = 0x7E;
  200. uart4_send_data[1] = 0x45;
  201. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
  202. uart4_send_data[2 + SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
  203. for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示重量
  204. uart4_send_data[10 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];
  205. // USART_Send_DMA(displaySerial,18);
  206. uart4_send_data[18]=0;
  207. for (int i = 2; i <18; i++) //校验和
  208. uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
  209. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  210. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  211. rt_sem_release(uart4_lock);
  212. }
  213. else if (WeightConst_SBType==3||WeightConst_SBType==7) {
  214. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示菜单标题
  215. {
  216. WeightConst_feed[ SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
  217. }
  218. for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示当前值
  219. {
  220. WeightConst_feed[8 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];
  221. }
  222. //----------------------------
  223. get_msg(0,//Xstart
  224. 12,//Ystart
  225. 1,//size
  226. 0,//reset
  227. 0,//speed
  228. 8,//字符个数
  229. 3,//界面数
  230. 0,//id
  231. 0xbF,//Xend
  232. 0,
  233. &WeightConst_feed[0]//字码
  234. );
  235. get_msg(0,//Xstart
  236. 12,//Ystart
  237. 2,//size
  238. 0,//reset
  239. 0,//speed
  240. 8,//字符个数
  241. 3,//界面数
  242. 1,//id
  243. 0xbF,//Xend
  244. 0,
  245. &WeightConst_feed[8]//字码
  246. );
  247. }
  248. else {
  249. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
  250. WeightConst_feed[SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
  251. //----------------------------
  252. //display_menu();
  253. if(isn==0)
  254. {
  255. clearScreenAll();
  256. display_Current_noweight();
  257. display_Now();
  258. for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j];
  259. send_uart4_send_data();
  260. for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j];
  261. send_uart4_send_data();
  262. for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j];
  263. send_uart4_send_data();
  264. for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j];
  265. send_uart4_send_data();
  266. for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j];
  267. send_uart4_send_data();
  268. }
  269. else {
  270. display_Current_noweight_();
  271. display_Now_(WeightConst_WeightCurTem);
  272. }
  273. }
  274. // HAL_IWDG_Refresh(&hiwdg);
  275. rt_thread_mdelay(400);
  276. }
  277. }
  278. static rt_thread_t display_tid = RT_NULL;
  279. void threadMenuDisplay_init(void)
  280. {
  281. //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  282. display_tid = rt_thread_create("MenuDisp",
  283. MenuDisplay_entry, RT_NULL,
  284. 0x200,
  285. 4, 5);
  286. /* 如果获得线程控制块,启动这个线程 */
  287. if (display_tid != RT_NULL) rt_thread_startup(display_tid);
  288. }
  289. void getDisplay(void)
  290. {
  291. rt_uint8_t nullindex;
  292. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  293. if (tsdb_recordcount('k')>0 || XbeeConst_CanSend==0)
  294. TDisplay++; //是否有按键需要传输
  295. else
  296. TDisplay = 1;
  297. rt_memset(WeightConst_Feed_display, 0x20, 40);
  298. if(WeightConst_DELAYON>0)
  299. {
  300. WeightConst_Feed_display[0]=0xC7;
  301. WeightConst_Feed_display[1]=0xEB;
  302. WeightConst_Feed_display[2]=0xBD;
  303. WeightConst_Feed_display[3]=0xC1;
  304. WeightConst_Feed_display[4]=0xB0;
  305. WeightConst_Feed_display[5]=0xE8;
  306. WeightConst_Feed_display[6]=0x20;
  307. WeightConst_Feed_display[7]=0x20;
  308. }
  309. else if (!isWeight){
  310. nullindex = 0;
  311. for (int i = 0; i < 40; i++) //显示标题
  312. {
  313. WeightConst_Feed_display[i] = WeightConst_feed[i];
  314. if (i>0 && nullindex==0 && WeightConst_feed[i]==0x20 && WeightConst_feed[i-1]==0x20 && WeightConst_feed[i-2]==0x20) {
  315. nullindex = i-2;
  316. }
  317. if ((nullindex>8 && nullindex<14)||(nullindex<7 && nullindex>0)) nullindex=nullindex+2;
  318. if (nullindex>1){
  319. if(TDisplay%2==0) {
  320. WeightConst_Feed_display[nullindex-1]=0x3E;
  321. WeightConst_Feed_display[nullindex-2]=0x3E;
  322. }
  323. else {
  324. WeightConst_Feed_display[nullindex-1]=WeightConst_feed[nullindex-1];
  325. WeightConst_Feed_display[nullindex-2]=WeightConst_feed[nullindex-2];
  326. }
  327. }
  328. }
  329. }
  330. if(WeightConst_DELAYON>0)
  331. {
  332. WeightConst_Weight_display[0]=0xEB;
  333. WeightConst_Weight_display[1]=0xC3;
  334. WeightConst_Weight_display[2]=0x20;
  335. WeightConst_Weight_display[3]=0x20;
  336. WeightConst_Weight_display[4]=0x20;
  337. WeightConst_Weight_display[5]=0x20;
  338. WeightConst_Weight_display[6]=0x20;
  339. WeightConst_Weight_display[7]=0x20;
  340. WeightConst_Weight_displayW = (pf_comp.data.delaytime * 60 - WeightConst_DELAYTIME);
  341. for (int SendDisplay_i = 2; SendDisplay_i < 8; SendDisplay_i++) {
  342. if (SendDisplay_i>2) WeightConst_Weight_displayW=WeightConst_Weight_displayW/10;
  343. if (abs(WeightConst_Weight_displayW)>0)
  344. WeightConst_Weight_display[SendDisplay_i] = abs((WeightConst_Weight_displayW)%10)+'0';
  345. else break;
  346. }
  347. }
  348. else
  349. {
  350. if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
  351. WeightConst_Weight_displayW = WeightConst_WeightCurTem - WeightConst_WeightTarget;
  352. else
  353. WeightConst_Weight_displayW = WeightConst_WeightCurTem;
  354. WeightConst_Weight_displayCurW = WeightConst_WeightCurTem;
  355. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量
  356. WeightConst_Weight_display[SendDisplay_i]=0x20;
  357. if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
  358. {
  359. if ((WeightConst_Weight_displayW<=0 && pf_comp.data.addorout==0) ||
  360. (WeightConst_Weight_displayW>=0 && pf_comp.data.addorout == 1)
  361. ) { //少
  362. WeightConst_Weight_display[6]=0xD9;
  363. WeightConst_Weight_display[7]=0xC9;
  364. }
  365. else {
  366. WeightConst_Weight_display[6]=0xE0; //多
  367. WeightConst_Weight_display[7]=0xB6;
  368. }
  369. }
  370. else {
  371. if (WeightConst_Weight_displayW<0) {
  372. WeightConst_Weight_display[6]=0x2D; //-
  373. WeightConst_Weight_display[7]=0x20;
  374. }
  375. else {
  376. WeightConst_Weight_display[6]=0x20; //
  377. WeightConst_Weight_display[7]=0x20;
  378. }
  379. }
  380. if (WeightConst_Weight_displayW==0) {
  381. WeightConst_Weight_display[0]=0x30;
  382. }
  383. else
  384. {
  385. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  386. if (SendDisplay_i>0)
  387. WeightConst_Weight_displayW=WeightConst_Weight_displayW/10;
  388. if (abs(WeightConst_Weight_displayW)>0)
  389. WeightConst_Weight_display[SendDisplay_i] = abs(WeightConst_Weight_displayW%10)+'0';
  390. else break;
  391. }
  392. if (WeightConst_WeightWS>0) {
  393. for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--)
  394. if (WeightConst_Weight_display[SendDisplay_i]!=0x20)
  395. WeightConst_Weight_display[SendDisplay_i+1]=WeightConst_Weight_display[SendDisplay_i];
  396. WeightConst_Weight_display[WeightConst_WeightWS]=0x2E;
  397. if (WeightConst_Weight_display[WeightConst_WeightWS+1]==0x20) WeightConst_Weight_display[WeightConst_WeightWS+1] = 0x30;
  398. for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++)
  399. if (WeightConst_Weight_display[SendDisplay_i]==0x20) WeightConst_Weight_display[SendDisplay_i] = 0x30;
  400. }
  401. }
  402. /////////////////广泽
  403. if (remote_sumweight==1)
  404. {
  405. for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++)
  406. {
  407. WeightConst_WeightCur_display[SendDisplay_i] = 0x20;
  408. };
  409. if (WeightConst_Weight_displayCurW==0){
  410. WeightConst_WeightCur_display[0] = 0x30;
  411. }
  412. else
  413. {
  414. if (WeightConst_Weight_displayCurW<0) {
  415. WeightConst_WeightCur_display[4]=0x2D; //-
  416. }
  417. for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
  418. if (SendDisplay_i>0)
  419. WeightConst_Weight_displayCurW=WeightConst_Weight_displayCurW/10;
  420. if (abs(WeightConst_Weight_displayCurW)>0)
  421. WeightConst_WeightCur_display[SendDisplay_i] = abs(WeightConst_Weight_displayCurW%10)+'0';
  422. else break;
  423. }
  424. if (WeightConst_WeightWS>0) {
  425. for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--)
  426. if (WeightConst_WeightCur_display[SendDisplay_i]!=0x20)
  427. WeightConst_WeightCur_display[SendDisplay_i+1]=WeightConst_WeightCur_display[SendDisplay_i];
  428. WeightConst_WeightCur_display[WeightConst_WeightWS]=0x2E;
  429. if (WeightConst_WeightCur_display[WeightConst_WeightWS+1]==0x20) WeightConst_WeightCur_display[WeightConst_WeightWS+1] = 0x30;
  430. for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++)
  431. if (WeightConst_WeightCur_display[SendDisplay_i]==0x20) WeightConst_WeightCur_display[SendDisplay_i] = 0x30;
  432. }
  433. }
  434. }
  435. /////////////////广泽 end
  436. if (WeightConst_WeightHaveBegin==0 && pf_comp.data.needBegin == 1)
  437. {
  438. if (WeightConst_SBType==1||WeightConst_SBType==6) {
  439. //for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //如果没有开始则空显示重量
  440. // WeightConst_Weight_display[SendDisplay_i]=0x20;
  441. WeightConst_Weight_display[5]=WeightConst_Weight_display[6];
  442. WeightConst_Weight_display[6]=0xF8;
  443. WeightConst_Weight_display[7]=0xCB;
  444. }
  445. else if (WeightConst_SBType==3) {
  446. WeightConst_Weight_display[5]=WeightConst_Weight_display[6];
  447. WeightConst_Weight_display[6]=0xF8;
  448. WeightConst_Weight_display[7]=0xCB;
  449. /*
  450. WeightConst_Weight_display[0]=0xCC;
  451. WeightConst_Weight_display[1]=0xC5;
  452. WeightConst_Weight_display[2]=0xD3;
  453. WeightConst_Weight_display[3]=0xB3;
  454. WeightConst_Weight_display[4]=0xD5;
  455. WeightConst_Weight_display[5]=0xBF;
  456. WeightConst_Weight_display[6]=0xE5;
  457. WeightConst_Weight_display[7]=0xC7;//清空秤盘
  458. */
  459. }
  460. else if (WeightConst_SBType==4||WeightConst_SBType==6) {
  461. WeightConst_Weight_display[0]=0xBC;
  462. WeightConst_Weight_display[1]=0xCA;
  463. WeightConst_Weight_display[2]=0xAA;
  464. WeightConst_Weight_display[3]=0xBF;
  465. WeightConst_Weight_display[4]=0xCF;
  466. WeightConst_Weight_display[5]=0xC8;
  467. WeightConst_Weight_display[6]=0xB7;
  468. WeightConst_Weight_display[7]=0xC8;//确认开始
  469. };
  470. };
  471. }
  472. rt_sem_release(display_lock);
  473. }
  474. static void sendRemote(void *parameter)
  475. {
  476. rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0;
  477. while(1)
  478. {
  479. if (RemoteSendDisplay == 1 )
  480. {
  481. if ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI>=3))||
  482. (flag_uart3_send==0 && XbeeConst_UseAPI==0))
  483. {
  484. if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[0] = 28;
  485. else XbeeConst_FRemoteTxBuf[0] = 23;
  486. XbeeConst_FRemoteTxBuf[1] = 0x7E;
  487. XbeeConst_FRemoteTxBuf[2] = 0x15;
  488. if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[2] = 0x1A;
  489. else XbeeConst_FRemoteTxBuf[2] = 0x15;
  490. XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
  491. if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3)
  492. XbeeConst_FRemoteTxBuf[4] = 0xA1;
  493. else
  494. {
  495. if (WeightConst_ChanCheShu>9)
  496. XbeeConst_FRemoteTxBuf[4] = 0xA1;
  497. else
  498. XbeeConst_FRemoteTxBuf[4] = 0xF1;
  499. }
  500. XbeeConst_FRemoteTxBuf[5] = 0x7E;
  501. XbeeConst_FRemoteTxBuf[6] = 0x45;
  502. haveAscii=0;
  503. for(rt_uint8_t i=0; i<8; i++){
  504. if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); }
  505. }
  506. ismulti = 0;
  507. for(rt_uint8_t i=8;i<16;i++){
  508. if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; }
  509. }
  510. if (ismulti==0) displayrow = 0;
  511. if (forcount<1) forcount++;
  512. else{
  513. forcount = 0;
  514. if (ismulti==1 && displayrow==1) displayrow = 0;
  515. else if (ismulti==1 && displayrow==0) displayrow = 1;
  516. }
  517. for (rt_uint8_t i = 0; i < 8; i++) //显示标题
  518. {
  519. if (haveAscii==1 && displayrow==1)
  520. XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i+displayrow*8-1];//显示标题
  521. else if (haveAscii==1 && displayrow==0){
  522. if (i==7)
  523. XbeeConst_FRemoteTxBuf[7+i] = 0x20;
  524. else
  525. XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8];
  526. }
  527. else XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8];
  528. };
  529. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  530. XbeeConst_FRemoteTxBuf[15+SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];//显示重量
  531. }
  532. ////////////广泽
  533. if(remote_sumweight==1){
  534. for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
  535. XbeeConst_FRemoteTxBuf[23+SendDisplay_i] = WeightConst_WeightCur_display[4-SendDisplay_i];//显示重量
  536. }
  537. }
  538. ////////////广泽
  539. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0x00;
  540. for (int SendDisplay_i = 1; SendDisplay_i < XbeeConst_FRemoteTxBuf[0]; SendDisplay_i++) {
  541. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] =
  542. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]+XbeeConst_FRemoteTxBuf[SendDisplay_i];
  543. }
  544. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0xFF - XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]];
  545. if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3) {
  546. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  547. if (XbeeConst_UseAPI==1)
  548. setSendFrame_t(0x01,0x02,0x40);
  549. else setSendFrame_t(0x02,0x02,0x40);
  550. XbeeConst_PRemoteTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
  551. for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出
  552. usart2_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i];
  553. if (XbeeConst_UseAPI==1 || (XbeeConst_UseAPI==3 && ccsend==1))
  554. {
  555. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial
  556. rt_thread_mdelay(50);
  557. }
  558. rt_sem_release(uart2_lock);
  559. rt_thread_mdelay(XbeeConst_DeviceAddress*30);
  560. // rt_thread_mdelay(200);
  561. }
  562. else if (XbeeConst_UseAPI>3) {
  563. rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
  564. AT_on();
  565. for(int xcount=0;xcount<2;xcount++){
  566. XbeeConst_PRemoteTxBuf0 = BleApp2MakeFrame(0xFFFF, 0x00, xcount, XbeeConst_FRemoteTxBuf);
  567. for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出
  568. usart3_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i];
  569. HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial
  570. rt_thread_mdelay(100);
  571. }
  572. AT_off();
  573. rt_sem_release(uart3_lock);
  574. }
  575. else
  576. {
  577. if (iscowweight<1 )
  578. {
  579. rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
  580. for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FRemoteTxBuf[0]; SendWifi_i++) //将缓冲区发出
  581. usart3_send_data[SendWifi_i-1] = XbeeConst_FRemoteTxBuf[SendWifi_i];
  582. HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]); //remoteSerial
  583. rt_thread_mdelay(50);
  584. rt_sem_release(uart3_lock);
  585. }
  586. }
  587. }
  588. }
  589. if (XbeeConst_UseAPI<4)
  590. rt_thread_mdelay(500);
  591. else rt_thread_mdelay(250);
  592. }
  593. }
  594. void ChancheShow(void) {
  595. uart4_send_data[0] = 0x7E;
  596. uart4_send_data[1] = 0x45;
  597. uart4_send_data[2] = XbeeConst_RemoteAddress + '0';
  598. for (int i = 3; i < 18; i++) //将缓冲区发出
  599. uart4_send_data[i] = 0x20;
  600. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  601. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 12);
  602. rt_sem_release(uart4_lock);
  603. }
  604. void send_uart4_send_data(void)
  605. {
  606. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  607. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
  608. rt_sem_release(uart4_lock);
  609. rt_thread_mdelay(100);
  610. // rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  611. // HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
  612. // rt_sem_release(uart4_lock);
  613. // rt_thread_mdelay(100);
  614. }
  615. extern unsigned char inMenu;
  616. static void Display_entry(void *parameter) {
  617. rt_uint32_t e;
  618. rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0,row=0,rowx=5;
  619. extern IWDG_HandleTypeDef hiwdg;
  620. while (1) {
  621. getDisplay();
  622. ismulti = 0;
  623. haveAscii=0;
  624. for(rt_uint8_t i=0;i<8;i++){
  625. if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); }
  626. }
  627. for(rt_uint8_t i=8;i<16;i++){
  628. if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; }
  629. }
  630. if (ismulti==0) displayrow = 0;
  631. if (forcount<2) forcount++;
  632. else{
  633. forcount = 0;
  634. if (ismulti==1 && displayrow==1) displayrow = 0;
  635. else if (ismulti==1 && displayrow==0) displayrow = 1;
  636. }
  637. if (WeightConst_SBType<3||WeightConst_SBType==6) {
  638. uart4_send_data[0] = 0x7E;
  639. uart4_send_data[1] = 0x45;
  640. for (int i = 0; i < 8; i++) //显示标题
  641. {
  642. if (haveAscii==1 && displayrow==1)
  643. uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8 - 1];
  644. else if (haveAscii==1 && displayrow==0){
  645. if (i==7)
  646. uart4_send_data[i+2] = 0x20;
  647. else
  648. uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
  649. }
  650. else uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
  651. };
  652. for (int i = 7; i >=0; i--) //显示重量
  653. uart4_send_data[i + 10] = WeightConst_Weight_display[7-i];
  654. uart4_send_data[18]=0;
  655. for (int i = 2; i <18; i++) //校验和
  656. uart4_send_data[18] = uart4_send_data[18] + uart4_send_data[i];
  657. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  658. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  659. rt_sem_release(uart4_lock);
  660. // HAL_IWDG_Refresh(&hiwdg);
  661. rt_thread_mdelay(500);
  662. }
  663. else if (WeightConst_SBType==4)
  664. {
  665. if (rt_event_recv(&display_event, (EVENT_clearall | EVENT_Current_noweight
  666. | EVENT_PlanName | EVENT_Current | EVENT_Stop | EVENT_Next) ,
  667. RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 10, &e) == RT_EOK)
  668. {
  669. if (e & EVENT_clearall)
  670. {
  671. if(isn>=1 ) {
  672. clearScreenAll_();
  673. }
  674. else
  675. {
  676. clearScreenAll();
  677. }
  678. }
  679. if (e & EVENT_Current_noweight)
  680. {
  681. if(isn>=1 ) {
  682. display_Current_noweight_();
  683. }
  684. else
  685. {
  686. display_Current_noweight();;
  687. }
  688. }
  689. if (e & EVENT_PlanName)
  690. {
  691. if(isn>=1 ) {
  692. display_productName_(0);
  693. }
  694. else
  695. {
  696. display_productName();
  697. }
  698. }
  699. if (e & EVENT_Current)
  700. {
  701. if(isn>=1 ) {
  702. display_Current_(WeightConst_WeightTargetTemp);
  703. }
  704. else
  705. {
  706. display_Current(WeightConst_WeightTargetTemp);
  707. }
  708. }
  709. if (e & EVENT_Stop)
  710. {
  711. if(isn>=1 ) {
  712. ;
  713. }
  714. else
  715. {
  716. ;
  717. }
  718. }
  719. if (e & EVENT_Next)
  720. {
  721. if(isn>=1) {
  722. display_Next_();
  723. }
  724. else
  725. {
  726. display_Next();
  727. }
  728. }
  729. }
  730. // if(WeightConst_Run || inMenu==1)
  731. {
  732. if (isn>=1)
  733. {
  734. display_Now_(WeightConst_WeightCurTem);
  735. }
  736. else{
  737. display_Now();
  738. display_Total(WeightConst_WeightCurTem);
  739. row++;
  740. if (row%rowx==0){
  741. for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j];
  742. send_uart4_send_data();
  743. }
  744. for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j];
  745. send_uart4_send_data();
  746. for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j];
  747. send_uart4_send_data();
  748. for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j];
  749. send_uart4_send_data();
  750. if (row%rowx==0){
  751. for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j];
  752. send_uart4_send_data();
  753. }
  754. if (row%rowx==0){
  755. for (int j=0; j<39; j++) uart4_send_data[j] = display_Stop_v[j];
  756. send_uart4_send_data();
  757. }
  758. }
  759. }
  760. if (isn>=1){
  761. rt_thread_mdelay(500);
  762. }
  763. else{
  764. rt_thread_mdelay(300);
  765. }
  766. // HAL_IWDG_Refresh(&hiwdg);
  767. }
  768. else if (WeightConst_SBType==3){// || WeightConst_SBType==7) {
  769. // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
  770. {
  771. get_msg(0,//Xstart
  772. 0,//Ystart
  773. 1,//size
  774. 0,//reset
  775. 0,//speed
  776. 16,//字符个数
  777. 3,//界面数
  778. 0,//id
  779. 0xBF,//Xend
  780. 0,
  781. &WeightConst_feed[0]//字码
  782. );
  783. get_msg(92,//Xstart
  784. 4,//Ystart
  785. 2,//size
  786. 0,//reset
  787. 0,//speed
  788. 8,//字符个数
  789. 3,//界面数
  790. 1,//id
  791. 0xBF,//Xend
  792. 1,
  793. &WeightConst_Weight_display[0]//字码
  794. );
  795. if(WeightConst_Product_Run)
  796. {
  797. rt_uint8_t index = 0,value = 0;
  798. signed long WeightConst_WeightCurTem_ = 0;
  799. uart4_send_data[0]=0x20;uart4_send_data[1]=0x20;uart4_send_data[2]=0x20;
  800. uart4_send_data[3]=0x20;uart4_send_data[4]=0x30;
  801. if (WeightConst_WeightCurTem<0)
  802. {
  803. WeightConst_WeightCurTem_ = WeightConst_WeightCurTem*-1;
  804. uart4_send_data[0] = 0x2D;
  805. }
  806. else WeightConst_WeightCurTem_ = WeightConst_WeightCurTem;
  807. for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
  808. if (SendDisplay_i>0) WeightConst_WeightCurTem_=WeightConst_WeightCurTem_/10;
  809. if (WeightConst_WeightCurTem_>0)
  810. uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCurTem_)%10+'0';
  811. else break;
  812. }
  813. get_msg(0,//Xstart
  814. 0,//Ystart
  815. 1,//size
  816. 0,//reset
  817. 0,//speed
  818. 5,//字符个数
  819. 3,//界面数
  820. 4,//id
  821. 0xBF,//Xend
  822. 0,
  823. &uart4_send_data[0]//字码
  824. );
  825. index = 0;
  826. for(int i = 0;i< 22;i++)
  827. {
  828. if(WeightConst_product[i] >= 0xA0) {
  829. uart4_send_data[index++] = WeightConst_product[i++];
  830. uart4_send_data[index++] = WeightConst_product[i];
  831. // uart4_send_data[index++] = 0xA1;
  832. // uart4_send_data[index++] = 0xA2;
  833. }
  834. else {
  835. if(WeightConst_product[i] != 0x20 && WeightConst_product[i] != 0)
  836. {
  837. uart4_send_data[index++] = WeightConst_product[i];
  838. // uart4_send_data[index++] = 0xA1;
  839. // uart4_send_data[index++] = 0xA2;
  840. }
  841. }
  842. }
  843. uart4_send_data[index++] = 0x10;
  844. //
  845. // value = (plan_comp.data .sumweight / 10000) % 10;
  846. // if(value != 0) {
  847. // uart4_send_data[index++] = value + 0x30;
  848. // uart4_send_data[index++] = (plan_comp.data .sumweight / 1000) % 10 + 0x30;
  849. // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
  850. // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
  851. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  852. // }
  853. // else {
  854. // value = (plan_comp.data .sumweight / 1000) % 10;
  855. // if(value != 0) {
  856. // uart4_send_data[index++] = value + 0x30;
  857. // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
  858. // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
  859. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  860. // }
  861. // else {
  862. // value = (plan_comp.data .sumweight / 100) % 10;
  863. // if(value != 0) {
  864. // uart4_send_data[index++] = value + 0x30;
  865. // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
  866. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  867. // }
  868. // else {
  869. // value = (plan_comp.data .sumweight / 10) % 10;
  870. // if(value != 0) {
  871. // uart4_send_data[index++] = value + 0x30;
  872. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  873. // }
  874. // else {
  875. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  876. // }
  877. // }
  878. // }
  879. // }
  880. uart4_send_data[index++] = 0x10;
  881. WeightConst_WeightCurTem_ = WeightConst_WeightTargetTemp;
  882. value = (WeightConst_WeightCurTem_ / 10000) % 10;
  883. if(value != 0) {
  884. uart4_send_data[index++] = value + 0x30;
  885. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 1000) % 10 + 0x30;
  886. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
  887. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
  888. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  889. }
  890. else {
  891. value = (WeightConst_WeightCurTem_ / 1000) % 10;
  892. if(value != 0) {
  893. uart4_send_data[index++] = value + 0x30;
  894. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
  895. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
  896. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  897. }
  898. else {
  899. value = (WeightConst_WeightCurTem_ / 100) % 10;
  900. if(value != 0) {
  901. uart4_send_data[index++] = value + 0x30;
  902. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
  903. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  904. }
  905. else {
  906. value = (WeightConst_WeightCurTem_ / 10) % 10;
  907. if(value != 0) {
  908. uart4_send_data[index++] = value + 0x30;
  909. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  910. }
  911. else {
  912. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  913. }
  914. }
  915. }
  916. }
  917. uart4_send_data[index++] = 0x10;
  918. for(int i = 0;i< 16;i++)
  919. {
  920. uart4_send_data[index++] = WeightConst_Nextfeed[i];
  921. if (WeightConst_Nextfeed[i] ==0x20) break;
  922. }
  923. uart4_send_data[index++] = 0x10;
  924. if (pf_comp.data.isMix==1){
  925. uart4_send_data[index++] = 0xD7;
  926. uart4_send_data[index++] = 0xE9;
  927. uart4_send_data[index++] = 0xBA;
  928. uart4_send_data[index++] = 0xCF;
  929. uart4_send_data[index++] = 0xC1;
  930. uart4_send_data[index++] = 0xCF;
  931. }
  932. uart4_send_data[index++] = 0x10;
  933. get_msg(0,//Xstart
  934. 0,//Ystart
  935. 1,//size
  936. 0,//reset
  937. 3,//speed
  938. index,//字符个数
  939. 3,//界面数
  940. 2,//id
  941. 0xBF,//Xend
  942. 0,
  943. &uart4_send_data[0]//字码
  944. );
  945. if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
  946. {
  947. int tempw;
  948. uart4_send_data[1]=0;
  949. uart4_send_data[2]=0;
  950. uart4_send_data[3]=0;
  951. if ((WeightConst_WeightTarget < WeightConst_WeightCurTem && pf_comp.data.addorout==0)
  952. || (WeightConst_WeightTarget > WeightConst_WeightCurTem && pf_comp.data.addorout==1))
  953. {
  954. uart4_send_data[0]= 100;
  955. uart4_send_data[1]=0xFF;
  956. }
  957. else
  958. {
  959. if (WeightConst_WeightCurTem<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) && pf_comp.data.addorout==0)
  960. tempw=0;
  961. else if (WeightConst_WeightCurTem>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) && pf_comp.data.addorout==1)
  962. tempw=0;
  963. else if (pf_comp.data.addorout==0)
  964. tempw = ( WeightConst_WeightCurTem-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp));
  965. else
  966. tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCurTem);
  967. uart4_send_data[0]=tempw*100/WeightConst_WeightTargetTemp;
  968. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) ||
  969. (WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1)
  970. )
  971. {
  972. uart4_send_data[2]=0xFF;
  973. }
  974. else if ((WeightConst_WeightCurTem+30>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)||
  975. (WeightConst_WeightCurTem-30<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
  976. {uart4_send_data[1]=0xFF; uart4_send_data[3]=0xFF;
  977. }
  978. else
  979. uart4_send_data[3]=0xFF;
  980. }
  981. get_msg(0,//Xstart
  982. 0,//Ystart
  983. 1,//size
  984. 0,//reset
  985. 0,//speed
  986. 4,//字符个数
  987. 3,//界面数
  988. 3,//id
  989. 0xBF,//Xend
  990. 0,
  991. &uart4_send_data[0]//字码
  992. );
  993. }
  994. }
  995. else{
  996. uart4_send_data[0]=0;
  997. uart4_send_data[1]=0;
  998. uart4_send_data[2]=0;
  999. uart4_send_data[3]=0;
  1000. get_msg(0,//Xstart
  1001. 0,//Ystart
  1002. 1,//size
  1003. 0,//reset
  1004. 0,//speed
  1005. 4,//字符个数
  1006. 3,//界面数
  1007. 3,//id
  1008. 0xBF,//Xend
  1009. 0,
  1010. &uart4_send_data[0]//字码
  1011. );
  1012. uart4_send_data[0]=0x20;
  1013. get_msg(0,//Xstart
  1014. 0,//Ystart
  1015. 1,//size
  1016. 0,//reset
  1017. 0,//speed
  1018. 1,//字符个数
  1019. 3,//界面数
  1020. 4,//id
  1021. 0xBF,//Xend
  1022. 0,
  1023. &uart4_send_data[0]//字码
  1024. );
  1025. uart4_send_data[0]=0x10;
  1026. uart4_send_data[0]=0x10;
  1027. uart4_send_data[0]=0x10;
  1028. uart4_send_data[0]=0x10;
  1029. get_msg(0,//Xstart
  1030. 0,//Ystart
  1031. 1,//size
  1032. 0,//reset
  1033. 0,//speed
  1034. 4,//字符个数
  1035. 3,//界面数
  1036. 2,//id
  1037. 0xBF,//Xend
  1038. 0,
  1039. &uart4_send_data[0]//字码
  1040. );
  1041. }
  1042. }
  1043. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
  1044. {
  1045. WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
  1046. }
  1047. rt_thread_mdelay(300);
  1048. // HAL_IWDG_Refresh(&hiwdg);
  1049. }
  1050. // if (WeightConst_SBType==3 || WeightConst_SBType==7) {
  1051. // // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
  1052. // {
  1053. // get_msg(92,//Xstart
  1054. // 4,//Ystart
  1055. // 2,//size
  1056. // 0,//reset
  1057. // 0,//speed
  1058. // 8,//字符个数
  1059. // 3,//界面数
  1060. // 1,//id
  1061. // 0xBF,//Xend
  1062. // 1,
  1063. // &WeightConst_Weight_display[0]//字码
  1064. // );
  1065. // break;
  1066. // }
  1067. // for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
  1068. // {
  1069. // WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
  1070. // }
  1071. // }
  1072. // if (WeightConst_SBType==4||WeightConst_SBType==6) {
  1073. // if (WeightConst_Product_Run) {
  1074. // if(isn!=1 && (ScreenBufSize()<100)) {
  1075. // display_Now();
  1076. // display_Total(WeightConst_WeightCurTem);
  1077. // }
  1078. // else if(isn==1) display_Now_(WeightConst_WeightCurTem);
  1079. // }
  1080. // else if(isn==1 && WeightConst_Run==1) display_Now_(WeightConst_WeightCurTem);
  1081. // }
  1082. // if (SendRemote_timer>700 && RemoteSendDisplay &&
  1083. // ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3))||
  1084. // (flag_uart3_send==0 && XbeeConst_UseAPI==0)))
  1085. // {
  1086. // SendRemote_timer = 0;
  1087. // }
  1088. }
  1089. }
  1090. static void Display_clear_entry(void *parameter) {
  1091. uint8_t i=0;
  1092. while (i<10) {
  1093. // while (WeightConst_Run<1) {
  1094. if (WeightConst_Run<1){
  1095. if (isn>=1) display_KPT_TMRWatch_();
  1096. // if (isn>=1) display_KPT_TMRWatch_weight_();
  1097. else display_KPT_TMRWatch();
  1098. }
  1099. rt_thread_mdelay(1000);
  1100. i++;
  1101. }
  1102. }
  1103. void threadDisplay_init(void)
  1104. {
  1105. if (WeightConst_SBType == 4)
  1106. {
  1107. if(isn>=1) clearScreenAll_();
  1108. else clearScreenAll();
  1109. }
  1110. //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  1111. display_tid = rt_thread_create("Display",
  1112. Display_entry, RT_NULL,
  1113. 0x400,
  1114. 5, 5);
  1115. /* 如果获得线程控制块,启动这个线程 */
  1116. if (display_tid != RT_NULL) rt_thread_startup(display_tid);
  1117. }
  1118. static rt_thread_t display_clear_tid = RT_NULL;
  1119. void threadDisplay_delay_init(void)
  1120. {
  1121. display_clear_tid = rt_thread_create("Displaydelay",
  1122. Display_clear_entry, RT_NULL,
  1123. 0x100,
  1124. 5, 5);
  1125. /* 如果获得线程控制块,启动这个线程 */
  1126. if (display_clear_tid != RT_NULL) rt_thread_startup(display_clear_tid);
  1127. }
  1128. static rt_thread_t remotedisplay_tid = RT_NULL;
  1129. void threadRemoteDisplay_init(void)
  1130. {
  1131. //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  1132. remotedisplay_tid = rt_thread_create("RemoteD",
  1133. sendRemote, RT_NULL,
  1134. 0x300,
  1135. 5, 5);
  1136. /* 如果获得线程控制块,启动这个线程 */
  1137. if (remotedisplay_tid != RT_NULL) rt_thread_startup(remotedisplay_tid);
  1138. }
  1139. void display_usart_Init(UART_HandleTypeDef* uartHandle)
  1140. {
  1141. extern unsigned char WeightConst_TQ;
  1142. if ((uartHandle->Instance==UART4 && (WeightConst_SBType==0x04 && isn==0)))
  1143. {
  1144. uartHandle->Init.BaudRate = 9600;
  1145. }
  1146. else
  1147. uartHandle->Init.BaudRate = 57600;
  1148. }
  1149. //CRC校验的函数
  1150. unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen)
  1151. {
  1152. unsigned char uchCRCHi = 0xFF ;
  1153. unsigned char uchCRCLo = 0xFF ;
  1154. unsigned uIndex ;
  1155. while (usDataLen--)
  1156. {
  1157. uIndex = uchCRCHi ^ *puchMsg++ ; /* 计算CRC */
  1158. uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
  1159. uchCRCLo = auchCRCLo[uIndex] ;
  1160. }
  1161. return (uchCRCHi << 8 | uchCRCLo) ;
  1162. }
  1163. unsigned char uart_send_buf_cp[100];
  1164. unsigned char get_msg( unsigned char Xstart,// 0 - 191
  1165. unsigned char Ystart, //0 - 47
  1166. unsigned char ZiTiSize,//1 or 2 or 3
  1167. unsigned char reset_enable,//0 or 1
  1168. unsigned char speed,//速度 0 or 1 or 2 or 3
  1169. unsigned char ZiFuCount,//字符个数
  1170. unsigned char JieMianCount,//3
  1171. unsigned char JieMianID,//0 or 1 or 2
  1172. unsigned char Xend,
  1173. unsigned char f,
  1174. unsigned char * ASCII_buf)
  1175. {
  1176. unsigned char i=0;
  1177. unsigned char len=0;
  1178. unsigned short int calcCRC;
  1179. extern IWDG_HandleTypeDef hiwdg;
  1180. uart_send_buf_cp[0] = 0x7E;
  1181. uart_send_buf_cp[1] = Xstart;
  1182. uart_send_buf_cp[2] = (Ystart<<2) |(ZiTiSize & 0x03);
  1183. // uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|((speed<<5)&0x60);
  1184. uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|(speed & 0x0F);
  1185. uart_send_buf_cp[4] = ZiFuCount;
  1186. uart_send_buf_cp[5] = ((JieMianCount<<4)&0xF0)|(JieMianID&0x0F);
  1187. uart_send_buf_cp[6] = Xend;
  1188. if (f==0)
  1189. for(i=0; i<ZiFuCount; i++) uart_send_buf_cp[7+i] = ASCII_buf[i];
  1190. else
  1191. for(i=ZiFuCount; i>0; i--) uart_send_buf_cp[7+i-1] = ASCII_buf[ZiFuCount-i];
  1192. len = ZiFuCount + 7;
  1193. calcCRC = CRC16(uart_send_buf_cp, len);
  1194. uart_send_buf_cp[7+ZiFuCount] = (unsigned char)(calcCRC>>8); //低位
  1195. uart_send_buf_cp[7+ZiFuCount+1] = (unsigned char)(calcCRC); //高位
  1196. for(i=0; i<=8+ZiFuCount; i++) uart4_send_data[i] = uart_send_buf_cp[i];
  1197. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  1198. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 9+ZiFuCount);
  1199. rt_sem_release(uart4_lock);
  1200. rt_thread_mdelay(150);
  1201. return 0;
  1202. }