display.c 47 KB

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