control.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832
  1. #include <control.h>
  2. /*
  3. * Copyright (c) 2006-2020, RT-Thread Development Team
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-05-30 Administrator the first version
  10. */
  11. #include "beep.h"
  12. #include "hmi.h"
  13. #include "easyflash.h"
  14. #include "stdio.h"
  15. #include "sound.h"
  16. #include "dtu_uart2.h"
  17. #include "sht30_collect.h"
  18. #include "string.h"
  19. #define DBG_ENABLE
  20. #define DBG_COLOR
  21. #define DBG_TAG "control"
  22. #define DBG_LEVEL DBG_LOG
  23. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  24. //工作检测
  25. #define WORK_CHECK_THREAD_PRIORITY 23 //线程优先级
  26. #define WORK_CHECK_THREAD_STACK_SIZE 1024 //栈大小
  27. #define WORK_CHECK_THREAD_TIMESLICE 5 //时间片
  28. //工作流程
  29. #define WORK_LOOP_THREAD_PRIORITY 12 //线程优先级
  30. #define WORK_LOOP_THREAD_STACK_SIZE 2048 //栈大小
  31. #define WORK_LOOP_THREAD_TIMESLICE 5 //时间片
  32. #define PWM_EN 1 //0关闭,1-打开
  33. //设备状态表结构体
  34. Device_Status_typedef device_status;
  35. rt_thread_t tid_workloop = RT_NULL;
  36. rt_thread_t tid_wkstc = RT_NULL;
  37. rt_thread_t tid_ctr = RT_NULL;
  38. rt_thread_t tid_heat = RT_NULL;
  39. int thread_delete_workloop(void)
  40. {
  41. rt_err_t result;
  42. if(tid_workloop!=RT_NULL)
  43. {
  44. result = rt_thread_delete(tid_workloop);
  45. }
  46. return result;
  47. }
  48. int thread_restart_workloop(void)
  49. {
  50. rt_err_t result;
  51. result = Work_Loop_Task();
  52. return result;
  53. }
  54. /**************************1.0定制2000W*************************************/
  55. uint8_t ctr_Fan_PUT(uint8_t status_ws)
  56. {
  57. rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
  58. if(status_ws==ON)
  59. {
  60. rt_pin_write(FAN_P,ON);
  61. }
  62. else {
  63. rt_pin_write(FAN_P, OFF);
  64. }
  65. return 0;
  66. }
  67. uint8_t ctr_Fan_IN(uint8_t status_ws)
  68. {
  69. rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
  70. if(status_ws==ON)
  71. {
  72. rt_pin_write(FAN_I,ON);
  73. }
  74. else {
  75. rt_pin_write(FAN_I, OFF);
  76. }
  77. return 0;
  78. }
  79. /****************************定制色诱*************************************/
  80. /**/
  81. #if Color_EN == 1
  82. uint8_t Read_Color_Key(rt_base_t key_pin)
  83. {
  84. rt_uint32_t sta_s = 0;
  85. rt_pin_mode(key_pin, PIN_MODE_INPUT);
  86. while(rt_pin_read(key_pin)==1)
  87. {
  88. sta_s++;
  89. /*持续的*/
  90. rt_thread_delay(50);
  91. }
  92. while(rt_pin_read(key_pin)==0)
  93. {
  94. rt_thread_delay(50);
  95. if(sta_s>0) break;
  96. }
  97. LOG_W("检测到IO0翻转!!!");
  98. return 1;
  99. }
  100. /*读限位开关状态*/
  101. uint8_t Read_Color_Limit(rt_base_t pin_limit)
  102. {
  103. uint8_t l_sta = 0;
  104. rt_pin_mode(pin_limit, PIN_MODE_INPUT);
  105. l_sta = rt_pin_read(pin_limit);
  106. rt_thread_delay(20);
  107. l_sta = rt_pin_read(pin_limit);
  108. return l_sta;
  109. }
  110. /*色诱板*/
  111. int ctr_Color_board(uint8_t forward,uint16_t time_board)
  112. {
  113. if(forward==CLOSE) //归位
  114. {
  115. if(device_status.cul_time>0)
  116. device_status.cul_time--;
  117. ctr_cangmen_down(OFF);
  118. ctr_cangmen_up(OFF);
  119. rt_thread_delay(1000);
  120. // if(device_status.cul_time>7) device_status.cul_time=7;
  121. // if(device_status.cul_time!=7)
  122. // {
  123. // uint8_t ct = device_status.cul_time;
  124. // while(1)
  125. // {
  126. // Beep_Tip(100);
  127. // rt_thread_delay(100);
  128. // ct--;
  129. // if(ct==0) break;
  130. // }
  131. // //return device_status.cul_time;
  132. // }
  133. if(Read_Color_Limit(LIMIT_RESET)==0)
  134. {
  135. device_status.cul_time = 0;
  136. LOG_W("已在初始位置!");
  137. Beep_Tip(1000);
  138. return 0;
  139. //黄板已经在复位状态,直接返回0;
  140. }
  141. ctr_cangmen_up(CLOSE);
  142. rt_thread_delay(20000);
  143. ctr_cangmen_up(OFF);
  144. // if(device_status.cul_time==7&&Read_Color_Limit(LIMIT_BOARD)==0)
  145. // {
  146. // LOG_W("第七天!!!");
  147. // ctr_cangmen_down(CLOSE);
  148. // rt_thread_delay(500);
  149. // }
  150. LOG_W("先打开运行到限位的右侧!");
  151. while(Read_Color_Limit(LIMIT_BOARD)==0)
  152. {
  153. LOG_W("归位:到达限位中间");
  154. ctr_cangmen_down(CLOSE);
  155. if(Read_Color_Limit(LIMIT_RESET)==0)
  156. {
  157. ctr_cangmen_down(OFF);
  158. break;
  159. }
  160. }
  161. //先打开运行到限位的右侧
  162. while(Read_Color_Limit(LIMIT_BOARD)==1)
  163. {
  164. LOG_W("归位:运行!");
  165. ctr_cangmen_down(CLOSE);
  166. if(Read_Color_Limit(LIMIT_RESET)==0)
  167. {
  168. ctr_cangmen_down(OFF);
  169. break;
  170. }
  171. }
  172. while(Read_Color_Limit(LIMIT_BOARD)==0) //到达限位中间 继续运行
  173. {
  174. LOG_W("归位:到达限位中间");
  175. ctr_cangmen_down(CLOSE);
  176. if(Read_Color_Limit(LIMIT_RESET)==0)
  177. {
  178. ctr_cangmen_down(OFF);
  179. break;
  180. }
  181. }
  182. if(Read_Color_Limit(LIMIT_RESET)==0) return 0;
  183. LOG_W("到达限位左侧!");
  184. //停止电机
  185. ctr_cangmen_down(OFF);
  186. rt_thread_delay(2000);
  187. //将推杆电机归位
  188. LOG_D("*推杆电机归位*");
  189. /*推杆电机伸出*/
  190. ctr_cangmen_up(OPEN);
  191. rt_thread_delay(20000);
  192. ctr_cangmen_up(OFF);
  193. return 2;
  194. }
  195. else if(forward==OPEN)
  196. {
  197. ctr_cangmen_down(OFF);
  198. ctr_cangmen_up(OFF);
  199. rt_thread_delay(1000);
  200. if(device_status.cul_time==7)
  201. {
  202. Beep_Tip(5000);
  203. return 7;
  204. }
  205. LOG_W("打开推杆电机!");
  206. //2023-04-18:add
  207. //if(Read_Color_Limit(LIMIT_BOARD)==0)
  208. {
  209. LOG_D("*推杆电机归位*");
  210. /*推杆电机归位*/
  211. ctr_cangmen_up(CLOSE);
  212. rt_thread_delay(20000);
  213. ctr_cangmen_up(OFF);
  214. }
  215. if(device_status.cul_time<7)
  216. device_status.cul_time++;
  217. while(Read_Color_Limit(LIMIT_BOARD)==0)
  218. {
  219. ctr_cangmen_down(forward);
  220. rt_thread_delay(50);
  221. }
  222. while(Read_Color_Limit(LIMIT_BOARD)==1)
  223. {
  224. time_board--;
  225. if(time_board==0) break;
  226. ctr_cangmen_down(forward);
  227. rt_thread_delay(50);
  228. }
  229. ctr_cangmen_down(OFF);
  230. rt_thread_delay(1000);
  231. ctr_cangmen_up(OPEN);
  232. rt_thread_delay(20000);
  233. ctr_cangmen_up(OFF);
  234. // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  235. return OPEN;
  236. }
  237. else if (forward==RESET) {
  238. ctr_cangmen_up(OFF);
  239. ctr_cangmen_down(OFF);
  240. if(Read_Color_Limit(LIMIT_RESET)==0)
  241. {
  242. device_status.cul_time = 0;
  243. //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  244. LOG_W("已在初始位置!");
  245. Beep_Tip(1000);
  246. ctr_cangmen_up(CLOSE);
  247. rt_thread_delay(20000);
  248. ctr_cangmen_up(OFF);
  249. device_status.cul_time = 0;
  250. return 0;
  251. //黄板已经在复位状态,直接返回0;
  252. }
  253. //if(Read_Color_Limit(LIMIT_BOARD)==0)
  254. {
  255. LOG_D("*推杆电机归位*");
  256. /*推杆电机归位*/
  257. ctr_cangmen_up(CLOSE);
  258. rt_thread_delay(20000);
  259. ctr_cangmen_up(OFF);
  260. }
  261. while(Read_Color_Limit(LIMIT_RESET)==1)
  262. {
  263. time_board--;
  264. if(time_board==0) break;
  265. ctr_cangmen_down(CLOSE);
  266. rt_thread_delay(20);
  267. }
  268. device_status.cul_time = 0;
  269. ctr_cangmen_down(OFF);
  270. }
  271. // device_status.cul_time = 0;
  272. //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  273. return RESET; //复位返回0
  274. }
  275. #endif
  276. /****************************5.0***********************************/
  277. void ctr_turnv5(void)
  278. {
  279. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  280. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  281. // 转出
  282. rt_pin_write(CLEAR_R,ON);
  283. rt_pin_write(CLEAR_L,OFF);
  284. rt_thread_mdelay(300);
  285. //停止
  286. rt_pin_write(CLEAR_R,OFF);
  287. rt_pin_write(CLEAR_L,OFF);
  288. rt_thread_mdelay(300);
  289. //转入
  290. rt_pin_write(CLEAR_R,OFF);
  291. rt_pin_write(CLEAR_L,ON);
  292. rt_thread_mdelay(300);
  293. //停止
  294. rt_pin_write(CLEAR_R,OFF);
  295. rt_pin_write(CLEAR_L,OFF);
  296. rt_thread_mdelay(300);
  297. }
  298. /**************************机器人********************************/
  299. void ctr_Motor_Robot(uint8_t status_ws)
  300. {
  301. unsigned int close_timeout = 0;
  302. unsigned int open_timeout = 0;
  303. rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
  304. rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
  305. rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
  306. rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
  307. rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
  308. rt_pin_write(Motor_Power,OFF);
  309. rt_pin_write(Motor_Direction_Ctr,ON);
  310. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  311. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  312. if(status_ws == ON)
  313. {
  314. //检测按键状态
  315. while(rt_pin_read(Motor_Direction_Button)==1)
  316. {
  317. if(rt_pin_read(LIMIT_CLOSE)==1)
  318. {
  319. rt_pin_write(Motor_Direction_Ctr,ON);
  320. close_timeout++;
  321. //打开电机驱动器电源,默认关闭
  322. rt_pin_write(Motor_Power,ON);
  323. if(close_timeout==2)
  324. {
  325. rt_pin_write(CLEAR_R,ON);
  326. rt_pin_write(CLEAR_L,OFF);
  327. rt_pin_write(Motor_Power,OFF);
  328. rt_thread_delay(20);
  329. rt_pin_write(Motor_Power,ON);
  330. }
  331. rt_thread_delay(20);
  332. if(close_timeout>500)
  333. {
  334. close_timeout = 600;
  335. rt_pin_write(Motor_Power,OFF);
  336. rt_pin_write(CLEAR_R,OFF);
  337. rt_pin_write(CLEAR_L,OFF);
  338. }
  339. }
  340. else
  341. {
  342. close_timeout = 0;
  343. rt_pin_write(Motor_Power,OFF); //关闭驱动器电源
  344. rt_pin_write(CLEAR_R,OFF);
  345. rt_pin_write(CLEAR_L,OFF);
  346. }
  347. rt_thread_delay(20);
  348. }
  349. rt_pin_write(Motor_Power,OFF);
  350. rt_thread_delay(1000*2);
  351. while(rt_pin_read(Motor_Direction_Button)==0)
  352. {
  353. if(rt_pin_read(LIMIT_OPEN)==1)
  354. {
  355. open_timeout ++;
  356. //打开电机驱动器电源,默认关闭
  357. if(open_timeout==2){
  358. rt_pin_write(CLEAR_R,OFF);
  359. rt_pin_write(CLEAR_L,ON);
  360. }
  361. rt_pin_write(Motor_Power,ON);
  362. rt_pin_write(Motor_Direction_Ctr,OFF);
  363. if(open_timeout>500)
  364. {
  365. open_timeout = 600;
  366. rt_pin_write(Motor_Power,OFF);
  367. rt_pin_write(CLEAR_R,OFF);
  368. rt_pin_write(CLEAR_L,OFF);
  369. }
  370. rt_thread_delay(20);
  371. }
  372. if(rt_pin_read(LIMIT_OPEN)==0)
  373. {
  374. open_timeout = 0;
  375. rt_pin_write(Motor_Power,OFF);
  376. rt_pin_write(CLEAR_R,OFF);
  377. rt_pin_write(CLEAR_L,OFF);
  378. }
  379. rt_thread_delay(20);
  380. close_timeout = 0;
  381. }
  382. open_timeout = 0;
  383. close_timeout = 0;
  384. }
  385. else {
  386. rt_pin_write(Motor_Power,OFF);
  387. }
  388. }
  389. /*************************吸虫塔*********************************/
  390. //吸虫电机
  391. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  392. {
  393. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  394. if(status_ws==ON)
  395. {
  396. rt_pin_write(MOTOR1_CTR_PIN,ON);
  397. }
  398. else {
  399. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  400. }
  401. return 0;
  402. }
  403. uint8_t ctr_Camera_Power(uint8_t status_ws)
  404. {
  405. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  406. if(status_ws==ON)
  407. {
  408. rt_pin_write(MOTOR1_CTR_PIN,ON);
  409. }
  410. else {
  411. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  412. }
  413. return 0;
  414. }
  415. //吸附电机
  416. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  417. {
  418. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  419. if(status_ws==ON)
  420. {
  421. rt_pin_write(MOTOR2_CTR_PIN,ON);
  422. }
  423. else {
  424. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  425. }
  426. return 0;
  427. }
  428. //清扫-卷带电机
  429. void ctr_JD_Clear(uint8_t shake_sw)
  430. {
  431. rt_uint16_t turn_timeout = 0;
  432. rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
  433. ctr_cangmen_up(OFF); //清扫传送带的电机
  434. if(shake_sw==ON)
  435. {
  436. ctr_Heat(ON); //清洁风机
  437. Motor_shake(ON, 0);
  438. ctr_cangmen_up(OPEN); //打开清扫
  439. }
  440. else {
  441. Motor_shake(OFF, 0);
  442. ctr_cangmen_up(OPEN); //打开清扫
  443. }
  444. while(rt_pin_read(MOTOR_C_LIMIT)==0)
  445. {
  446. Motor_Juandai(ON);
  447. rt_thread_delay(50);
  448. turn_timeout++;
  449. if(turn_timeout==1000) break;
  450. }
  451. turn_timeout = 0;
  452. while(rt_pin_read(MOTOR_C_LIMIT)==1)
  453. {
  454. Motor_Juandai(ON);
  455. turn_timeout++;
  456. rt_thread_delay(50);
  457. if(turn_timeout==1000) break;
  458. }
  459. Motor_shake(OFF, 1);
  460. Motor_Juandai(OFF);
  461. ctr_cangmen_up(OFF); //关闭清扫
  462. ctr_Heat(OFF);
  463. }
  464. //工作任务流程
  465. void WorkTask_XCT(void)
  466. {
  467. while(device_status.work_status==1&&device_status.ds==1)
  468. {
  469. ctr_Motor_xifu(ON);
  470. //打开相机供电
  471. ctr_Camera_Power(ON);
  472. //ctr_Heat(ON); //清洁风机
  473. uint32_t photo_fre = 0;
  474. photo_fre = device_status.dattim * 60;
  475. while(photo_fre!=0)
  476. {
  477. photo_fre --;
  478. rt_thread_delay(1000);
  479. LOG_I("收集中,等待开始拍照:%d",photo_fre);
  480. }
  481. //卷带
  482. ctr_JD_Clear(OFF);
  483. //拍照
  484. HK_TakePhoto();
  485. //关闭吸附风机
  486. ctr_Motor_xifu(OFF);
  487. //关闭相机供电
  488. //ctr_Heat(OFF);
  489. ctr_Camera_Power(OFF);
  490. //卷带
  491. ctr_JD_Clear(ON);
  492. // rt_thread_delay(1000);
  493. // ctr_JD_Clear(ON);
  494. //震动
  495. Motor_shake(ON, device_status.shake_sec);
  496. }
  497. //关闭风机
  498. ctr_Motor_xichong(OFF);
  499. ctr_Motor_xifu(OFF);
  500. LOG_I("不在工作时间,未工作!!!");
  501. }
  502. /**********************************************************************/
  503. /*光控*/
  504. uint8_t In_Light_status(void)
  505. {
  506. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  507. return rt_pin_read(LIGHT_PIN);
  508. }
  509. /*雨控*/
  510. uint8_t In_Rain_status(void)
  511. {
  512. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  513. return rt_pin_read(RAIN_PIN);
  514. }
  515. /*加热*/
  516. uint8_t ctr_Heat(uint8_t status_heat)
  517. {
  518. device_status.heat_status = status_heat;
  519. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  520. rt_pin_write(Heat_Pin,status_heat);
  521. return status_heat;
  522. }
  523. /*制冷*/
  524. uint8_t ctr_Cold(uint8_t status_cold)
  525. {
  526. device_status.cold_status = status_cold;
  527. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  528. rt_pin_write(Cold_Pin,status_cold);
  529. return status_cold;
  530. }
  531. /*相机供电*/
  532. void ctr_photo(uint8_t status_photo)
  533. {
  534. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  535. rt_pin_write(PHOTO,status_photo);
  536. }
  537. /*************************************************
  538. Function: ctr_Cool_Fan
  539. Description: 散热风机的开关
  540. Calls:
  541. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  542. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  543. Input: ON-开,OFF-关
  544. Output: NULL
  545. Return: ON-开,OFF-关
  546. Others: NULL
  547. *************************************************/
  548. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  549. {
  550. device_status.cool_fan_status = status_cool;
  551. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  552. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  553. if(status_cool==OFF)
  554. {
  555. rt_pin_write(Cool_Fan_L,OFF);
  556. rt_pin_write(Cool_Fan_R,OFF);
  557. }
  558. if(status_cool==ON)
  559. {
  560. rt_pin_write(Cool_Fan_L,ON);
  561. rt_pin_write(Cool_Fan_R,OFF);
  562. }
  563. return device_status.cool_fan_status;
  564. }
  565. /*************************************************
  566. Function: ctr_Collect_Fan
  567. Description: 采集风机的开关
  568. Calls:
  569. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  570. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  571. Input: ON-开,OFF-关
  572. Output: NULL
  573. Return: ON-开,OFF-关
  574. Others: NULL
  575. *************************************************/
  576. void ctr_develop(void)
  577. {
  578. rt_kprintf("===============开始培养=================:%d\n",device_status.cul_time);
  579. //已经培养的时间-分钟
  580. device_status.stay_time = 0;
  581. rt_uint32_t ii = 0;
  582. while(device_status.develop_flag==1)
  583. {
  584. float stayedtime = 0.01;
  585. char stayed[5];
  586. stayedtime = (float)device_status.stay_time / 60.0;
  587. sprintf(stayed,"%0.02f",stayedtime);
  588. HMI_WRITE("workSta.staytime.txt=\"%s\"",stayed);
  589. ii++;
  590. LOG_I("developing...................................%d\n",ii);
  591. LOG_I("============================设定的培养温度:%d\n",device_status.heatvalue);
  592. LOG_I("============================培养仓实时温度:%d\n",device_status.pre_temp);
  593. if(device_status.pre_temp<(device_status.heatvalue-5))
  594. {
  595. //未制冷
  596. if(device_status.cold_status==0)
  597. {
  598. ctr_Heat(ON);
  599. }
  600. }
  601. else
  602. {
  603. ctr_Heat(OFF);
  604. }
  605. LOG_I("============================制冷开关:%d\n",device_status.cold_sw);
  606. if(device_status.cold_sw==1)
  607. {
  608. if(device_status.pre_temp>(device_status.heatvalue-10))
  609. {
  610. if(device_status.heat_status==0)
  611. {
  612. ctr_Cold(ON);
  613. }
  614. }
  615. else
  616. {
  617. ctr_Cold(OFF);
  618. }
  619. }
  620. if(ii%60==0)
  621. {
  622. device_status.stay_time++;
  623. if(device_status.stay_time / 60 == device_status.cul_time) device_status.develop_flag = 0;
  624. LOG_I("developed...................................%d分钟\n",device_status.stay_time);
  625. }
  626. if(device_status.box_temp>35)
  627. {
  628. ctr_Cool_Fan(ON);
  629. }
  630. else if (device_status.box_temp<30)
  631. {
  632. ctr_Cool_Fan(OFF);
  633. }
  634. rt_thread_delay(1000);
  635. }
  636. ctr_Cold(OFF);
  637. ctr_Heat(OFF);
  638. LOG_I("=========!!!培养完成!!!==========");
  639. }
  640. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  641. {
  642. device_status.collect_fan_status = status_collect;
  643. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  644. if(status_collect==OFF)
  645. {
  646. rt_pin_write(Collect_Fan,OFF);
  647. }
  648. if(status_collect==ON)
  649. {
  650. rt_pin_write(Collect_Fan,ON);
  651. }
  652. return device_status.collect_fan_status;
  653. }
  654. /*************************************************
  655. Function: ctr_develop
  656. Description: 培养载玻片孢子
  657. Calls:
  658. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  659. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  660. Input: v=0(复位) v=90转90度
  661. Output: NULL
  662. Return: NULL
  663. Others: NULL
  664. *************************************************/
  665. /*上仓门*/
  666. uint8_t ctr_cangmen_up(uint8_t status_up)
  667. {
  668. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  669. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  670. if(status_up==OFF)
  671. {
  672. rt_pin_write(Collect_fan_R,ON);
  673. rt_pin_write(Collect_fan_L,ON);
  674. device_status.ctr_up_motor = 0;
  675. rt_thread_delay(1000);
  676. }
  677. if(status_up==OPEN)
  678. {
  679. device_status.up_status = 1;
  680. rt_pin_write(Collect_fan_R,OFF);
  681. rt_pin_write(Collect_fan_L,OFF);
  682. rt_pin_write(Collect_fan_R,ON);
  683. rt_pin_write(Collect_fan_L,OFF);
  684. }
  685. if(status_up==CLOSE)
  686. {
  687. device_status.up_status = 0;
  688. rt_pin_write(Collect_fan_R,OFF);
  689. rt_pin_write(Collect_fan_L,OFF);
  690. rt_pin_write(Collect_fan_R,OFF);
  691. rt_pin_write(Collect_fan_L,ON);
  692. }
  693. return device_status.up_status;
  694. }
  695. //下仓门
  696. uint8_t ctr_cangmen_down(uint8_t status_down)
  697. {
  698. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  699. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  700. if(status_down==OFF)
  701. {
  702. rt_pin_write(C_DOWN_R,ON);
  703. rt_pin_write(C_DOWN_L,ON);
  704. device_status.ctr_down_motor = 0;
  705. rt_thread_delay(1000);
  706. }
  707. if(status_down==OPEN)
  708. {
  709. device_status.down_status = 1;
  710. rt_pin_write(C_DOWN_R,OFF);
  711. rt_pin_write(C_DOWN_L,OFF);
  712. rt_pin_write(C_DOWN_R,ON);
  713. rt_pin_write(C_DOWN_L,OFF);
  714. }
  715. if(status_down==CLOSE)
  716. {
  717. device_status.down_status = 0;
  718. rt_pin_write(C_DOWN_R,OFF);
  719. rt_pin_write(C_DOWN_L,OFF);
  720. rt_pin_write(C_DOWN_R,OFF);
  721. rt_pin_write(C_DOWN_L,ON);
  722. }
  723. return device_status.down_status;
  724. }
  725. //镇流器
  726. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num)
  727. {
  728. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  729. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  730. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  731. if(status_lamp==ON)
  732. {
  733. switch(lamp_num){
  734. case 1:
  735. rt_pin_write(LAMP_SW,ON);
  736. device_status.lamp_status = status_lamp;
  737. break;
  738. case 2:
  739. rt_pin_write(LAMP_1_SW,ON);
  740. device_status.lamp_status = status_lamp;
  741. break;
  742. case 3:
  743. rt_pin_write(LAMP_2_SW,ON);
  744. device_status.lamp_status = status_lamp;
  745. break;
  746. default:
  747. break;
  748. }
  749. }
  750. else {
  751. switch(lamp_num){
  752. case 1:
  753. rt_pin_write(LAMP_SW,OFF);
  754. device_status.lamp_status = status_lamp;
  755. break;
  756. case 2:
  757. rt_pin_write(LAMP_1_SW,OFF);
  758. device_status.lamp1_status = status_lamp;
  759. break;
  760. case 3:
  761. rt_pin_write(LAMP_2_SW,OFF);
  762. device_status.lamp2_status = status_lamp;
  763. break;
  764. default:
  765. break;
  766. }
  767. }
  768. HMI_WRITE("sysTest.switchLamp.val=%d",device_status.lamp_status);
  769. return device_status.lamp_status;
  770. }
  771. //震动电机
  772. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
  773. {
  774. static rt_uint16_t shake_i = 0;
  775. shake_i = atoi(device_status.power);
  776. LOG_I("震动电机待机电流:%d",shake_i);
  777. if(device_status.dtype==7&&shake_sec!=0)
  778. DTU_Write("drop");
  779. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  780. #if 0
  781. rt_pin_write(SHAKE_SW,ON);
  782. return 0;
  783. #endif
  784. if(status_shake==ON&&device_status.shake_ws==1)
  785. {
  786. #if 0
  787. for(int8_t s = 0;s++;s<2)
  788. {
  789. rt_pin_write(SHAKE_SW,ON);
  790. rt_thread_delay(100);
  791. rt_pin_write(SHAKE_SW,OFF);
  792. rt_thread_delay(1000);
  793. }
  794. #endif
  795. rt_pin_write(SHAKE_SW,ON);
  796. if(device_status.dtype==3)
  797. {
  798. while(shake_sec--)
  799. {
  800. rt_thread_delay(100);
  801. if(shake_sec==20&&device_status.clear_status==0&&device_status.work_status==1&&atoi(device_status.power)-shake_i<100&&shake_i!=0&&shake_i<5000)
  802. {
  803. char * shake_warn = makeJson_Warn("电流不足", "震动电机");
  804. DTU_Write("%s",shake_warn);
  805. rt_free(shake_warn);
  806. }
  807. LOG_D("震动电机:%d",atoi(device_status.power));
  808. }
  809. }
  810. if(device_status.dtype==7) rt_thread_delay(shake_sec*1000);
  811. rt_pin_write(SHAKE_SW,OFF);
  812. HMI_WRITE("cangWei.switchShake.val=%d",0);
  813. }
  814. else
  815. {
  816. rt_pin_write(SHAKE_SW,OFF);
  817. HMI_WRITE("cangWei.switchShake.val=%d",0);
  818. }
  819. if(device_status.dtype==7)
  820. HMI_WRITE("sysTest.switchDrop.val=%d",OFF);
  821. return status_shake;
  822. }
  823. //补光
  824. uint8_t ctr_led(uint8_t status_led)
  825. {
  826. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  827. if(device_status.version_type==6)
  828. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  829. if(status_led==ON)
  830. {
  831. rt_pin_write(LED_SW,ON);
  832. if(device_status.version_type==6)
  833. rt_pin_write(LED_P,ON);
  834. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  835. }
  836. else if(status_led==OFF){
  837. rt_pin_write(LED_SW,OFF);
  838. if(device_status.version_type==6)
  839. rt_pin_write(LED_P,OFF);
  840. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  841. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  842. }
  843. return status_led;
  844. }
  845. /*************************************************
  846. Function: ctr_turn
  847. Description: 转盘驱动
  848. Calls:
  849. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  850. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  851. Input: v=0(复位) v=90转90度
  852. Output: NULL
  853. Return: NULL
  854. Others: NULL
  855. *************************************************/
  856. void ctr_turn(uint8_t v,uint8_t sta)
  857. {
  858. DTU_Write("turn.mp3");
  859. LOG_I("================v===============:%d",v);
  860. rt_uint16_t turn_cnt = 0;
  861. rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
  862. rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
  863. rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
  864. rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
  865. //if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
  866. while(rt_pin_read(LIMIT_0)==0||rt_pin_read(LIMIT_90)==0)
  867. {
  868. rt_pin_write(TURN_ZP_R, ON);
  869. rt_pin_write(TURN_ZP_L, OFF);
  870. //Motor_shake(ON,0);
  871. turn_cnt ++;
  872. rt_thread_delay(100);
  873. if(turn_cnt==1000)
  874. {
  875. turn_cnt = 0;
  876. rt_pin_write(TURN_ZP_R, OFF);
  877. rt_pin_write(TURN_ZP_L, OFF);
  878. //Motor_shake(OFF,0);
  879. char *turn_warn =makeJson_Warn("未检测到限位", "转盘");
  880. DTU_Write("%s",turn_warn);
  881. rt_free(turn_warn);
  882. break;
  883. }
  884. }
  885. turn_cnt = 0;
  886. while(v==0&&rt_pin_read(LIMIT_0)==1)
  887. {
  888. rt_pin_write(TURN_ZP_R, ON);
  889. rt_pin_write(TURN_ZP_L, OFF);
  890. Motor_shake(ON,0);
  891. rt_thread_delay(200); //10 to 100
  892. turn_cnt ++;
  893. if(turn_cnt==300) //6000 to 600
  894. {
  895. turn_cnt = 0;
  896. // rt_pin_write(TURN_ZP_R, OFF);
  897. // rt_pin_write(TURN_ZP_L, OFF);
  898. // char *turn_warn =makeJson_Warn("超时", "转盘复位");
  899. // DTU_Write("%s",turn_warn);
  900. // rt_free(turn_warn);
  901. break;
  902. }
  903. }
  904. while(v==0&&rt_pin_read(LIMIT_0)==1)
  905. {
  906. rt_pin_write(TURN_ZP_R, ON);
  907. rt_pin_write(TURN_ZP_L, OFF);
  908. //Motor_shake(ON,0);
  909. rt_thread_delay(50); //10 to 50
  910. turn_cnt ++;
  911. if(turn_cnt==10) //6000 to 1200
  912. {
  913. turn_cnt = 0;
  914. rt_pin_write(TURN_ZP_R, OFF);
  915. rt_pin_write(TURN_ZP_L, OFF);
  916. //Motor_shake(OFF,0);
  917. char *turn_warn =makeJson_Warn("超时", "转盘复位");
  918. DTU_Write("%s",turn_warn);
  919. rt_free(turn_warn);
  920. break;
  921. }
  922. }
  923. turn_cnt = 0;
  924. while(v==90&&rt_pin_read(LIMIT_90)==1)
  925. {
  926. rt_pin_write(TURN_ZP_R, ON);
  927. rt_pin_write(TURN_ZP_L, OFF);
  928. //Motor_shake(ON,0);
  929. rt_thread_delay(200);
  930. turn_cnt ++;
  931. if(turn_cnt==150)
  932. {
  933. turn_cnt = 0;
  934. // rt_pin_write(TURN_ZP_R, OFF);
  935. // rt_pin_write(TURN_ZP_L, OFF);
  936. // char *turn_warn =makeJson_Warn("超时", "转盘");
  937. // DTU_Write(turn_warn);
  938. // rt_free(turn_warn);
  939. break;
  940. }
  941. }
  942. while(v==90&&rt_pin_read(LIMIT_90)==1)
  943. {
  944. // rt_pin_write(TURN_ZP_R, ON);
  945. // rt_pin_write(TURN_ZP_L, OFF);
  946. Motor_shake(ON,0);
  947. rt_thread_delay(50);
  948. turn_cnt ++;
  949. if(turn_cnt==10)
  950. {
  951. turn_cnt = 0;
  952. rt_pin_write(TURN_ZP_R, OFF);
  953. rt_pin_write(TURN_ZP_L, OFF);
  954. //Motor_shake(OFF,0);
  955. char *turn_warn =makeJson_Warn("超时", "转盘");
  956. DTU_Write(turn_warn);
  957. rt_free(turn_warn);
  958. break;
  959. }
  960. }
  961. if(sta!=0)
  962. {
  963. //保存位置
  964. device_status.run_sta = sta;
  965. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  966. }
  967. turn_cnt = 0;
  968. rt_pin_write(TURN_ZP_R, OFF);
  969. rt_pin_write(TURN_ZP_L, OFF);
  970. Motor_shake(OFF,0);
  971. HMI_WRITE("cangWei.rotateFlag.val=0");
  972. }
  973. /*************************************************
  974. Function: ctr_Motor_Driver
  975. Description: 步进电机驱动
  976. Calls:
  977. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  978. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  979. Input: 50000000
  980. Output: NULL
  981. Return: shake_sec
  982. Others: NULL
  983. *************************************************/
  984. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out)
  985. {
  986. beep_init();
  987. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  988. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  989. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  990. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  991. if(EN==0)
  992. {
  993. rt_pin_write(Motor_Power,0);
  994. }
  995. else{
  996. rt_pin_write(Motor_EN, EN);
  997. }
  998. rt_pin_write(Motor_DIR, DIR);
  999. beep_set(pwm, pwm/2); //200kzh - 50%
  1000. while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
  1001. {
  1002. if(time_out==0)
  1003. {
  1004. break;
  1005. }
  1006. rt_thread_delay(50);
  1007. time_out --;
  1008. }
  1009. while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
  1010. {
  1011. if(time_out==0)
  1012. {
  1013. break;
  1014. }
  1015. rt_thread_delay(50);
  1016. time_out --;
  1017. }
  1018. rt_pin_write(Motor_EN, OFF);
  1019. if(device_status.autotakepic==0)
  1020. ctr_lamp(OFF, 1);
  1021. beep_set(0, 0); //200kzh - 50%
  1022. }
  1023. /*************************************************
  1024. Function: ctr_Petroleum_jelly
  1025. Description: 涂凡士林
  1026. Calls:
  1027. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  1028. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  1029. Input: NULL
  1030. Output: NULL
  1031. Return: NULL
  1032. Others: NULL
  1033. *************************************************/
  1034. void ctr_Petroleum_jelly(rt_uint32_t delay)
  1035. {
  1036. beep_init();
  1037. pwm_on(2,50000);
  1038. rt_thread_delay(delay*1000);
  1039. pwm_off(2,0);
  1040. rt_thread_delay(1000);
  1041. pwm_on(3, 50000);
  1042. rt_thread_delay(delay*1000);
  1043. pwm_off(3,0);
  1044. device_status.fsl_sw = 0;
  1045. }
  1046. //1.0转仓
  1047. void turnzp(void)
  1048. {
  1049. static uint16_t turn_timeout = 0;
  1050. // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1051. // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1052. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  1053. // rt_pin_write(CLEAR_R,OFF);
  1054. // rt_pin_write(CLEAR_L,OFF);
  1055. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1056. {
  1057. rt_thread_delay(20);
  1058. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1059. {
  1060. // rt_pin_write(CLEAR_R,ON);
  1061. // rt_pin_write(CLEAR_L,OFF);
  1062. Motor_Juandai(ON);
  1063. rt_thread_delay(50);
  1064. turn_timeout++;
  1065. if(turn_timeout==600)
  1066. {
  1067. LOG_E("检测不到限位,电机强制停止");
  1068. char *ctr_zp_limit_warn =makeJson_Warn("电流不足/限位超时","转盘电机");
  1069. DTU_Write("%s",ctr_zp_limit_warn);
  1070. rt_free(ctr_zp_limit_warn);
  1071. break;
  1072. }
  1073. }
  1074. break;
  1075. }
  1076. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  1077. {
  1078. rt_thread_delay(20);
  1079. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  1080. {
  1081. // rt_pin_write(CLEAR_R,ON);
  1082. // rt_pin_write(CLEAR_L,OFF);
  1083. Motor_Juandai(ON);
  1084. rt_thread_delay(50);
  1085. turn_timeout++;
  1086. if(turn_timeout==600)
  1087. {
  1088. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  1089. char *ctr_zp_limit_warn =makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障","转盘电机");
  1090. DTU_Write("%s",ctr_zp_limit_warn);
  1091. rt_free(ctr_zp_limit_warn);
  1092. break;
  1093. }
  1094. }
  1095. break;
  1096. }
  1097. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1098. {
  1099. rt_thread_delay(20);
  1100. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  1101. {
  1102. // rt_pin_write(CLEAR_R,OFF);
  1103. // rt_pin_write(CLEAR_L,OFF);
  1104. Motor_Juandai(OFF);
  1105. break;
  1106. }
  1107. else {
  1108. break;
  1109. }
  1110. }
  1111. Motor_Juandai(OFF);
  1112. // rt_pin_write(CLEAR_R,OFF);
  1113. // rt_pin_write(CLEAR_L,OFF);
  1114. turn_timeout = 0;
  1115. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1116. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1117. rt_thread_delay(1000);
  1118. }
  1119. //清扫-常闭型限位开关
  1120. //新结构使用推杆电机做清扫
  1121. uint8_t ctr_clear(uint16_t status_clear)
  1122. {
  1123. static uint16_t clear_num = 0;
  1124. #if PWM_EN == 0
  1125. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1126. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1127. #endif
  1128. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  1129. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  1130. /*************************************************************外接清扫
  1131. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1132. rt_pin_write(POWER_CLEAR,ON);
  1133. rt_thread_delay(1000*100);
  1134. rt_pin_write(POWER_CLEAR,OFF);
  1135. ************************************************************/
  1136. //停止
  1137. #if PWM_EN == 0
  1138. rt_pin_write(CLEAR_R,OFF);
  1139. rt_pin_write(CLEAR_L,OFF);
  1140. #else
  1141. Motor_Qingsao_R_PWM(OFF);
  1142. Motor_Qingsao_L_PWM(OFF);
  1143. #endif
  1144. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  1145. rt_thread_delay(100);
  1146. //如果清扫位置在中间
  1147. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  1148. {
  1149. #if PWM_EN == 0
  1150. rt_pin_write(CLEAR_R,ON);
  1151. rt_pin_write(CLEAR_L,OFF);
  1152. #else
  1153. Motor_Qingsao_R_PWM(ON);
  1154. Motor_Qingsao_L_PWM(OFF);
  1155. #endif
  1156. rt_thread_delay(50);
  1157. clear_num++;
  1158. //已到达检测位置
  1159. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  1160. {
  1161. #if PWM_EN == 0
  1162. rt_pin_write(CLEAR_R,ON);
  1163. rt_pin_write(CLEAR_L,ON);
  1164. #else
  1165. Motor_Qingsao_R_PWM(OFF);
  1166. Motor_Qingsao_L_PWM(OFF);
  1167. #endif
  1168. rt_thread_delay(2000);
  1169. break;
  1170. }
  1171. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1172. {
  1173. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1174. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1175. #if PWM_EN == 0
  1176. rt_pin_write(CLEAR_R,ON);
  1177. rt_pin_write(CLEAR_L,ON);
  1178. #else
  1179. Motor_Qingsao_R_PWM(OFF);
  1180. Motor_Qingsao_L_PWM(OFF);
  1181. #endif
  1182. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  1183. if(Read_Real_Voltage()/100<12)
  1184. {
  1185. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1186. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1187. device_status.clear_status = 0;
  1188. return 0;
  1189. }
  1190. break;
  1191. }
  1192. }
  1193. clear_num = 0;
  1194. //如果清扫位置在左侧
  1195. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1196. {
  1197. #if PWM_EN == 0
  1198. rt_pin_write(CLEAR_R,ON);
  1199. rt_pin_write(CLEAR_L,OFF);
  1200. #else
  1201. Motor_Qingsao_R_PWM(ON);
  1202. Motor_Qingsao_L_PWM(OFF);
  1203. #endif
  1204. rt_thread_delay(50);
  1205. clear_num++;
  1206. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1207. {
  1208. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1209. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1210. #if PWM_EN == 0
  1211. rt_pin_write(CLEAR_R,ON);
  1212. rt_pin_write(CLEAR_L,ON);
  1213. #else
  1214. Motor_Qingsao_R_PWM(OFF);
  1215. Motor_Qingsao_L_PWM(OFF);
  1216. #endif
  1217. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  1218. if(Read_Real_Voltage()/100<12)
  1219. {
  1220. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1221. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1222. device_status.clear_status = 0;
  1223. return 0;
  1224. }
  1225. break;
  1226. }
  1227. }
  1228. clear_num = 0;
  1229. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  1230. {
  1231. #if PWM_EN == 0
  1232. rt_pin_write(CLEAR_R,ON);
  1233. rt_pin_write(CLEAR_L,ON);
  1234. #else
  1235. Motor_Qingsao_R_PWM(OFF);
  1236. Motor_Qingsao_L_PWM(OFF);
  1237. #endif
  1238. if(Read_Real_Voltage()/100<12)
  1239. {
  1240. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1241. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1242. device_status.clear_status = 0;
  1243. return 0;
  1244. }
  1245. rt_thread_delay(2000);
  1246. break;
  1247. }
  1248. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  1249. {
  1250. #if PWM_EN == 0
  1251. rt_pin_write(CLEAR_R,OFF);
  1252. rt_pin_write(CLEAR_L,ON);
  1253. #else
  1254. Motor_Qingsao_R_PWM(OFF);
  1255. Motor_Qingsao_L_PWM(ON);
  1256. #endif
  1257. rt_thread_delay(50);
  1258. clear_num++;
  1259. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1260. {
  1261. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1262. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  1263. //DTU_Write("%s",Clear_ERR);
  1264. #if PWM_EN == 0
  1265. rt_pin_write(CLEAR_R,ON);
  1266. rt_pin_write(CLEAR_L,ON);
  1267. #else
  1268. Motor_Qingsao_R_PWM(OFF);
  1269. Motor_Qingsao_L_PWM(OFF);
  1270. #endif
  1271. rt_free(Clear_ERR);
  1272. if(Read_Real_Voltage()/100<12)
  1273. {
  1274. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1275. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1276. device_status.clear_status = 0;
  1277. return 0;
  1278. }
  1279. break;
  1280. }
  1281. }
  1282. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  1283. {
  1284. #if PWM_EN == 0
  1285. rt_pin_write(CLEAR_R,ON);
  1286. rt_pin_write(CLEAR_L,ON);
  1287. #else
  1288. Motor_Qingsao_R_PWM(OFF);
  1289. Motor_Qingsao_L_PWM(OFF);
  1290. #endif
  1291. rt_thread_delay(2000);
  1292. break;
  1293. }
  1294. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  1295. {
  1296. #if PWM_EN == 0
  1297. rt_pin_write(CLEAR_R,ON);
  1298. rt_pin_write(CLEAR_L,ON);
  1299. #else
  1300. Motor_Qingsao_R_PWM(OFF);
  1301. Motor_Qingsao_L_PWM(OFF);
  1302. #endif
  1303. if(device_status.version_type==41)
  1304. {
  1305. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  1306. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  1307. //DTU_Write("%s",Clear_ERR);
  1308. rt_free(Clear_ERR);
  1309. }
  1310. return 0;
  1311. }
  1312. clear_num = 0;
  1313. rt_thread_delay(2000);
  1314. #if PWM_EN == 0
  1315. rt_pin_write(CLEAR_R,ON);
  1316. rt_pin_write(CLEAR_L,ON);
  1317. #else
  1318. Motor_Qingsao_R_PWM(OFF);
  1319. Motor_Qingsao_L_PWM(OFF);
  1320. #endif
  1321. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1322. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1323. device_status.clear_status = 0;
  1324. return 1;
  1325. }
  1326. //路由器供电
  1327. void ctr_router(uint8_t status_router)
  1328. {
  1329. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  1330. if(device_status.version_type==6)
  1331. rt_pin_mode(ROUTER_P,PIN_MODE_OUTPUT);
  1332. //rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1333. if(status_router==ON)
  1334. {
  1335. rt_pin_write(ROUTER,ON);
  1336. //
  1337. #if LAMP_EN == 0
  1338. if(device_status.version_type==6)
  1339. rt_pin_write(ROUTER_P,ON);
  1340. #endif
  1341. }
  1342. else {
  1343. rt_pin_write(ROUTER,OFF);
  1344. //
  1345. #if LAMP_EN == 0
  1346. if(device_status.version_type==6)
  1347. rt_pin_write(ROUTER_P,OFF);
  1348. #endif
  1349. }
  1350. }
  1351. //清扫-推杆电机
  1352. void ctr_TG_Clear(uint16_t clear_timeout)
  1353. {
  1354. #if 0
  1355. int current_clear[200];
  1356. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1357. LOG_I("清扫电机待机:%d",Electric_current);
  1358. #endif
  1359. static uint16_t clear_count = 0;
  1360. clear_count = clear_timeout;
  1361. #if PWM_EN == 0
  1362. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1363. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1364. #endif
  1365. while(clear_count!=0)
  1366. {
  1367. #if PWM_EN == 0
  1368. rt_pin_write(CLEAR_R,ON);
  1369. rt_pin_write(CLEAR_L,OFF);
  1370. #else
  1371. Motor_Qingsao_R_PWM(ON);
  1372. Motor_Qingsao_L_PWM(OFF);
  1373. #endif
  1374. clear_count--;
  1375. rt_thread_delay(100);
  1376. }
  1377. #if PWM_EN == 0
  1378. rt_pin_write(CLEAR_R,ON);
  1379. rt_pin_write(CLEAR_L,ON);
  1380. #else
  1381. Motor_Qingsao_R_PWM(OFF);
  1382. Motor_Qingsao_L_PWM(OFF);
  1383. #endif
  1384. rt_thread_delay(3000);
  1385. clear_count = 0;
  1386. while(clear_timeout!=clear_count)
  1387. {
  1388. #if PWM_EN == 0
  1389. rt_pin_write(CLEAR_R,OFF);
  1390. rt_pin_write(CLEAR_L,ON);
  1391. #else
  1392. Motor_Qingsao_R_PWM(OFF);
  1393. Motor_Qingsao_L_PWM(ON);
  1394. #endif
  1395. // if(clear_count<200)
  1396. // current_clear[clear_count] = atoi(device_status.power);
  1397. clear_count++;
  1398. rt_thread_delay(100);
  1399. }
  1400. #if PWM_EN == 0
  1401. rt_pin_write(CLEAR_R,ON);
  1402. rt_pin_write(CLEAR_L,ON);
  1403. #else
  1404. Motor_Qingsao_R_PWM(OFF);
  1405. Motor_Qingsao_L_PWM(OFF);
  1406. #endif
  1407. #if 0
  1408. bubblesort(current_clear,200);
  1409. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1410. {
  1411. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1412. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1413. DTU_Write("%s",ctr_clear_warn);
  1414. rt_free(ctr_clear_warn);
  1415. }
  1416. #endif
  1417. rt_thread_delay(2000);
  1418. device_status.clear_status = 0;
  1419. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1420. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1421. }
  1422. //DTU,RTU供电
  1423. void ctr_RTU_DTU(uint8_t status_rtu)
  1424. {
  1425. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1426. if(status_rtu==ON)
  1427. {
  1428. rt_pin_write(RTU_DTU,ON);
  1429. }
  1430. else
  1431. {
  1432. LOG_W("RTU电源复位!!!");
  1433. rt_pin_write(RTU_DTU,OFF);
  1434. }
  1435. }
  1436. //海康拍照
  1437. void Hk_Take_io(void)
  1438. {
  1439. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1440. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1441. rt_pin_write(HK_TAKE, 1);
  1442. rt_pin_write(HK_IO, 0);
  1443. if(device_status.dtype==3)
  1444. Beep_Tip(1000);
  1445. if(device_status.dtype==7)
  1446. rt_thread_mdelay(1000);
  1447. rt_pin_write(HK_TAKE, 0);
  1448. rt_pin_write(HK_IO, 1);
  1449. }
  1450. void calorstat(uint16_t heat_time)
  1451. {
  1452. //uint8_t heat_up_cnt = 0;
  1453. uint16_t n = 0;
  1454. uint16_t delay_heat = 60;
  1455. FlagStatus heat_flg = RESET;
  1456. device_status.heat_time_min = 0;
  1457. device_status.run_sta = device_status.heattem; //初始化加热实时温度
  1458. ctr_Heat(ON);
  1459. // UpLoad_Data(); //开始加热时的第一条数据
  1460. //恒温模式
  1461. for(n=0;n < heat_time;n++)
  1462. {
  1463. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  1464. {
  1465. heat_flg = SET;
  1466. ctr_Heat(OFF);
  1467. while(delay_heat!=0)
  1468. {
  1469. delay_heat --;
  1470. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  1471. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
  1472. rt_thread_delay(1000);
  1473. if(device_status.heattem>device_status.run_sta + 1){
  1474. device_status.run_sta = device_status.heattem;
  1475. }
  1476. }
  1477. delay_heat = 60;
  1478. //跳出FOR循环
  1479. n = n + 60;
  1480. }
  1481. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  1482. {
  1483. device_status.run_sta = device_status.heattem;
  1484. ctr_Heat(ON);
  1485. }
  1486. else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
  1487. {
  1488. // if(heat_up_cnt==0)
  1489. // {
  1490. // UpLoad_Data(); //加热到设定温度的数据
  1491. // heat_up_cnt = 1;
  1492. // }
  1493. device_status.run_sta = device_status.heattem;
  1494. ctr_Heat(OFF);
  1495. }
  1496. if((n % 60)==0)
  1497. {
  1498. device_status.heat_time_min = device_status.heat_time_min + 1;
  1499. // if(device_status.heat_time_min % 5 == 0)
  1500. // {
  1501. // UpLoad_Data(); //从加热开始每5分钟上传的数据
  1502. // }
  1503. }
  1504. //如果触发异常退出加热
  1505. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1506. {
  1507. rt_thread_delay(1000);
  1508. if(device_status.bat_status == 1)
  1509. {
  1510. rt_kprintf("============================触发异常退出加热==========================");
  1511. ctr_lamp(OFF,1);
  1512. ctr_Heat(OFF);
  1513. break;
  1514. }
  1515. }
  1516. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1517. {
  1518. ctr_Heat(OFF);
  1519. rt_kprintf("异常退出!!!\n");
  1520. break;
  1521. }
  1522. rt_thread_delay(1000);
  1523. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  1524. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
  1525. }
  1526. ctr_Heat(OFF);
  1527. //UpLoad_Data(); //加热结束的数据
  1528. }
  1529. //初始化所有控制驱动,关闭
  1530. void HardWare_Init(uint8_t boot)
  1531. {
  1532. Beep_Tip(200);
  1533. //关闭上仓门
  1534. ctr_cangmen_up(OFF);
  1535. if(device_status.dtype==3){
  1536. //关闭下仓门电机
  1537. ctr_cangmen_down(OFF);
  1538. }
  1539. //关闭镇流器
  1540. if(device_status.autotakepic==0)
  1541. ctr_lamp(OFF,1);
  1542. //关闭震动电机
  1543. ctr_shake(OFF,0);
  1544. //关闭加热
  1545. ctr_Heat(OFF);
  1546. //关闭补光灯
  1547. ctr_led(OFF);
  1548. //关闭12V供电(海康相机,RTU)
  1549. //ctr_photo(OFF);
  1550. }
  1551. //拍照
  1552. void HK_TakePhoto(void)
  1553. {
  1554. //打开补光灯
  1555. ctr_led(ON);
  1556. //播放语音
  1557. DTU_Write("takephoto.mp3");
  1558. rt_thread_delay(1000);
  1559. //吸虫塔,水稻
  1560. if(device_status.version_type!=6&&device_status.version_type!=4)
  1561. {
  1562. rt_thread_delay(1000*15);
  1563. }
  1564. char *takephotojson = makeJson_takephoto();
  1565. DTU_Write("%s",takephotojson);
  1566. rt_free(takephotojson);
  1567. //触发海康相机拍照
  1568. Hk_Take_io();
  1569. if(device_status.version_type!=6)
  1570. {
  1571. rt_thread_delay(1000*45);
  1572. }
  1573. else {
  1574. ctr_led(ON);
  1575. rt_thread_delay(1000*19);
  1576. }
  1577. ctr_led(OFF);
  1578. }
  1579. //光控测试任务
  1580. void SunTest(void)
  1581. {
  1582. rt_uint16_t ui_timeout_l = 0;
  1583. //未检测到光照,一秒扫描等待,超时30S
  1584. while(Read_Light_Voltage()<500)
  1585. {
  1586. ui_timeout_l ++;
  1587. rt_thread_delay(1000);
  1588. if(ui_timeout_l==30) break;
  1589. }
  1590. rt_thread_delay(3000);
  1591. if(Read_Light_Voltage()<500)
  1592. {
  1593. device_status.sun_status = 0;//光控状态
  1594. }
  1595. if(Read_Light_Voltage()>500)
  1596. {
  1597. rt_thread_delay(1000);
  1598. }
  1599. rt_thread_delay(3000);
  1600. if(Read_Light_Voltage()>500)
  1601. {
  1602. device_status.sun_status = 1;
  1603. ctr_lamp(OFF,1);
  1604. }
  1605. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1606. device_status.sun_test = 0;
  1607. device_status.work_status=0;
  1608. }
  1609. /*上电初始化*/
  1610. void ResetInit(void)
  1611. {
  1612. if(device_status.dtype==7)
  1613. {
  1614. ctr_Motor_Driver(0, 0, 0, 0);
  1615. //关闭电磁阀
  1616. ctr_shake(OFF, 0);
  1617. //关闭加热
  1618. ctr_Heat(OFF);
  1619. //关闭制冷
  1620. ctr_Cold(OFF);
  1621. //关闭补光灯
  1622. ctr_led(OFF);
  1623. //转盘复位
  1624. if(device_status.run_sta==0)
  1625. ctr_turn(0, 0);
  1626. }
  1627. if(device_status.version_type!=6&&device_status.version_type!=7)
  1628. {
  1629. device_status.work_done = 1;
  1630. //1.打开路由器供电
  1631. if(device_status.power_status==1)
  1632. {
  1633. ctr_router(ON);
  1634. ctr_RTU_DTU(ON);
  1635. //2.打开相机供电
  1636. ctr_photo(ON);
  1637. }
  1638. //3.关闭镇流器
  1639. ctr_lamp(OFF,1);
  1640. #if LAMP_EN == 1
  1641. ctr_lamp(OFF,2);
  1642. ctr_lamp(OFF,3);
  1643. #endif
  1644. //4.关闭震动电机
  1645. ctr_shake(OFF, 0);
  1646. //5.关闭加热
  1647. ctr_Heat(OFF);
  1648. //6.关闭补光灯
  1649. ctr_led(OFF);
  1650. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  1651. {
  1652. LOG_W("欠压!");
  1653. return;
  1654. }
  1655. //7.关闭上仓门
  1656. device_status.ctr_up_motor = 2;
  1657. // while(device_status.ctr_up_motor!=0)
  1658. // {
  1659. // LOG_I("关闭上仓门...");
  1660. // rt_thread_delay(100);
  1661. // }
  1662. //8.关闭下仓门
  1663. device_status.ctr_down_motor = 2;
  1664. while(device_status.ctr_down_motor!=0)
  1665. {
  1666. LOG_I("关闭下仓门....");
  1667. rt_thread_delay(100);
  1668. }
  1669. //9.清扫
  1670. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1671. {
  1672. LOG_W("异常退出!!!\n");
  1673. return;
  1674. }
  1675. #if 0//LAMP_EN == 0
  1676. ctr_Fan_PUT(OFF);
  1677. ctr_Fan_IN(OFF);
  1678. #endif
  1679. if(device_status.version_type==4||device_status.version_type==41||device_status.version_type==42||device_status.version_type==12)
  1680. {
  1681. device_status.clear_status=1;
  1682. while(device_status.clear_status==1){
  1683. rt_thread_delay(1000);
  1684. }
  1685. }
  1686. #if LAMP_EN == 0
  1687. //排虫
  1688. if(device_status.handle_bugger==0){
  1689. device_status.run_sta = 111; //排虫
  1690. }else{
  1691. device_status.run_sta = 112; //收虫
  1692. }
  1693. #endif
  1694. }
  1695. else {
  1696. if(device_status.power_status==1)
  1697. {
  1698. //1.打开路由器供电
  1699. ctr_router(ON);
  1700. ctr_RTU_DTU(ON);
  1701. //2.打开相机供电
  1702. ctr_photo(ON);
  1703. }
  1704. //5.关闭加热
  1705. //6.关闭补光灯
  1706. ctr_led(OFF);
  1707. }
  1708. }
  1709. /*三色光源*/
  1710. void Led_Check(uint8_t tp)
  1711. {
  1712. if(tp==3)
  1713. {
  1714. if(device_status.light_over_tim>2*3600)
  1715. {
  1716. device_status.work_status = 1;
  1717. device_status.lamp_status = 1;
  1718. device_status.lamp1_status = 0;
  1719. device_status.lamp2_status = 0;
  1720. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1721. }
  1722. else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
  1723. device_status.work_status = 1;
  1724. device_status.lamp_status = 0;
  1725. device_status.lamp1_status = 1;
  1726. device_status.lamp2_status = 0;
  1727. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1728. }
  1729. else if (device_status.light_over_tim<1*3600) {
  1730. device_status.work_status = 1;
  1731. device_status.lamp_status = 0;
  1732. device_status.lamp1_status = 0;
  1733. device_status.lamp2_status = 1;
  1734. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1735. }
  1736. }
  1737. else if (tp==6) {
  1738. if(device_status.light_over_tim>4*3600)
  1739. {
  1740. device_status.work_status = 1;
  1741. device_status.lamp_status = 1;
  1742. device_status.lamp1_status = 0;
  1743. device_status.lamp2_status = 0;
  1744. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1745. }
  1746. else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
  1747. device_status.work_status = 1;
  1748. device_status.lamp_status = 0;
  1749. device_status.lamp1_status = 1;
  1750. device_status.lamp2_status = 0;
  1751. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1752. }
  1753. else if (device_status.light_over_tim<7200) {
  1754. device_status.work_status = 1;
  1755. device_status.lamp_status = 0;
  1756. device_status.lamp1_status = 0;
  1757. device_status.lamp2_status = 1;
  1758. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1759. }
  1760. }
  1761. else if (tp==9) {
  1762. if(device_status.light_over_tim>6*3600)
  1763. {
  1764. device_status.work_status = 1;
  1765. device_status.lamp_status = 1;
  1766. device_status.lamp1_status = 0;
  1767. device_status.lamp2_status = 0;
  1768. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1769. }
  1770. else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
  1771. device_status.work_status = 1;
  1772. device_status.lamp_status = 0;
  1773. device_status.lamp1_status = 1;
  1774. device_status.lamp2_status = 0;
  1775. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1776. }
  1777. else if (device_status.light_over_tim<3*3600) {
  1778. device_status.work_status = 1;
  1779. device_status.lamp_status = 0;
  1780. device_status.lamp1_status = 0;
  1781. device_status.lamp2_status = 1;
  1782. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1783. }
  1784. }
  1785. }
  1786. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1787. void HardWare_Check(uint8_t boot)
  1788. {
  1789. if(boot==0&&device_status.version_type!=6)
  1790. {
  1791. //停止所有动作 -完成
  1792. HardWare_Init(boot);
  1793. }
  1794. else {
  1795. //停止所有动作
  1796. //读取记录待机功耗(实测大概70mA)
  1797. //(需减去屏幕的功耗大概120mA)
  1798. //动作上仓门,读取功率值保存
  1799. //动作下仓门,读取功率值保存
  1800. //动作清扫,读取功率值保存
  1801. //打开镇流器,读取功率值保存
  1802. //打开海康相机供电,读取功率值保存
  1803. //打开补光灯,读取功率值保存
  1804. //打开路由器/RTU供电,读取功率值保存
  1805. //打开加热,读取功率值保存
  1806. }
  1807. }
  1808. #if 0
  1809. //工作状态检测
  1810. void WorkCheck(void)
  1811. {
  1812. static rt_uint32_t light_timeout = 3600;
  1813. //雨控检测,温控检测,电池电压检测
  1814. while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  1815. {
  1816. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1817. if(device_status.timeSwitch==1)
  1818. {
  1819. LOG_I("***********时控*****************");
  1820. if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
  1821. device_status.work_status = 1;
  1822. LOG_I("24 hours work...");
  1823. #if LAMP_EN == 1
  1824. device_status.lamp_status = 1;
  1825. device_status.lamp1_status = 0;
  1826. device_status.lamp2_status = 0;
  1827. if(device_status.sun_status==1){
  1828. ctr_lamp(OFF, 1);
  1829. ctr_lamp(OFF, 2);
  1830. ctr_lamp(OFF, 3);
  1831. }
  1832. #endif
  1833. }
  1834. //如果开始和结束是同一天
  1835. if(device_status.startBar<device_status.stopBar)
  1836. {
  1837. LOG_I("开始和结束是同一天");
  1838. time_t now;
  1839. time(&now);
  1840. static struct tm nowtime; //现在
  1841. static struct tm starttime; //开始
  1842. static struct tm endtime; //结束
  1843. //获取当前时间戳
  1844. nowtime =*localtime(&now);
  1845. nowtime.tm_hour = nowtime.tm_hour-8;
  1846. //获取定时开始的时间戳
  1847. starttime = *localtime(&now);
  1848. starttime.tm_hour = device_status.startBar-8;
  1849. starttime.tm_min = 0;
  1850. starttime.tm_sec = 0;
  1851. //获取定时结束的时间戳
  1852. endtime = *localtime(&now);
  1853. endtime.tm_hour = device_status.stopBar-8;
  1854. endtime.tm_min = 0;
  1855. endtime.tm_sec = 0;
  1856. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1857. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1858. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  1859. {
  1860. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1861. device_status.work_status = 1;
  1862. }
  1863. //如果当前时间小于开始时间
  1864. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  1865. {
  1866. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1867. device_status.work_status = 0;
  1868. }
  1869. //当前时间大于结束时间
  1870. else {
  1871. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1872. device_status.work_status = 0;
  1873. }
  1874. #if LAMP_EN == 1
  1875. //如果当前时间超过20点,未到21点
  1876. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
  1877. {
  1878. LOG_I("3led:20~21");
  1879. device_status.lamp_status = 1;
  1880. device_status.lamp1_status = 0;
  1881. device_status.lamp2_status = 0;
  1882. }
  1883. else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
  1884. LOG_I("3led:21~22");
  1885. device_status.lamp1_status = 1;
  1886. device_status.lamp_status = 0;
  1887. device_status.lamp2_status = 0;
  1888. }
  1889. else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
  1890. LOG_I("3led:22~23");
  1891. device_status.lamp2_status = 1;
  1892. device_status.lamp_status = 0;
  1893. device_status.lamp1_status =0;
  1894. }
  1895. #endif
  1896. }
  1897. //如果结束时间是第二天
  1898. else if (device_status.startBar>device_status.stopBar) {
  1899. time_t now;
  1900. time(&now);
  1901. static struct tm nowtime; //现在
  1902. static struct tm starttime; //开始
  1903. static struct tm endtime; //结束
  1904. //获取当前时间戳
  1905. nowtime =*localtime(&now);
  1906. nowtime.tm_hour = nowtime.tm_hour-8;
  1907. //获取定时开始的时间戳
  1908. starttime = *localtime(&now);
  1909. starttime.tm_hour = device_status.startBar-8;
  1910. starttime.tm_min = 0;
  1911. starttime.tm_sec = 0;
  1912. //获取定时结束的时间戳
  1913. endtime = *localtime(&now);
  1914. endtime.tm_hour = device_status.stopBar-8;
  1915. endtime.tm_min = 0;
  1916. endtime.tm_sec = 0;
  1917. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1918. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  1919. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  1920. {
  1921. //获取定时结束的时间戳
  1922. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1923. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1924. endtime.tm_min = 0;
  1925. endtime.tm_sec = 0;
  1926. device_status.work_status = 1;
  1927. LOG_I("当前前时间大于开始时间,且没有开始工作");
  1928. }
  1929. //当前时间小于开始时间
  1930. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  1931. {
  1932. //获取定时结束的时间戳
  1933. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1934. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1935. endtime.tm_min = 0;
  1936. endtime.tm_sec = 0;
  1937. //如果当前时间戳小于结束时间戳
  1938. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  1939. {
  1940. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  1941. device_status.work_status = 1;
  1942. }
  1943. else
  1944. {
  1945. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  1946. device_status.work_status = 0; //不在工作时间,待机
  1947. }
  1948. }
  1949. }
  1950. }
  1951. else {
  1952. LOG_I("光控定时模式!");
  1953. /*
  1954. time_t now;
  1955. time(&now);
  1956. static struct tm nowstamp;
  1957. nowstamp =*localtime(&now);
  1958. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  1959. static rt_uint32_t nowstamp_num = 0;
  1960. nowstamp_num = mktime(&nowstamp);
  1961. rt_kprintf("now stamp:%d\n",nowstamp_num);
  1962. */
  1963. if(device_status.sun_status==0&&device_status.light_over_tim!=0)
  1964. {
  1965. device_status.light_over_tim--;
  1966. light_timeout = 3600;
  1967. #if LAMP_EN == 1
  1968. Led_Check(device_status.sunBar);
  1969. #else
  1970. device_status.work_status = 1;;
  1971. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1972. #endif
  1973. }
  1974. else
  1975. {
  1976. light_timeout --;
  1977. //没有在测试并且没有在自检
  1978. if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
  1979. {
  1980. ctr_lamp(OFF,1);
  1981. #if LAMP_EN == 1
  1982. ctr_lamp(OFF,2);
  1983. ctr_lamp(OFF,3);
  1984. #endif
  1985. }
  1986. device_status.work_status = 0;
  1987. if(light_timeout==0) device_status.light_over_tim=0;
  1988. if(device_status.light_over_tim==0&&device_status.sun_status==1) device_status.light_over_tim = device_status.sunBar * 3600;
  1989. LOG_I("光控中,白天:%d!!!",device_status.sun_status);
  1990. }
  1991. }
  1992. rt_thread_delay(1000);
  1993. }
  1994. LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  1995. device_status.work_status = 0;
  1996. rt_thread_delay(1000);
  1997. }
  1998. #endif
  1999. void WorkCheck(void)
  2000. {
  2001. static rt_uint32_t light_timeout = 3600;
  2002. while(device_status.ds == 1 &&
  2003. device_status.rain_status == 0 &&
  2004. device_status.temp_status == 0 &&
  2005. device_status.bat_status == 0)
  2006. {
  2007. if(device_status.timeSwitch == 1) // 时控模式
  2008. {
  2009. LOG_I("***********时控*****************");
  2010. if(device_status.startBar == device_status.stopBar)
  2011. {
  2012. // 开始结束时间相同则24小时模式
  2013. device_status.work_status = 1;
  2014. rt_thread_delay(10000);
  2015. continue;
  2016. }
  2017. time_t now;
  2018. time(&now);
  2019. struct tm now_tm = *localtime(&now);
  2020. rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
  2021. rt_uint32_t start_sec = device_status.startBar * 3600;
  2022. rt_uint32_t end_sec = device_status.stopBar * 3600;
  2023. // 修复跨天判断逻辑
  2024. if (start_sec < end_sec)
  2025. {
  2026. // 不跨天模式
  2027. device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
  2028. }
  2029. else
  2030. {
  2031. // 跨天模式
  2032. device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
  2033. }
  2034. LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
  2035. device_status.work_status ? "工作" : "待机",
  2036. now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
  2037. device_status.startBar, device_status.stopBar);
  2038. rt_thread_delay(10000);
  2039. }
  2040. else // 光控模式
  2041. {
  2042. LOG_I("光控定时模式!");
  2043. if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
  2044. {
  2045. device_status.light_over_tim--;
  2046. light_timeout = 3600; // 重置超时计数器
  2047. device_status.work_status = 1;
  2048. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  2049. }
  2050. else
  2051. {
  2052. // 仅在白天递减超时计数器
  2053. if(device_status.sun_status == 1 && light_timeout > 0) {
  2054. light_timeout--;
  2055. }
  2056. device_status.work_status = 0;
  2057. //没有在测试并且没有在自检
  2058. if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
  2059. {
  2060. ctr_lamp(OFF,1);
  2061. }
  2062. // 连续1小时白天后重置
  2063. if(light_timeout == 0) {
  2064. device_status.light_over_tim = 0;
  2065. light_timeout = 3600; // 重置防止负数
  2066. }
  2067. // 白天且倒计时结束:重置夜晚时长
  2068. if(device_status.light_over_tim == 0 &&
  2069. device_status.sun_status == 1)
  2070. {
  2071. device_status.light_over_tim = device_status.sunBar * 3600;
  2072. }
  2073. }
  2074. }
  2075. rt_thread_delay(1000);
  2076. }
  2077. // 异常状态处理
  2078. device_status.work_status = 0;
  2079. rt_thread_delay(1000);
  2080. }
  2081. void WorkTask_BZY(void)
  2082. {
  2083. if(device_status.ds==1)
  2084. {
  2085. //时间段判断
  2086. //先判断第一个时间段
  2087. time_t now;
  2088. time(&now);
  2089. static struct tm now_stamp; //现在
  2090. static struct tm cul_sh1_stamp; //开始1
  2091. static struct tm cul_eh1_stamp; //结束1
  2092. static struct tm cul_sh2_stamp; //开始2
  2093. static struct tm cul_eh2_stamp; //结束2
  2094. static struct tm cul_sh3_stamp; //开始3
  2095. static struct tm cul_eh3_stamp; //结束3
  2096. now_stamp = *localtime(&now);
  2097. //获取定时开始的时间戳
  2098. cul_sh1_stamp = *localtime(&now);
  2099. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2100. cul_sh1_stamp.tm_min = 0;
  2101. cul_sh1_stamp.tm_sec = 0;
  2102. cul_sh2_stamp = *localtime(&now);
  2103. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2104. cul_sh2_stamp.tm_min = 0;
  2105. cul_sh2_stamp.tm_sec = 0;
  2106. cul_sh3_stamp = *localtime(&now);
  2107. cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
  2108. cul_sh3_stamp.tm_min = 0;
  2109. cul_sh3_stamp.tm_sec = 0;
  2110. //获取定时结束的时间戳
  2111. cul_eh1_stamp = *localtime(&now);
  2112. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2113. cul_eh1_stamp.tm_min = 0;
  2114. cul_eh1_stamp.tm_sec = 0;
  2115. cul_eh2_stamp = *localtime(&now);
  2116. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2117. cul_eh2_stamp.tm_min = 0;
  2118. cul_eh2_stamp.tm_sec = 0;
  2119. cul_eh3_stamp = *localtime(&now);
  2120. cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
  2121. cul_eh3_stamp.tm_min = 0;
  2122. cul_eh3_stamp.tm_sec = 0;
  2123. LOG_I("采集时间1-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh1_stamp.tm_year+1900,cul_sh1_stamp.tm_mon+1,cul_sh1_stamp.tm_mday,cul_sh1_stamp.tm_hour,cul_sh1_stamp.tm_min,cul_sh1_stamp.tm_sec);
  2124. LOG_I("采集时间2-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh2_stamp.tm_year+1900,cul_sh2_stamp.tm_mon+1,cul_sh2_stamp.tm_mday,cul_sh2_stamp.tm_hour,cul_sh2_stamp.tm_min,cul_sh2_stamp.tm_sec);
  2125. LOG_I("采集时间3-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh3_stamp.tm_year+1900,cul_sh3_stamp.tm_mon+1,cul_sh3_stamp.tm_mday,cul_sh3_stamp.tm_hour,cul_sh3_stamp.tm_min,cul_sh3_stamp.tm_sec);
  2126. LOG_I("结束时间1-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh1_stamp.tm_year+1900,cul_eh1_stamp.tm_mon+1,cul_eh1_stamp.tm_mday,cul_eh1_stamp.tm_hour,cul_eh1_stamp.tm_min,cul_eh1_stamp.tm_sec);
  2127. LOG_I("结束时间2-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh2_stamp.tm_year+1900,cul_eh2_stamp.tm_mon+1,cul_eh2_stamp.tm_mday,cul_eh2_stamp.tm_hour,cul_eh2_stamp.tm_min,cul_eh2_stamp.tm_sec);
  2128. LOG_I("结束时间3-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh3_stamp.tm_year+1900,cul_eh3_stamp.tm_mon+1,cul_eh3_stamp.tm_mday,cul_eh3_stamp.tm_hour,cul_eh3_stamp.tm_min,cul_eh3_stamp.tm_sec);
  2129. //此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2130. //当前时间戳小于第一段开始时间戳
  2131. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2132. {
  2133. time_t now;
  2134. time(&now);
  2135. cul_sh1_stamp = *localtime(&now);
  2136. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2137. cul_sh1_stamp.tm_min = 0;
  2138. cul_sh1_stamp.tm_sec = 0;
  2139. now_stamp = *localtime(&now);
  2140. LOG_I("======收集时间1:%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh1_stamp.tm_year+1900,cul_sh1_stamp.tm_mon+1,cul_sh1_stamp.tm_mday,cul_sh1_stamp.tm_hour,cul_sh1_stamp.tm_min,cul_sh1_stamp.tm_sec);
  2141. LOG_I("======未到收集时间1:%04d年%02d月%02d日%02d时%02d分%02d秒.",now_stamp.tm_year+1900,now_stamp.tm_mon+1,now_stamp.tm_mday,now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec);
  2142. LOG_D("run_sta:%d",device_status.run_sta);
  2143. }
  2144. //当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2145. if(difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0&&difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2146. {
  2147. time_t now;
  2148. time(&now);
  2149. cul_sh2_stamp = *localtime(&now);
  2150. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2151. cul_sh2_stamp.tm_min = 0;
  2152. cul_sh2_stamp.tm_sec = 0;
  2153. now_stamp = *localtime(&now);
  2154. LOG_I("==============收集时间2:%04d年%02d月%02d日%02d时%02d分%02d秒.\n",cul_sh2_stamp.tm_year+1900,cul_sh2_stamp.tm_mon+1,cul_sh2_stamp.tm_mday,cul_sh2_stamp.tm_hour,cul_sh2_stamp.tm_min,cul_sh2_stamp.tm_sec);
  2155. LOG_I("==============未到收集时间2:%04d年%02d月%02d日%02d时%02d分%02d秒.\n",now_stamp.tm_year+1900,now_stamp.tm_mon+1,now_stamp.tm_mday,now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec);
  2156. LOG_D("run_sta:%d",device_status.run_sta);
  2157. }
  2158. //如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2159. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0&&difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2160. {
  2161. //转盘到涂凡士林位置
  2162. if(device_status.run_sta==0)
  2163. {
  2164. LOG_I("start to collect!!!");
  2165. DTU_Write("collect.mp3");
  2166. ctr_turn(90,4);
  2167. rt_thread_delay(2000);
  2168. //涂凡士林
  2169. ctr_Petroleum_jelly(10);
  2170. rt_thread_delay(5000);
  2171. }
  2172. /*转盘到采集位置*/
  2173. if(device_status.run_sta==4)
  2174. ctr_turn(90,1);
  2175. //只有开始和结束时刻不同的时间段,才有效
  2176. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)||(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0))
  2177. {
  2178. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)&& difftime(mktime(&now_stamp),mktime(&cul_sh1_stamp)) > 0)
  2179. {
  2180. device_status.work_status = 1;
  2181. ctr_Collect_Fan(ON);
  2182. //当前时间戳小于第一段结束时间戳
  2183. while(difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp))>0)
  2184. {
  2185. time(&now);
  2186. now_stamp = *localtime(&now);
  2187. cul_eh1_stamp = *localtime(&now);
  2188. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2189. cul_eh1_stamp.tm_min = 0;
  2190. cul_eh1_stamp.tm_sec = 0;
  2191. if(device_status.run_sta!=1) break;
  2192. LOG_I("1===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh1_stamp));
  2193. rt_thread_mdelay(10000);
  2194. }
  2195. }
  2196. else {
  2197. device_status.work_status=0;
  2198. ctr_Collect_Fan(OFF);
  2199. LOG_I("未到收集1时间!");
  2200. }
  2201. if(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0 && difftime(mktime(&now_stamp),mktime(&cul_sh2_stamp)) > 0)
  2202. {
  2203. device_status.work_status = 1;
  2204. ctr_Collect_Fan(ON);
  2205. while(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp))>0)
  2206. {
  2207. time(&now);
  2208. now_stamp = *localtime(&now);
  2209. cul_eh2_stamp = *localtime(&now);
  2210. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2211. cul_eh2_stamp.tm_min = 0;
  2212. cul_eh2_stamp.tm_sec = 0;
  2213. if(device_status.run_sta!=1) break;
  2214. LOG_I("2===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh2_stamp));
  2215. rt_thread_mdelay(10000);
  2216. }
  2217. }
  2218. else {
  2219. device_status.work_status=0;
  2220. ctr_Collect_Fan(OFF);
  2221. LOG_I("未到收集2时间!");
  2222. }
  2223. }
  2224. else
  2225. {
  2226. LOG_I("this collect time is 0s,The wait time cannot be negative!");
  2227. }
  2228. }
  2229. if(device_status.run_sta==2)
  2230. {
  2231. ctr_Collect_Fan(OFF);
  2232. device_status.develop_flag = 1;
  2233. device_status.work_status = 2;
  2234. ctr_develop(); //培养
  2235. ctr_turn(90,3);
  2236. }
  2237. if(device_status.run_sta==3)
  2238. {
  2239. ctr_Collect_Fan(OFF);
  2240. device_status.work_status = 3;
  2241. device_status.autotakepic=1; //对焦拍照
  2242. }
  2243. //在培养之前再次确认时间戳
  2244. time(&now);
  2245. now_stamp = *localtime(&now);
  2246. cul_eh2_stamp = *localtime(&now);
  2247. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2248. cul_eh2_stamp.tm_min = 0;
  2249. cul_eh2_stamp.tm_sec = 0;
  2250. //当前时间戳大于收集结束时间戳并且run_sta==1
  2251. if(device_status.run_sta==1 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) > 0)
  2252. {
  2253. ctr_Collect_Fan(OFF);
  2254. LOG_I("===============collect ok,turn to drop!!!");
  2255. device_status.develop_flag=1;
  2256. device_status.work_status=2; //现在是培养
  2257. DTU_Write("develop.mp3");
  2258. if(device_status.run_sta==1)
  2259. ctr_turn(90,2); /*转盘到培养位置*/
  2260. rt_thread_delay(1000);
  2261. ctr_shake(ON,device_status.shake_sec);
  2262. rt_thread_delay(1000);
  2263. ctr_develop(); //培养
  2264. if(device_status.run_sta==2)
  2265. ctr_turn(90,3); /*转盘到拍照位置*/
  2266. rt_thread_delay(1000);
  2267. device_status.work_status=3; //现在是拍照
  2268. device_status.autotakepic=1; //对焦拍照
  2269. while(device_status.autotakepic==0)
  2270. {
  2271. rt_thread_delay(1000);
  2272. LOG_I("正在对焦拍照............");
  2273. }
  2274. device_status.work_status = 0; //待机
  2275. DTU_Write("wait.mp3");
  2276. LOG_I("=====================work finished==================");
  2277. }
  2278. rt_thread_delay(1000);
  2279. }
  2280. device_status.work_status = 0; //待机
  2281. LOG_W("==================!!!设备已待机!!!===================");
  2282. }
  2283. void WorkTask_BZYV2(void)
  2284. {
  2285. //打开采集风机
  2286. ctr_Collect_Fan(ON);
  2287. //打开胶带步进电机
  2288. //等待采集结束
  2289. //拍照
  2290. //打开相机供电
  2291. //打开补光灯
  2292. //滑台归位
  2293. //滑台启动
  2294. }
  2295. //工作任务流程s
  2296. void WorkTask(void)
  2297. {
  2298. static int clt_time = 0; //收集时间差秒数
  2299. static int heat_time = 0;
  2300. LOG_I("工作状态:%d",device_status.work_status);
  2301. LOG_I("开关机状态:%d",device_status.ds);
  2302. while(device_status.work_status==1&&device_status.temp_status==0&&device_status.bat_status==0&&device_status.rain_status==0&&device_status.ds==1&&device_status.clear_status==0)
  2303. {
  2304. device_status.work_done = 0;
  2305. if(clt_time==0)
  2306. {
  2307. #if 0
  2308. if(device_status.version_type==41&&atoi(device_status.power)<350)
  2309. {
  2310. LOG_W("相机电流不足!");
  2311. char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
  2312. DTU_Write("%s",ctr_hk_p_warn);
  2313. rt_free(ctr_hk_p_warn);
  2314. }
  2315. #endif
  2316. #if 0//LAMP_EN == 0
  2317. ctr_Fan_PUT(ON);
  2318. #endif
  2319. DTU_Write("workstart.mp3");
  2320. }
  2321. //1.打开灯管
  2322. #if LAMP_EN == 1
  2323. if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
  2324. {
  2325. ctr_lamp(ON,1);
  2326. ctr_lamp(OFF,2);
  2327. ctr_lamp(OFF,3);
  2328. }
  2329. else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
  2330. ctr_lamp(OFF,1);
  2331. ctr_lamp(ON,2);
  2332. ctr_lamp(OFF,3);
  2333. }
  2334. else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
  2335. ctr_lamp(OFF,1);
  2336. ctr_lamp(OFF,2);
  2337. ctr_lamp(ON,3);
  2338. }
  2339. #else
  2340. ctr_lamp(ON,1);
  2341. if(device_status.version_type==12)
  2342. {
  2343. ctr_Heat(ON);
  2344. }
  2345. #endif
  2346. LOG_I("打开灯管!!!");
  2347. #if 0
  2348. rt_thread_delay(2000);
  2349. if(atoi(device_status.power)<450)
  2350. {
  2351. LOG_I("Current is:%d",atoi(device_status.power));
  2352. if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
  2353. {
  2354. char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
  2355. DTU_Write("%s",lamp_err_warn);
  2356. rt_free(lamp_err_warn);
  2357. }
  2358. }
  2359. #endif
  2360. if(device_status.version_type!=5)
  2361. {
  2362. rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
  2363. //2.打开上仓门
  2364. LOG_I("打开上仓门!!!");
  2365. device_status.ctr_up_motor = 1;
  2366. //3.收集
  2367. clt_time = device_status.clt_time * 60;
  2368. while(clt_time!=1)
  2369. {
  2370. #if 0//LAMP_EN == 0
  2371. ctr_Fan_IN(ON);
  2372. #endif
  2373. clt_time --;
  2374. rt_thread_delay(1000);
  2375. #if 0//LAMP_EN == 0
  2376. if(clt_time%30==0)
  2377. ctr_Fan_PUT(OFF);
  2378. #endif
  2379. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  2380. HMI_WRITE("workSta.g0.txt=\"正在收集.....剩余时间:%d分-%d秒\"",device_status.clt_time,clt_time);
  2381. //如果触发异常
  2382. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2383. {
  2384. ctr_lamp(OFF,1);
  2385. #if LAMP_EN == 1
  2386. ctr_lamp(OFF,2);
  2387. ctr_lamp(OFF,3);
  2388. #endif
  2389. #if 0//LAMP_EN == 0
  2390. ctr_Fan_IN(OFF);
  2391. #endif
  2392. rt_kprintf("异常退出!!!\n");
  2393. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2394. break;
  2395. }
  2396. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2397. {
  2398. ctr_lamp(OFF,1);
  2399. #if LAMP_EN == 1
  2400. ctr_lamp(OFF,2);
  2401. ctr_lamp(OFF,3);
  2402. #endif
  2403. #if 0//LAMP_EN == 0
  2404. ctr_Fan_IN(OFF);
  2405. #endif
  2406. rt_kprintf("异常退出!!!\n");
  2407. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2408. break;
  2409. }
  2410. }
  2411. clt_time = 1;
  2412. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2413. {
  2414. ctr_lamp(OFF,1);
  2415. #if LAMP_EN == 1
  2416. ctr_lamp(OFF,2);
  2417. ctr_lamp(OFF,3);
  2418. #endif
  2419. #if 0//LAMP_EN == 0
  2420. ctr_Fan_IN(OFF);
  2421. #endif
  2422. rt_kprintf("异常退出!!!\n");
  2423. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2424. break;
  2425. }
  2426. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2427. {
  2428. ctr_lamp(OFF,1);
  2429. #if LAMP_EN == 1
  2430. ctr_lamp(OFF,2);
  2431. ctr_lamp(OFF,3);
  2432. #endif
  2433. #if 0//LAMP_EN == 0
  2434. ctr_Fan_IN(OFF);
  2435. #endif
  2436. rt_kprintf("异常退出!!!\n");
  2437. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2438. break;
  2439. }
  2440. #if 0//LAMP_EN == 0
  2441. ctr_Fan_IN(OFF);
  2442. #endif
  2443. //4.关闭上仓门
  2444. device_status.ctr_up_motor = 2;
  2445. rt_kprintf("关闭上仓门!!!\n");
  2446. HMI_WRITE("workSta.g0.txt=\"关闭上仓门!\"");
  2447. while(device_status.ctr_up_motor!=0)
  2448. {
  2449. rt_thread_delay(100);
  2450. LOG_I("等待上仓门关闭!!!");
  2451. }
  2452. //5.加热
  2453. if(device_status.heat_sw==0&&device_status.version_type!=12)
  2454. {
  2455. calorstat(device_status.heattime*60);
  2456. }
  2457. else {
  2458. heat_time = device_status.heattime * 60;
  2459. while(heat_time!=0)
  2460. {
  2461. heat_time--;
  2462. LOG_I("正在加热状态!!!");
  2463. rt_thread_delay(1000);
  2464. }
  2465. }
  2466. //6.打开下仓门
  2467. if(device_status.rain_status==0)
  2468. {
  2469. device_status.ctr_down_motor =1;
  2470. }
  2471. else {
  2472. device_status.ctr_down_motor = 2;
  2473. device_status.ctr_up_motor = 2;
  2474. }
  2475. //待下仓门完全打开
  2476. while(device_status.ctr_down_motor!=0)
  2477. {
  2478. rt_thread_delay(100);
  2479. rt_kprintf("等待下仓门打开!!!\n");
  2480. HMI_WRITE("workSta.g0.txt=\"等待下仓门打开!\"");
  2481. }
  2482. rt_thread_delay(3000);
  2483. //关闭下仓门
  2484. device_status.ctr_down_motor = 2;
  2485. while(device_status.ctr_down_motor!=0)
  2486. {
  2487. rt_thread_delay(100);
  2488. rt_kprintf("等待下仓门关闭!!!\n");
  2489. HMI_WRITE("workSta.g0.txt=\"等待下仓门关闭!\"");
  2490. }
  2491. //2022-04-12add:
  2492. LOG_I("打开上仓门!!!");
  2493. HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
  2494. device_status.ctr_up_motor = 1;
  2495. if(device_status.version_type==4||device_status.version_type==41||strstr(device_status.project,"A7_RTU_V3")!=RT_NULL)
  2496. {
  2497. //震动
  2498. ctr_shake(ON, device_status.shake_sec);
  2499. //补光&&拍照
  2500. LOG_I("拍照!!!");
  2501. HMI_WRITE("workSta.g0.txt=\"拍照!\"");
  2502. ctr_led(ON);
  2503. HK_TakePhoto();
  2504. //清扫
  2505. device_status.clear_status=1;
  2506. //清扫失效则使用震动
  2507. //ctr_shake(ON, 100);
  2508. }
  2509. }
  2510. else {
  2511. //打开高压
  2512. ctr_Heat(ON);
  2513. //打开补光
  2514. ctr_led(ON);
  2515. LOG_I("打开补光!!");
  2516. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  2517. //2.翻转清虫
  2518. while(rt_pin_read(CLEAR_L_LIMIT)==1) rt_thread_delay(20);
  2519. rt_thread_delay(500);
  2520. Hk_Take_io(); //触发海康相机拍照
  2521. rt_thread_delay(500);
  2522. ctr_turnv5(); //摆动清虫
  2523. LOG_I("摆动清虫!");
  2524. }
  2525. }
  2526. if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
  2527. {
  2528. rt_kprintf("-------------------not work--------------------\n");
  2529. device_status.work_status = 0;
  2530. }
  2531. //工作结束
  2532. if(device_status.work_done==0&&device_status.work_status==0)
  2533. {
  2534. DTU_Write("workdone");
  2535. HMI_WRITE("workSta.g0.txt=\"工作任务已完成!\"");
  2536. if (device_status.version_type==1) {
  2537. turnzp(); //2024-03-21 :开机不再转仓
  2538. }
  2539. ResetInit();
  2540. clt_time = 0;
  2541. }
  2542. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  2543. }
  2544. /* 入口函数-工作状态检测 */
  2545. static void Work_status_thread_entry(void *parameter)
  2546. {
  2547. static uint16_t sun_status_num = 120;
  2548. //如果是光控定时,进行光控监测的消抖
  2549. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  2550. {
  2551. rt_kprintf("光控定时!!!\n");
  2552. while(sun_status_num!=0)
  2553. {
  2554. sun_status_num--;
  2555. rt_thread_delay(1000);
  2556. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  2557. }
  2558. device_status.light_over_tim = device_status.sunBar * 3600;
  2559. device_status.test_flag = 0;
  2560. }
  2561. while(1)
  2562. {
  2563. WorkCheck();
  2564. }
  2565. }
  2566. /*入口函数-工作流程*/
  2567. static void Work_Loop_thread_entry(void *parameter)
  2568. {
  2569. rt_thread_delay(1000);
  2570. ResetInit();
  2571. while(1)
  2572. {
  2573. if(device_status.dtype==7)
  2574. {
  2575. WorkTask_BZY();
  2576. }
  2577. if(device_status.version_type!=6&&device_status.dtype==3)
  2578. {
  2579. WorkTask();
  2580. }
  2581. if(device_status.version_type==6)
  2582. {
  2583. WorkTask_XCT();
  2584. }
  2585. rt_thread_delay(1000);
  2586. }
  2587. }
  2588. /*入口函数清扫*/
  2589. static void Control_Clear_thread_entry(void *parameter)
  2590. {
  2591. static int selfcheck_cnt = 0;
  2592. float voltage_f = 0.0;
  2593. while(1)
  2594. {
  2595. #if ROBOT_EN ==1
  2596. ctr_Motor_Robot(ON);
  2597. rt_thread_delay(100);
  2598. #else
  2599. #if Color_EN ==1
  2600. /*复位*/
  2601. if(Read_Color_Key(KEY_RESET)==1)
  2602. {
  2603. ctr_Color_board(RESET, 1200);
  2604. rt_thread_delay(5000);
  2605. }
  2606. #else
  2607. if(device_status.selfcheck_ws==1){
  2608. selfcheck_cnt ++;
  2609. if(selfcheck_cnt==1){
  2610. ctr_lamp(ON,1);
  2611. rt_thread_delay(1000);
  2612. device_status.ctr_up_motor = 1;
  2613. device_status.ctr_down_motor = 1;
  2614. //记录当前电压
  2615. voltage_f = atof(device_status.voltage);
  2616. rt_thread_delay(1500);
  2617. //开启加热
  2618. ctr_Heat(ON);
  2619. }
  2620. if(selfcheck_cnt==50){
  2621. double voltage_n = atof(device_status.voltage);
  2622. //判断当前电压和加热前的电压差
  2623. if(voltage_f-voltage_n<0.5){
  2624. device_status.heat_sta = 1; //加热异常
  2625. //上报预警,加热故障
  2626. char *heat_warn = makeJson_Warn("加热报警", "heat-error");
  2627. DTU_Write("%s", heat_warn);
  2628. rt_free(heat_warn);
  2629. }else{
  2630. device_status.heat_sta = 0;
  2631. }
  2632. rt_thread_delay(1000);
  2633. //关闭加热
  2634. ctr_Heat(OFF);
  2635. //振动
  2636. ctr_shake(ON, 1);
  2637. //device_status.clear_status = 1;
  2638. ctr_lamp(OFF, 1);
  2639. }
  2640. if(selfcheck_cnt>1800){ //超过3分钟
  2641. device_status.selfcheck_ws = 0;
  2642. device_status.ctr_up_motor = 0;
  2643. device_status.ctr_down_motor = 0;
  2644. //
  2645. device_status.camsta = 1; //相机异常
  2646. device_status.led_sta = 1;
  2647. //上报自检结果
  2648. //上报自检结果
  2649. char *json_temp = makeJson_selfCheck_(1);
  2650. DTU_Write("%s",json_temp);
  2651. free(json_temp);
  2652. }
  2653. }
  2654. if(device_status.selfcheck_ws==0){
  2655. selfcheck_cnt = 0;
  2656. }
  2657. if(device_status.clear_status==1)
  2658. {
  2659. if(ctr_clear(1200)==0)
  2660. ctr_TG_Clear(400);
  2661. }
  2662. rt_thread_delay(100);
  2663. #endif
  2664. #endif
  2665. }
  2666. }
  2667. /*入口函数加热*/
  2668. static void Control_Heat_thread_entry(void *parameter)
  2669. {
  2670. while(1)
  2671. {
  2672. if(device_status.work_status==1&&device_status.heat_sw==1)
  2673. {
  2674. ctr_lamp(ON, 1);
  2675. rt_thread_delay(10000);
  2676. calorstat(device_status.heattime*60);
  2677. }
  2678. else
  2679. {
  2680. LOG_I("Not calorstat!%d",device_status.selfcheck_ws);
  2681. if(device_status.selfcheck_ws==2)
  2682. {
  2683. static int total_seconds = 200;
  2684. static int current_second = 0;
  2685. while(current_second <= total_seconds)
  2686. {
  2687. int process = (current_second * 100) / total_seconds;
  2688. device_status.process = process / 100.0;
  2689. LOG_I("process:%d",process);
  2690. HMI_WRITE("selfcheck.s106.val=%d",process);
  2691. rt_thread_delay(1000);
  2692. current_second++;
  2693. if(device_status.selfcheck_ws==0)
  2694. {
  2695. HMI_WRITE("selfcheck.s106.val=100");
  2696. break;
  2697. }
  2698. }
  2699. HMI_WRITE("selfcheck.s106.val=100");
  2700. }
  2701. }
  2702. rt_thread_delay(1000);
  2703. }
  2704. }
  2705. /*清扫线程*/
  2706. int Control_clear(void)
  2707. {
  2708. /* 创建线程*/
  2709. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  2710. Control_Clear_thread_entry, RT_NULL,
  2711. 2048, //2048
  2712. 24, //23
  2713. WORK_CHECK_THREAD_TIMESLICE); //5
  2714. if(tid_ctr!=RT_NULL)
  2715. {
  2716. rt_thread_startup(tid_ctr);
  2717. }
  2718. return 0;
  2719. }
  2720. /*恒温加热线程*/
  2721. int Control_heat(void)
  2722. {
  2723. /* 创建线程*/
  2724. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  2725. Control_Heat_thread_entry, RT_NULL,
  2726. 1024, //2048
  2727. 25, //23
  2728. WORK_CHECK_THREAD_TIMESLICE); //5
  2729. if(tid_heat!=RT_NULL)
  2730. {
  2731. rt_thread_startup(tid_heat);
  2732. }
  2733. return 0;
  2734. }
  2735. /* 创建线程 -工作状态检测*/
  2736. int Workstatus_check(void)
  2737. {
  2738. /* 创建线程*/
  2739. tid_wkstc = rt_thread_create("work_status_check_thread",
  2740. Work_status_thread_entry, RT_NULL,
  2741. WORK_CHECK_THREAD_STACK_SIZE, //1024
  2742. WORK_CHECK_THREAD_PRIORITY, //23
  2743. WORK_CHECK_THREAD_TIMESLICE); //5
  2744. if(tid_wkstc!=RT_NULL)
  2745. {
  2746. rt_thread_startup(tid_wkstc);
  2747. }
  2748. return 0;
  2749. }
  2750. /*工作流程线程*/
  2751. int Work_Loop_Task(void)
  2752. {
  2753. /* 创建线程*/
  2754. tid_workloop = rt_thread_create("work_loop_thread",
  2755. Work_Loop_thread_entry, RT_NULL,
  2756. WORK_LOOP_THREAD_STACK_SIZE, //2048
  2757. WORK_LOOP_THREAD_PRIORITY, //12
  2758. WORK_LOOP_THREAD_TIMESLICE); //5
  2759. #if Color_EN == 0
  2760. if(tid_workloop!=RT_NULL)
  2761. {
  2762. rt_thread_startup(tid_workloop);
  2763. }
  2764. #endif
  2765. return 0;
  2766. }
  2767. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  2768. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  2769. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  2770. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);