123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362 |
- #include <rtthread.h>
- #include "main.h"
- #include "flash.h"
- #include "display.h"
- #include "buffer.h"
- #include "button.h"
- #include "usart.h"
- #include <stdlib.h>
- #include "weight.h"
- #include "plan.h"
- #include "daScreen.h"
- #include "xBeeAppEscapingMode.h"
- rt_sem_t display_lock = RT_NULL;
- rt_sem_t displayRemote_lock = RT_NULL;
- rt_sem_t sendLora_lock = RT_NULL;
- struct rt_event display_event;
- uint8_t MenuItem=0; //当前菜单
- uint8_t WeightConst_Feed_display[40]; //显示标题
- uint8_t WeightConst_Weight_display[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量
- uint8_t WeightConst_WeightCur_display[5] = {0x20,0x20,0x20,0x20,0x20}; //显示重量
- uint8_t WeightConst_Weight_display_old[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量
- static signed long WeightConst_Weight_displayW; //显示重量
- static signed long WeightConst_Weight_displayCurW; //显示重量
- unsigned char WeightConst_displayTotal = 0; //0差重,1实重
- unsigned char WeightConst_remoteDisplay = 0;
- unsigned char RemoteSendDisplay = 1;extern unsigned char iscowweight;
- extern unsigned char remote_sumweight;
- const uint8_t MenuItemList[12][8] = {{0xC9,0xE8,0xB1,0xB8,0xB5,0xD8,0xD6,0xB7}, //设备地址
- {0xCC,0xE1,0xC8,0xA1,0xB7,0xBD,0xCA,0xBD}, //提取方式
- {0xCD,0xF8,0xC2,0xE7,0xB1,0xE0,0xBA,0xC5}, //网络编号
- {0xC9,0xE8,0xB1,0xB8,0xC0,0xE0,0xD0,0xCD}, //设备类型
- {0x54,0x4D,0x52,0xCA,0xFD,0xC1,0xBF,0x20}, //铲车数量
- {0x41,0x50,0x49,0x20,0x20,0x20,0x20,0x20}, //API
- {0xD0,0xA3,0xD5,0xFD,0xD6,0xD8,0xC1,0xBF}, //校正重量
- {0xD7,0xEE,0xB4,0xF3,0xB3,0xC6,0xC1,0xBF}, //最大称量
- {0xC2,0xCB,0xB2,0xA8,0xC9,0xEE,0xB6,0xC8}, //滤波深度
- {0xD0,0xA1,0xCA,0xFD,0xB5,0xE3,0x20,0x20}, //小数点
- {0xB7,0xD6,0xB6,0xC8,0xD6,0xB5,0x20,0x20}, //分度值
- {0xB8,0xF4,0xC0,0xEB,0xD6,0xD8,0xC1,0xBF} //重量隔离
- };
- const uint8_t MenuTQTypeList[15][8] = {
- {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
- {0x4E,0x45,0x57,0x4C,0x61,0x62,0x65,0x6C}, //NewLabel
- {0x5A,0x4D,0x33,0x30,0x33,0x20,0x20,0x20}, //AWT_ZM303
- {0x58,0x4B,0x33,0x31,0x39,0x30,0x20,0x20}, //XK3190_A27E()
- {0x54,0x4D,0x52,0x20,0x32,0x20,0x20,0x20}, //TMR2
- {0x54,0x4D,0x52,0x20,0x33,0x20,0x20,0x20}, //TMR3
- {0x45,0x5A,0x33,0x34,0x30,0x30,0x20,0x20}, //EZ3400
- {0x41,0x44,0x32,0x35,0x30,0x20,0x20,0x20}, //AD250 TQ
- {0x50,0x54,0x4D,0x20,0x20,0x20,0x20,0x20}, //PTM
- {0x54,0x2D,0x32,0x30,0x30,0x30,0x20,0x20}, //T_2000
- {0x53,0x4C,0x31,0x30,0x30,0x30,0x30,0x20}, //XL10000
- {0x58,0x4B,0x33,0x31,0x39,0x30,0x43,0x38}, //P_XK3190_C8();
- {0x54,0x44,0x49,0x32,0x30,0x30,0x49,0x20}, //TDI200I
- {0x49,0x44,0x35,0x31,0x31,0x20,0x20,0x20}, //ID511;
- {0xD7,0xD4,0xB6,0xAF,0x20,0x20,0x20,0x20} //自动
- };
- const uint8_t MenuSBTypeList[5][8] = {
- {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
- {0xBF,0xD8,0xD6,0xC6,0xC6,0xF7,0x20,0x20}, //控制器
- {0xD4,0xB6,0xB3,0xCC,0xCF,0xD4,0xCA,0xBE}, //远程显示
- {0xB4,0xF3,0xC6,0xC1,0x20,0x20,0x20,0x20}, //大屏
- {0xB4,0xF3,0xC6,0xC1,0x31,0x20,0x20,0x20} //LED大屏
- };
- static uint8_t TDisplay = 1;
-
- // CRC 高位字节值表
- const unsigned char auchCRCHi[] = {
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
- 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
- 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
- 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
- 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
- 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
- 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
- 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
- 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
- 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
- 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- } ;
- // CRC 低位字节值表
- const unsigned char auchCRCLo[] = {
- 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
- 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
- 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
- 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
- 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
- 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
- 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
- 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
- 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
- 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
- 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
- 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
- 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
- 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
- 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
- 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
- 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
- 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
- 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
- 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
- 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
- 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
- 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
- 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
- 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
- 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
- };
-
- static void MenuDisplay_entry(void *parameter) {
- extern IWDG_HandleTypeDef hiwdg;
- while(1)
- {
- if (MenuItem<11)
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量
- WeightConst_Weight_display[SendDisplay_i]=0x20;
- if (MenuItem==0)
- {
- if (XbeeConst_DeviceAddress>9) {
- WeightConst_Weight_display[6] = (XbeeConst_DeviceAddress/10)%10 + 0x30;
- WeightConst_Weight_display[5] = XbeeConst_DeviceAddress%10 + 0x30;
- }
- else WeightConst_Weight_display[6] = XbeeConst_DeviceAddress + 0x30;
- }
- else if (MenuItem==1)
- {
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
- WeightConst_Weight_display[SendDisplay_i] = MenuTQTypeList[WeightConst_TQ][7-SendDisplay_i];
- }
- else if (MenuItem==2)
- {
- if (XbeeConst_NetAddress>99) WeightConst_Weight_display[7] = XbeeConst_NetAddress/100 + 0x30;
- if (XbeeConst_NetAddress>9) WeightConst_Weight_display[6] = (XbeeConst_NetAddress/10)%10 + 0x30;
- WeightConst_Weight_display[5] = XbeeConst_NetAddress%10 + 0x30;
- }
- else if (MenuItem==3)
- {
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
- WeightConst_Weight_display[SendDisplay_i] = MenuSBTypeList[WeightConst_SBType][7-SendDisplay_i];
- }
- else if (MenuItem==4)
- {
- if (WeightConst_ChanCheShu>9) {
- WeightConst_Weight_display[6] = (WeightConst_ChanCheShu/10)%10 + 0x30;
- WeightConst_Weight_display[5] = WeightConst_ChanCheShu%10 + 0x30;
- }
- else WeightConst_Weight_display[6] = WeightConst_ChanCheShu + 0x30;
- }
- else if (MenuItem==5)
- {
- WeightConst_Weight_display[6] = XbeeConst_UseAPI + 0x30;
- }
- else if (MenuItem==6)
- { TDisplay++;
- WeightConst_Weight_display[4] = (WeightConst_JZZ_==4 && TDisplay%2? 0x20:(WeightConst_JZZ>9999 ? (WeightConst_JZZ/10000)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[3] = (WeightConst_JZZ_==3 && TDisplay%2? 0x20:(WeightConst_JZZ>999 ? (WeightConst_JZZ/1000)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[2] = (WeightConst_JZZ_==2 && TDisplay%2? 0x20:(WeightConst_JZZ>99 ? (WeightConst_JZZ/100)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[1] = (WeightConst_JZZ_==1 && TDisplay%2? 0x20:(WeightConst_JZZ>9 ? (WeightConst_JZZ/10)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[0] = (WeightConst_JZZ_==0 && TDisplay%2? 0x20:(WeightConst_JZZ%10 + 0x30));
- }
- else if (MenuItem==7)
- { TDisplay++;
- WeightConst_Weight_display[4] = (WeightConst_ZD_==4 && TDisplay%2? 0x20:(Maxval>9999 ? (Maxval/10000)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[3] = (WeightConst_ZD_==3 && TDisplay%2? 0x20:(Maxval>999 ? (Maxval/1000)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[2] = (WeightConst_ZD_==2 && TDisplay%2? 0x20:(Maxval>99 ? (Maxval/100)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[1] = (WeightConst_ZD_==1 && TDisplay%2? 0x20:(Maxval>9 ? (Maxval/10)%10 : 0x00) + 0x30);
- WeightConst_Weight_display[0] = (WeightConst_ZD_==0 && TDisplay%2? 0x20:(Maxval%10 + 0x30));
- }
- else if (MenuItem==8)
- {
- WeightConst_Weight_display[6] = ad_FS + 0x30;
- }
- else if (MenuItem==9)
- {
- WeightConst_Weight_display[6] = ad_Point + 0x30;
- }
- else if (MenuItem==10)
- {
- WeightConst_Weight_display[6] = ad_Inteval + 0x30;
- }
- else if (MenuItem==11)
- {
- WeightConst_Weight_display[6] = WeightConst_BLE + 0x30;
- }
- if (WeightConst_SBType<3 || WeightConst_SBType==6) {
- uart4_send_data[0] = 0x7E;
- uart4_send_data[1] = 0x45;
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
- uart4_send_data[2 + SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
- for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示重量
- uart4_send_data[10 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];
- // USART_Send_DMA(displaySerial,18);
- uart4_send_data[18]=0;
- for (int i = 2; i <18; i++) //校验和
- uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
- rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
- rt_sem_release(uart4_lock);
- }
- else if (WeightConst_SBType==3||WeightConst_SBType==7) {
-
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示菜单标题
- {
- WeightConst_feed[ SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
- }
- for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示当前值
- {
- WeightConst_feed[8 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];
- }
- //----------------------------
- get_msg(0,//Xstart
- 12,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 8,//字符个数
- 3,//界面数
- 0,//id
- 0xbF,//Xend
- 0,
- &WeightConst_feed[0]//字码
- );
- get_msg(0,//Xstart
- 12,//Ystart
- 2,//size
- 0,//reset
- 0,//speed
- 8,//字符个数
- 3,//界面数
- 1,//id
- 0xbF,//Xend
- 0,
- &WeightConst_feed[8]//字码
- );
- }
- else {
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题
- WeightConst_feed[SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i];
- //----------------------------
- //display_menu();
- if(isn==0)
- {
- clearScreenAll();
- display_Current_noweight();
- display_Now();
- for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j];
- send_uart4_send_data();
- }
- else {
- display_Current_noweight_();
- display_Now_(WeightConst_WeightCurTem);
- }
- }
- // HAL_IWDG_Refresh(&hiwdg);
- rt_thread_mdelay(400);
- }
- }
- static rt_thread_t display_tid = RT_NULL;
- void threadMenuDisplay_init(void)
- {
- //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
- display_tid = rt_thread_create("MenuDisp",
- MenuDisplay_entry, RT_NULL,
- 0x200,
- 4, 5);
- /* 如果获得线程控制块,启动这个线程 */
- if (display_tid != RT_NULL) rt_thread_startup(display_tid);
- }
- void getDisplay(void)
- {
- rt_uint8_t nullindex;
- rt_sem_take(display_lock, RT_WAITING_FOREVER);
- if (tsdb_recordcount('k')>0 || XbeeConst_CanSend==0)
- TDisplay++; //是否有按键需要传输
- else
- TDisplay = 1;
-
- rt_memset(WeightConst_Feed_display, 0x20, 40);
- if(WeightConst_DELAYON>0)
- {
- WeightConst_Feed_display[0]=0xC7;
- WeightConst_Feed_display[1]=0xEB;
- WeightConst_Feed_display[2]=0xBD;
- WeightConst_Feed_display[3]=0xC1;
- WeightConst_Feed_display[4]=0xB0;
- WeightConst_Feed_display[5]=0xE8;
- WeightConst_Feed_display[6]=0x20;
- WeightConst_Feed_display[7]=0x20;
- }
- else if (!isWeight){
- nullindex = 0;
- for (int i = 0; i < 40; i++) //显示标题
- {
- WeightConst_Feed_display[i] = WeightConst_feed[i];
- if (i>0 && nullindex==0 && WeightConst_feed[i]==0x20 && WeightConst_feed[i-1]==0x20 && WeightConst_feed[i-2]==0x20) {
- nullindex = i-2;
- }
- if ((nullindex>8 && nullindex<14)||(nullindex<7 && nullindex>0)) nullindex=nullindex+2;
- if (nullindex>1){
- if(TDisplay%2==0) {
- WeightConst_Feed_display[nullindex-1]=0x3E;
- WeightConst_Feed_display[nullindex-2]=0x3E;
- }
- else {
- WeightConst_Feed_display[nullindex-1]=WeightConst_feed[nullindex-1];
- WeightConst_Feed_display[nullindex-2]=WeightConst_feed[nullindex-2];
- }
- }
- }
- }
-
- if(WeightConst_DELAYON>0)
- {
- WeightConst_Weight_display[0]=0xEB;
- WeightConst_Weight_display[1]=0xC3;
- WeightConst_Weight_display[2]=0x20;
- WeightConst_Weight_display[3]=0x20;
- WeightConst_Weight_display[4]=0x20;
- WeightConst_Weight_display[5]=0x20;
- WeightConst_Weight_display[6]=0x20;
- WeightConst_Weight_display[7]=0x20;
- WeightConst_Weight_displayW = (pf_comp.data.delaytime * 60 - WeightConst_DELAYTIME);
- for (int SendDisplay_i = 2; SendDisplay_i < 8; SendDisplay_i++) {
- if (SendDisplay_i>2) WeightConst_Weight_displayW=WeightConst_Weight_displayW/10;
- if (abs(WeightConst_Weight_displayW)>0)
- WeightConst_Weight_display[SendDisplay_i] = abs((WeightConst_Weight_displayW)%10)+'0';
- else break;
- }
- }
- else
- {
- if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
- WeightConst_Weight_displayW = WeightConst_WeightCurTem - WeightConst_WeightTarget;
- else
- WeightConst_Weight_displayW = WeightConst_WeightCurTem;
- WeightConst_Weight_displayCurW = WeightConst_WeightCurTem;
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量
- WeightConst_Weight_display[SendDisplay_i]=0x20;
- if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
- {
- if ((WeightConst_Weight_displayW<=0 && pf_comp.data.addorout==0) ||
- (WeightConst_Weight_displayW>=0 && pf_comp.data.addorout == 1)
- ) { //少
- WeightConst_Weight_display[6]=0xD9;
- WeightConst_Weight_display[7]=0xC9;
- }
- else {
- WeightConst_Weight_display[6]=0xE0; //多
- WeightConst_Weight_display[7]=0xB6;
- }
- }
- else {
- if (WeightConst_Weight_displayW<0) {
- WeightConst_Weight_display[6]=0x2D; //-
- WeightConst_Weight_display[7]=0x20;
- }
- else {
- WeightConst_Weight_display[6]=0x20; //
- WeightConst_Weight_display[7]=0x20;
- }
- }
- if (WeightConst_Weight_displayW==0) {
- WeightConst_Weight_display[0]=0x30;
- }
- else
- {
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
- if (SendDisplay_i>0)
- WeightConst_Weight_displayW=WeightConst_Weight_displayW/10;
- if (abs(WeightConst_Weight_displayW)>0)
- WeightConst_Weight_display[SendDisplay_i] = abs(WeightConst_Weight_displayW%10)+'0';
- else break;
- }
- if (WeightConst_WeightWS>0) {
- for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--)
- if (WeightConst_Weight_display[SendDisplay_i]!=0x20)
- WeightConst_Weight_display[SendDisplay_i+1]=WeightConst_Weight_display[SendDisplay_i];
- WeightConst_Weight_display[WeightConst_WeightWS]=0x2E;
- if (WeightConst_Weight_display[WeightConst_WeightWS+1]==0x20) WeightConst_Weight_display[WeightConst_WeightWS+1] = 0x30;
- for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++)
- if (WeightConst_Weight_display[SendDisplay_i]==0x20) WeightConst_Weight_display[SendDisplay_i] = 0x30;
- }
-
- }
- /////////////////广泽
- if (remote_sumweight==1)
- {
- for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++)
- {
- WeightConst_WeightCur_display[SendDisplay_i] = 0x20;
- };
- if (WeightConst_Weight_displayCurW==0){
- WeightConst_WeightCur_display[0] = 0x30;
- }
- else
- {
- if (WeightConst_Weight_displayCurW<0) {
- WeightConst_WeightCur_display[4]=0x2D; //-
- }
- for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
- if (SendDisplay_i>0)
- WeightConst_Weight_displayCurW=WeightConst_Weight_displayCurW/10;
- if (abs(WeightConst_Weight_displayCurW)>0)
- WeightConst_WeightCur_display[SendDisplay_i] = abs(WeightConst_Weight_displayCurW%10)+'0';
- else break;
- }
- if (WeightConst_WeightWS>0) {
- for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--)
- if (WeightConst_WeightCur_display[SendDisplay_i]!=0x20)
- WeightConst_WeightCur_display[SendDisplay_i+1]=WeightConst_WeightCur_display[SendDisplay_i];
- WeightConst_WeightCur_display[WeightConst_WeightWS]=0x2E;
- if (WeightConst_WeightCur_display[WeightConst_WeightWS+1]==0x20) WeightConst_WeightCur_display[WeightConst_WeightWS+1] = 0x30;
- for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++)
- if (WeightConst_WeightCur_display[SendDisplay_i]==0x20) WeightConst_WeightCur_display[SendDisplay_i] = 0x30;
- }
- }
- }
- /////////////////广泽 end
- if (WeightConst_WeightHaveBegin==0 && pf_comp.data.needBegin == 1)
- {
- if (WeightConst_SBType==1||WeightConst_SBType==6) {
- //for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //如果没有开始则空显示重量
- // WeightConst_Weight_display[SendDisplay_i]=0x20;
- WeightConst_Weight_display[5]=WeightConst_Weight_display[6];
- WeightConst_Weight_display[6]=0xF8;
- WeightConst_Weight_display[7]=0xCB;
- }
- else if (WeightConst_SBType==3) {
- WeightConst_Weight_display[5]=WeightConst_Weight_display[6];
- WeightConst_Weight_display[6]=0xF8;
- WeightConst_Weight_display[7]=0xCB;
- /*
- WeightConst_Weight_display[0]=0xCC;
- WeightConst_Weight_display[1]=0xC5;
- WeightConst_Weight_display[2]=0xD3;
- WeightConst_Weight_display[3]=0xB3;
- WeightConst_Weight_display[4]=0xD5;
- WeightConst_Weight_display[5]=0xBF;
- WeightConst_Weight_display[6]=0xE5;
- WeightConst_Weight_display[7]=0xC7;//清空秤盘
- */
- }
- else if (WeightConst_SBType==4||WeightConst_SBType==6) {
- WeightConst_Weight_display[0]=0xBC;
- WeightConst_Weight_display[1]=0xCA;
- WeightConst_Weight_display[2]=0xAA;
- WeightConst_Weight_display[3]=0xBF;
- WeightConst_Weight_display[4]=0xCF;
- WeightConst_Weight_display[5]=0xC8;
- WeightConst_Weight_display[6]=0xB7;
- WeightConst_Weight_display[7]=0xC8;//确认开始
- };
- };
- }
-
- rt_sem_release(display_lock);
- }
- static void sendRemote(void *parameter)
- {
- rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0;
-
- while(1)
- {
- if (RemoteSendDisplay == 1 )
- {
- if (XbeeConst_UseAPI==0 && isnewLora==1) {
- rt_sem_take(displayRemote_lock, RT_WAITING_FOREVER);
- rt_thread_mdelay((XbeeConst_DeviceAddress-1)*80);
- } else if (XbeeConst_UseAPI<4)
- {rt_thread_mdelay(500); }
- else {rt_thread_mdelay(250);}
-
- if ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI>=3))||
- (flag_uart3_send==0 && XbeeConst_UseAPI==0))
- {
- if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[0] = 28;
- else XbeeConst_FRemoteTxBuf[0] = 23;
- XbeeConst_FRemoteTxBuf[1] = 0x7E;
- XbeeConst_FRemoteTxBuf[2] = 0x15;
- if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[2] = 0x1A;
- else XbeeConst_FRemoteTxBuf[2] = 0x15;
- XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
- if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3)
- XbeeConst_FRemoteTxBuf[4] = 0xA1;
- else
- {
- if (WeightConst_ChanCheShu>9)
- XbeeConst_FRemoteTxBuf[4] = 0xA1;
- else
- XbeeConst_FRemoteTxBuf[4] = 0xF1;
- }
- XbeeConst_FRemoteTxBuf[5] = 0x7E;
- XbeeConst_FRemoteTxBuf[6] = 0x45;
-
- haveAscii=0;
- for(rt_uint8_t i=0; i<8; i++){
- if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); }
- }
-
- ismulti = 0;
- for(rt_uint8_t i=8;i<16;i++){
- if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; }
- }
- if (ismulti==0) displayrow = 0;
- if (forcount<1) forcount++;
- else{
- forcount = 0;
- if (ismulti==1 && displayrow==1) displayrow = 0;
- else if (ismulti==1 && displayrow==0) displayrow = 1;
- }
-
- for (rt_uint8_t i = 0; i < 8; i++) //显示标题
- {
- if (haveAscii==1 && displayrow==1)
- XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i+displayrow*8-1];//显示标题
- else if (haveAscii==1 && displayrow==0){
- if (i==7)
- XbeeConst_FRemoteTxBuf[7+i] = 0x20;
- else
- XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8];
- }
- else XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8];
- };
-
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
- XbeeConst_FRemoteTxBuf[15+SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];//显示重量
- }
- ////////////广泽
- if(remote_sumweight==1){
- for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
- XbeeConst_FRemoteTxBuf[23+SendDisplay_i] = WeightConst_WeightCur_display[4-SendDisplay_i];//显示重量
- }
- }
- ////////////广泽
- XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0x00;
- for (int SendDisplay_i = 1; SendDisplay_i < XbeeConst_FRemoteTxBuf[0]; SendDisplay_i++) {
- XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] =
- XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]+XbeeConst_FRemoteTxBuf[SendDisplay_i];
- }
- XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0xFF - XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]];
- if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3) {
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- if (XbeeConst_UseAPI==1)
- setSendFrame_t(0x01,0x02,0x40);
- else setSendFrame_t(0x02,0x02,0x40);
- XbeeConst_PRemoteTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出
- usart2_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i];
-
- if (XbeeConst_UseAPI==1 || (XbeeConst_UseAPI==3 && ccsend==1))
- {
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial
- rt_thread_mdelay(50);
- }
- rt_sem_release(uart2_lock);
- rt_thread_mdelay(XbeeConst_DeviceAddress*30);
- // rt_thread_mdelay(200);
- }
- else if (XbeeConst_UseAPI>3) {
- rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
- // AT_on();
- for(int xcount=0;xcount<2;xcount++){
- XbeeConst_PRemoteTxBuf0 = BleApp2MakeFrame(0xFFFF, 0x00, xcount, XbeeConst_FRemoteTxBuf);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出
- usart3_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial
- rt_thread_mdelay(100);
- }
-
- // AT_off();
- rt_sem_release(uart3_lock);
- }
- else
- {
- if (iscowweight<1 )
- {
-
- rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FRemoteTxBuf[0]; SendWifi_i++) //将缓冲区发出
- usart3_send_data[SendWifi_i-1] = XbeeConst_FRemoteTxBuf[SendWifi_i];
-
- HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]); //remoteSerial
- rt_thread_mdelay(50);
- rt_sem_release(uart3_lock);
- }
- }
- }
- }
-
-
- }
- }
- void ChancheShow(void) {
- uart4_send_data[0] = 0x7E;
- uart4_send_data[1] = 0x45;
- if (XbeeConst_RemoteAddress>9) {
- uart4_send_data[2] = 1 + '0';
- uart4_send_data[3] = XbeeConst_RemoteAddress%10 + '0';
- }else{
- uart4_send_data[2] = XbeeConst_RemoteAddress + '0';
- uart4_send_data[3] = 0x20;
- }
- for (int i = 4; i < 18; i++) //将缓冲区发出
- uart4_send_data[i] = 0x20;
-
- rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 12);
- rt_sem_release(uart4_lock);
- }
- void send_uart4_send_data(void)
- {
- rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
- rt_sem_release(uart4_lock);
- rt_thread_mdelay(100);
- // rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- // HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39);
- // rt_sem_release(uart4_lock);
- // rt_thread_mdelay(100);
- }
- extern unsigned char inMenu;
- static void Display_entry(void *parameter) {
- rt_uint32_t e;
- rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0,row=0,rowx=5;
- extern IWDG_HandleTypeDef hiwdg;
-
- while (1) {
- getDisplay();
- ismulti = 0;
- haveAscii=0;
- for(rt_uint8_t i=0;i<8;i++){
- if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); }
- }
- for(rt_uint8_t i=8;i<16;i++){
- if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; }
- }
- if (ismulti==0) displayrow = 0;
- if (forcount<2) forcount++;
- else{
- forcount = 0;
- if (ismulti==1 && displayrow==1) displayrow = 0;
- else if (ismulti==1 && displayrow==0) displayrow = 1;
- }
- if (WeightConst_SBType<3||WeightConst_SBType==6) {
-
- uart4_send_data[0] = 0x7E;
- uart4_send_data[1] = 0x45;
-
- for (int i = 0; i < 8; i++) //显示标题
- {
- if (haveAscii==1 && displayrow==1)
- uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8 - 1];
- else if (haveAscii==1 && displayrow==0){
- if (i==7)
- uart4_send_data[i+2] = 0x20;
- else
- uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
- }
- else uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8];
- };
-
- for (int i = 7; i >=0; i--) //显示重量
- uart4_send_data[i + 10] = WeightConst_Weight_display[7-i];
- uart4_send_data[18]=0;
- for (int i = 2; i <18; i++) //校验和
- uart4_send_data[18] = uart4_send_data[18] + uart4_send_data[i];
-
- rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
- rt_sem_release(uart4_lock);
- // HAL_IWDG_Refresh(&hiwdg);
- rt_thread_mdelay(500);
- }
- else if (WeightConst_SBType==4)
- {
- if (rt_event_recv(&display_event, (EVENT_clearall | EVENT_Current_noweight
- | EVENT_PlanName | EVENT_Current | EVENT_Stop | EVENT_Next) ,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 10, &e) == RT_EOK)
- {
-
- if (e & EVENT_clearall)
- {
- if(isn>=1 ) {
- clearScreenAll_();
- }
- else
- {
- clearScreenAll();
- }
- }
- if (e & EVENT_Current_noweight)
- {
- if(isn>=1 ) {
- display_Current_noweight_();
- }
- else
- {
- display_Current_noweight();;
- }
- }
- if (e & EVENT_PlanName)
- {
- if(isn>=1 ) {
- display_productName_(0);
- }
- else
- {
- display_productName();
- }
- }
- if (e & EVENT_Current)
- {
- if(isn>=1 ) {
- display_Current_(WeightConst_WeightTargetTemp);
- }
- else
- {
- display_Current(WeightConst_WeightTargetTemp);
- }
- }
-
- if (e & EVENT_Stop)
- {
- if(isn>=1 ) {
- ;
- }
- else
- {
- ;
- }
- }
-
- if (e & EVENT_Next)
- {
- if(isn>=1) {
- display_Next_();
- }
- else
- {
- display_Next();
- }
- }
- }
- // if(WeightConst_Run || inMenu==1)
- {
- if (isn>=1)
- {
- display_Now_(WeightConst_WeightCurTem);
- }
- else{
- display_Now();
- display_Total(WeightConst_WeightCurTem);
- row++;
- if (row%rowx==0){
- for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j];
- send_uart4_send_data();
- }
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j];
- send_uart4_send_data();
-
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j];
- send_uart4_send_data();
-
- if (row%rowx==0){
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j];
- send_uart4_send_data();
- }
- if (row%rowx==0){
- for (int j=0; j<39; j++) uart4_send_data[j] = display_Stop_v[j];
- send_uart4_send_data();
- }
- }
- }
- if (isn>=1){
- rt_thread_mdelay(500);
- }
- else{
- rt_thread_mdelay(300);
- }
- // HAL_IWDG_Refresh(&hiwdg);
- }
- else if (WeightConst_SBType==3){// || WeightConst_SBType==7) {
- // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
- {
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 16,//字符个数
- 3,//界面数
- 0,//id
- 0xBF,//Xend
- 0,
- &WeightConst_feed[0]//字码
- );
-
-
- get_msg(92,//Xstart
- 4,//Ystart
- 2,//size
- 0,//reset
- 0,//speed
- 8,//字符个数
- 3,//界面数
- 1,//id
- 0xBF,//Xend
- 1,
- &WeightConst_Weight_display[0]//字码
- );
- if(WeightConst_Product_Run)
- {
- rt_uint8_t index = 0,value = 0;
- signed long WeightConst_WeightCur_ = 0;
- uart4_send_data[0]=0x20;uart4_send_data[1]=0x20;uart4_send_data[2]=0x20;
- uart4_send_data[3]=0x20;uart4_send_data[4]=0x30;
- if (WeightConst_WeightCurTem<0)
- {
- WeightConst_WeightCur_ = WeightConst_WeightCurTem*-1;
- uart4_send_data[0] = 0x2D;
- }
- else WeightConst_WeightCur_ = WeightConst_WeightCurTem;
-
-
- for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
- if (SendDisplay_i>0) WeightConst_WeightCur_=WeightConst_WeightCur_/10;
- if (WeightConst_WeightCur_>0)
- uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCur_)%10+'0';
- else break;
- }
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 5,//字符个数
- 3,//界面数
- 4,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
- index = 0;
- for(int i = 0;i< 22;i++)
- {
- if(WeightConst_product[i] >= 0xA0) {
- uart4_send_data[index++] = WeightConst_product[i++];
- uart4_send_data[index++] = WeightConst_product[i];
- // uart4_send_data[index++] = 0xA1;
- // uart4_send_data[index++] = 0xA2;
- }
- else {
- if(WeightConst_product[i] != 0x20 && WeightConst_product[i] != 0)
- {
- uart4_send_data[index++] = WeightConst_product[i];
- // uart4_send_data[index++] = 0xA1;
- // uart4_send_data[index++] = 0xA2;
- }
- }
- }
-
- uart4_send_data[index++] = 0x10;
- //
- // value = (plan_comp.data .sumweight / 10000) % 10;
- // if(value != 0) {
- // uart4_send_data[index++] = value + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 1000) % 10 + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
- // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
- // }
- // else {
- // value = (plan_comp.data .sumweight / 1000) % 10;
- // if(value != 0) {
- // uart4_send_data[index++] = value + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
- // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
- // }
- // else {
- // value = (plan_comp.data .sumweight / 100) % 10;
- // if(value != 0) {
- // uart4_send_data[index++] = value + 0x30;
- // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30;
- // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
- // }
- // else {
- // value = (plan_comp.data .sumweight / 10) % 10;
- // if(value != 0) {
- // uart4_send_data[index++] = value + 0x30;
- // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
- // }
- // else {
- // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30;
- // }
- // }
- // }
- // }
- uart4_send_data[index++] = 0x10;
-
- WeightConst_WeightCur_ = WeightConst_WeightTargetTemp;
- value = (WeightConst_WeightCur_ / 10000) % 10;
- if(value != 0) {
- uart4_send_data[index++] = value + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 1000) % 10 + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 100) % 10 + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
- uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
- }
- else {
- value = (WeightConst_WeightCur_ / 1000) % 10;
- if(value != 0) {
- uart4_send_data[index++] = value + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 100) % 10 + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
- uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
- }
- else {
- value = (WeightConst_WeightCur_ / 100) % 10;
- if(value != 0) {
- uart4_send_data[index++] = value + 0x30;
- uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
- uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
- }
- else {
- value = (WeightConst_WeightCur_ / 10) % 10;
- if(value != 0) {
- uart4_send_data[index++] = value + 0x30;
- uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
- }
- else {
- uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
- }
- }
- }
- }
- uart4_send_data[index++] = 0x10;
- for(int i = 0;i< 16;i++)
- {
- uart4_send_data[index++] = WeightConst_Nextfeed[i];
- if (WeightConst_Nextfeed[i] ==0x20) break;
- }
-
- uart4_send_data[index++] = 0x10;
- if (pf_comp.data.isMix==1){
- uart4_send_data[index++] = 0xD7;
- uart4_send_data[index++] = 0xE9;
- uart4_send_data[index++] = 0xBA;
- uart4_send_data[index++] = 0xCF;
- uart4_send_data[index++] = 0xC1;
- uart4_send_data[index++] = 0xCF;
- }
- uart4_send_data[index++] = 0x10;
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 3,//speed
- index,//字符个数
- 3,//界面数
- 2,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
- if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
- {
- int tempw;
-
- uart4_send_data[1]=0;
- uart4_send_data[2]=0;
- uart4_send_data[3]=0;
- if ((WeightConst_WeightTarget < WeightConst_WeightCur && pf_comp.data.addorout==0)
- || (WeightConst_WeightTarget > WeightConst_WeightCur && pf_comp.data.addorout==1))
- {
- uart4_send_data[0]= 100;
- uart4_send_data[1]=0xFF;
- }
- else
- {
- if (WeightConst_WeightCur<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) && pf_comp.data.addorout==0)
- tempw=0;
- else if (WeightConst_WeightCur>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) && pf_comp.data.addorout==1)
- tempw=0;
- else if (pf_comp.data.addorout==0)
- tempw = ( WeightConst_WeightCurTem-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp));
- else
- tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCurTem);
- uart4_send_data[0]=tempw*100/WeightConst_WeightTargetTemp;
-
-
- if ((WeightConst_WeightCur>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) ||
- (WeightConst_WeightCur<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1)
- )
- {
- uart4_send_data[2]=0xFF;
- }
- else if ((WeightConst_WeightCur+30>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)||
- (WeightConst_WeightCur-30<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
- {uart4_send_data[1]=0xFF; uart4_send_data[3]=0xFF;
- }
- else
- uart4_send_data[3]=0xFF;
- }
-
-
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 4,//字符个数
- 3,//界面数
- 3,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
- }
- }
-
- else{
- uart4_send_data[0]=0;
- uart4_send_data[1]=0;
- uart4_send_data[2]=0;
- uart4_send_data[3]=0;
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 4,//字符个数
- 3,//界面数
- 3,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
- uart4_send_data[0]=0x20;
-
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 1,//字符个数
- 3,//界面数
- 4,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
-
- uart4_send_data[0]=0x10;
- uart4_send_data[0]=0x10;
- uart4_send_data[0]=0x10;
- uart4_send_data[0]=0x10;
- get_msg(0,//Xstart
- 0,//Ystart
- 1,//size
- 0,//reset
- 0,//speed
- 4,//字符个数
- 3,//界面数
- 2,//id
- 0xBF,//Xend
- 0,
- &uart4_send_data[0]//字码
- );
- }
- }
-
-
- for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
- {
- WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
- }
-
- rt_thread_mdelay(300);
- // HAL_IWDG_Refresh(&hiwdg);
- }
- // if (WeightConst_SBType==3 || WeightConst_SBType==7) {
- // // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i])
- // {
- // get_msg(92,//Xstart
- // 4,//Ystart
- // 2,//size
- // 0,//reset
- // 0,//speed
- // 8,//字符个数
- // 3,//界面数
- // 1,//id
- // 0xBF,//Xend
- // 1,
- // &WeightConst_Weight_display[0]//字码
- // );
- // break;
- // }
- // for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示原料名称
- // {
- // WeightConst_Weight_display_old[SendDisplay_i] = WeightConst_Weight_display[SendDisplay_i];
- // }
- // }
- // if (WeightConst_SBType==4||WeightConst_SBType==6) {
- // if (WeightConst_Product_Run) {
- // if(isn!=1 && (ScreenBufSize()<100)) {
- // display_Now();
- // display_Total(WeightConst_WeightCur);
- // }
- // else if(isn==1) display_Now_(WeightConst_WeightCur);
- // }
- // else if(isn==1 && WeightConst_Run==1) display_Now_(WeightConst_WeightCur);
- // }
- // if (SendRemote_timer>700 && RemoteSendDisplay &&
- // ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3))||
- // (flag_uart3_send==0 && XbeeConst_UseAPI==0)))
- // {
- // SendRemote_timer = 0;
-
- // }
-
- }
- }
- static void Display_clear_entry(void *parameter) {
- uint8_t i=0;
- while (i<10) {
- // while (WeightConst_Run<1) {
- if (WeightConst_Run<1){
- if (isn>=1) display_KPT_TMRWatch_();
- // if (isn>=1) display_KPT_TMRWatch_weight_();
- else display_KPT_TMRWatch();
- }
- rt_thread_mdelay(1000);
- i++;
- }
- }
- void threadDisplay_init(void)
- {
- if (WeightConst_SBType == 4)
- {
- if(isn>=1) clearScreenAll_();
- else clearScreenAll();
- }
- //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
- display_tid = rt_thread_create("Display",
- Display_entry, RT_NULL,
- 0x400,
- 5, 5);
- /* 如果获得线程控制块,启动这个线程 */
- if (display_tid != RT_NULL) rt_thread_startup(display_tid);
- }
-
- static rt_thread_t display_clear_tid = RT_NULL;
- void threadDisplay_delay_init(void)
- {
- display_clear_tid = rt_thread_create("Displaydelay",
- Display_clear_entry, RT_NULL,
- 0x100,
- 5, 5);
- /* 如果获得线程控制块,启动这个线程 */
- if (display_clear_tid != RT_NULL) rt_thread_startup(display_clear_tid);
- }
- static rt_thread_t remotedisplay_tid = RT_NULL;
- void threadRemoteDisplay_init(void)
- {
- //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
- remotedisplay_tid = rt_thread_create("RemoteD",
- sendRemote, RT_NULL,
- 0x300,
- 5, 5);
- /* 如果获得线程控制块,启动这个线程 */
- if (remotedisplay_tid != RT_NULL) rt_thread_startup(remotedisplay_tid);
- }
- void display_usart_Init(UART_HandleTypeDef* uartHandle)
- {
- extern unsigned char WeightConst_TQ;
- if ((uartHandle->Instance==UART4 && (WeightConst_SBType==0x04 && isn==0)))
- {
- uartHandle->Init.BaudRate = 9600;
- }
- else
- uartHandle->Init.BaudRate = 57600;
- }
- //CRC校验的函数
- unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen)
- {
- unsigned char uchCRCHi = 0xFF ;
- unsigned char uchCRCLo = 0xFF ;
- unsigned uIndex ;
-
- while (usDataLen--)
- {
- uIndex = uchCRCHi ^ *puchMsg++ ; /* 计算CRC */
- uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
- uchCRCLo = auchCRCLo[uIndex] ;
- }
- return (uchCRCHi << 8 | uchCRCLo) ;
- }
- unsigned char uart_send_buf_cp[100];
- unsigned char get_msg( unsigned char Xstart,// 0 - 191
- unsigned char Ystart, //0 - 47
- unsigned char ZiTiSize,//1 or 2 or 3
- unsigned char reset_enable,//0 or 1
- unsigned char speed,//速度 0 or 1 or 2 or 3
- unsigned char ZiFuCount,//字符个数
- unsigned char JieMianCount,//3
- unsigned char JieMianID,//0 or 1 or 2
- unsigned char Xend,
- unsigned char f,
- unsigned char * ASCII_buf)
- {
- unsigned char i=0;
- unsigned char len=0;
- unsigned short int calcCRC;
-
- extern IWDG_HandleTypeDef hiwdg;
-
- uart_send_buf_cp[0] = 0x7E;
- uart_send_buf_cp[1] = Xstart;
- uart_send_buf_cp[2] = (Ystart<<2) |(ZiTiSize & 0x03);
- // uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|((speed<<5)&0x60);
- uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|(speed & 0x0F);
- uart_send_buf_cp[4] = ZiFuCount;
- uart_send_buf_cp[5] = ((JieMianCount<<4)&0xF0)|(JieMianID&0x0F);
- uart_send_buf_cp[6] = Xend;
- if (f==0)
- for(i=0; i<ZiFuCount; i++) uart_send_buf_cp[7+i] = ASCII_buf[i];
- else
- for(i=ZiFuCount; i>0; i--) uart_send_buf_cp[7+i-1] = ASCII_buf[ZiFuCount-i];
- len = ZiFuCount + 7;
- calcCRC = CRC16(uart_send_buf_cp, len);
- uart_send_buf_cp[7+ZiFuCount] = (unsigned char)(calcCRC>>8); //低位
- uart_send_buf_cp[7+ZiFuCount+1] = (unsigned char)(calcCRC); //高位
- for(i=0; i<=8+ZiFuCount; i++) uart4_send_data[i] = uart_send_buf_cp[i];
- rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
- HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 9+ZiFuCount);
- rt_sem_release(uart4_lock);
- rt_thread_mdelay(150);
- return 0;
- }
- //01 05 20 00 FF 00 87 FA
- unsigned char uart_send_buf_modbus[10];
- unsigned char get_modbusmsg(unsigned char addr,// 0 - 191
- unsigned char func, //0 - 47
- unsigned short dataaddr,//1 or 2 or 3
- unsigned short state)
- {
- unsigned char i=0;
- unsigned short int calcCRC;
- uart_send_buf_modbus[0] = addr;
- uart_send_buf_modbus[1] = func;
- uart_send_buf_modbus[2] = (dataaddr>>8)&0xFF;
- uart_send_buf_modbus[3] = dataaddr&0xFF;
- uart_send_buf_modbus[4] = (state>>8)&0xFF;
- uart_send_buf_modbus[5] = state&0xFF;
- calcCRC = CRC16(uart_send_buf_modbus, 6);
- uart_send_buf_modbus[6] = (unsigned char)(calcCRC>>8); //低位
- uart_send_buf_modbus[7] = (unsigned char)(calcCRC); //高位
- for(i=0; i<=7; i++)
- HAL_UART_Transmit(&huart5, (uint8_t *)&uart_send_buf_modbus[i], 1, 1);
- rt_thread_mdelay(150);
- return 0;
- }
|