display.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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
  563. {
  564. if (iscowweight<1 )
  565. {
  566. rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
  567. for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FRemoteTxBuf[0]; SendWifi_i++) //将缓冲区发出
  568. usart3_send_data[SendWifi_i-1] = XbeeConst_FRemoteTxBuf[SendWifi_i];
  569. HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]); //remoteSerial
  570. rt_thread_mdelay(50);
  571. rt_sem_release(uart3_lock);
  572. }
  573. }
  574. }
  575. }
  576. rt_thread_mdelay(500);
  577. }
  578. }
  579. void ChancheShow(void) {
  580. uart4_send_data[0] = 0x7E;
  581. uart4_send_data[1] = 0x45;
  582. uart4_send_data[2] = XbeeConst_RemoteAddress + '0';
  583. for (int i = 3; i < 18; i++) //将缓冲区发出
  584. uart4_send_data[i] = 0x20;
  585. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  586. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 12);
  587. rt_sem_release(uart4_lock);
  588. }
  589. void send_uart4_send_data(void)
  590. {
  591. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  592. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
  593. rt_sem_release(uart4_lock);
  594. rt_thread_mdelay(100);
  595. // rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  596. // HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
  597. // rt_sem_release(uart4_lock);
  598. // rt_thread_mdelay(100);
  599. }
  600. extern unsigned char inMenu;
  601. static void Display_entry(void *parameter) {
  602. rt_uint32_t e;
  603. rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0,row=0,rowx=5;
  604. extern IWDG_HandleTypeDef hiwdg;
  605. while (1) {
  606. getDisplay();
  607. ismulti = 0;
  608. haveAscii=0;
  609. for(rt_uint8_t i=0;i<8;i++){
  610. if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); }
  611. }
  612. for(rt_uint8_t i=8;i<16;i++){
  613. if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; }
  614. }
  615. if (ismulti==0) displayrow = 0;
  616. if (forcount<2) forcount++;
  617. else{
  618. forcount = 0;
  619. if (ismulti==1 && displayrow==1) displayrow = 0;
  620. else if (ismulti==1 && displayrow==0) displayrow = 1;
  621. }
  622. if (WeightConst_SBType<3||WeightConst_SBType==6) {
  623. uart4_send_data[0] = 0x7E;
  624. uart4_send_data[1] = 0x45;
  625. for (int i = 0; i < 8; i++) //显示标题
  626. {
  627. if (haveAscii==1 && displayrow==1)
  628. uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8 - 1];
  629. else if (haveAscii==1 && displayrow==0){
  630. if (i==7)
  631. uart4_send_data[i+2] = 0x20;
  632. else
  633. uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
  634. }
  635. else uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
  636. };
  637. for (int i = 7; i >=0; i--) //显示重量
  638. uart4_send_data[i + 10] = WeightConst_Weight_display[7-i];
  639. uart4_send_data[18]=0;
  640. for (int i = 2; i <18; i++) //校验和
  641. uart4_send_data[18] = uart4_send_data[18] + uart4_send_data[i];
  642. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  643. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  644. rt_sem_release(uart4_lock);
  645. HAL_IWDG_Refresh(&hiwdg);
  646. rt_thread_mdelay(500);
  647. }
  648. else if (WeightConst_SBType==4)
  649. {
  650. if (rt_event_recv(&display_event, (EVENT_clearall | EVENT_Current_noweight
  651. | EVENT_PlanName | EVENT_Current | EVENT_Stop | EVENT_Next) ,
  652. RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 10, &e) == RT_EOK)
  653. {
  654. if (e & EVENT_clearall)
  655. {
  656. if(isn>=1 ) {
  657. clearScreenAll_();
  658. }
  659. else
  660. {
  661. clearScreenAll();
  662. }
  663. }
  664. if (e & EVENT_Current_noweight)
  665. {
  666. if(isn>=1 ) {
  667. display_Current_noweight_();
  668. }
  669. else
  670. {
  671. display_Current_noweight();;
  672. }
  673. }
  674. if (e & EVENT_PlanName)
  675. {
  676. if(isn>=1 ) {
  677. display_productName_(0);
  678. }
  679. else
  680. {
  681. display_productName();
  682. }
  683. }
  684. if (e & EVENT_Current)
  685. {
  686. if(isn>=1 ) {
  687. display_Current_(WeightConst_WeightTargetTemp);
  688. }
  689. else
  690. {
  691. display_Current(WeightConst_WeightTargetTemp);
  692. }
  693. }
  694. if (e & EVENT_Stop)
  695. {
  696. if(isn>=1 ) {
  697. ;
  698. }
  699. else
  700. {
  701. ;
  702. }
  703. }
  704. if (e & EVENT_Next)
  705. {
  706. if(isn>=1) {
  707. display_Next_();
  708. }
  709. else
  710. {
  711. display_Next();
  712. }
  713. }
  714. }
  715. if(WeightConst_Run || inMenu==1)
  716. {
  717. if (isn>=1)
  718. {
  719. display_Now_(WeightConst_WeightCurTem);
  720. }
  721. else{
  722. display_Now();
  723. display_Total(WeightConst_WeightCurTem);
  724. row++;
  725. if (row%rowx==0){
  726. for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j];
  727. send_uart4_send_data();
  728. }
  729. for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j];
  730. send_uart4_send_data();
  731. for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j];
  732. send_uart4_send_data();
  733. for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j];
  734. send_uart4_send_data();
  735. if (row%rowx==0){
  736. for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j];
  737. send_uart4_send_data();
  738. }
  739. if (row%rowx==0){
  740. for (int j=0; j<39; j++) uart4_send_data[j] = display_Stop_v[j];
  741. send_uart4_send_data();
  742. }
  743. }
  744. }
  745. if (isn>=1){
  746. rt_thread_mdelay(500);
  747. }
  748. else{
  749. rt_thread_mdelay(300);
  750. }
  751. HAL_IWDG_Refresh(&hiwdg);
  752. }
  753. else if (WeightConst_SBType==3){// || WeightConst_SBType==7) {
  754. // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
  755. {
  756. get_msg(0,//Xstart
  757. 0,//Ystart
  758. 1,//size
  759. 0,//reset
  760. 0,//speed
  761. 16,//字符个数
  762. 3,//界面数
  763. 0,//id
  764. 0xBF,//Xend
  765. 0,
  766. &WeightConst_feed[0]//字码
  767. );
  768. get_msg(92,//Xstart
  769. 4,//Ystart
  770. 2,//size
  771. 0,//reset
  772. 0,//speed
  773. 8,//字符个数
  774. 3,//界面数
  775. 1,//id
  776. 0xBF,//Xend
  777. 1,
  778. &WeightConst_Weight_display[0]//字码
  779. );
  780. if(WeightConst_Product_Run)
  781. {
  782. rt_uint8_t index = 0,value = 0;
  783. signed long WeightConst_WeightCurTem_ = 0;
  784. uart4_send_data[0]=0x20;uart4_send_data[1]=0x20;uart4_send_data[2]=0x20;
  785. uart4_send_data[3]=0x20;uart4_send_data[4]=0x30;
  786. if (WeightConst_WeightCurTem<0)
  787. {
  788. WeightConst_WeightCurTem_ = WeightConst_WeightCurTem*-1;
  789. uart4_send_data[0] = 0x2D;
  790. }
  791. else WeightConst_WeightCurTem_ = WeightConst_WeightCurTem;
  792. for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
  793. if (SendDisplay_i>0) WeightConst_WeightCurTem_=WeightConst_WeightCurTem_/10;
  794. if (WeightConst_WeightCurTem_>0)
  795. uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCurTem_)%10+'0';
  796. else break;
  797. }
  798. get_msg(0,//Xstart
  799. 0,//Ystart
  800. 1,//size
  801. 0,//reset
  802. 0,//speed
  803. 5,//字符个数
  804. 3,//界面数
  805. 4,//id
  806. 0xBF,//Xend
  807. 0,
  808. &uart4_send_data[0]//字码
  809. );
  810. index = 0;
  811. for(int i = 0;i< 22;i++)
  812. {
  813. if(WeightConst_product[i] >= 0xA0) {
  814. uart4_send_data[index++] = WeightConst_product[i++];
  815. uart4_send_data[index++] = WeightConst_product[i];
  816. // uart4_send_data[index++] = 0xA1;
  817. // uart4_send_data[index++] = 0xA2;
  818. }
  819. else {
  820. if(WeightConst_product[i] != 0x20 && WeightConst_product[i] != 0)
  821. {
  822. uart4_send_data[index++] = WeightConst_product[i];
  823. // uart4_send_data[index++] = 0xA1;
  824. // uart4_send_data[index++] = 0xA2;
  825. }
  826. }
  827. }
  828. uart4_send_data[index++] = 0x10;
  829. //
  830. // value = (plan_comp.data .sumweight / 10000) % 10;
  831. // if(value != 0) {
  832. // uart4_send_data[index++] = value + 0x30;
  833. // uart4_send_data[index++] = (plan_comp.data .sumweight / 1000) % 10 + 0x30;
  834. // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
  835. // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
  836. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  837. // }
  838. // else {
  839. // value = (plan_comp.data .sumweight / 1000) % 10;
  840. // if(value != 0) {
  841. // uart4_send_data[index++] = value + 0x30;
  842. // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
  843. // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
  844. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  845. // }
  846. // else {
  847. // value = (plan_comp.data .sumweight / 100) % 10;
  848. // if(value != 0) {
  849. // uart4_send_data[index++] = value + 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 / 10) % 10;
  855. // if(value != 0) {
  856. // uart4_send_data[index++] = value + 0x30;
  857. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  858. // }
  859. // else {
  860. // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
  861. // }
  862. // }
  863. // }
  864. // }
  865. uart4_send_data[index++] = 0x10;
  866. WeightConst_WeightCurTem_ = WeightConst_WeightTargetTemp;
  867. value = (WeightConst_WeightCurTem_ / 10000) % 10;
  868. if(value != 0) {
  869. uart4_send_data[index++] = value + 0x30;
  870. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 1000) % 10 + 0x30;
  871. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
  872. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
  873. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  874. }
  875. else {
  876. value = (WeightConst_WeightCurTem_ / 1000) % 10;
  877. if(value != 0) {
  878. uart4_send_data[index++] = value + 0x30;
  879. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
  880. uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
  881. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  882. }
  883. else {
  884. value = (WeightConst_WeightCurTem_ / 100) % 10;
  885. if(value != 0) {
  886. uart4_send_data[index++] = value + 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_ / 10) % 10;
  892. if(value != 0) {
  893. uart4_send_data[index++] = value + 0x30;
  894. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  895. }
  896. else {
  897. uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
  898. }
  899. }
  900. }
  901. }
  902. uart4_send_data[index++] = 0x10;
  903. for(int i = 0;i< 16;i++)
  904. {
  905. uart4_send_data[index++] = WeightConst_Nextfeed[i];
  906. if (WeightConst_Nextfeed[i] ==0x20) break;
  907. }
  908. uart4_send_data[index++] = 0x10;
  909. if (pf_comp.data.isMix==1){
  910. uart4_send_data[index++] = 0xD7;
  911. uart4_send_data[index++] = 0xE9;
  912. uart4_send_data[index++] = 0xBA;
  913. uart4_send_data[index++] = 0xCF;
  914. uart4_send_data[index++] = 0xC1;
  915. uart4_send_data[index++] = 0xCF;
  916. }
  917. uart4_send_data[index++] = 0x10;
  918. get_msg(0,//Xstart
  919. 0,//Ystart
  920. 1,//size
  921. 0,//reset
  922. 3,//speed
  923. index,//字符个数
  924. 3,//界面数
  925. 2,//id
  926. 0xBF,//Xend
  927. 0,
  928. &uart4_send_data[0]//字码
  929. );
  930. if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
  931. {
  932. int tempw;
  933. uart4_send_data[1]=0;
  934. uart4_send_data[2]=0;
  935. uart4_send_data[3]=0;
  936. if ((WeightConst_WeightTarget < WeightConst_WeightCurTem && pf_comp.data.addorout==0)
  937. || (WeightConst_WeightTarget > WeightConst_WeightCurTem && pf_comp.data.addorout==1))
  938. {
  939. uart4_send_data[0]= 100;
  940. uart4_send_data[1]=0xFF;
  941. }
  942. else
  943. {
  944. if (WeightConst_WeightCurTem<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) && pf_comp.data.addorout==0)
  945. tempw=0;
  946. else if (WeightConst_WeightCurTem>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) && pf_comp.data.addorout==1)
  947. tempw=0;
  948. else if (pf_comp.data.addorout==0)
  949. tempw = ( WeightConst_WeightCurTem-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp));
  950. else
  951. tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCurTem);
  952. uart4_send_data[0]=tempw*100/WeightConst_WeightTargetTemp;
  953. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) ||
  954. (WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1)
  955. )
  956. {
  957. uart4_send_data[2]=0xFF;
  958. }
  959. else if ((WeightConst_WeightCurTem+30>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)||
  960. (WeightConst_WeightCurTem-30<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
  961. {uart4_send_data[1]=0xFF; uart4_send_data[3]=0xFF;
  962. }
  963. else
  964. uart4_send_data[3]=0xFF;
  965. }
  966. get_msg(0,//Xstart
  967. 0,//Ystart
  968. 1,//size
  969. 0,//reset
  970. 0,//speed
  971. 4,//字符个数
  972. 3,//界面数
  973. 3,//id
  974. 0xBF,//Xend
  975. 0,
  976. &uart4_send_data[0]//字码
  977. );
  978. }
  979. }
  980. else{
  981. uart4_send_data[0]=0;
  982. uart4_send_data[1]=0;
  983. uart4_send_data[2]=0;
  984. uart4_send_data[3]=0;
  985. get_msg(0,//Xstart
  986. 0,//Ystart
  987. 1,//size
  988. 0,//reset
  989. 0,//speed
  990. 4,//字符个数
  991. 3,//界面数
  992. 3,//id
  993. 0xBF,//Xend
  994. 0,
  995. &uart4_send_data[0]//字码
  996. );
  997. uart4_send_data[0]=0x20;
  998. get_msg(0,//Xstart
  999. 0,//Ystart
  1000. 1,//size
  1001. 0,//reset
  1002. 0,//speed
  1003. 1,//字符个数
  1004. 3,//界面数
  1005. 4,//id
  1006. 0xBF,//Xend
  1007. 0,
  1008. &uart4_send_data[0]//字码
  1009. );
  1010. uart4_send_data[0]=0x10;
  1011. uart4_send_data[0]=0x10;
  1012. uart4_send_data[0]=0x10;
  1013. uart4_send_data[0]=0x10;
  1014. get_msg(0,//Xstart
  1015. 0,//Ystart
  1016. 1,//size
  1017. 0,//reset
  1018. 0,//speed
  1019. 4,//字符个数
  1020. 3,//界面数
  1021. 2,//id
  1022. 0xBF,//Xend
  1023. 0,
  1024. &uart4_send_data[0]//字码
  1025. );
  1026. }
  1027. }
  1028. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
  1029. {
  1030. WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
  1031. }
  1032. rt_thread_mdelay(300);
  1033. HAL_IWDG_Refresh(&hiwdg);
  1034. }
  1035. // if (WeightConst_SBType==3 || WeightConst_SBType==7) {
  1036. // // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
  1037. // {
  1038. // get_msg(92,//Xstart
  1039. // 4,//Ystart
  1040. // 2,//size
  1041. // 0,//reset
  1042. // 0,//speed
  1043. // 8,//字符个数
  1044. // 3,//界面数
  1045. // 1,//id
  1046. // 0xBF,//Xend
  1047. // 1,
  1048. // &WeightConst_Weight_display[0]//字码
  1049. // );
  1050. // break;
  1051. // }
  1052. // for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
  1053. // {
  1054. // WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
  1055. // }
  1056. // }
  1057. // if (WeightConst_SBType==4||WeightConst_SBType==6) {
  1058. // if (WeightConst_Product_Run) {
  1059. // if(isn!=1 && (ScreenBufSize()<100)) {
  1060. // display_Now();
  1061. // display_Total(WeightConst_WeightCurTem);
  1062. // }
  1063. // else if(isn==1) display_Now_(WeightConst_WeightCurTem);
  1064. // }
  1065. // else if(isn==1 && WeightConst_Run==1) display_Now_(WeightConst_WeightCurTem);
  1066. // }
  1067. // if (SendRemote_timer>700 && RemoteSendDisplay &&
  1068. // ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3))||
  1069. // (flag_uart3_send==0 && XbeeConst_UseAPI==0)))
  1070. // {
  1071. // SendRemote_timer = 0;
  1072. // }
  1073. }
  1074. }
  1075. static void Display_clear_entry(void *parameter) {
  1076. uint8_t i=0;
  1077. while (i<10) {
  1078. if (WeightConst_Run<1){
  1079. if (isn>=1) display_KPT_TMRWatch_();
  1080. else display_KPT_TMRWatch();
  1081. }
  1082. rt_thread_mdelay(1*1000);
  1083. i++;
  1084. }
  1085. }
  1086. void threadDisplay_init(void)
  1087. {
  1088. if (WeightConst_SBType == 4)
  1089. {
  1090. if(isn>=1) clearScreenAll_();
  1091. else clearScreenAll();
  1092. }
  1093. //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  1094. display_tid = rt_thread_create("Display",
  1095. Display_entry, RT_NULL,
  1096. 0x400,
  1097. 5, 5);
  1098. /* 如果获得线程控制块,启动这个线程 */
  1099. if (display_tid != RT_NULL) rt_thread_startup(display_tid);
  1100. }
  1101. static rt_thread_t display_clear_tid = RT_NULL;
  1102. void threadDisplay_delay_init(void)
  1103. {
  1104. display_clear_tid = rt_thread_create("Displaydelay",
  1105. Display_clear_entry, RT_NULL,
  1106. 0x100,
  1107. 5, 5);
  1108. /* 如果获得线程控制块,启动这个线程 */
  1109. if (display_clear_tid != RT_NULL) rt_thread_startup(display_clear_tid);
  1110. }
  1111. static rt_thread_t remotedisplay_tid = RT_NULL;
  1112. void threadRemoteDisplay_init(void)
  1113. {
  1114. //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  1115. remotedisplay_tid = rt_thread_create("RemoteD",
  1116. sendRemote, RT_NULL,
  1117. 0x100,
  1118. 5, 5);
  1119. /* 如果获得线程控制块,启动这个线程 */
  1120. if (remotedisplay_tid != RT_NULL) rt_thread_startup(remotedisplay_tid);
  1121. }
  1122. void display_usart_Init(UART_HandleTypeDef* uartHandle)
  1123. {
  1124. extern unsigned char WeightConst_TQ;
  1125. if ((uartHandle->Instance==UART4 && (WeightConst_SBType==0x04 && isn==0)))
  1126. {
  1127. uartHandle->Init.BaudRate = 9600;
  1128. }
  1129. else
  1130. uartHandle->Init.BaudRate = 57600;
  1131. }
  1132. //CRC校验的函数
  1133. unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen)
  1134. {
  1135. unsigned char uchCRCHi = 0xFF ;
  1136. unsigned char uchCRCLo = 0xFF ;
  1137. unsigned uIndex ;
  1138. while (usDataLen--)
  1139. {
  1140. uIndex = uchCRCHi ^ *puchMsg++ ; /* 计算CRC */
  1141. uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
  1142. uchCRCLo = auchCRCLo[uIndex] ;
  1143. }
  1144. return (uchCRCHi << 8 | uchCRCLo) ;
  1145. }
  1146. unsigned char uart_send_buf_cp[100];
  1147. unsigned char get_msg( unsigned char Xstart,// 0 - 191
  1148. unsigned char Ystart, //0 - 47
  1149. unsigned char ZiTiSize,//1 or 2 or 3
  1150. unsigned char reset_enable,//0 or 1
  1151. unsigned char speed,//速度 0 or 1 or 2 or 3
  1152. unsigned char ZiFuCount,//字符个数
  1153. unsigned char JieMianCount,//3
  1154. unsigned char JieMianID,//0 or 1 or 2
  1155. unsigned char Xend,
  1156. unsigned char f,
  1157. unsigned char * ASCII_buf)
  1158. {
  1159. unsigned char i=0;
  1160. unsigned char len=0;
  1161. unsigned short int calcCRC;
  1162. extern IWDG_HandleTypeDef hiwdg;
  1163. uart_send_buf_cp[0] = 0x7E;
  1164. uart_send_buf_cp[1] = Xstart;
  1165. uart_send_buf_cp[2] = (Ystart<<2) |(ZiTiSize & 0x03);
  1166. // uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|((speed<<5)&0x60);
  1167. uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|(speed & 0x0F);
  1168. uart_send_buf_cp[4] = ZiFuCount;
  1169. uart_send_buf_cp[5] = ((JieMianCount<<4)&0xF0)|(JieMianID&0x0F);
  1170. uart_send_buf_cp[6] = Xend;
  1171. if (f==0)
  1172. for(i=0; i<ZiFuCount; i++) uart_send_buf_cp[7+i] = ASCII_buf[i];
  1173. else
  1174. for(i=ZiFuCount; i>0; i--) uart_send_buf_cp[7+i-1] = ASCII_buf[ZiFuCount-i];
  1175. len = ZiFuCount + 7;
  1176. calcCRC = CRC16(uart_send_buf_cp, len);
  1177. uart_send_buf_cp[7+ZiFuCount] = (unsigned char)(calcCRC>>8); //低位
  1178. uart_send_buf_cp[7+ZiFuCount+1] = (unsigned char)(calcCRC); //高位
  1179. for(i=0; i<=8+ZiFuCount; i++) uart4_send_data[i] = uart_send_buf_cp[i];
  1180. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  1181. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 9+ZiFuCount);
  1182. rt_sem_release(uart4_lock);
  1183. rt_thread_mdelay(150);
  1184. return 0;
  1185. }