control.c 96 KB

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