display.c 48 KB

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