control.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  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 <user_mb_app.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. rt_thread_t tid_485_play = RT_NULL;
  40. rt_event_t event_485_play;
  41. extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
  42. /***************************************************************************/
  43. int thread_delete_workloop(void)
  44. {
  45. rt_err_t result;
  46. if(tid_workloop!=RT_NULL)
  47. {
  48. result = rt_thread_delete(tid_workloop);
  49. }
  50. return result;
  51. }
  52. int thread_restart_workloop(void)
  53. {
  54. rt_err_t result;
  55. result = Work_Loop_Task();
  56. return result;
  57. }
  58. /**************************1.0定制2000W*************************************/
  59. uint8_t ctr_Fan_PUT(uint8_t status_ws)
  60. {
  61. rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
  62. if(status_ws==ON)
  63. {
  64. rt_pin_write(FAN_P,ON);
  65. }
  66. else {
  67. rt_pin_write(FAN_P, OFF);
  68. }
  69. return 0;
  70. }
  71. uint8_t ctr_Fan_IN(uint8_t status_ws)
  72. {
  73. rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
  74. if(status_ws==ON)
  75. {
  76. rt_pin_write(FAN_I,ON);
  77. }
  78. else {
  79. rt_pin_write(FAN_I, OFF);
  80. }
  81. return 0;
  82. }
  83. /****************************5.0***********************************/
  84. void ctr_turnv5(void)
  85. {
  86. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  87. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  88. // 转出
  89. rt_pin_write(CLEAR_R,ON);
  90. rt_pin_write(CLEAR_L,OFF);
  91. rt_thread_mdelay(300);
  92. //停止
  93. rt_pin_write(CLEAR_R,OFF);
  94. rt_pin_write(CLEAR_L,OFF);
  95. rt_thread_mdelay(300);
  96. //转入
  97. rt_pin_write(CLEAR_R,OFF);
  98. rt_pin_write(CLEAR_L,ON);
  99. rt_thread_mdelay(300);
  100. //停止
  101. rt_pin_write(CLEAR_R,OFF);
  102. rt_pin_write(CLEAR_L,OFF);
  103. rt_thread_mdelay(300);
  104. }
  105. /**************************机器人********************************/
  106. void ctr_Motor_Robot(uint8_t status_ws)
  107. {
  108. unsigned int close_timeout = 0;
  109. unsigned int open_timeout = 0;
  110. rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
  111. rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
  112. rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
  113. rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
  114. rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
  115. rt_pin_write(Motor_Power,OFF);
  116. rt_pin_write(Motor_Direction_Ctr,ON);
  117. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  118. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  119. if(status_ws == ON)
  120. {
  121. //检测按键状态
  122. while(rt_pin_read(Motor_Direction_Button)==1)
  123. {
  124. if(rt_pin_read(LIMIT_CLOSE)==1)
  125. {
  126. rt_pin_write(Motor_Direction_Ctr,ON);
  127. close_timeout++;
  128. //打开电机驱动器电源,默认关闭
  129. rt_pin_write(Motor_Power,ON);
  130. if(close_timeout==2)
  131. {
  132. rt_pin_write(CLEAR_R,ON);
  133. rt_pin_write(CLEAR_L,OFF);
  134. rt_pin_write(Motor_Power,OFF);
  135. rt_thread_delay(20);
  136. rt_pin_write(Motor_Power,ON);
  137. }
  138. rt_thread_delay(20);
  139. if(close_timeout>500)
  140. {
  141. close_timeout = 600;
  142. rt_pin_write(Motor_Power,OFF);
  143. rt_pin_write(CLEAR_R,OFF);
  144. rt_pin_write(CLEAR_L,OFF);
  145. }
  146. }
  147. else
  148. {
  149. close_timeout = 0;
  150. rt_pin_write(Motor_Power,OFF); //关闭驱动器电源
  151. rt_pin_write(CLEAR_R,OFF);
  152. rt_pin_write(CLEAR_L,OFF);
  153. }
  154. rt_thread_delay(20);
  155. }
  156. rt_pin_write(Motor_Power,OFF);
  157. rt_thread_delay(1000*2);
  158. while(rt_pin_read(Motor_Direction_Button)==0)
  159. {
  160. if(rt_pin_read(LIMIT_OPEN)==1)
  161. {
  162. open_timeout ++;
  163. //打开电机驱动器电源,默认关闭
  164. if(open_timeout==2){
  165. rt_pin_write(CLEAR_R,OFF);
  166. rt_pin_write(CLEAR_L,ON);
  167. }
  168. rt_pin_write(Motor_Power,ON);
  169. rt_pin_write(Motor_Direction_Ctr,OFF);
  170. if(open_timeout>500)
  171. {
  172. open_timeout = 600;
  173. rt_pin_write(Motor_Power,OFF);
  174. rt_pin_write(CLEAR_R,OFF);
  175. rt_pin_write(CLEAR_L,OFF);
  176. }
  177. rt_thread_delay(20);
  178. }
  179. if(rt_pin_read(LIMIT_OPEN)==0)
  180. {
  181. open_timeout = 0;
  182. rt_pin_write(Motor_Power,OFF);
  183. rt_pin_write(CLEAR_R,OFF);
  184. rt_pin_write(CLEAR_L,OFF);
  185. }
  186. rt_thread_delay(20);
  187. close_timeout = 0;
  188. }
  189. open_timeout = 0;
  190. close_timeout = 0;
  191. }
  192. else {
  193. rt_pin_write(Motor_Power,OFF);
  194. }
  195. }
  196. /*************************吸虫塔*********************************/
  197. //吸虫电机
  198. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  199. {
  200. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  201. if(status_ws==ON)
  202. {
  203. rt_pin_write(MOTOR1_CTR_PIN,ON);
  204. }
  205. else {
  206. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  207. }
  208. return 0;
  209. }
  210. uint8_t ctr_Camera_Power(uint8_t status_ws)
  211. {
  212. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  213. if(status_ws==ON)
  214. {
  215. rt_pin_write(MOTOR1_CTR_PIN,ON);
  216. }
  217. else {
  218. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  219. }
  220. return 0;
  221. }
  222. //吸附电机
  223. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  224. {
  225. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  226. if(status_ws==ON)
  227. {
  228. rt_pin_write(MOTOR2_CTR_PIN,ON);
  229. }
  230. else {
  231. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  232. }
  233. return 0;
  234. }
  235. //清扫-卷带电机
  236. void ctr_JD_Clear(uint8_t shake_sw)
  237. {
  238. rt_uint16_t turn_timeout = 0;
  239. rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
  240. ctr_cangmen_up(OFF); //清扫传送带的电机
  241. if(shake_sw==ON)
  242. {
  243. ctr_Heat(ON); //清洁风机
  244. Motor_shake(ON, 0);
  245. ctr_cangmen_up(OPEN); //打开清扫
  246. }
  247. else {
  248. Motor_shake(OFF, 0);
  249. ctr_cangmen_up(OPEN); //打开清扫
  250. }
  251. while(rt_pin_read(MOTOR_C_LIMIT)==0)
  252. {
  253. Motor_Juandai(ON);
  254. rt_thread_delay(50);
  255. turn_timeout++;
  256. if(turn_timeout==1000) break;
  257. }
  258. turn_timeout = 0;
  259. while(rt_pin_read(MOTOR_C_LIMIT)==1)
  260. {
  261. Motor_Juandai(ON);
  262. turn_timeout++;
  263. rt_thread_delay(50);
  264. if(turn_timeout==1000) break;
  265. }
  266. Motor_shake(OFF, 1);
  267. Motor_Juandai(OFF);
  268. ctr_cangmen_up(OFF); //关闭清扫
  269. ctr_Heat(OFF);
  270. }
  271. //工作任务流程
  272. void WorkTask_XCT(void)
  273. {
  274. while(device_status.work_status==1&&device_status.ds==1)
  275. {
  276. ctr_Motor_xifu(ON);
  277. //打开相机供电
  278. ctr_Camera_Power(ON);
  279. //ctr_Heat(ON); //清洁风机
  280. uint32_t photo_fre = 0;
  281. photo_fre = device_status.dattim * 60;
  282. while(photo_fre!=0)
  283. {
  284. photo_fre --;
  285. rt_thread_delay(1000);
  286. LOG_I("收集中,等待开始拍照:%d",photo_fre);
  287. }
  288. //卷带
  289. ctr_JD_Clear(OFF);
  290. //拍照
  291. HK_TakePhoto();
  292. //关闭吸附风机
  293. ctr_Motor_xifu(OFF);
  294. //关闭相机供电
  295. //ctr_Heat(OFF);
  296. ctr_Camera_Power(OFF);
  297. //卷带
  298. ctr_JD_Clear(ON);
  299. // rt_thread_delay(1000);
  300. // ctr_JD_Clear(ON);
  301. //震动
  302. Motor_shake(ON, device_status.shake_sec);
  303. }
  304. //关闭风机
  305. ctr_Motor_xichong(OFF);
  306. ctr_Motor_xifu(OFF);
  307. LOG_I("不在工作时间,未工作!!!");
  308. }
  309. /**********************************************************************/
  310. /*光控*/
  311. uint8_t In_Light_status(void)
  312. {
  313. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  314. return rt_pin_read(LIGHT_PIN);
  315. }
  316. /*雨控*/
  317. uint8_t In_Rain_status(void)
  318. {
  319. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  320. return rt_pin_read(RAIN_PIN);
  321. }
  322. /*加热*/
  323. uint8_t ctr_Heat(uint8_t status_heat)
  324. {
  325. device_status.heat_status = status_heat;
  326. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  327. rt_pin_write(Heat_Pin,status_heat);
  328. return status_heat;
  329. }
  330. /*制冷*/
  331. uint8_t ctr_Cold(uint8_t status_cold)
  332. {
  333. device_status.cold_status = status_cold;
  334. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  335. rt_pin_write(Cold_Pin,status_cold);
  336. return status_cold;
  337. }
  338. /*相机供电*/
  339. void ctr_photo(uint8_t status_photo)
  340. {
  341. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  342. rt_pin_write(PHOTO,status_photo);
  343. }
  344. /*************************************************
  345. Function: ctr_Cool_Fan
  346. Description: 散热风机的开关
  347. Calls:
  348. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  349. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  350. Input: ON-开,OFF-关
  351. Output: NULL
  352. Return: ON-开,OFF-关
  353. Others: NULL
  354. *************************************************/
  355. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  356. {
  357. device_status.cool_fan_status = status_cool;
  358. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  359. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  360. if(status_cool==OFF)
  361. {
  362. rt_pin_write(Cool_Fan_L,OFF);
  363. rt_pin_write(Cool_Fan_R,OFF);
  364. }
  365. if(status_cool==ON)
  366. {
  367. rt_pin_write(Cool_Fan_L,ON);
  368. rt_pin_write(Cool_Fan_R,OFF);
  369. }
  370. return device_status.cool_fan_status;
  371. }
  372. /*************************************************
  373. Function: ctr_Collect_Fan
  374. Description: 采集风机的开关
  375. Calls:
  376. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  377. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  378. Input: ON-开,OFF-关
  379. Output: NULL
  380. Return: ON-开,OFF-关
  381. Others: NULL
  382. *************************************************/
  383. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  384. {
  385. device_status.collect_fan_status = status_collect;
  386. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  387. if(status_collect==OFF)
  388. {
  389. rt_pin_write(Collect_Fan,OFF);
  390. }
  391. if(status_collect==ON)
  392. {
  393. rt_pin_write(Collect_Fan,ON);
  394. }
  395. return device_status.collect_fan_status;
  396. }
  397. /*************************************************
  398. Function: ctr_develop
  399. Description: 培养载玻片孢子
  400. Calls:
  401. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  402. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  403. Input: v=0(复位) v=90转90度
  404. Output: NULL
  405. Return: NULL
  406. Others: NULL
  407. *************************************************/
  408. /*上仓门*/
  409. uint8_t ctr_cangmen_up(uint8_t status_up)
  410. {
  411. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  412. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  413. if(status_up==OFF)
  414. {
  415. rt_pin_write(Collect_fan_R,ON);
  416. rt_pin_write(Collect_fan_L,ON);
  417. device_status.ctr_up_motor = 0;
  418. rt_thread_delay(1000);
  419. }
  420. if(status_up==OPEN)
  421. {
  422. device_status.up_status = 1;
  423. rt_pin_write(Collect_fan_R,OFF);
  424. rt_pin_write(Collect_fan_L,OFF);
  425. rt_pin_write(Collect_fan_R,ON);
  426. rt_pin_write(Collect_fan_L,OFF);
  427. }
  428. if(status_up==CLOSE)
  429. {
  430. device_status.up_status = 0;
  431. rt_pin_write(Collect_fan_R,OFF);
  432. rt_pin_write(Collect_fan_L,OFF);
  433. rt_pin_write(Collect_fan_R,OFF);
  434. rt_pin_write(Collect_fan_L,ON);
  435. }
  436. return device_status.up_status;
  437. }
  438. //下仓门
  439. uint8_t ctr_cangmen_down(uint8_t status_down)
  440. {
  441. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  442. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  443. if(status_down==OFF)
  444. {
  445. rt_pin_write(C_DOWN_R,ON);
  446. rt_pin_write(C_DOWN_L,ON);
  447. device_status.ctr_down_motor = 0;
  448. rt_thread_delay(1000);
  449. }
  450. if(status_down==OPEN)
  451. {
  452. device_status.down_status = 1;
  453. rt_pin_write(C_DOWN_R,OFF);
  454. rt_pin_write(C_DOWN_L,OFF);
  455. rt_pin_write(C_DOWN_R,ON);
  456. rt_pin_write(C_DOWN_L,OFF);
  457. }
  458. if(status_down==CLOSE)
  459. {
  460. device_status.down_status = 0;
  461. rt_pin_write(C_DOWN_R,OFF);
  462. rt_pin_write(C_DOWN_L,OFF);
  463. rt_pin_write(C_DOWN_R,OFF);
  464. rt_pin_write(C_DOWN_L,ON);
  465. }
  466. return device_status.down_status;
  467. }
  468. //镇流器
  469. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num)
  470. {
  471. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  472. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  473. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  474. if(status_lamp==ON)
  475. {
  476. switch(lamp_num){
  477. case 1:
  478. rt_pin_write(LAMP_SW,ON);
  479. device_status.lamp_status = status_lamp;
  480. break;
  481. case 2:
  482. rt_pin_write(LAMP_1_SW,ON);
  483. device_status.lamp_status = status_lamp;
  484. break;
  485. case 3:
  486. rt_pin_write(LAMP_2_SW,ON);
  487. device_status.lamp_status = status_lamp;
  488. break;
  489. default:
  490. break;
  491. }
  492. }
  493. else {
  494. switch(lamp_num){
  495. case 1:
  496. rt_pin_write(LAMP_SW,OFF);
  497. device_status.lamp_status = status_lamp;
  498. break;
  499. case 2:
  500. rt_pin_write(LAMP_1_SW,OFF);
  501. device_status.lamp1_status = status_lamp;
  502. break;
  503. case 3:
  504. rt_pin_write(LAMP_2_SW,OFF);
  505. device_status.lamp2_status = status_lamp;
  506. break;
  507. default:
  508. break;
  509. }
  510. }
  511. HMI_WRITE("sysTest.switchLamp.val=%d",device_status.lamp_status);
  512. return device_status.lamp_status;
  513. }
  514. //震动电机
  515. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
  516. {
  517. static rt_uint16_t shake_i = 0;
  518. shake_i = atoi(device_status.power);
  519. LOG_I("震动电机待机电流:%d",shake_i);
  520. if(device_status.dtype==7&&shake_sec!=0)
  521. DTU_Write("drop");
  522. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  523. #if 0
  524. rt_pin_write(SHAKE_SW,ON);
  525. return 0;
  526. #endif
  527. if(status_shake==ON&&device_status.shake_ws==1)
  528. {
  529. #if 0
  530. for(int8_t s = 0;s++;s<2)
  531. {
  532. rt_pin_write(SHAKE_SW,ON);
  533. rt_thread_delay(100);
  534. rt_pin_write(SHAKE_SW,OFF);
  535. rt_thread_delay(1000);
  536. }
  537. #endif
  538. rt_pin_write(SHAKE_SW,ON);
  539. if(device_status.dtype==3)
  540. {
  541. while(shake_sec--)
  542. {
  543. rt_thread_delay(100);
  544. 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)
  545. {
  546. char * shake_warn = makeJson_Warn("电流不足", "震动电机");
  547. DTU_Write("%s",shake_warn);
  548. rt_free(shake_warn);
  549. }
  550. LOG_D("震动电机:%d",atoi(device_status.power));
  551. }
  552. }
  553. if(device_status.dtype==7) rt_thread_delay(shake_sec*1000);
  554. rt_pin_write(SHAKE_SW,OFF);
  555. HMI_WRITE("cangWei.switchShake.val=%d",0);
  556. }
  557. else
  558. {
  559. rt_pin_write(SHAKE_SW,OFF);
  560. HMI_WRITE("cangWei.switchShake.val=%d",0);
  561. }
  562. if(device_status.dtype==7)
  563. HMI_WRITE("sysTest.switchDrop.val=%d",OFF);
  564. return status_shake;
  565. }
  566. //补光
  567. uint8_t ctr_led(uint8_t status_led)
  568. {
  569. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  570. if(device_status.version_type==6)
  571. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  572. if(status_led==ON)
  573. {
  574. rt_pin_write(LED_SW,ON);
  575. if(device_status.version_type==6)
  576. rt_pin_write(LED_P,ON);
  577. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  578. }
  579. else if(status_led==OFF){
  580. rt_pin_write(LED_SW,OFF);
  581. if(device_status.version_type==6)
  582. rt_pin_write(LED_P,OFF);
  583. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  584. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  585. }
  586. return status_led;
  587. }
  588. /*************************************************
  589. Function: ctr_turn
  590. Description: 转盘驱动
  591. Calls:
  592. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  593. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  594. Input: v=0(复位) v=90转90度
  595. Output: NULL
  596. Return: NULL
  597. Others: NULL
  598. *************************************************/
  599. void ctr_turn(uint8_t v,uint8_t sta)
  600. {
  601. DTU_Write("turn.mp3");
  602. LOG_I("================v===============:%d",v);
  603. rt_uint16_t turn_cnt = 0;
  604. rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
  605. rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
  606. rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
  607. rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
  608. //if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
  609. while(rt_pin_read(LIMIT_0)==0||rt_pin_read(LIMIT_90)==0)
  610. {
  611. rt_pin_write(TURN_ZP_R, ON);
  612. rt_pin_write(TURN_ZP_L, OFF);
  613. //Motor_shake(ON,0);
  614. turn_cnt ++;
  615. rt_thread_delay(100);
  616. if(turn_cnt==1000)
  617. {
  618. turn_cnt = 0;
  619. rt_pin_write(TURN_ZP_R, OFF);
  620. rt_pin_write(TURN_ZP_L, OFF);
  621. //Motor_shake(OFF,0);
  622. char *turn_warn =makeJson_Warn("未检测到限位", "转盘");
  623. DTU_Write("%s",turn_warn);
  624. rt_free(turn_warn);
  625. break;
  626. }
  627. }
  628. turn_cnt = 0;
  629. while(v==0&&rt_pin_read(LIMIT_0)==1)
  630. {
  631. rt_pin_write(TURN_ZP_R, ON);
  632. rt_pin_write(TURN_ZP_L, OFF);
  633. Motor_shake(ON,0);
  634. rt_thread_delay(200); //10 to 100
  635. turn_cnt ++;
  636. if(turn_cnt==300) //6000 to 600
  637. {
  638. turn_cnt = 0;
  639. // rt_pin_write(TURN_ZP_R, OFF);
  640. // rt_pin_write(TURN_ZP_L, OFF);
  641. // char *turn_warn =makeJson_Warn("超时", "转盘复位");
  642. // DTU_Write("%s",turn_warn);
  643. // rt_free(turn_warn);
  644. break;
  645. }
  646. }
  647. while(v==0&&rt_pin_read(LIMIT_0)==1)
  648. {
  649. rt_pin_write(TURN_ZP_R, ON);
  650. rt_pin_write(TURN_ZP_L, OFF);
  651. //Motor_shake(ON,0);
  652. rt_thread_delay(50); //10 to 50
  653. turn_cnt ++;
  654. if(turn_cnt==10) //6000 to 1200
  655. {
  656. turn_cnt = 0;
  657. rt_pin_write(TURN_ZP_R, OFF);
  658. rt_pin_write(TURN_ZP_L, OFF);
  659. //Motor_shake(OFF,0);
  660. char *turn_warn =makeJson_Warn("超时", "转盘复位");
  661. DTU_Write("%s",turn_warn);
  662. rt_free(turn_warn);
  663. break;
  664. }
  665. }
  666. turn_cnt = 0;
  667. while(v==90&&rt_pin_read(LIMIT_90)==1)
  668. {
  669. rt_pin_write(TURN_ZP_R, ON);
  670. rt_pin_write(TURN_ZP_L, OFF);
  671. //Motor_shake(ON,0);
  672. rt_thread_delay(200);
  673. turn_cnt ++;
  674. if(turn_cnt==150)
  675. {
  676. turn_cnt = 0;
  677. // rt_pin_write(TURN_ZP_R, OFF);
  678. // rt_pin_write(TURN_ZP_L, OFF);
  679. // char *turn_warn =makeJson_Warn("超时", "转盘");
  680. // DTU_Write(turn_warn);
  681. // rt_free(turn_warn);
  682. break;
  683. }
  684. }
  685. while(v==90&&rt_pin_read(LIMIT_90)==1)
  686. {
  687. // rt_pin_write(TURN_ZP_R, ON);
  688. // rt_pin_write(TURN_ZP_L, OFF);
  689. Motor_shake(ON,0);
  690. rt_thread_delay(50);
  691. turn_cnt ++;
  692. if(turn_cnt==10)
  693. {
  694. turn_cnt = 0;
  695. rt_pin_write(TURN_ZP_R, OFF);
  696. rt_pin_write(TURN_ZP_L, OFF);
  697. //Motor_shake(OFF,0);
  698. char *turn_warn =makeJson_Warn("超时", "转盘");
  699. DTU_Write(turn_warn);
  700. rt_free(turn_warn);
  701. break;
  702. }
  703. }
  704. if(sta!=0)
  705. {
  706. //保存位置
  707. device_status.run_sta = sta;
  708. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  709. }
  710. turn_cnt = 0;
  711. rt_pin_write(TURN_ZP_R, OFF);
  712. rt_pin_write(TURN_ZP_L, OFF);
  713. Motor_shake(OFF,0);
  714. HMI_WRITE("cangWei.rotateFlag.val=0");
  715. }
  716. /*
  717. *
  718. * */
  719. void ctr_Motor_Driver_Power(uint8_t status_ws)
  720. {
  721. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  722. rt_pin_write(SHAKE_SW, status_ws);
  723. }
  724. /*************************************************
  725. Function: ctr_Motor_Driver
  726. Description: 步进电机驱动
  727. Calls:
  728. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  729. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  730. Input: 50000000
  731. Output: NULL
  732. Return: shake_sec
  733. Others: NULL
  734. *************************************************/
  735. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out)
  736. {
  737. beep_init();
  738. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  739. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  740. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  741. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  742. if(EN==0)
  743. {
  744. rt_pin_write(Motor_Power,0);
  745. }
  746. else{
  747. rt_pin_write(Motor_EN, EN);
  748. }
  749. rt_pin_write(Motor_DIR, DIR);
  750. beep_set(pwm, pwm/2); //200kzh - 50%
  751. while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
  752. {
  753. if(time_out==0)
  754. {
  755. break;
  756. }
  757. rt_thread_delay(50);
  758. time_out --;
  759. }
  760. while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
  761. {
  762. if(time_out==0)
  763. {
  764. break;
  765. }
  766. rt_thread_delay(50);
  767. time_out --;
  768. }
  769. //rt_pin_write(Motor_EN, OFF);
  770. //if(device_status.autotakepic==0)
  771. //ctr_lamp(OFF, 1);
  772. beep_set(0, 0); //200kzh - 50%
  773. rt_thread_delay(50);
  774. }
  775. /*************************************************
  776. Function: ctr_Petroleum_jelly
  777. Description: 涂凡士林
  778. Calls:
  779. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  780. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  781. Input: NULL
  782. Output: NULL
  783. Return: NULL
  784. Others: NULL
  785. *************************************************/
  786. void ctr_Petroleum_jelly(rt_uint32_t delay)
  787. {
  788. beep_init();
  789. pwm_on(2,50000);
  790. rt_thread_delay(delay*1000);
  791. pwm_off(2,0);
  792. rt_thread_delay(1000);
  793. pwm_on(3, 50000);
  794. rt_thread_delay(delay*1000);
  795. pwm_off(3,0);
  796. device_status.fsl_sw = 0;
  797. }
  798. //1.0转仓
  799. void turnzp(void)
  800. {
  801. static uint16_t turn_timeout = 0;
  802. // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  803. // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  804. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  805. // rt_pin_write(CLEAR_R,OFF);
  806. // rt_pin_write(CLEAR_L,OFF);
  807. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  808. {
  809. rt_thread_delay(20);
  810. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  811. {
  812. // rt_pin_write(CLEAR_R,ON);
  813. // rt_pin_write(CLEAR_L,OFF);
  814. Motor_Juandai(ON);
  815. rt_thread_delay(50);
  816. turn_timeout++;
  817. if(turn_timeout==600)
  818. {
  819. LOG_E("检测不到限位,电机强制停止");
  820. char *ctr_zp_limit_warn =makeJson_Warn("电流不足/限位超时","转盘电机");
  821. DTU_Write("%s",ctr_zp_limit_warn);
  822. rt_free(ctr_zp_limit_warn);
  823. break;
  824. }
  825. }
  826. break;
  827. }
  828. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  829. {
  830. rt_thread_delay(20);
  831. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  832. {
  833. // rt_pin_write(CLEAR_R,ON);
  834. // rt_pin_write(CLEAR_L,OFF);
  835. Motor_Juandai(ON);
  836. rt_thread_delay(50);
  837. turn_timeout++;
  838. if(turn_timeout==600)
  839. {
  840. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  841. char *ctr_zp_limit_warn =makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障","转盘电机");
  842. DTU_Write("%s",ctr_zp_limit_warn);
  843. rt_free(ctr_zp_limit_warn);
  844. break;
  845. }
  846. }
  847. break;
  848. }
  849. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  850. {
  851. rt_thread_delay(20);
  852. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  853. {
  854. // rt_pin_write(CLEAR_R,OFF);
  855. // rt_pin_write(CLEAR_L,OFF);
  856. Motor_Juandai(OFF);
  857. break;
  858. }
  859. else {
  860. break;
  861. }
  862. }
  863. Motor_Juandai(OFF);
  864. // rt_pin_write(CLEAR_R,OFF);
  865. // rt_pin_write(CLEAR_L,OFF);
  866. turn_timeout = 0;
  867. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  868. HMI_WRITE("sysTest.switchClear.val=%d",0);
  869. rt_thread_delay(1000);
  870. }
  871. //清扫-常闭型限位开关
  872. //新结构使用推杆电机做清扫
  873. uint8_t ctr_clear(uint16_t status_clear)
  874. {
  875. static uint16_t clear_num = 0;
  876. #if PWM_EN == 0
  877. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  878. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  879. #endif
  880. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  881. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  882. /*************************************************************外接清扫
  883. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  884. rt_pin_write(POWER_CLEAR,ON);
  885. rt_thread_delay(1000*100);
  886. rt_pin_write(POWER_CLEAR,OFF);
  887. ************************************************************/
  888. //停止
  889. #if PWM_EN == 0
  890. rt_pin_write(CLEAR_R,OFF);
  891. rt_pin_write(CLEAR_L,OFF);
  892. #else
  893. Motor_Qingsao_R_PWM(OFF);
  894. Motor_Qingsao_L_PWM(OFF);
  895. #endif
  896. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  897. rt_thread_delay(100);
  898. //如果清扫位置在中间
  899. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  900. {
  901. #if PWM_EN == 0
  902. rt_pin_write(CLEAR_R,ON);
  903. rt_pin_write(CLEAR_L,OFF);
  904. #else
  905. Motor_Qingsao_R_PWM(ON);
  906. Motor_Qingsao_L_PWM(OFF);
  907. #endif
  908. rt_thread_delay(50);
  909. clear_num++;
  910. //已到达检测位置
  911. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  912. {
  913. #if PWM_EN == 0
  914. rt_pin_write(CLEAR_R,ON);
  915. rt_pin_write(CLEAR_L,ON);
  916. #else
  917. Motor_Qingsao_R_PWM(OFF);
  918. Motor_Qingsao_L_PWM(OFF);
  919. #endif
  920. rt_thread_delay(2000);
  921. break;
  922. }
  923. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  924. {
  925. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  926. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  927. #if PWM_EN == 0
  928. rt_pin_write(CLEAR_R,ON);
  929. rt_pin_write(CLEAR_L,ON);
  930. #else
  931. Motor_Qingsao_R_PWM(OFF);
  932. Motor_Qingsao_L_PWM(OFF);
  933. #endif
  934. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  935. if(Read_Real_Voltage()/100<12)
  936. {
  937. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  938. HMI_WRITE("sysTest.switchClear.val=%d",0);
  939. device_status.clear_status = 0;
  940. return 0;
  941. }
  942. break;
  943. }
  944. }
  945. clear_num = 0;
  946. //如果清扫位置在左侧
  947. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  948. {
  949. #if PWM_EN == 0
  950. rt_pin_write(CLEAR_R,ON);
  951. rt_pin_write(CLEAR_L,OFF);
  952. #else
  953. Motor_Qingsao_R_PWM(ON);
  954. Motor_Qingsao_L_PWM(OFF);
  955. #endif
  956. rt_thread_delay(50);
  957. clear_num++;
  958. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  959. {
  960. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  961. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  962. #if PWM_EN == 0
  963. rt_pin_write(CLEAR_R,ON);
  964. rt_pin_write(CLEAR_L,ON);
  965. #else
  966. Motor_Qingsao_R_PWM(OFF);
  967. Motor_Qingsao_L_PWM(OFF);
  968. #endif
  969. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  970. if(Read_Real_Voltage()/100<12)
  971. {
  972. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  973. HMI_WRITE("sysTest.switchClear.val=%d",0);
  974. device_status.clear_status = 0;
  975. return 0;
  976. }
  977. break;
  978. }
  979. }
  980. clear_num = 0;
  981. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  982. {
  983. #if PWM_EN == 0
  984. rt_pin_write(CLEAR_R,ON);
  985. rt_pin_write(CLEAR_L,ON);
  986. #else
  987. Motor_Qingsao_R_PWM(OFF);
  988. Motor_Qingsao_L_PWM(OFF);
  989. #endif
  990. if(Read_Real_Voltage()/100<12)
  991. {
  992. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  993. HMI_WRITE("sysTest.switchClear.val=%d",0);
  994. device_status.clear_status = 0;
  995. return 0;
  996. }
  997. rt_thread_delay(2000);
  998. break;
  999. }
  1000. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  1001. {
  1002. #if PWM_EN == 0
  1003. rt_pin_write(CLEAR_R,OFF);
  1004. rt_pin_write(CLEAR_L,ON);
  1005. #else
  1006. Motor_Qingsao_R_PWM(OFF);
  1007. Motor_Qingsao_L_PWM(ON);
  1008. #endif
  1009. rt_thread_delay(50);
  1010. clear_num++;
  1011. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1012. {
  1013. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1014. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  1015. //DTU_Write("%s",Clear_ERR);
  1016. #if PWM_EN == 0
  1017. rt_pin_write(CLEAR_R,ON);
  1018. rt_pin_write(CLEAR_L,ON);
  1019. #else
  1020. Motor_Qingsao_R_PWM(OFF);
  1021. Motor_Qingsao_L_PWM(OFF);
  1022. #endif
  1023. rt_free(Clear_ERR);
  1024. if(Read_Real_Voltage()/100<12)
  1025. {
  1026. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1027. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1028. device_status.clear_status = 0;
  1029. return 0;
  1030. }
  1031. break;
  1032. }
  1033. }
  1034. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  1035. {
  1036. #if PWM_EN == 0
  1037. rt_pin_write(CLEAR_R,ON);
  1038. rt_pin_write(CLEAR_L,ON);
  1039. #else
  1040. Motor_Qingsao_R_PWM(OFF);
  1041. Motor_Qingsao_L_PWM(OFF);
  1042. #endif
  1043. rt_thread_delay(2000);
  1044. break;
  1045. }
  1046. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  1047. {
  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. if(device_status.version_type==41)
  1056. {
  1057. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  1058. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  1059. //DTU_Write("%s",Clear_ERR);
  1060. rt_free(Clear_ERR);
  1061. }
  1062. return 0;
  1063. }
  1064. clear_num = 0;
  1065. rt_thread_delay(2000);
  1066. #if PWM_EN == 0
  1067. rt_pin_write(CLEAR_R,ON);
  1068. rt_pin_write(CLEAR_L,ON);
  1069. #else
  1070. Motor_Qingsao_R_PWM(OFF);
  1071. Motor_Qingsao_L_PWM(OFF);
  1072. #endif
  1073. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1074. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1075. device_status.clear_status = 0;
  1076. return 1;
  1077. }
  1078. //路由器供电
  1079. void ctr_router(uint8_t status_router)
  1080. {
  1081. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  1082. if(device_status.version_type==6)
  1083. rt_pin_mode(ROUTER_P,PIN_MODE_OUTPUT);
  1084. //rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1085. if(status_router==ON)
  1086. {
  1087. rt_pin_write(ROUTER,ON);
  1088. //
  1089. #if LAMP_EN == 0
  1090. if(device_status.version_type==6)
  1091. rt_pin_write(ROUTER_P,ON);
  1092. #endif
  1093. }
  1094. else {
  1095. rt_pin_write(ROUTER,OFF);
  1096. //
  1097. #if LAMP_EN == 0
  1098. if(device_status.version_type==6)
  1099. rt_pin_write(ROUTER_P,OFF);
  1100. #endif
  1101. }
  1102. }
  1103. //清扫-推杆电机
  1104. void ctr_TG_Clear(uint16_t clear_timeout)
  1105. {
  1106. #if 0
  1107. int current_clear[200];
  1108. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1109. LOG_I("清扫电机待机:%d",Electric_current);
  1110. #endif
  1111. static uint16_t clear_count = 0;
  1112. clear_count = clear_timeout;
  1113. #if PWM_EN == 0
  1114. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1115. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1116. #endif
  1117. while(clear_count!=0)
  1118. {
  1119. #if PWM_EN == 0
  1120. rt_pin_write(CLEAR_R,ON);
  1121. rt_pin_write(CLEAR_L,OFF);
  1122. #else
  1123. Motor_Qingsao_R_PWM(ON);
  1124. Motor_Qingsao_L_PWM(OFF);
  1125. #endif
  1126. clear_count--;
  1127. rt_thread_delay(100);
  1128. }
  1129. #if PWM_EN == 0
  1130. rt_pin_write(CLEAR_R,ON);
  1131. rt_pin_write(CLEAR_L,ON);
  1132. #else
  1133. Motor_Qingsao_R_PWM(OFF);
  1134. Motor_Qingsao_L_PWM(OFF);
  1135. #endif
  1136. rt_thread_delay(3000);
  1137. clear_count = 0;
  1138. while(clear_timeout!=clear_count)
  1139. {
  1140. #if PWM_EN == 0
  1141. rt_pin_write(CLEAR_R,OFF);
  1142. rt_pin_write(CLEAR_L,ON);
  1143. #else
  1144. Motor_Qingsao_R_PWM(OFF);
  1145. Motor_Qingsao_L_PWM(ON);
  1146. #endif
  1147. // if(clear_count<200)
  1148. // current_clear[clear_count] = atoi(device_status.power);
  1149. clear_count++;
  1150. rt_thread_delay(100);
  1151. }
  1152. #if PWM_EN == 0
  1153. rt_pin_write(CLEAR_R,ON);
  1154. rt_pin_write(CLEAR_L,ON);
  1155. #else
  1156. Motor_Qingsao_R_PWM(OFF);
  1157. Motor_Qingsao_L_PWM(OFF);
  1158. #endif
  1159. #if 0
  1160. bubblesort(current_clear,200);
  1161. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1162. {
  1163. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1164. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1165. DTU_Write("%s",ctr_clear_warn);
  1166. rt_free(ctr_clear_warn);
  1167. }
  1168. #endif
  1169. rt_thread_delay(2000);
  1170. device_status.clear_status = 0;
  1171. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1172. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1173. }
  1174. //DTU,RTU供电
  1175. void ctr_RTU_DTU(uint8_t status_rtu)
  1176. {
  1177. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1178. if(status_rtu==ON)
  1179. {
  1180. rt_pin_write(RTU_DTU,ON);
  1181. }
  1182. else
  1183. {
  1184. LOG_W("RTU电源复位!!!");
  1185. rt_pin_write(RTU_DTU,OFF);
  1186. }
  1187. }
  1188. //海康拍照
  1189. void Hk_Take_io(void)
  1190. {
  1191. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1192. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1193. rt_pin_write(HK_TAKE, 1);
  1194. rt_pin_write(HK_IO, 0);
  1195. if(device_status.dtype==3)
  1196. Beep_Tip(1000);
  1197. if(device_status.dtype==7)
  1198. rt_thread_mdelay(1000);
  1199. rt_pin_write(HK_TAKE, 0);
  1200. rt_pin_write(HK_IO, 1);
  1201. }
  1202. void calorstat(uint16_t heat_time)
  1203. {
  1204. //uint8_t heat_up_cnt = 0;
  1205. uint16_t n = 0;
  1206. uint16_t delay_heat = 60;
  1207. FlagStatus heat_flg = RESET;
  1208. device_status.heat_time_min = 0;
  1209. device_status.run_sta = device_status.heattem; //初始化加热实时温度
  1210. ctr_Heat(ON);
  1211. // UpLoad_Data(); //开始加热时的第一条数据
  1212. //恒温模式
  1213. for(n=0;n < heat_time;n++)
  1214. {
  1215. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  1216. {
  1217. heat_flg = SET;
  1218. ctr_Heat(OFF);
  1219. while(delay_heat!=0)
  1220. {
  1221. delay_heat --;
  1222. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  1223. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
  1224. rt_thread_delay(1000);
  1225. if(device_status.heattem>device_status.run_sta + 1){
  1226. device_status.run_sta = device_status.heattem;
  1227. }
  1228. }
  1229. delay_heat = 60;
  1230. //跳出FOR循环
  1231. n = n + 60;
  1232. }
  1233. if(device_status.heattem>device_status.run_sta + 1){
  1234. device_status.run_sta = device_status.heattem;
  1235. }
  1236. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  1237. {
  1238. //device_status.run_sta = device_status.heattem;
  1239. ctr_Heat(ON);
  1240. }
  1241. else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
  1242. {
  1243. // if(heat_up_cnt==0)
  1244. // {
  1245. // UpLoad_Data(); //加热到设定温度的数据
  1246. // heat_up_cnt = 1;
  1247. // }
  1248. //device_status.run_sta = device_status.heattem;
  1249. ctr_Heat(OFF);
  1250. }
  1251. if((n % 60)==0)
  1252. {
  1253. device_status.heat_time_min = device_status.heat_time_min + 1;
  1254. // if(device_status.heat_time_min % 5 == 0)
  1255. // {
  1256. // UpLoad_Data(); //从加热开始每5分钟上传的数据
  1257. // }
  1258. }
  1259. //如果触发异常退出加热
  1260. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1261. {
  1262. rt_thread_delay(1000);
  1263. if(device_status.bat_status == 1)
  1264. {
  1265. rt_kprintf("============================触发异常退出加热==========================");
  1266. ctr_lamp(OFF,1);
  1267. ctr_Heat(OFF);
  1268. break;
  1269. }
  1270. }
  1271. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1272. {
  1273. ctr_Heat(OFF);
  1274. rt_kprintf("异常退出!!!\n");
  1275. break;
  1276. }
  1277. rt_thread_delay(1000);
  1278. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  1279. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
  1280. }
  1281. ctr_Heat(OFF);
  1282. //UpLoad_Data(); //加热结束的数据
  1283. }
  1284. //初始化所有控制驱动,关闭
  1285. void HardWare_Init(uint8_t boot)
  1286. {
  1287. Beep_Tip(200);
  1288. //关闭上仓门
  1289. ctr_cangmen_up(OFF);
  1290. if(device_status.dtype==3){
  1291. //关闭下仓门电机
  1292. ctr_cangmen_down(OFF);
  1293. }
  1294. //关闭镇流器
  1295. if(device_status.autotakepic==0)
  1296. ctr_lamp(OFF,1);
  1297. //关闭震动电机
  1298. ctr_shake(OFF,0);
  1299. //关闭加热
  1300. ctr_Heat(OFF);
  1301. //关闭补光灯
  1302. ctr_led(OFF);
  1303. //关闭12V供电(海康相机,RTU)
  1304. ctr_photo(OFF);
  1305. //关闭清扫电机驱动
  1306. ctr_clear(OFF);
  1307. }
  1308. //拍照
  1309. void HK_TakePhoto(void)
  1310. {
  1311. //打开补光灯
  1312. DTU_Write("takephoto.mp3");
  1313. rt_thread_delay(10000);
  1314. char *takephotojson = makeJson_takephoto();
  1315. DTU_Write("%s",takephotojson);
  1316. rt_free(takephotojson);
  1317. //吸虫塔
  1318. if(device_status.version_type!=6)
  1319. {
  1320. ctr_led(ON);
  1321. if(device_status.version_type==48)
  1322. {
  1323. rt_thread_delay(1000*60);
  1324. }
  1325. else {
  1326. rt_thread_delay(1000*15);
  1327. }
  1328. }
  1329. //触发海康相机拍照
  1330. Hk_Take_io();
  1331. if(device_status.version_type!=6)
  1332. {
  1333. rt_thread_delay(1000*45);
  1334. }
  1335. else {
  1336. ctr_led(ON);
  1337. rt_thread_delay(1000*19);
  1338. }
  1339. ctr_led(OFF);
  1340. }
  1341. //光控测试任务
  1342. void SunTest(void)
  1343. {
  1344. rt_uint16_t ui_timeout_l = 0;
  1345. //未检测到光照,一秒扫描等待,超时30S
  1346. while(Read_Light_Voltage()<500)
  1347. {
  1348. ui_timeout_l ++;
  1349. rt_thread_delay(1000);
  1350. if(ui_timeout_l==30) break;
  1351. }
  1352. rt_thread_delay(3000);
  1353. if(Read_Light_Voltage()<500)
  1354. {
  1355. device_status.sun_status = 0;//光控状态
  1356. }
  1357. if(Read_Light_Voltage()>500)
  1358. {
  1359. rt_thread_delay(1000);
  1360. }
  1361. rt_thread_delay(3000);
  1362. if(Read_Light_Voltage()>500)
  1363. {
  1364. device_status.sun_status = 1;
  1365. ctr_lamp(OFF,1);
  1366. }
  1367. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1368. device_status.sun_test = 0;
  1369. device_status.work_status=0;
  1370. }
  1371. /*上电初始化*/
  1372. void ResetInit(void)
  1373. {
  1374. if(device_status.dtype==7)
  1375. {
  1376. ctr_Motor_Driver(0, 0, 0, 0);
  1377. //关闭电磁阀
  1378. ctr_shake(OFF, 0);
  1379. //关闭加热
  1380. ctr_Heat(OFF);
  1381. //关闭制冷
  1382. ctr_Cold(OFF);
  1383. //关闭补光灯
  1384. ctr_led(OFF);
  1385. //转盘复位
  1386. if(device_status.run_sta==0)
  1387. ctr_turn(0, 0);
  1388. }
  1389. if(device_status.version_type!=6&&device_status.version_type!=7)
  1390. {
  1391. device_status.work_done = 1;
  1392. //1.打开路由器供电
  1393. if(device_status.power_status==1)
  1394. {
  1395. ctr_router(ON);
  1396. ctr_RTU_DTU(ON);
  1397. //2.打开相机供电
  1398. ctr_photo(ON);
  1399. }
  1400. //3.关闭镇流器
  1401. ctr_lamp(OFF,1);
  1402. //4.关闭震动电机
  1403. ctr_shake(OFF, 0);
  1404. //5.关闭加热
  1405. ctr_Heat(OFF);
  1406. //6.关闭补光灯
  1407. ctr_led(OFF);
  1408. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  1409. {
  1410. LOG_W("欠压!");
  1411. return;
  1412. }
  1413. //7.关闭上仓门
  1414. device_status.ctr_up_motor = 2;
  1415. // while(device_status.ctr_up_motor!=0)
  1416. // {
  1417. // LOG_I("关闭上仓门...");
  1418. // rt_thread_delay(100);
  1419. // }
  1420. //8.关闭下仓门
  1421. device_status.ctr_down_motor = 2;
  1422. while(device_status.ctr_down_motor!=0)
  1423. {
  1424. LOG_I("关闭下仓门....");
  1425. rt_thread_delay(100);
  1426. }
  1427. //9.清扫
  1428. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1429. {
  1430. LOG_W("异常退出!!!\n");
  1431. return;
  1432. }
  1433. #if 0//LAMP_EN == 0
  1434. ctr_Fan_PUT(OFF);
  1435. ctr_Fan_IN(OFF);
  1436. #endif
  1437. if(device_status.version_type==4||device_status.version_type==41)
  1438. {
  1439. device_status.clear_status=1;
  1440. while(device_status.clear_status==1){
  1441. rt_thread_delay(1000);
  1442. }
  1443. }
  1444. }
  1445. else {
  1446. if(device_status.power_status==1)
  1447. {
  1448. //1.打开路由器供电
  1449. ctr_router(ON);
  1450. ctr_RTU_DTU(ON);
  1451. //2.打开相机供电
  1452. ctr_photo(ON);
  1453. }
  1454. //5.关闭加热
  1455. //6.关闭补光灯
  1456. ctr_led(OFF);
  1457. }
  1458. }
  1459. /*三色光源*/
  1460. void Led_Check(uint8_t tp)
  1461. {
  1462. if(tp==3)
  1463. {
  1464. if(device_status.light_over_tim>2*3600)
  1465. {
  1466. device_status.work_status = 1;
  1467. device_status.lamp_status = 1;
  1468. device_status.lamp1_status = 0;
  1469. device_status.lamp2_status = 0;
  1470. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1471. }
  1472. else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
  1473. device_status.work_status = 1;
  1474. device_status.lamp_status = 0;
  1475. device_status.lamp1_status = 1;
  1476. device_status.lamp2_status = 0;
  1477. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1478. }
  1479. else if (device_status.light_over_tim<1*3600) {
  1480. device_status.work_status = 1;
  1481. device_status.lamp_status = 0;
  1482. device_status.lamp1_status = 0;
  1483. device_status.lamp2_status = 1;
  1484. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1485. }
  1486. }
  1487. else if (tp==6) {
  1488. if(device_status.light_over_tim>4*3600)
  1489. {
  1490. device_status.work_status = 1;
  1491. device_status.lamp_status = 1;
  1492. device_status.lamp1_status = 0;
  1493. device_status.lamp2_status = 0;
  1494. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1495. }
  1496. else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
  1497. device_status.work_status = 1;
  1498. device_status.lamp_status = 0;
  1499. device_status.lamp1_status = 1;
  1500. device_status.lamp2_status = 0;
  1501. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1502. }
  1503. else if (device_status.light_over_tim<7200) {
  1504. device_status.work_status = 1;
  1505. device_status.lamp_status = 0;
  1506. device_status.lamp1_status = 0;
  1507. device_status.lamp2_status = 1;
  1508. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1509. }
  1510. }
  1511. else if (tp==9) {
  1512. if(device_status.light_over_tim>6*3600)
  1513. {
  1514. device_status.work_status = 1;
  1515. device_status.lamp_status = 1;
  1516. device_status.lamp1_status = 0;
  1517. device_status.lamp2_status = 0;
  1518. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1519. }
  1520. else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
  1521. device_status.work_status = 1;
  1522. device_status.lamp_status = 0;
  1523. device_status.lamp1_status = 1;
  1524. device_status.lamp2_status = 0;
  1525. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1526. }
  1527. else if (device_status.light_over_tim<3*3600) {
  1528. device_status.work_status = 1;
  1529. device_status.lamp_status = 0;
  1530. device_status.lamp1_status = 0;
  1531. device_status.lamp2_status = 1;
  1532. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1533. }
  1534. }
  1535. }
  1536. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1537. void HardWare_Check(uint8_t boot)
  1538. {
  1539. if(boot==0&&device_status.version_type!=6)
  1540. {
  1541. //停止所有动作 -完成
  1542. HardWare_Init(boot);
  1543. }
  1544. else {
  1545. //停止所有动作
  1546. //读取记录待机功耗(实测大概70mA)
  1547. //(需减去屏幕的功耗大概120mA)
  1548. //动作上仓门,读取功率值保存
  1549. //动作下仓门,读取功率值保存
  1550. //动作清扫,读取功率值保存
  1551. //打开镇流器,读取功率值保存
  1552. //打开海康相机供电,读取功率值保存
  1553. //打开补光灯,读取功率值保存
  1554. //打开路由器/RTU供电,读取功率值保存
  1555. //打开加热,读取功率值保存
  1556. }
  1557. }
  1558. //工作状态检测
  1559. void WorkCheck(void)
  1560. {
  1561. //雨控检测,温控检测,电池电压检测
  1562. while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  1563. {
  1564. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1565. if(device_status.timeSwitch==1)
  1566. {
  1567. LOG_I("***********时控*****************");
  1568. if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
  1569. device_status.work_status = 1;
  1570. LOG_I("24 hours work...");
  1571. #if LAMP_EN == 1
  1572. device_status.lamp_status = 1;
  1573. device_status.lamp1_status = 0;
  1574. device_status.lamp2_status = 0;
  1575. if(device_status.sun_status==1){
  1576. ctr_lamp(OFF, 1);
  1577. ctr_lamp(OFF, 2);
  1578. ctr_lamp(OFF, 3);
  1579. }
  1580. #endif
  1581. }
  1582. //如果开始和结束是同一天
  1583. if(device_status.startBar<device_status.stopBar)
  1584. {
  1585. LOG_I("开始和结束是同一天");
  1586. time_t now;
  1587. time(&now);
  1588. static struct tm nowtime; //现在
  1589. static struct tm starttime; //开始
  1590. static struct tm endtime; //结束
  1591. //获取当前时间戳
  1592. nowtime =*localtime(&now);
  1593. nowtime.tm_hour = nowtime.tm_hour-8;
  1594. //获取定时开始的时间戳
  1595. starttime = *localtime(&now);
  1596. starttime.tm_hour = device_status.startBar-8;
  1597. starttime.tm_min = 0;
  1598. starttime.tm_sec = 0;
  1599. //获取定时结束的时间戳
  1600. endtime = *localtime(&now);
  1601. endtime.tm_hour = device_status.stopBar-8;
  1602. endtime.tm_min = 0;
  1603. endtime.tm_sec = 0;
  1604. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1605. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1606. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  1607. {
  1608. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1609. device_status.work_status = 1;
  1610. }
  1611. //如果当前时间小于开始时间
  1612. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  1613. {
  1614. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1615. device_status.work_status = 0;
  1616. }
  1617. //当前时间大于结束时间
  1618. else {
  1619. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1620. device_status.work_status = 0;
  1621. }
  1622. #if LAMP_EN == 1
  1623. //如果当前时间超过20点,未到21点
  1624. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
  1625. {
  1626. LOG_I("3led:20~21");
  1627. device_status.lamp_status = 1;
  1628. device_status.lamp1_status = 0;
  1629. device_status.lamp2_status = 0;
  1630. }
  1631. else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
  1632. LOG_I("3led:21~22");
  1633. device_status.lamp1_status = 1;
  1634. device_status.lamp_status = 0;
  1635. device_status.lamp2_status = 0;
  1636. }
  1637. else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
  1638. LOG_I("3led:22~23");
  1639. device_status.lamp2_status = 1;
  1640. device_status.lamp_status = 0;
  1641. device_status.lamp1_status =0;
  1642. }
  1643. #endif
  1644. }
  1645. //如果结束时间是第二天
  1646. else if (device_status.startBar>device_status.stopBar) {
  1647. time_t now;
  1648. time(&now);
  1649. static struct tm nowtime; //现在
  1650. static struct tm starttime; //开始
  1651. static struct tm endtime; //结束
  1652. //获取当前时间戳
  1653. nowtime =*localtime(&now);
  1654. nowtime.tm_hour = nowtime.tm_hour-8;
  1655. //获取定时开始的时间戳
  1656. starttime = *localtime(&now);
  1657. starttime.tm_hour = device_status.startBar-8;
  1658. starttime.tm_min = 0;
  1659. starttime.tm_sec = 0;
  1660. //获取定时结束的时间戳
  1661. endtime = *localtime(&now);
  1662. endtime.tm_hour = device_status.stopBar-8;
  1663. endtime.tm_min = 0;
  1664. endtime.tm_sec = 0;
  1665. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1666. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  1667. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  1668. {
  1669. //获取定时结束的时间戳
  1670. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1671. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1672. endtime.tm_min = 0;
  1673. endtime.tm_sec = 0;
  1674. device_status.work_status = 1;
  1675. LOG_I("当前前时间大于开始时间,且没有开始工作");
  1676. }
  1677. //当前时间小于开始时间
  1678. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  1679. {
  1680. //获取定时结束的时间戳
  1681. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1682. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1683. endtime.tm_min = 0;
  1684. endtime.tm_sec = 0;
  1685. //如果当前时间戳小于结束时间戳
  1686. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  1687. {
  1688. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  1689. device_status.work_status = 1;
  1690. }
  1691. else
  1692. {
  1693. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  1694. device_status.work_status = 0; //不在工作时间,待机
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else {
  1700. LOG_I("光控定时模式!");
  1701. /*
  1702. time_t now;
  1703. time(&now);
  1704. static struct tm nowstamp;
  1705. nowstamp =*localtime(&now);
  1706. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  1707. static rt_uint32_t nowstamp_num = 0;
  1708. nowstamp_num = mktime(&nowstamp);
  1709. rt_kprintf("now stamp:%d\n",nowstamp_num);
  1710. */
  1711. if(device_status.sun_status==0&&device_status.light_over_tim!=0)
  1712. {
  1713. device_status.light_over_tim--;
  1714. #if LAMP_EN == 1
  1715. Led_Check(device_status.sunBar);
  1716. #else
  1717. device_status.work_status = 1;;
  1718. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1719. #endif
  1720. }
  1721. else
  1722. {
  1723. //没有在测试并且没有在自检
  1724. if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
  1725. {
  1726. ctr_lamp(OFF,1);
  1727. #if LAMP_EN == 1
  1728. ctr_lamp(OFF,2);
  1729. ctr_lamp(OFF,3);
  1730. #endif
  1731. }
  1732. device_status.work_status = 0;
  1733. if(device_status.light_over_tim==0&&device_status.sun_status==1) device_status.light_over_tim = device_status.sunBar * 3600;
  1734. LOG_I("光控中,白天:%d!!!",device_status.sun_status);
  1735. }
  1736. }
  1737. rt_thread_delay(1000);
  1738. }
  1739. LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  1740. device_status.work_status = 0;
  1741. rt_thread_delay(1000);
  1742. }
  1743. //工作任务流程s
  1744. void WorkTask(void)
  1745. {
  1746. static int clt_time = 0; //收集时间差秒数
  1747. static int heat_time = 0;
  1748. LOG_I("工作状态:%d",device_status.work_status);
  1749. LOG_I("开关机状态:%d",device_status.ds);
  1750. 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)
  1751. {
  1752. device_status.work_done = 0;
  1753. if(clt_time==0)
  1754. {
  1755. #if 0
  1756. if(device_status.version_type==41&&atoi(device_status.power)<350)
  1757. {
  1758. LOG_W("相机电流不足!");
  1759. char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
  1760. DTU_Write("%s",ctr_hk_p_warn);
  1761. rt_free(ctr_hk_p_warn);
  1762. }
  1763. #endif
  1764. #if 0//LAMP_EN == 0
  1765. ctr_Fan_PUT(ON);
  1766. #endif
  1767. DTU_Write("workstart.mp3");
  1768. }
  1769. //1.打开灯管
  1770. #if LAMP_EN == 1
  1771. if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
  1772. {
  1773. ctr_lamp(ON,1);
  1774. ctr_lamp(OFF,2);
  1775. ctr_lamp(OFF,3);
  1776. }
  1777. else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
  1778. ctr_lamp(OFF,1);
  1779. ctr_lamp(ON,2);
  1780. ctr_lamp(OFF,3);
  1781. }
  1782. else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
  1783. ctr_lamp(OFF,1);
  1784. ctr_lamp(OFF,2);
  1785. ctr_lamp(ON,3);
  1786. }
  1787. #else
  1788. ctr_lamp(ON,1);
  1789. #endif
  1790. LOG_I("打开灯管!!!");
  1791. #if 0
  1792. rt_thread_delay(2000);
  1793. if(atoi(device_status.power)<450)
  1794. {
  1795. LOG_I("Current is:%d",atoi(device_status.power));
  1796. if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
  1797. {
  1798. char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
  1799. DTU_Write("%s",lamp_err_warn);
  1800. rt_free(lamp_err_warn);
  1801. }
  1802. }
  1803. #endif
  1804. if(device_status.version_type!=5)
  1805. {
  1806. rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
  1807. //2.打开上仓门
  1808. LOG_I("打开上仓门!!!");
  1809. device_status.ctr_up_motor = 1;
  1810. //3.收集
  1811. clt_time = device_status.clt_time * 60;
  1812. while(clt_time!=1)
  1813. {
  1814. #if 0//LAMP_EN == 0
  1815. ctr_Fan_IN(ON);
  1816. #endif
  1817. clt_time --;
  1818. rt_thread_delay(1000);
  1819. #if 0//LAMP_EN == 0
  1820. if(clt_time%30==0)
  1821. ctr_Fan_PUT(OFF);
  1822. #endif
  1823. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  1824. //如果触发异常
  1825. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1826. {
  1827. ctr_lamp(OFF,1);
  1828. #if LAMP_EN == 1
  1829. ctr_lamp(OFF,2);
  1830. ctr_lamp(OFF,3);
  1831. #endif
  1832. #if 0//LAMP_EN == 0
  1833. ctr_Fan_IN(OFF);
  1834. #endif
  1835. rt_kprintf("异常退出!!!\n");
  1836. break;
  1837. }
  1838. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1839. {
  1840. ctr_lamp(OFF,1);
  1841. #if LAMP_EN == 1
  1842. ctr_lamp(OFF,2);
  1843. ctr_lamp(OFF,3);
  1844. #endif
  1845. #if 0//LAMP_EN == 0
  1846. ctr_Fan_IN(OFF);
  1847. #endif
  1848. rt_kprintf("异常退出!!!\n");
  1849. break;
  1850. }
  1851. }
  1852. clt_time = 1;
  1853. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1854. {
  1855. ctr_lamp(OFF,1);
  1856. #if LAMP_EN == 1
  1857. ctr_lamp(OFF,2);
  1858. ctr_lamp(OFF,3);
  1859. #endif
  1860. #if 0//LAMP_EN == 0
  1861. ctr_Fan_IN(OFF);
  1862. #endif
  1863. rt_kprintf("异常退出!!!\n");
  1864. break;
  1865. }
  1866. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1867. {
  1868. ctr_lamp(OFF,1);
  1869. #if LAMP_EN == 1
  1870. ctr_lamp(OFF,2);
  1871. ctr_lamp(OFF,3);
  1872. #endif
  1873. #if 0//LAMP_EN == 0
  1874. ctr_Fan_IN(OFF);
  1875. #endif
  1876. rt_kprintf("异常退出!!!\n");
  1877. break;
  1878. }
  1879. #if 0//LAMP_EN == 0
  1880. ctr_Fan_IN(OFF);
  1881. #endif
  1882. //4.关闭上仓门
  1883. device_status.ctr_up_motor = 2;
  1884. rt_kprintf("关闭上仓门!!!\n");
  1885. while(device_status.ctr_up_motor!=0)
  1886. {
  1887. rt_thread_delay(100);
  1888. LOG_I("等待上仓门关闭!!!");
  1889. }
  1890. //5.加热
  1891. if(device_status.heat_sw==0)
  1892. {
  1893. calorstat(device_status.heattime*60);
  1894. }
  1895. else {
  1896. heat_time = device_status.heattime * 60;
  1897. while(heat_time!=0)
  1898. {
  1899. heat_time--;
  1900. LOG_I("正在加热状态!!!");
  1901. rt_thread_delay(1000);
  1902. }
  1903. }
  1904. //6.打开下仓门
  1905. if(device_status.rain_status==0)
  1906. {
  1907. device_status.ctr_down_motor =1;
  1908. }
  1909. else {
  1910. device_status.ctr_down_motor = 2;
  1911. device_status.ctr_up_motor = 2;
  1912. }
  1913. //待下仓门完全打开
  1914. while(device_status.ctr_down_motor!=0)
  1915. {
  1916. rt_thread_delay(100);
  1917. rt_kprintf("等待下仓门打开!!!\n");
  1918. }
  1919. rt_thread_delay(3000);
  1920. //关闭下仓门
  1921. device_status.ctr_down_motor = 2;
  1922. while(device_status.ctr_down_motor!=0)
  1923. {
  1924. rt_thread_delay(100);
  1925. rt_kprintf("等待下仓门关闭!!!\n");
  1926. }
  1927. //2022-04-12add:
  1928. LOG_I("打开上仓门!!!");
  1929. device_status.ctr_up_motor = 1;
  1930. if(device_status.version_type==4||device_status.version_type==41)
  1931. {
  1932. //震动
  1933. ctr_shake(ON, device_status.shake_sec);
  1934. //补光&&拍照
  1935. LOG_I("拍照!!!");
  1936. ctr_led(ON);
  1937. HK_TakePhoto();
  1938. //清扫
  1939. device_status.clear_status=1;
  1940. //清扫失效则使用震动
  1941. //ctr_shake(ON, 100);
  1942. }
  1943. }
  1944. }
  1945. if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
  1946. {
  1947. LOG_I("-------------------not work--------------------");
  1948. device_status.work_status = 0;
  1949. }
  1950. //工作结束
  1951. if(device_status.work_done==0&&device_status.work_status==0)
  1952. {
  1953. DTU_Write("workdone");
  1954. if (device_status.version_type==1) {
  1955. turnzp(); //2024-03-21 :开机不再转仓
  1956. }
  1957. ResetInit();
  1958. clt_time = 0;
  1959. }
  1960. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  1961. }
  1962. void guanshan_on(void *args)
  1963. {
  1964. LOG_W("guanshan_on!");
  1965. rt_event_send(event_485_play, 0x01);
  1966. }
  1967. static void pin_guangshan_bind(void)
  1968. {
  1969. /* PC14引脚为输入模式 */
  1970. rt_pin_mode(GUANG_SHAN, PIN_MODE_INPUT);
  1971. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  1972. rt_pin_attach_irq(GUANG_SHAN, PIN_IRQ_MODE_RISING, guanshan_on, RT_NULL);
  1973. /* 使能中断 */
  1974. rt_pin_irq_enable(GUANG_SHAN, PIN_IRQ_ENABLE);
  1975. }
  1976. static void pin_guangshan_unbind(void)
  1977. {
  1978. rt_pin_detach_irq(GUANG_SHAN);
  1979. }
  1980. /*
  1981. * 灯管
  1982. *
  1983. * */
  1984. void WorkTask_CB5(void)
  1985. {
  1986. static int work_loop = 0;
  1987. 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)
  1988. {
  1989. work_loop++;
  1990. device_status.work_done = 0;
  1991. //发送串口消息,通知yolo是被及相机采集模块启动,定期将模块的运行状态展示到屏幕上
  1992. if(work_loop%60==0||work_loop==1)
  1993. {
  1994. DTU_Write("{\"cmd\":\"workstart\"}");
  1995. //推杆电机1打开,导流板到落虫通道
  1996. device_status.ctr_up_motor = 1;
  1997. while(device_status.ctr_up_motor!=0)
  1998. {
  1999. rt_thread_delay(2000);
  2000. LOG_I("等待上仓门打开....");
  2001. }
  2002. //推杆电机2关闭,益虫仓门关闭
  2003. device_status.ctr_down_motor = 2;
  2004. while(device_status.ctr_down_motor!=0)
  2005. {
  2006. rt_thread_delay(2000);
  2007. LOG_I("等待益虫仓门打开....");
  2008. }
  2009. //打开86步进电机驱动器供电
  2010. ctr_Motor_Driver_Power(ON);
  2011. //风机启动
  2012. //打开灯管
  2013. ctr_lamp(ON,1);
  2014. //打开补光灯
  2015. ctr_led(ON);
  2016. //光栅启动
  2017. ctr_photo(ON);
  2018. //
  2019. pin_guangshan_bind();
  2020. pin_motor_86_bind();
  2021. }
  2022. rt_thread_delay(1000);
  2023. }
  2024. device_status.work_status = 0;
  2025. //工作结束
  2026. if(device_status.work_done==0&&device_status.work_status==0)
  2027. {
  2028. pin_guangshan_unbind();
  2029. pin_motor_86_unbind();
  2030. //打开推杆电机,益虫放生
  2031. device_status.ctr_down_motor = 1;
  2032. DTU_Write("{\"cmd\":\"workdone\"}");
  2033. ResetInit();
  2034. }
  2035. work_loop = 0;
  2036. while(device_status.work_status==0)
  2037. {
  2038. work_loop++;
  2039. LOG_I("WorkTask_CB5 sleeping......%d",work_loop);
  2040. if(work_loop>120)
  2041. {
  2042. work_loop = 0;
  2043. DTU_Write("{\"cmd\":\"workdone\"}");
  2044. }
  2045. rt_thread_delay(5000);
  2046. }
  2047. }
  2048. /* 入口函数-工作状态检测 */
  2049. static void Work_status_thread_entry(void *parameter)
  2050. {
  2051. static uint16_t sun_status_num = 120;
  2052. //如果是光控定时,进行光控监测的消抖
  2053. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  2054. {
  2055. rt_kprintf("光控定时!!!\n");
  2056. while(sun_status_num!=0)
  2057. {
  2058. sun_status_num--;
  2059. rt_thread_delay(1000);
  2060. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  2061. }
  2062. device_status.light_over_tim = device_status.sunBar * 3600;
  2063. device_status.test_flag = 0;
  2064. }
  2065. while(1)
  2066. {
  2067. WorkCheck();
  2068. }
  2069. }
  2070. /*入口函数-工作流程*/
  2071. static void Work_Loop_thread_entry(void *parameter)
  2072. {
  2073. rt_thread_delay(1000);
  2074. ResetInit();
  2075. while(1)
  2076. {
  2077. if(device_status.version_type!=5&&device_status.dtype==3)
  2078. {
  2079. WorkTask();
  2080. }
  2081. if(device_status.version_type==5)
  2082. {
  2083. WorkTask_CB5();
  2084. }
  2085. rt_thread_delay(1000);
  2086. }
  2087. }
  2088. /*入口函数清扫*/
  2089. static void Control_Clear_thread_entry(void *parameter)
  2090. {
  2091. while(1)
  2092. {
  2093. if(device_status.clear_status==1)
  2094. {
  2095. ctr_TG_Clear(250);
  2096. }
  2097. rt_thread_delay(100);
  2098. }
  2099. }
  2100. /*入口函数加热*/
  2101. static void Control_Heat_thread_entry(void *parameter)
  2102. {
  2103. static int total_seconds = 200;
  2104. static int current_second = 0;
  2105. static int process = 0;
  2106. while(1)
  2107. {
  2108. if(device_status.work_status==1&&device_status.heat_sw==1)
  2109. {
  2110. ctr_lamp(ON, 1);
  2111. rt_thread_delay(10000);
  2112. calorstat(device_status.heattime*60);
  2113. }
  2114. else
  2115. {
  2116. if(device_status.selfcheck_ws==2)
  2117. {
  2118. while(current_second <= total_seconds)
  2119. {
  2120. process = (current_second * 100) / total_seconds;
  2121. device_status.process = process / 100.0;
  2122. LOG_I("process:%d",process);
  2123. HMI_WRITE("selfcheck.s106.val=%d",process);
  2124. rt_thread_delay(1000);
  2125. current_second++;
  2126. if(device_status.selfcheck_ws==0)
  2127. {
  2128. HMI_WRITE("selfcheck.s106.val=100");
  2129. break;
  2130. }
  2131. }
  2132. HMI_WRITE("selfcheck.s106.val=100");
  2133. }else {
  2134. process = 0;
  2135. current_second = 0;
  2136. }
  2137. }
  2138. rt_thread_delay(1000);
  2139. }
  2140. }
  2141. static void thread_485_play_entry(void *param)
  2142. {
  2143. static USHORT sound105[] = {0x736F,0x756E,0x6431,0x3037};
  2144. rt_uint32_t e;
  2145. // 创建事件控制块
  2146. event_485_play = rt_event_create("event", RT_IPC_FLAG_FIFO);
  2147. if (event_485_play == RT_NULL)
  2148. {
  2149. LOG_E("Event create failed!");
  2150. return;
  2151. }
  2152. while(1)
  2153. {
  2154. //等待事件
  2155. if(rt_event_recv(event_485_play, 0x01, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e)==RT_EOK)
  2156. {
  2157. LOG_I("Interrupt occurred and processed.");
  2158. _485_play(sound105, 4);
  2159. //发送串口消息,通知JETSON计算卡进行拍照
  2160. DTU_Write("{\"guangshan\":\"on\"}");
  2161. }
  2162. }
  2163. }
  2164. /*清扫线程*/
  2165. int Control_clear(void)
  2166. {
  2167. /* 创建线程*/
  2168. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  2169. Control_Clear_thread_entry, RT_NULL,
  2170. 2048, //2048
  2171. 24, //23
  2172. WORK_CHECK_THREAD_TIMESLICE); //5
  2173. if(tid_ctr!=RT_NULL)
  2174. {
  2175. rt_thread_startup(tid_ctr);
  2176. }
  2177. return 0;
  2178. }
  2179. /*恒温加热线程*/
  2180. int Control_heat(void)
  2181. {
  2182. /* 创建线程*/
  2183. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  2184. Control_Heat_thread_entry, RT_NULL,
  2185. 1024, //2048
  2186. 25, //23
  2187. WORK_CHECK_THREAD_TIMESLICE); //5
  2188. if(tid_heat!=RT_NULL)
  2189. {
  2190. rt_thread_startup(tid_heat);
  2191. }
  2192. return 0;
  2193. }
  2194. int thread_485_play(void)
  2195. {
  2196. tid_485_play = rt_thread_create("thread_485play",
  2197. thread_485_play_entry, RT_NULL,
  2198. 1024, //1024
  2199. 26, //23
  2200. 5); //5
  2201. if(tid_485_play!=RT_NULL)
  2202. {
  2203. rt_thread_startup(tid_485_play);
  2204. }
  2205. else {
  2206. LOG_E("thread_485_play start failed!");
  2207. }
  2208. return 0;
  2209. }
  2210. /* 创建线程 -工作状态检测*/
  2211. int Workstatus_check(void)
  2212. {
  2213. /* 创建线程*/
  2214. tid_wkstc = rt_thread_create("work_status_check_thread",
  2215. Work_status_thread_entry, RT_NULL,
  2216. WORK_CHECK_THREAD_STACK_SIZE, //1024
  2217. WORK_CHECK_THREAD_PRIORITY, //23
  2218. WORK_CHECK_THREAD_TIMESLICE); //5
  2219. if(tid_wkstc!=RT_NULL)
  2220. {
  2221. rt_thread_startup(tid_wkstc);
  2222. }
  2223. return 0;
  2224. }
  2225. /*工作流程线程*/
  2226. int Work_Loop_Task(void)
  2227. {
  2228. rt_err_t result_loop = 0;
  2229. /* 创建线程*/
  2230. tid_workloop = rt_thread_create("work_loop_thread",
  2231. Work_Loop_thread_entry, RT_NULL,
  2232. WORK_LOOP_THREAD_STACK_SIZE, //2048
  2233. WORK_LOOP_THREAD_PRIORITY, //12
  2234. WORK_LOOP_THREAD_TIMESLICE); //5
  2235. if(tid_workloop!=RT_NULL)
  2236. {
  2237. result_loop = rt_thread_startup(tid_workloop);
  2238. }
  2239. return result_loop;
  2240. }
  2241. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  2242. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  2243. MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
  2244. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  2245. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
  2246. //INIT_APP_EXPORT(Control_heat);