control.c 95 KB

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