control.c 75 KB

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