control.c 95 KB

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