control.c 93 KB

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