control.c 95 KB

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