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. /***************************************************************************/
  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. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  577. {
  578. device_status.collect_fan_status = status_collect;
  579. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  580. if(status_collect==OFF)
  581. {
  582. rt_pin_write(Collect_Fan,OFF);
  583. }
  584. if(status_collect==ON)
  585. {
  586. rt_pin_write(Collect_Fan,ON);
  587. }
  588. return device_status.collect_fan_status;
  589. }
  590. /*************************************************
  591. Function: ctr_develop
  592. Description: 培养载玻片孢子
  593. Calls:
  594. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  595. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  596. Input: v=0(复位) v=90转90度
  597. Output: NULL
  598. Return: NULL
  599. Others: NULL
  600. *************************************************/
  601. void ctr_develop(void)
  602. {
  603. rt_kprintf("===============开始培养=================:%d\n",device_status.cul_time);
  604. //已经培养的时间-分钟
  605. device_status.stay_time = 0;
  606. rt_uint32_t ii = 0;
  607. while(device_status.develop_flag==1)
  608. {
  609. float stayedtime = 0.01;
  610. char stayed[5];
  611. stayedtime = (float)device_status.stay_time / 60.0;
  612. sprintf(stayed,"%0.02f",stayedtime);
  613. HMI_WRITE("workSta.staytime.txt=\"%s\"",stayed);
  614. ii++;
  615. LOG_I("developing...................................%d\n",ii);
  616. LOG_I("============================设定的培养温度:%d\n",device_status.heatvalue);
  617. LOG_I("============================培养仓实时温度:%d\n",device_status.pre_temp);
  618. if(device_status.pre_temp<(device_status.heatvalue-5))
  619. {
  620. //未制冷
  621. if(device_status.cold_status==0)
  622. {
  623. ctr_Heat(ON);
  624. }
  625. }
  626. else
  627. {
  628. ctr_Heat(OFF);
  629. }
  630. LOG_I("============================制冷开关:%d\n",device_status.cold_sw);
  631. if(device_status.cold_sw==1)
  632. {
  633. if(device_status.pre_temp>(device_status.heatvalue-10))
  634. {
  635. if(device_status.heat_status==0)
  636. {
  637. ctr_Cold(ON);
  638. }
  639. }
  640. else
  641. {
  642. ctr_Cold(OFF);
  643. }
  644. }
  645. if(ii%60==0)
  646. {
  647. device_status.stay_time++;
  648. if(device_status.stay_time / 60 == device_status.cul_time) device_status.develop_flag = 0;
  649. LOG_I("developed...................................%d分钟\n",device_status.stay_time);
  650. }
  651. if(device_status.box_temp>35)
  652. {
  653. ctr_Cool_Fan(ON);
  654. }
  655. else if (device_status.box_temp<30)
  656. {
  657. ctr_Cool_Fan(OFF);
  658. }
  659. rt_thread_delay(1000);
  660. }
  661. ctr_Cold(OFF);
  662. ctr_Heat(OFF);
  663. LOG_I("=========!!!培养完成!!!==========");
  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. ctr_clear(OFF);
  1552. }
  1553. //拍照
  1554. void HK_TakePhoto(void)
  1555. {
  1556. //打开补光灯
  1557. DTU_Write("takephoto.mp3");
  1558. rt_thread_delay(10000);
  1559. char *takephotojson = makeJson_takephoto();
  1560. DTU_Write("%s",takephotojson);
  1561. rt_free(takephotojson);
  1562. //吸虫塔
  1563. if(device_status.version_type!=6)
  1564. {
  1565. ctr_led(ON);
  1566. if(device_status.version_type==48)
  1567. {
  1568. rt_thread_delay(1000*60);
  1569. }
  1570. else {
  1571. rt_thread_delay(1000*15);
  1572. }
  1573. }
  1574. //触发海康相机拍照
  1575. Hk_Take_io();
  1576. if(device_status.version_type!=6)
  1577. {
  1578. rt_thread_delay(1000*45);
  1579. }
  1580. else {
  1581. ctr_led(ON);
  1582. rt_thread_delay(1000*19);
  1583. }
  1584. ctr_led(OFF);
  1585. }
  1586. //光控测试任务
  1587. void SunTest(void)
  1588. {
  1589. rt_uint16_t ui_timeout_l = 0;
  1590. //未检测到光照,一秒扫描等待,超时30S
  1591. while(Read_Light_Voltage()<500)
  1592. {
  1593. ui_timeout_l ++;
  1594. rt_thread_delay(1000);
  1595. if(ui_timeout_l==30) break;
  1596. }
  1597. rt_thread_delay(3000);
  1598. if(Read_Light_Voltage()<500)
  1599. {
  1600. device_status.sun_status = 0;//光控状态
  1601. }
  1602. if(Read_Light_Voltage()>500)
  1603. {
  1604. rt_thread_delay(1000);
  1605. }
  1606. rt_thread_delay(3000);
  1607. if(Read_Light_Voltage()>500)
  1608. {
  1609. device_status.sun_status = 1;
  1610. ctr_lamp(OFF,1);
  1611. }
  1612. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1613. device_status.sun_test = 0;
  1614. device_status.work_status=0;
  1615. }
  1616. /*上电初始化*/
  1617. void ResetInit(void)
  1618. {
  1619. if(device_status.dtype==7)
  1620. {
  1621. ctr_Motor_Driver(0, 0, 0, 0);
  1622. //关闭电磁阀
  1623. ctr_shake(OFF, 0);
  1624. //关闭加热
  1625. ctr_Heat(OFF);
  1626. //关闭制冷
  1627. ctr_Cold(OFF);
  1628. //关闭补光灯
  1629. ctr_led(OFF);
  1630. //转盘复位
  1631. if(device_status.run_sta==0)
  1632. ctr_turn(0, 0);
  1633. }
  1634. if(device_status.version_type!=6&&device_status.version_type!=7)
  1635. {
  1636. device_status.work_done = 1;
  1637. //1.打开路由器供电
  1638. if(device_status.power_status==1)
  1639. {
  1640. ctr_router(ON);
  1641. ctr_RTU_DTU(ON);
  1642. //2.打开相机供电
  1643. ctr_photo(ON);
  1644. }
  1645. //3.关闭镇流器
  1646. ctr_lamp(OFF,1);
  1647. #if LAMP_EN == 1
  1648. ctr_lamp(OFF,2);
  1649. ctr_lamp(OFF,3);
  1650. #endif
  1651. //4.关闭震动电机
  1652. ctr_shake(OFF, 0);
  1653. //5.关闭加热
  1654. ctr_Heat(OFF);
  1655. //6.关闭补光灯
  1656. ctr_led(OFF);
  1657. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  1658. {
  1659. LOG_W("欠压!");
  1660. return;
  1661. }
  1662. //7.关闭上仓门
  1663. device_status.ctr_up_motor = 2;
  1664. // while(device_status.ctr_up_motor!=0)
  1665. // {
  1666. // LOG_I("关闭上仓门...");
  1667. // rt_thread_delay(100);
  1668. // }
  1669. //8.关闭下仓门
  1670. device_status.ctr_down_motor = 2;
  1671. while(device_status.ctr_down_motor!=0)
  1672. {
  1673. LOG_I("关闭下仓门....");
  1674. rt_thread_delay(100);
  1675. }
  1676. //9.清扫
  1677. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1678. {
  1679. LOG_W("异常退出!!!\n");
  1680. return;
  1681. }
  1682. #if 0//LAMP_EN == 0
  1683. ctr_Fan_PUT(OFF);
  1684. ctr_Fan_IN(OFF);
  1685. #endif
  1686. if(device_status.version_type==4||device_status.version_type==41)
  1687. {
  1688. device_status.clear_status=1;
  1689. while(device_status.clear_status==1){
  1690. rt_thread_delay(1000);
  1691. }
  1692. }
  1693. //排虫
  1694. if(device_status.handle_bugger==0){
  1695. device_status.run_sta = 111; //排虫
  1696. }else{
  1697. device_status.run_sta = 112; //收虫
  1698. }
  1699. }
  1700. else {
  1701. if(device_status.power_status==1)
  1702. {
  1703. //1.打开路由器供电
  1704. ctr_router(ON);
  1705. ctr_RTU_DTU(ON);
  1706. //2.打开相机供电
  1707. ctr_photo(ON);
  1708. }
  1709. //5.关闭加热
  1710. //6.关闭补光灯
  1711. ctr_led(OFF);
  1712. }
  1713. }
  1714. /*三色光源*/
  1715. void Led_Check(uint8_t tp)
  1716. {
  1717. if(tp==3)
  1718. {
  1719. if(device_status.light_over_tim>2*3600)
  1720. {
  1721. device_status.work_status = 1;
  1722. device_status.lamp_status = 1;
  1723. device_status.lamp1_status = 0;
  1724. device_status.lamp2_status = 0;
  1725. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1726. }
  1727. else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
  1728. device_status.work_status = 1;
  1729. device_status.lamp_status = 0;
  1730. device_status.lamp1_status = 1;
  1731. device_status.lamp2_status = 0;
  1732. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1733. }
  1734. else if (device_status.light_over_tim<1*3600) {
  1735. device_status.work_status = 1;
  1736. device_status.lamp_status = 0;
  1737. device_status.lamp1_status = 0;
  1738. device_status.lamp2_status = 1;
  1739. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1740. }
  1741. }
  1742. else if (tp==6) {
  1743. if(device_status.light_over_tim>4*3600)
  1744. {
  1745. device_status.work_status = 1;
  1746. device_status.lamp_status = 1;
  1747. device_status.lamp1_status = 0;
  1748. device_status.lamp2_status = 0;
  1749. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1750. }
  1751. else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
  1752. device_status.work_status = 1;
  1753. device_status.lamp_status = 0;
  1754. device_status.lamp1_status = 1;
  1755. device_status.lamp2_status = 0;
  1756. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1757. }
  1758. else if (device_status.light_over_tim<7200) {
  1759. device_status.work_status = 1;
  1760. device_status.lamp_status = 0;
  1761. device_status.lamp1_status = 0;
  1762. device_status.lamp2_status = 1;
  1763. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1764. }
  1765. }
  1766. else if (tp==9) {
  1767. if(device_status.light_over_tim>6*3600)
  1768. {
  1769. device_status.work_status = 1;
  1770. device_status.lamp_status = 1;
  1771. device_status.lamp1_status = 0;
  1772. device_status.lamp2_status = 0;
  1773. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1774. }
  1775. else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
  1776. device_status.work_status = 1;
  1777. device_status.lamp_status = 0;
  1778. device_status.lamp1_status = 1;
  1779. device_status.lamp2_status = 0;
  1780. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1781. }
  1782. else if (device_status.light_over_tim<3*3600) {
  1783. device_status.work_status = 1;
  1784. device_status.lamp_status = 0;
  1785. device_status.lamp1_status = 0;
  1786. device_status.lamp2_status = 1;
  1787. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1788. }
  1789. }
  1790. }
  1791. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1792. void HardWare_Check(uint8_t boot)
  1793. {
  1794. if(boot==0&&device_status.version_type!=6)
  1795. {
  1796. //停止所有动作 -完成
  1797. HardWare_Init(boot);
  1798. }
  1799. else {
  1800. //停止所有动作
  1801. //读取记录待机功耗(实测大概70mA)
  1802. //(需减去屏幕的功耗大概120mA)
  1803. //动作上仓门,读取功率值保存
  1804. //动作下仓门,读取功率值保存
  1805. //动作清扫,读取功率值保存
  1806. //打开镇流器,读取功率值保存
  1807. //打开海康相机供电,读取功率值保存
  1808. //打开补光灯,读取功率值保存
  1809. //打开路由器/RTU供电,读取功率值保存
  1810. //打开加热,读取功率值保存
  1811. }
  1812. }
  1813. //工作状态检测
  1814. void WorkCheck(void)
  1815. {
  1816. //雨控检测,温控检测,电池电压检测
  1817. while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  1818. {
  1819. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1820. if(device_status.timeSwitch==1)
  1821. {
  1822. LOG_I("***********时控*****************");
  1823. if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
  1824. device_status.work_status = 1;
  1825. LOG_I("24 hours work...");
  1826. #if LAMP_EN == 1
  1827. device_status.lamp_status = 1;
  1828. device_status.lamp1_status = 0;
  1829. device_status.lamp2_status = 0;
  1830. if(device_status.sun_status==1){
  1831. ctr_lamp(OFF, 1);
  1832. ctr_lamp(OFF, 2);
  1833. ctr_lamp(OFF, 3);
  1834. }
  1835. #endif
  1836. }
  1837. //如果开始和结束是同一天
  1838. if(device_status.startBar<device_status.stopBar)
  1839. {
  1840. LOG_I("开始和结束是同一天");
  1841. time_t now;
  1842. time(&now);
  1843. static struct tm nowtime; //现在
  1844. static struct tm starttime; //开始
  1845. static struct tm endtime; //结束
  1846. //获取当前时间戳
  1847. nowtime =*localtime(&now);
  1848. nowtime.tm_hour = nowtime.tm_hour-8;
  1849. //获取定时开始的时间戳
  1850. starttime = *localtime(&now);
  1851. starttime.tm_hour = device_status.startBar-8;
  1852. starttime.tm_min = 0;
  1853. starttime.tm_sec = 0;
  1854. //获取定时结束的时间戳
  1855. endtime = *localtime(&now);
  1856. endtime.tm_hour = device_status.stopBar-8;
  1857. endtime.tm_min = 0;
  1858. endtime.tm_sec = 0;
  1859. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1860. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1861. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  1862. {
  1863. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1864. device_status.work_status = 1;
  1865. }
  1866. //如果当前时间小于开始时间
  1867. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  1868. {
  1869. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1870. device_status.work_status = 0;
  1871. }
  1872. //当前时间大于结束时间
  1873. else {
  1874. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1875. device_status.work_status = 0;
  1876. }
  1877. #if LAMP_EN == 1
  1878. //如果当前时间超过20点,未到21点
  1879. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
  1880. {
  1881. LOG_I("3led:20~21");
  1882. device_status.lamp_status = 1;
  1883. device_status.lamp1_status = 0;
  1884. device_status.lamp2_status = 0;
  1885. }
  1886. else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
  1887. LOG_I("3led:21~22");
  1888. device_status.lamp1_status = 1;
  1889. device_status.lamp_status = 0;
  1890. device_status.lamp2_status = 0;
  1891. }
  1892. else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
  1893. LOG_I("3led:22~23");
  1894. device_status.lamp2_status = 1;
  1895. device_status.lamp_status = 0;
  1896. device_status.lamp1_status =0;
  1897. }
  1898. #endif
  1899. }
  1900. //如果结束时间是第二天
  1901. else if (device_status.startBar>device_status.stopBar) {
  1902. time_t now;
  1903. time(&now);
  1904. static struct tm nowtime; //现在
  1905. static struct tm starttime; //开始
  1906. static struct tm endtime; //结束
  1907. //获取当前时间戳
  1908. nowtime =*localtime(&now);
  1909. nowtime.tm_hour = nowtime.tm_hour-8;
  1910. //获取定时开始的时间戳
  1911. starttime = *localtime(&now);
  1912. starttime.tm_hour = device_status.startBar-8;
  1913. starttime.tm_min = 0;
  1914. starttime.tm_sec = 0;
  1915. //获取定时结束的时间戳
  1916. endtime = *localtime(&now);
  1917. endtime.tm_hour = device_status.stopBar-8;
  1918. endtime.tm_min = 0;
  1919. endtime.tm_sec = 0;
  1920. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1921. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  1922. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  1923. {
  1924. //获取定时结束的时间戳
  1925. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1926. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1927. endtime.tm_min = 0;
  1928. endtime.tm_sec = 0;
  1929. device_status.work_status = 1;
  1930. LOG_I("当前前时间大于开始时间,且没有开始工作");
  1931. }
  1932. //当前时间小于开始时间
  1933. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  1934. {
  1935. //获取定时结束的时间戳
  1936. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1937. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1938. endtime.tm_min = 0;
  1939. endtime.tm_sec = 0;
  1940. //如果当前时间戳小于结束时间戳
  1941. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  1942. {
  1943. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  1944. device_status.work_status = 1;
  1945. }
  1946. else
  1947. {
  1948. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  1949. device_status.work_status = 0; //不在工作时间,待机
  1950. }
  1951. }
  1952. }
  1953. }
  1954. else {
  1955. LOG_I("光控定时模式!");
  1956. /*
  1957. time_t now;
  1958. time(&now);
  1959. static struct tm nowstamp;
  1960. nowstamp =*localtime(&now);
  1961. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  1962. static rt_uint32_t nowstamp_num = 0;
  1963. nowstamp_num = mktime(&nowstamp);
  1964. rt_kprintf("now stamp:%d\n",nowstamp_num);
  1965. */
  1966. if(device_status.sun_status==0&&device_status.light_over_tim!=0)
  1967. {
  1968. device_status.light_over_tim--;
  1969. #if LAMP_EN == 1
  1970. Led_Check(device_status.sunBar);
  1971. #else
  1972. device_status.work_status = 1;;
  1973. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1974. #endif
  1975. }
  1976. else
  1977. {
  1978. //没有在测试并且没有在自检
  1979. if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
  1980. {
  1981. ctr_lamp(OFF,1);
  1982. #if LAMP_EN == 1
  1983. ctr_lamp(OFF,2);
  1984. ctr_lamp(OFF,3);
  1985. #endif
  1986. }
  1987. device_status.work_status = 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. void WorkTask_BZY(void)
  1999. {
  2000. if(device_status.ds==1)
  2001. {
  2002. //时间段判断
  2003. //先判断第一个时间段
  2004. time_t now;
  2005. time(&now);
  2006. static struct tm now_stamp; //现在
  2007. static struct tm cul_sh1_stamp; //开始1
  2008. static struct tm cul_eh1_stamp; //结束1
  2009. static struct tm cul_sh2_stamp; //开始2
  2010. static struct tm cul_eh2_stamp; //结束2
  2011. static struct tm cul_sh3_stamp; //开始3
  2012. static struct tm cul_eh3_stamp; //结束3
  2013. now_stamp = *localtime(&now);
  2014. //获取定时开始的时间戳
  2015. cul_sh1_stamp = *localtime(&now);
  2016. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2017. cul_sh1_stamp.tm_min = 0;
  2018. cul_sh1_stamp.tm_sec = 0;
  2019. cul_sh2_stamp = *localtime(&now);
  2020. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2021. cul_sh2_stamp.tm_min = 0;
  2022. cul_sh2_stamp.tm_sec = 0;
  2023. cul_sh3_stamp = *localtime(&now);
  2024. cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
  2025. cul_sh3_stamp.tm_min = 0;
  2026. cul_sh3_stamp.tm_sec = 0;
  2027. //获取定时结束的时间戳
  2028. cul_eh1_stamp = *localtime(&now);
  2029. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2030. cul_eh1_stamp.tm_min = 0;
  2031. cul_eh1_stamp.tm_sec = 0;
  2032. cul_eh2_stamp = *localtime(&now);
  2033. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2034. cul_eh2_stamp.tm_min = 0;
  2035. cul_eh2_stamp.tm_sec = 0;
  2036. cul_eh3_stamp = *localtime(&now);
  2037. cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
  2038. cul_eh3_stamp.tm_min = 0;
  2039. cul_eh3_stamp.tm_sec = 0;
  2040. 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);
  2041. 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);
  2042. 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);
  2043. 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);
  2044. 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);
  2045. 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);
  2046. //此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2047. //当前时间戳小于第一段开始时间戳
  2048. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2049. {
  2050. time_t now;
  2051. time(&now);
  2052. cul_sh1_stamp = *localtime(&now);
  2053. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2054. cul_sh1_stamp.tm_min = 0;
  2055. cul_sh1_stamp.tm_sec = 0;
  2056. now_stamp = *localtime(&now);
  2057. 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);
  2058. 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);
  2059. LOG_D("run_sta:%d",device_status.run_sta);
  2060. }
  2061. //当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2062. if(difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0&&difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2063. {
  2064. time_t now;
  2065. time(&now);
  2066. cul_sh2_stamp = *localtime(&now);
  2067. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2068. cul_sh2_stamp.tm_min = 0;
  2069. cul_sh2_stamp.tm_sec = 0;
  2070. now_stamp = *localtime(&now);
  2071. 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);
  2072. 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);
  2073. LOG_D("run_sta:%d",device_status.run_sta);
  2074. }
  2075. //如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2076. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0&&difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2077. {
  2078. //转盘到涂凡士林位置
  2079. if(device_status.run_sta==0)
  2080. {
  2081. LOG_I("start to collect!!!");
  2082. DTU_Write("collect.mp3");
  2083. ctr_turn(90,4);
  2084. rt_thread_delay(2000);
  2085. //涂凡士林
  2086. ctr_Petroleum_jelly(10);
  2087. rt_thread_delay(5000);
  2088. }
  2089. /*转盘到采集位置*/
  2090. if(device_status.run_sta==4)
  2091. ctr_turn(90,1);
  2092. //只有开始和结束时刻不同的时间段,才有效
  2093. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)||(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0))
  2094. {
  2095. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)&& difftime(mktime(&now_stamp),mktime(&cul_sh1_stamp)) > 0)
  2096. {
  2097. device_status.work_status = 1;
  2098. ctr_Collect_Fan(ON);
  2099. //当前时间戳小于第一段结束时间戳
  2100. while(difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp))>0)
  2101. {
  2102. time(&now);
  2103. now_stamp = *localtime(&now);
  2104. cul_eh1_stamp = *localtime(&now);
  2105. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2106. cul_eh1_stamp.tm_min = 0;
  2107. cul_eh1_stamp.tm_sec = 0;
  2108. if(device_status.run_sta!=1) break;
  2109. LOG_I("1===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh1_stamp));
  2110. rt_thread_mdelay(10000);
  2111. }
  2112. }
  2113. else {
  2114. device_status.work_status=0;
  2115. ctr_Collect_Fan(OFF);
  2116. LOG_I("未到收集1时间!");
  2117. }
  2118. if(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0 && difftime(mktime(&now_stamp),mktime(&cul_sh2_stamp)) > 0)
  2119. {
  2120. device_status.work_status = 1;
  2121. ctr_Collect_Fan(ON);
  2122. while(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp))>0)
  2123. {
  2124. time(&now);
  2125. now_stamp = *localtime(&now);
  2126. cul_eh2_stamp = *localtime(&now);
  2127. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2128. cul_eh2_stamp.tm_min = 0;
  2129. cul_eh2_stamp.tm_sec = 0;
  2130. if(device_status.run_sta!=1) break;
  2131. LOG_I("2===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh2_stamp));
  2132. rt_thread_mdelay(10000);
  2133. }
  2134. }
  2135. else {
  2136. device_status.work_status=0;
  2137. ctr_Collect_Fan(OFF);
  2138. LOG_I("未到收集2时间!");
  2139. }
  2140. }
  2141. else
  2142. {
  2143. LOG_I("this collect time is 0s,The wait time cannot be negative!");
  2144. }
  2145. }
  2146. if(device_status.run_sta==2)
  2147. {
  2148. ctr_Collect_Fan(OFF);
  2149. device_status.develop_flag = 1;
  2150. device_status.work_status = 2;
  2151. ctr_develop(); //培养
  2152. ctr_turn(90,3);
  2153. }
  2154. if(device_status.run_sta==3)
  2155. {
  2156. ctr_Collect_Fan(OFF);
  2157. device_status.work_status = 3;
  2158. device_status.autotakepic=1; //对焦拍照
  2159. }
  2160. //在培养之前再次确认时间戳
  2161. time(&now);
  2162. now_stamp = *localtime(&now);
  2163. cul_eh2_stamp = *localtime(&now);
  2164. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2165. cul_eh2_stamp.tm_min = 0;
  2166. cul_eh2_stamp.tm_sec = 0;
  2167. //当前时间戳大于收集结束时间戳并且run_sta==1
  2168. if(device_status.run_sta==1 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) > 0)
  2169. {
  2170. ctr_Collect_Fan(OFF);
  2171. LOG_I("===============collect ok,turn to drop!!!");
  2172. device_status.develop_flag=1;
  2173. device_status.work_status=2; //现在是培养
  2174. DTU_Write("develop.mp3");
  2175. if(device_status.run_sta==1)
  2176. ctr_turn(90,2); /*转盘到培养位置*/
  2177. rt_thread_delay(1000);
  2178. ctr_shake(ON,device_status.shake_sec);
  2179. rt_thread_delay(1000);
  2180. ctr_develop(); //培养
  2181. if(device_status.run_sta==2)
  2182. ctr_turn(90,3); /*转盘到拍照位置*/
  2183. rt_thread_delay(1000);
  2184. device_status.work_status=3; //现在是拍照
  2185. device_status.autotakepic=1; //对焦拍照
  2186. while(device_status.autotakepic==0)
  2187. {
  2188. rt_thread_delay(1000);
  2189. LOG_I("正在对焦拍照............");
  2190. }
  2191. device_status.work_status = 0; //待机
  2192. DTU_Write("wait.mp3");
  2193. LOG_I("=====================work finished==================");
  2194. }
  2195. rt_thread_delay(1000);
  2196. }
  2197. device_status.work_status = 0; //待机
  2198. LOG_W("==================!!!设备已待机!!!===================");
  2199. }
  2200. void WorkTask_BZYV2(void)
  2201. {
  2202. //打开采集风机
  2203. ctr_Collect_Fan(ON);
  2204. //打开胶带步进电机
  2205. //等待采集结束
  2206. //拍照
  2207. //打开相机供电
  2208. //打开补光灯
  2209. //滑台归位
  2210. //滑台启动
  2211. }
  2212. //工作任务流程s
  2213. void WorkTask(void)
  2214. {
  2215. static int clt_time = 0; //收集时间差秒数
  2216. static int heat_time = 0;
  2217. LOG_I("工作状态:%d",device_status.work_status);
  2218. LOG_I("开关机状态:%d",device_status.ds);
  2219. 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)
  2220. {
  2221. device_status.work_done = 0;
  2222. if(clt_time==0)
  2223. {
  2224. #if 0
  2225. if(device_status.version_type==41&&atoi(device_status.power)<350)
  2226. {
  2227. LOG_W("相机电流不足!");
  2228. char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
  2229. DTU_Write("%s",ctr_hk_p_warn);
  2230. rt_free(ctr_hk_p_warn);
  2231. }
  2232. #endif
  2233. #if 0//LAMP_EN == 0
  2234. ctr_Fan_PUT(ON);
  2235. #endif
  2236. DTU_Write("workstart.mp3");
  2237. }
  2238. //1.打开灯管
  2239. #if LAMP_EN == 1
  2240. if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
  2241. {
  2242. ctr_lamp(ON,1);
  2243. ctr_lamp(OFF,2);
  2244. ctr_lamp(OFF,3);
  2245. }
  2246. else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
  2247. ctr_lamp(OFF,1);
  2248. ctr_lamp(ON,2);
  2249. ctr_lamp(OFF,3);
  2250. }
  2251. else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
  2252. ctr_lamp(OFF,1);
  2253. ctr_lamp(OFF,2);
  2254. ctr_lamp(ON,3);
  2255. }
  2256. #else
  2257. ctr_lamp(ON,1);
  2258. #endif
  2259. LOG_I("打开灯管!!!");
  2260. #if 0
  2261. rt_thread_delay(2000);
  2262. if(atoi(device_status.power)<450)
  2263. {
  2264. LOG_I("Current is:%d",atoi(device_status.power));
  2265. if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
  2266. {
  2267. char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
  2268. DTU_Write("%s",lamp_err_warn);
  2269. rt_free(lamp_err_warn);
  2270. }
  2271. }
  2272. #endif
  2273. if(device_status.version_type!=5)
  2274. {
  2275. rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
  2276. //2.打开上仓门
  2277. LOG_I("打开上仓门!!!");
  2278. device_status.ctr_up_motor = 1;
  2279. //3.收集
  2280. clt_time = device_status.clt_time * 60;
  2281. while(clt_time!=1)
  2282. {
  2283. #if 0//LAMP_EN == 0
  2284. ctr_Fan_IN(ON);
  2285. #endif
  2286. clt_time --;
  2287. rt_thread_delay(1000);
  2288. #if 0//LAMP_EN == 0
  2289. if(clt_time%30==0)
  2290. ctr_Fan_PUT(OFF);
  2291. #endif
  2292. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  2293. HMI_WRITE("workSta.g0.txt=\"正在收集.....剩余时间:%d分-%d秒\"",device_status.clt_time,clt_time);
  2294. //如果触发异常
  2295. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2296. {
  2297. ctr_lamp(OFF,1);
  2298. #if LAMP_EN == 1
  2299. ctr_lamp(OFF,2);
  2300. ctr_lamp(OFF,3);
  2301. #endif
  2302. #if 0//LAMP_EN == 0
  2303. ctr_Fan_IN(OFF);
  2304. #endif
  2305. rt_kprintf("异常退出!!!\n");
  2306. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2307. break;
  2308. }
  2309. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2310. {
  2311. ctr_lamp(OFF,1);
  2312. #if LAMP_EN == 1
  2313. ctr_lamp(OFF,2);
  2314. ctr_lamp(OFF,3);
  2315. #endif
  2316. #if 0//LAMP_EN == 0
  2317. ctr_Fan_IN(OFF);
  2318. #endif
  2319. rt_kprintf("异常退出!!!\n");
  2320. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2321. break;
  2322. }
  2323. }
  2324. clt_time = 1;
  2325. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2326. {
  2327. ctr_lamp(OFF,1);
  2328. #if LAMP_EN == 1
  2329. ctr_lamp(OFF,2);
  2330. ctr_lamp(OFF,3);
  2331. #endif
  2332. #if 0//LAMP_EN == 0
  2333. ctr_Fan_IN(OFF);
  2334. #endif
  2335. rt_kprintf("异常退出!!!\n");
  2336. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2337. break;
  2338. }
  2339. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2340. {
  2341. ctr_lamp(OFF,1);
  2342. #if LAMP_EN == 1
  2343. ctr_lamp(OFF,2);
  2344. ctr_lamp(OFF,3);
  2345. #endif
  2346. #if 0//LAMP_EN == 0
  2347. ctr_Fan_IN(OFF);
  2348. #endif
  2349. rt_kprintf("异常退出!!!\n");
  2350. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2351. break;
  2352. }
  2353. #if 0//LAMP_EN == 0
  2354. ctr_Fan_IN(OFF);
  2355. #endif
  2356. //4.关闭上仓门
  2357. device_status.ctr_up_motor = 2;
  2358. rt_kprintf("关闭上仓门!!!\n");
  2359. HMI_WRITE("workSta.g0.txt=\"关闭上仓门!\"");
  2360. while(device_status.ctr_up_motor!=0)
  2361. {
  2362. rt_thread_delay(100);
  2363. LOG_I("等待上仓门关闭!!!");
  2364. }
  2365. //5.加热
  2366. if(device_status.heat_sw==0)
  2367. {
  2368. calorstat(device_status.heattime*60);
  2369. }
  2370. else {
  2371. heat_time = device_status.heattime * 60;
  2372. while(heat_time!=0)
  2373. {
  2374. heat_time--;
  2375. LOG_I("正在加热状态!!!");
  2376. rt_thread_delay(1000);
  2377. }
  2378. }
  2379. //6.打开下仓门
  2380. if(device_status.rain_status==0)
  2381. {
  2382. device_status.ctr_down_motor =1;
  2383. }
  2384. else {
  2385. device_status.ctr_down_motor = 2;
  2386. device_status.ctr_up_motor = 2;
  2387. }
  2388. //待下仓门完全打开
  2389. while(device_status.ctr_down_motor!=0)
  2390. {
  2391. rt_thread_delay(100);
  2392. rt_kprintf("等待下仓门打开!!!\n");
  2393. HMI_WRITE("workSta.g0.txt=\"等待下仓门打开!\"");
  2394. }
  2395. rt_thread_delay(3000);
  2396. //关闭下仓门
  2397. device_status.ctr_down_motor = 2;
  2398. while(device_status.ctr_down_motor!=0)
  2399. {
  2400. rt_thread_delay(100);
  2401. rt_kprintf("等待下仓门关闭!!!\n");
  2402. HMI_WRITE("workSta.g0.txt=\"等待下仓门关闭!\"");
  2403. }
  2404. //2022-04-12add:
  2405. LOG_I("打开上仓门!!!");
  2406. HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
  2407. device_status.ctr_up_motor = 1;
  2408. if(device_status.version_type==4||device_status.version_type==41)
  2409. {
  2410. //震动
  2411. ctr_shake(ON, device_status.shake_sec);
  2412. //补光&&拍照
  2413. LOG_I("拍照!!!");
  2414. HMI_WRITE("workSta.g0.txt=\"拍照!\"");
  2415. ctr_led(ON);
  2416. HK_TakePhoto();
  2417. //清扫
  2418. device_status.clear_status=1;
  2419. //清扫失效则使用震动
  2420. //ctr_shake(ON, 100);
  2421. }
  2422. }
  2423. else {
  2424. //打开高压
  2425. ctr_Heat(ON);
  2426. //打开补光
  2427. ctr_led(ON);
  2428. LOG_I("打开补光!!");
  2429. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  2430. //2.翻转清虫
  2431. while(rt_pin_read(CLEAR_L_LIMIT)==1) rt_thread_delay(20);
  2432. rt_thread_delay(500);
  2433. Hk_Take_io(); //触发海康相机拍照
  2434. rt_thread_delay(500);
  2435. ctr_turnv5(); //摆动清虫
  2436. LOG_I("摆动清虫!");
  2437. }
  2438. }
  2439. if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
  2440. {
  2441. rt_kprintf("-------------------not work--------------------\n");
  2442. device_status.work_status = 0;
  2443. }
  2444. //工作结束
  2445. if(device_status.work_done==0&&device_status.work_status==0)
  2446. {
  2447. DTU_Write("workdone");
  2448. HMI_WRITE("workSta.g0.txt=\"工作任务已完成!\"");
  2449. if (device_status.version_type==1) {
  2450. turnzp(); //2024-03-21 :开机不再转仓
  2451. }
  2452. ResetInit();
  2453. clt_time = 0;
  2454. }
  2455. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  2456. }
  2457. /* 入口函数-工作状态检测 */
  2458. static void Work_status_thread_entry(void *parameter)
  2459. {
  2460. static uint16_t sun_status_num = 120;
  2461. //如果是光控定时,进行光控监测的消抖
  2462. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  2463. {
  2464. rt_kprintf("光控定时!!!\n");
  2465. while(sun_status_num!=0)
  2466. {
  2467. sun_status_num--;
  2468. rt_thread_delay(1000);
  2469. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  2470. }
  2471. device_status.light_over_tim = device_status.sunBar * 3600;
  2472. device_status.test_flag = 0;
  2473. }
  2474. while(1)
  2475. {
  2476. WorkCheck();
  2477. }
  2478. }
  2479. /*入口函数-工作流程*/
  2480. static void Work_Loop_thread_entry(void *parameter)
  2481. {
  2482. rt_thread_delay(1000);
  2483. ResetInit();
  2484. while(1)
  2485. {
  2486. if(device_status.dtype==7)
  2487. {
  2488. WorkTask_BZY();
  2489. }
  2490. if(device_status.version_type!=6&&device_status.dtype==3)
  2491. {
  2492. WorkTask();
  2493. }
  2494. if(device_status.version_type==6)
  2495. {
  2496. WorkTask_XCT();
  2497. }
  2498. rt_thread_delay(1000);
  2499. }
  2500. }
  2501. /*入口函数清扫*/
  2502. static void Control_Clear_thread_entry(void *parameter)
  2503. {
  2504. static int selfcheck_cnt = 0;
  2505. float voltage_f = 0.0;
  2506. while(1)
  2507. {
  2508. #if ROBOT_EN ==1
  2509. ctr_Motor_Robot(ON);
  2510. rt_thread_delay(100);
  2511. #else
  2512. #if Color_EN ==1
  2513. /*复位*/
  2514. if(Read_Color_Key(KEY_RESET)==1)
  2515. {
  2516. ctr_Color_board(RESET, 1200);
  2517. rt_thread_delay(5000);
  2518. }
  2519. #else
  2520. if(device_status.selfcheck_ws==1){
  2521. selfcheck_cnt ++;
  2522. if(selfcheck_cnt==1){
  2523. ctr_lamp(ON,1);
  2524. rt_thread_delay(1000);
  2525. device_status.ctr_up_motor = 1;
  2526. device_status.ctr_down_motor = 1;
  2527. //记录当前电压
  2528. voltage_f = atof(device_status.voltage);
  2529. rt_thread_delay(1500);
  2530. //开启加热
  2531. ctr_Heat(ON);
  2532. }
  2533. if(selfcheck_cnt==50){
  2534. double voltage_n = atof(device_status.voltage);
  2535. //判断当前电压和加热前的电压差
  2536. if(voltage_f-voltage_n<0.5){
  2537. device_status.heat_sta = 1; //加热异常
  2538. //上报预警,加热故障
  2539. char *heat_warn = makeJson_Warn("加热报警", "heat-error");
  2540. DTU_Write("%s", heat_warn);
  2541. rt_free(heat_warn);
  2542. }else{
  2543. device_status.heat_sta = 0;
  2544. }
  2545. rt_thread_delay(1000);
  2546. //关闭加热
  2547. ctr_Heat(OFF);
  2548. //振动
  2549. ctr_shake(ON, 1);
  2550. //device_status.clear_status = 1;
  2551. ctr_lamp(OFF, 1);
  2552. }
  2553. if(selfcheck_cnt>1800){ //超过3分钟
  2554. device_status.selfcheck_ws = 0;
  2555. device_status.ctr_up_motor = 0;
  2556. device_status.ctr_down_motor = 0;
  2557. //
  2558. device_status.camsta = 1; //相机异常
  2559. device_status.led_sta = 1;
  2560. //上报自检结果
  2561. //上报自检结果
  2562. char *json_temp = makeJson_selfCheck_(1);
  2563. DTU_Write("%s",json_temp);
  2564. free(json_temp);
  2565. }
  2566. }
  2567. if(device_status.rain_status==2)
  2568. {
  2569. ctr_shake(ON, 10); //震动1S
  2570. while(device_status.ctr_up_motor!=0) //等待上仓门完全打开
  2571. {
  2572. rt_thread_delay(1000);
  2573. }
  2574. ctr_shake(ON, 2); //震动200ms
  2575. rt_thread_delay(1000);
  2576. device_status.ctr_up_motor = 2; //关闭上仓门
  2577. calorstat(5*60); //加热5分钟
  2578. device_status.ctr_down_motor = 1; //打开下仓门
  2579. while(device_status.ctr_down_motor!=0) //等待下仓门完全打开
  2580. {
  2581. rt_thread_delay(1000);
  2582. }
  2583. rt_thread_delay(1000);
  2584. device_status.ctr_down_motor = 2; //关闭下仓门
  2585. device_status.clear_status= 1;
  2586. device_status.rain_status = 0; //解除雨控
  2587. }
  2588. if(device_status.selfcheck_ws==0)
  2589. {
  2590. selfcheck_cnt = 0;
  2591. }
  2592. if(device_status.clear_status==1)
  2593. {
  2594. ctr_TG_Clear(400);
  2595. }
  2596. rt_thread_delay(100);
  2597. #endif
  2598. #endif
  2599. }
  2600. }
  2601. /*入口函数加热*/
  2602. static void Control_Heat_thread_entry(void *parameter)
  2603. {
  2604. uint16_t var_clear = 0;
  2605. while(1)
  2606. {
  2607. if(device_status.work_status==1&&device_status.heat_sw==1)
  2608. {
  2609. ctr_lamp(ON, 1);
  2610. rt_thread_delay(10000);
  2611. calorstat(device_status.heattime*60);
  2612. }
  2613. else
  2614. {
  2615. LOG_I("Not calorstat!-%d",device_status.selfcheck_ws);
  2616. if(device_status.selfcheck_ws==2)
  2617. {
  2618. static int total_seconds = 200;
  2619. static int current_second = 0;
  2620. while(current_second <= total_seconds)
  2621. {
  2622. int process = (current_second * 100) / total_seconds;
  2623. device_status.process = process / 100.0;
  2624. LOG_I("process:%d",process);
  2625. HMI_WRITE("selfcheck.s106.val=%d",process);
  2626. rt_thread_delay(1000);
  2627. current_second++;
  2628. if(device_status.selfcheck_ws==0)
  2629. {
  2630. HMI_WRITE("selfcheck.s106.val=100");
  2631. break;
  2632. }
  2633. }
  2634. HMI_WRITE("selfcheck.s106.val=100");
  2635. }
  2636. }
  2637. rt_thread_delay(1000);
  2638. }
  2639. }
  2640. /*清扫线程*/
  2641. int Control_clear(void)
  2642. {
  2643. /* 创建线程*/
  2644. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  2645. Control_Clear_thread_entry, RT_NULL,
  2646. 2048, //2048
  2647. 24, //23
  2648. WORK_CHECK_THREAD_TIMESLICE); //5
  2649. if(tid_ctr!=RT_NULL)
  2650. {
  2651. rt_thread_startup(tid_ctr);
  2652. }
  2653. return 0;
  2654. }
  2655. /*恒温加热线程*/
  2656. int Control_heat(void)
  2657. {
  2658. /* 创建线程*/
  2659. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  2660. Control_Heat_thread_entry, RT_NULL,
  2661. 1024, //2048
  2662. 25, //23
  2663. WORK_CHECK_THREAD_TIMESLICE); //5
  2664. if(tid_heat!=RT_NULL)
  2665. {
  2666. rt_thread_startup(tid_heat);
  2667. }
  2668. return 0;
  2669. }
  2670. /* 创建线程 -工作状态检测*/
  2671. int Workstatus_check(void)
  2672. {
  2673. /* 创建线程*/
  2674. tid_wkstc = rt_thread_create("work_status_check_thread",
  2675. Work_status_thread_entry, RT_NULL,
  2676. WORK_CHECK_THREAD_STACK_SIZE, //1024
  2677. WORK_CHECK_THREAD_PRIORITY, //23
  2678. WORK_CHECK_THREAD_TIMESLICE); //5
  2679. if(tid_wkstc!=RT_NULL)
  2680. {
  2681. rt_thread_startup(tid_wkstc);
  2682. }
  2683. return 0;
  2684. }
  2685. /*工作流程线程*/
  2686. int Work_Loop_Task(void)
  2687. {
  2688. rt_err_t result_loop;
  2689. /* 创建线程*/
  2690. tid_workloop = rt_thread_create("work_loop_thread",
  2691. Work_Loop_thread_entry, RT_NULL,
  2692. WORK_LOOP_THREAD_STACK_SIZE, //2048
  2693. WORK_LOOP_THREAD_PRIORITY, //12
  2694. WORK_LOOP_THREAD_TIMESLICE); //5
  2695. #if Color_EN == 0
  2696. if(tid_workloop!=RT_NULL)
  2697. {
  2698. result_loop = rt_thread_startup(tid_workloop);
  2699. }
  2700. #endif
  2701. return result_loop;
  2702. }
  2703. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  2704. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  2705. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  2706. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
  2707. //INIT_APP_EXPORT(Control_heat);