| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830 |
- #include <control.h>
- /*
- * Copyright (c) 2006-2020, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-05-30 Administrator the first version
- */
- #include "beep.h"
- #include "hmi.h"
- #include "easyflash.h"
- #include "stdio.h"
- #include "sound.h"
- #include "dtu_uart2.h"
- #include "sht30_collect.h"
- #define DBG_ENABLE
- #define DBG_COLOR
- #define DBG_TAG "control"
- #define DBG_LEVEL DBG_LOG
- #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
- // 工作检测
- #define WORK_CHECK_THREAD_PRIORITY 23 // 线程优先级
- #define WORK_CHECK_THREAD_STACK_SIZE 1024 // 栈大小
- #define WORK_CHECK_THREAD_TIMESLICE 5 // 时间片
- // 工作流程
- #define WORK_LOOP_THREAD_PRIORITY 12 // 线程优先级
- #define WORK_LOOP_THREAD_STACK_SIZE 2048 // 栈大小
- #define WORK_LOOP_THREAD_TIMESLICE 5 // 时间片
- #define PWM_EN 1 // 0关闭,1-打开
- #define LOG_INR 10 // 默认的log打印间隔(作用域在本文件)
- // 设备状态表结构体
- Device_Status_typedef device_status;
- rt_thread_t tid_workloop = RT_NULL;
- rt_thread_t tid_wkstc = RT_NULL;
- rt_thread_t tid_ctr = RT_NULL;
- rt_thread_t tid_heat = RT_NULL;
- /**************************1.0定制2000W*************************************/
- /**
- * @brief 控制风扇输出
- *
- * @param status_ws 开关量
- * @return uint8_t -
- */
- uint8_t ctr_Fan_PUT(uint8_t status_ws)
- {
- rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- rt_pin_write(FAN_P, ON);
- }
- else
- {
- rt_pin_write(FAN_P, OFF);
- }
- return 0;
- }
- /**
- * @brief 控制风扇输出
- *
- * @param status_ws 开关量
- * @return uint8_t -
- */
- uint8_t ctr_Fan_IN(uint8_t status_ws)
- {
- rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- rt_pin_write(FAN_I, ON);
- }
- else
- {
- rt_pin_write(FAN_I, OFF);
- }
- return 0;
- }
- /****************************定制色诱*************************************/
- /**/
- #if Color_EN == 1
- /**
- * @brief 检测色诱按键是否有下降沿出现
- *
- * @param key_pin 引脚号
- * @return uint8_t 无意义
- */
- uint8_t Read_Color_Key(rt_base_t key_pin)
- {
- rt_uint32_t sta_s = 0;
- rt_pin_mode(key_pin, PIN_MODE_INPUT);
- while (rt_pin_read(key_pin) == 1)
- {
- sta_s++;
- /*持续的*/
- rt_thread_delay(50);
- }
- while (rt_pin_read(key_pin) == 0)
- {
- rt_thread_delay(50);
- if (sta_s > 0)
- break;
- }
- LOG_W("检测到IO0翻转!!!");
- return 1;
- }
- /*读限位开关状态*/
- /**
- * @brief 读取限位开关的状态
- *
- * @param pin_limit 引脚号
- * @return uint8_t 读取结果
- */
- uint8_t Read_Color_Limit(rt_base_t pin_limit)
- {
- uint8_t l_sta = 0;
- rt_pin_mode(pin_limit, PIN_MODE_INPUT);
- l_sta = rt_pin_read(pin_limit);
- rt_thread_delay(20);
- l_sta = rt_pin_read(pin_limit);
- return l_sta;
- }
- /*色诱板*/
- /**
- * @brief 色诱板的控制逻辑
- *
- * @param forward 下一步进行的动作
- * @param time_board 计数?
- * @return int 操作完成的动作
- */
- int ctr_Color_board(uint8_t forward, uint16_t time_board)
- {
- if (forward == CLOSE) // 归位
- {
- if (device_status.cul_time > 0)
- device_status.cul_time--;
- ctr_cangmen_down(OFF);
- ctr_cangmen_up(OFF);
- rt_thread_delay(1000);
- // if(device_status.cul_time>7) device_status.cul_time=7;
- // if(device_status.cul_time!=7)
- // {
- // uint8_t ct = device_status.cul_time;
- // while(1)
- // {
- // Beep_Tip(100);
- // rt_thread_delay(100);
- // ct--;
- // if(ct==0) break;
- // }
- // //return device_status.cul_time;
- // }
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- {
- device_status.cul_time = 0;
- LOG_W("已在初始位置!");
- Beep_Tip(1000);
- return 0;
- // 黄板已经在复位状态,直接返回0;
- }
- ctr_cangmen_up(CLOSE);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- // if(device_status.cul_time==7&&Read_Color_Limit(LIMIT_BOARD)==0)
- // {
- // LOG_W("第七天!!!");
- // ctr_cangmen_down(CLOSE);
- // rt_thread_delay(500);
- // }
- LOG_W("先打开运行到限位的右侧!");
- while (Read_Color_Limit(LIMIT_BOARD) == 0)
- {
- LOG_W("归位:到达限位中间");
- ctr_cangmen_down(CLOSE);
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- {
- ctr_cangmen_down(OFF);
- break;
- }
- }
- // 先打开运行到限位的右侧
- while (Read_Color_Limit(LIMIT_BOARD) == 1)
- {
- LOG_W("归位:运行!");
- ctr_cangmen_down(CLOSE);
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- {
- ctr_cangmen_down(OFF);
- break;
- }
- }
- while (Read_Color_Limit(LIMIT_BOARD) == 0) // 到达限位中间 继续运行
- {
- LOG_W("归位:到达限位中间");
- ctr_cangmen_down(CLOSE);
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- {
- ctr_cangmen_down(OFF);
- break;
- }
- }
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- return 0;
- LOG_W("到达限位左侧!");
- // 停止电机
- ctr_cangmen_down(OFF);
- rt_thread_delay(2000);
- // 将推杆电机归位
- LOG_D("*推杆电机归位*");
- /*推杆电机伸出*/
- ctr_cangmen_up(OPEN);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- return 2;
- }
- else if (forward == OPEN)
- {
- ctr_cangmen_down(OFF);
- ctr_cangmen_up(OFF);
- rt_thread_delay(1000);
- if (device_status.cul_time == 7)
- {
- Beep_Tip(5000);
- return 7;
- }
- LOG_W("打开推杆电机!");
- // 2023-04-18:add
- // if(Read_Color_Limit(LIMIT_BOARD)==0)
- {
- LOG_D("*推杆电机归位*");
- /*推杆电机归位*/
- ctr_cangmen_up(CLOSE);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- }
- if (device_status.cul_time < 7)
- device_status.cul_time++;
- while (Read_Color_Limit(LIMIT_BOARD) == 0)
- {
- ctr_cangmen_down(forward);
- rt_thread_delay(50);
- }
- while (Read_Color_Limit(LIMIT_BOARD) == 1)
- {
- time_board--;
- if (time_board == 0)
- break;
- ctr_cangmen_down(forward);
- rt_thread_delay(50);
- }
- ctr_cangmen_down(OFF);
- rt_thread_delay(1000);
- ctr_cangmen_up(OPEN);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
- return OPEN;
- }
- else if (forward == RESET)
- {
- ctr_cangmen_up(OFF);
- ctr_cangmen_down(OFF);
- if (Read_Color_Limit(LIMIT_RESET) == 0)
- {
- device_status.cul_time = 0;
- // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
- LOG_W("已在初始位置!");
- Beep_Tip(1000);
- ctr_cangmen_up(CLOSE);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- device_status.cul_time = 0;
- return 0;
- // 黄板已经在复位状态,直接返回0;
- }
- // if(Read_Color_Limit(LIMIT_BOARD)==0)
- {
- LOG_D("*推杆电机归位*");
- /*推杆电机归位*/
- ctr_cangmen_up(CLOSE);
- rt_thread_delay(20000);
- ctr_cangmen_up(OFF);
- }
- while (Read_Color_Limit(LIMIT_RESET) == 1)
- {
- time_board--;
- if (time_board == 0)
- break;
- ctr_cangmen_down(CLOSE);
- rt_thread_delay(20);
- }
- device_status.cul_time = 0;
- ctr_cangmen_down(OFF);
- }
- // device_status.cul_time = 0;
- // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
- return RESET; // 复位返回0
- }
- #endif
- /****************************5.0***********************************/
- void ctr_turnv5(void)
- {
- rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
- rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
- // 转出
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, OFF);
- rt_thread_mdelay(300);
- // 停止
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- rt_thread_mdelay(300);
- // 转入
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, ON);
- rt_thread_mdelay(300);
- // 停止
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- rt_thread_mdelay(300);
- }
- /**************************机器人********************************/
- void ctr_Motor_Robot(uint8_t status_ws)
- {
- unsigned int close_timeout = 0;
- unsigned int open_timeout = 0;
- rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
- rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
- rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
- rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
- rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
- rt_pin_write(Motor_Power, OFF);
- rt_pin_write(Motor_Direction_Ctr, ON);
- rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
- rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- // 检测按键状态
- while (rt_pin_read(Motor_Direction_Button) == 1)
- {
- if (rt_pin_read(LIMIT_CLOSE) == 1)
- {
- rt_pin_write(Motor_Direction_Ctr, ON);
- close_timeout++;
- // 打开电机驱动器电源,默认关闭
- rt_pin_write(Motor_Power, ON);
- if (close_timeout == 2)
- {
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, OFF);
- rt_pin_write(Motor_Power, OFF);
- rt_thread_delay(20);
- rt_pin_write(Motor_Power, ON);
- }
- rt_thread_delay(20);
- if (close_timeout > 500)
- {
- close_timeout = 600;
- rt_pin_write(Motor_Power, OFF);
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- }
- }
- else
- {
- close_timeout = 0;
- rt_pin_write(Motor_Power, OFF); // 关闭驱动器电源
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- }
- rt_thread_delay(20);
- }
- rt_pin_write(Motor_Power, OFF);
- rt_thread_delay(1000 * 2);
- while (rt_pin_read(Motor_Direction_Button) == 0)
- {
- if (rt_pin_read(LIMIT_OPEN) == 1)
- {
- open_timeout++;
- // 打开电机驱动器电源,默认关闭
- if (open_timeout == 2)
- {
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, ON);
- }
- rt_pin_write(Motor_Power, ON);
- rt_pin_write(Motor_Direction_Ctr, OFF);
- if (open_timeout > 500)
- {
- open_timeout = 600;
- rt_pin_write(Motor_Power, OFF);
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- }
- rt_thread_delay(20);
- }
- if (rt_pin_read(LIMIT_OPEN) == 0)
- {
- open_timeout = 0;
- rt_pin_write(Motor_Power, OFF);
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- }
- rt_thread_delay(20);
- close_timeout = 0;
- }
- open_timeout = 0;
- close_timeout = 0;
- }
- else
- {
- rt_pin_write(Motor_Power, OFF);
- }
- }
- /*************************吸虫塔*********************************/
- // 吸虫电机
- uint8_t ctr_Motor_xichong(uint8_t status_ws)
- {
- rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- rt_pin_write(MOTOR1_CTR_PIN, ON);
- }
- else
- {
- rt_pin_write(MOTOR1_CTR_PIN, OFF);
- }
- return 0;
- }
- uint8_t ctr_Camera_Power(uint8_t status_ws)
- {
- rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- rt_pin_write(MOTOR1_CTR_PIN, ON);
- }
- else
- {
- rt_pin_write(MOTOR1_CTR_PIN, OFF);
- }
- return 0;
- }
- // 吸附电机
- uint8_t ctr_Motor_xifu(uint8_t status_ws)
- {
- rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
- if (status_ws == ON)
- {
- rt_pin_write(MOTOR2_CTR_PIN, ON);
- }
- else
- {
- rt_pin_write(MOTOR2_CTR_PIN, OFF);
- }
- return 0;
- }
- // 清扫-卷带电机
- void ctr_JD_Clear(uint8_t shake_sw)
- {
- rt_uint16_t turn_timeout = 0;
- rt_pin_mode(MOTOR_C_LIMIT, PIN_MODE_INPUT);
- ctr_cangmen_up(OFF); // 清扫传送带的电机
- if (shake_sw == ON)
- {
- ctr_Heat(ON); // 清洁风机
- Motor_shake(ON, 0);
- ctr_cangmen_up(OPEN); // 打开清扫
- }
- else
- {
- Motor_shake(OFF, 0);
- ctr_cangmen_up(OPEN); // 打开清扫
- }
- while (rt_pin_read(MOTOR_C_LIMIT) == 0)
- {
- Motor_Juandai(ON);
- rt_thread_delay(50);
- turn_timeout++;
- if (turn_timeout == 1000)
- break;
- }
- turn_timeout = 0;
- while (rt_pin_read(MOTOR_C_LIMIT) == 1)
- {
- Motor_Juandai(ON);
- turn_timeout++;
- rt_thread_delay(50);
- if (turn_timeout == 1000)
- break;
- }
- Motor_shake(OFF, 1);
- Motor_Juandai(OFF);
- ctr_cangmen_up(OFF); // 关闭清扫
- ctr_Heat(OFF);
- }
- // 工作任务流程
- void WorkTask_XCT(void)
- {
- while (device_status.work_status == 1 && device_status.ds == 1)
- {
- ctr_Motor_xifu(ON);
- // 打开相机供电
- ctr_Camera_Power(ON);
- // ctr_Heat(ON); //清洁风机
- uint32_t photo_fre = 0;
- photo_fre = device_status.dattim * 60;
- while (photo_fre != 0)
- {
- photo_fre--;
- rt_thread_delay(1000);
- LOG_I("收集中,等待开始拍照:%d", photo_fre);
- }
- // 卷带
- ctr_JD_Clear(OFF);
- // 拍照
- HK_TakePhoto();
- // 关闭吸附风机
- ctr_Motor_xifu(OFF);
- // 关闭相机供电
- // ctr_Heat(OFF);
- ctr_Camera_Power(OFF);
- // 卷带
- ctr_JD_Clear(ON);
- // rt_thread_delay(1000);
- // ctr_JD_Clear(ON);
- // 震动
- Motor_shake(ON, device_status.shake_sec);
- }
- // 关闭风机
- ctr_Motor_xichong(OFF);
- ctr_Motor_xifu(OFF);
- LOG_I("不在工作时间,未工作!!!");
- }
- /**********************************************************************/
- /*光控*/
- uint8_t In_Light_status(void)
- {
- rt_pin_mode(LIGHT_PIN, PIN_MODE_INPUT);
- return rt_pin_read(LIGHT_PIN);
- }
- /*雨控*/
- uint8_t In_Rain_status(void)
- {
- rt_pin_mode(RAIN_PIN, PIN_MODE_INPUT);
- return rt_pin_read(RAIN_PIN);
- }
- /*加热*/
- uint8_t ctr_Heat(uint8_t status_heat)
- {
- device_status.heat_status = status_heat;
- rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
- rt_pin_write(Heat_Pin, status_heat);
- return status_heat;
- }
- /*制冷*/
- uint8_t ctr_Cold(uint8_t status_cold)
- {
- device_status.cold_status = status_cold;
- rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
- rt_pin_write(Cold_Pin, status_cold);
- return status_cold;
- }
- /*相机供电*/
- void ctr_photo(uint8_t status_photo)
- {
- rt_pin_mode(PHOTO, PIN_MODE_OUTPUT);
- rt_pin_write(PHOTO, status_photo);
- }
- /*************************************************
- Function: ctr_Cool_Fan
- Description: 散热风机的开关
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: ON-开,OFF-关
- Output: NULL
- Return: ON-开,OFF-关
- Others: NULL
- *************************************************/
- uint8_t ctr_Cool_Fan(uint8_t status_cool)
- {
- device_status.cool_fan_status = status_cool;
- rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
- rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
- if (status_cool == OFF)
- {
- rt_pin_write(Cool_Fan_L, OFF);
- rt_pin_write(Cool_Fan_R, OFF);
- }
- if (status_cool == ON)
- {
- rt_pin_write(Cool_Fan_L, ON);
- rt_pin_write(Cool_Fan_R, OFF);
- }
- return device_status.cool_fan_status;
- }
- /*************************************************
- Function: ctr_Collect_Fan
- Description: 采集风机的开关
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: ON-开,OFF-关
- Output: NULL
- Return: ON-开,OFF-关
- Others: NULL
- *************************************************/
- uint8_t ctr_Collect_Fan(uint8_t status_collect)
- {
- device_status.collect_fan_status = status_collect;
- rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
- if (status_collect == OFF)
- {
- rt_pin_write(Collect_Fan, OFF);
- }
- if (status_collect == ON)
- {
- rt_pin_write(Collect_Fan, ON);
- }
- return device_status.collect_fan_status;
- }
- /*************************************************
- Function: ctr_develop
- Description: 培养载玻片孢子
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: v=0(复位) v=90转90度
- Output: NULL
- Return: NULL
- Others: NULL
- *************************************************/
- void ctr_develop(void)
- {
- rt_kprintf("===============开始培养=================:%d\n", device_status.cul_time);
- // 已经培养的时间-分钟
- device_status.stay_time = 0;
- rt_uint32_t ii = 0;
- while (device_status.develop_flag == 1)
- {
- float stayedtime = 0.01;
- char stayed[5];
- stayedtime = (float)device_status.stay_time / 60.0;
- sprintf(stayed, "%0.02f", stayedtime);
- HMI_WRITE("workSta.staytime.txt=\"%s\"", stayed);
- ii++;
- LOG_I("developing...................................%d\n", ii);
- LOG_I("============================设定的培养温度:%d\n", device_status.heatvalue);
- LOG_I("============================培养仓实时温度:%d\n", device_status.pre_temp);
- if (device_status.pre_temp < (device_status.heatvalue - 5))
- {
- // 未制冷
- if (device_status.cold_status == 0)
- {
- ctr_Heat(ON);
- }
- }
- else
- {
- ctr_Heat(OFF);
- }
- LOG_I("============================制冷开关:%d\n", device_status.cold_sw);
- if (device_status.cold_sw == 1)
- {
- if (device_status.pre_temp > (device_status.heatvalue - 10))
- {
- if (device_status.heat_status == 0)
- {
- ctr_Cold(ON);
- }
- }
- else
- {
- ctr_Cold(OFF);
- }
- }
- if (ii % 60 == 0)
- {
- device_status.stay_time++;
- if (device_status.stay_time / 60 == device_status.cul_time)
- device_status.develop_flag = 0;
- LOG_I("developed...................................%d分钟\n", device_status.stay_time);
- }
- if (device_status.box_temp > 35)
- {
- ctr_Cool_Fan(ON);
- }
- else if (device_status.box_temp < 30)
- {
- ctr_Cool_Fan(OFF);
- }
- rt_thread_delay(1000);
- }
- ctr_Cold(OFF);
- ctr_Heat(OFF);
- LOG_I("=========!!!培养完成!!!==========");
- }
- /*上仓门*/
- /**
- * @brief 控制仓门升起
- *
- * @param status_down 指令
- * @return uint8_t 执行后的状态
- */
- uint8_t ctr_cangmen_up(uint8_t status_up)
- {
- rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
- rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
- if (status_up == OFF)
- {
- rt_pin_write(Collect_fan_R, ON);
- rt_pin_write(Collect_fan_L, ON);
- device_status.ctr_up_motor = 0;
- rt_thread_delay(1000);
- }
- if (status_up == OPEN)
- {
- device_status.up_status = 1;
- rt_pin_write(Collect_fan_R, OFF);
- rt_pin_write(Collect_fan_L, OFF);
- rt_pin_write(Collect_fan_R, ON);
- rt_pin_write(Collect_fan_L, OFF);
- }
- if (status_up == CLOSE)
- {
- device_status.up_status = 0;
- rt_pin_write(Collect_fan_R, OFF);
- rt_pin_write(Collect_fan_L, OFF);
- rt_pin_write(Collect_fan_R, OFF);
- rt_pin_write(Collect_fan_L, ON);
- }
- return device_status.up_status;
- }
- // 下仓门
- /**
- * @brief 控制仓门落下
- *
- * @param status_down 指令
- * @return uint8_t 执行后的状态
- */
- uint8_t ctr_cangmen_down(uint8_t status_down)
- {
- rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
- rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
- if (status_down == OFF)
- {
- rt_pin_write(C_DOWN_R, ON);
- rt_pin_write(C_DOWN_L, ON);
- device_status.ctr_down_motor = 0;
- rt_thread_delay(1000);
- }
- if (status_down == OPEN)
- {
- device_status.down_status = 1;
- rt_pin_write(C_DOWN_R, OFF);
- rt_pin_write(C_DOWN_L, OFF);
- rt_pin_write(C_DOWN_R, ON);
- rt_pin_write(C_DOWN_L, OFF);
- }
- if (status_down == CLOSE)
- {
- device_status.down_status = 0;
- rt_pin_write(C_DOWN_R, OFF);
- rt_pin_write(C_DOWN_L, OFF);
- rt_pin_write(C_DOWN_R, OFF);
- rt_pin_write(C_DOWN_L, ON);
- }
- return device_status.down_status;
- }
- // 镇流器
- /**
- * @brief 控制镇流器动作
- *
- * @param status_lamp 指令
- * @param lamp_num 镇流器编号
- * @return uint8_t 更新后的镇流器状态
- */
- uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num)
- {
- rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
- rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
- rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
- if (status_lamp == ON)
- {
- switch (lamp_num)
- {
- case 1:
- rt_pin_write(LAMP_SW, ON);
- device_status.lamp_status = status_lamp;
- break;
- case 2:
- rt_pin_write(LAMP_1_SW, ON);
- device_status.lamp_status = status_lamp;
- break;
- case 3:
- rt_pin_write(LAMP_2_SW, ON);
- device_status.lamp_status = status_lamp;
- break;
- default:
- break;
- }
- }
- else
- {
- switch (lamp_num)
- {
- case 1:
- rt_pin_write(LAMP_SW, OFF);
- device_status.lamp_status = status_lamp;
- break;
- case 2:
- rt_pin_write(LAMP_1_SW, OFF);
- device_status.lamp1_status = status_lamp;
- break;
- case 3:
- rt_pin_write(LAMP_2_SW, OFF);
- device_status.lamp2_status = status_lamp;
- break;
- default:
- break;
- }
- }
- HMI_WRITE("sysTest.switchLamp.val=%d", device_status.lamp_status);
- return device_status.lamp_status;
- }
- // 震动电机
- /**
- * @brief 控制震动电机动作
- *
- * @param status_shake 指令
- * @param shake_sec 震动时间(秒)
- * @return uint8_t 执行后的状态
- */
- uint8_t ctr_shake(uint8_t status_shake, uint16_t shake_sec)
- {
- static rt_uint16_t shake_i = 0;
- if (device_status.dtype == dt_BZY && device_status.version_type == vt_BZY_JD)
- {
- return 0;
- }
- shake_i = atoi(device_status.power);
- LOG_I("震动电机待机电流:%d", shake_i);
- if (device_status.dtype == 7 && shake_sec != 0)
- DTU_Write("drop");
- rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
- if (status_shake == ON && device_status.shake_ws == 1)
- {
- rt_pin_write(SHAKE_SW, ON);
- if (device_status.dtype == 3)
- {
- while (shake_sec--)
- {
- rt_thread_delay(100);
- 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)
- {
- char *shake_warn = makeJson_Warn("电流不足", "震动电机");
- DTU_Write("%s", shake_warn);
- rt_free(shake_warn);
- }
- LOG_D("震动电机:%d", atoi(device_status.power));
- }
- }
- if (device_status.dtype == 7)
- rt_thread_delay(shake_sec * 1000);
- rt_pin_write(SHAKE_SW, OFF);
- HMI_WRITE("cangWei.switchShake.val=%d", 0);
- }
- else
- {
- rt_pin_write(SHAKE_SW, OFF);
- HMI_WRITE("cangWei.switchShake.val=%d", 0);
- }
- if (device_status.dtype == 7)
- HMI_WRITE("sysTest.switchDrop.val=%d", OFF);
- return status_shake;
- }
- // 补光
- /**
- * @brief 控制补光灯动作
- *
- * @param status_led 指令
- * @return uint8_t 执行后的状态
- */
- uint8_t ctr_led(uint8_t status_led)
- {
- rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
- if (device_status.version_type == 6)
- rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
- if (status_led == ON)
- {
- rt_pin_write(LED_SW, ON);
- if (device_status.version_type == 6)
- rt_pin_write(LED_P, ON);
- HMI_WRITE("sysTest.switchFill.val=%d", ON);
- }
- else if (status_led == OFF)
- {
- rt_pin_write(LED_SW, OFF);
- if (device_status.version_type == 6)
- rt_pin_write(LED_P, OFF);
- HMI_WRITE("sysTest.switchPhoto.val=%d", OFF);
- HMI_WRITE("sysTest.switchFill.val=%d", OFF);
- }
- return status_led;
- }
- /*************************************************
- Function: ctr_turn
- Description: 转盘驱动
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: v=0(复位) v=90转90度
- Output: NULL
- Return: NULL
- Others: NULL
- *************************************************/
- void ctr_turn(uint8_t v, uint8_t sta)
- {
- if (device_status.dtype == dt_BZY && device_status.version_type == vt_BZY_JD)
- {
- return;
- }
- DTU_Write("turn.mp3");
- LOG_I("================v===============:%d", v);
- rt_uint16_t turn_cnt = 0;
- rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
- rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
- rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
- rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
- // if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
- while (rt_pin_read(LIMIT_0) == 0 || rt_pin_read(LIMIT_90) == 0)
- {
- rt_pin_write(TURN_ZP_R, ON);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(ON,0);
- turn_cnt++;
- rt_thread_delay(100);
- if (turn_cnt == 1000)
- {
- turn_cnt = 0;
- rt_pin_write(TURN_ZP_R, OFF);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(OFF,0);
- char *turn_warn = makeJson_Warn("未检测到限位", "转盘");
- DTU_Write("%s", turn_warn);
- rt_free(turn_warn);
- break;
- }
- }
- turn_cnt = 0;
- while (v == 0 && rt_pin_read(LIMIT_0) == 1)
- {
- rt_pin_write(TURN_ZP_R, ON);
- rt_pin_write(TURN_ZP_L, OFF);
- Motor_shake(ON, 0);
- rt_thread_delay(200); // 10 to 100
- turn_cnt++;
- if (turn_cnt == 300) // 6000 to 600
- {
- turn_cnt = 0;
- // rt_pin_write(TURN_ZP_R, OFF);
- // rt_pin_write(TURN_ZP_L, OFF);
- // char *turn_warn =makeJson_Warn("超时", "转盘复位");
- // DTU_Write("%s",turn_warn);
- // rt_free(turn_warn);
- break;
- }
- }
- while (v == 0 && rt_pin_read(LIMIT_0) == 1)
- {
- rt_pin_write(TURN_ZP_R, ON);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(ON,0);
- rt_thread_delay(50); // 10 to 50
- turn_cnt++;
- if (turn_cnt == 10) // 6000 to 1200
- {
- turn_cnt = 0;
- rt_pin_write(TURN_ZP_R, OFF);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(OFF,0);
- char *turn_warn = makeJson_Warn("超时", "转盘复位");
- DTU_Write("%s", turn_warn);
- rt_free(turn_warn);
- break;
- }
- }
- turn_cnt = 0;
- while (v == 90 && rt_pin_read(LIMIT_90) == 1)
- {
- rt_pin_write(TURN_ZP_R, ON);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(ON,0);
- rt_thread_delay(200);
- turn_cnt++;
- if (turn_cnt == 150)
- {
- turn_cnt = 0;
- // rt_pin_write(TURN_ZP_R, OFF);
- // rt_pin_write(TURN_ZP_L, OFF);
- // char *turn_warn =makeJson_Warn("超时", "转盘");
- // DTU_Write(turn_warn);
- // rt_free(turn_warn);
- break;
- }
- }
- while (v == 90 && rt_pin_read(LIMIT_90) == 1)
- {
- // rt_pin_write(TURN_ZP_R, ON);
- // rt_pin_write(TURN_ZP_L, OFF);
- Motor_shake(ON, 0);
- rt_thread_delay(50);
- turn_cnt++;
- if (turn_cnt == 10)
- {
- turn_cnt = 0;
- rt_pin_write(TURN_ZP_R, OFF);
- rt_pin_write(TURN_ZP_L, OFF);
- // Motor_shake(OFF,0);
- char *turn_warn = makeJson_Warn("超时", "转盘");
- DTU_Write(turn_warn);
- rt_free(turn_warn);
- break;
- }
- }
- if (sta != 0)
- {
- // 保存位置
- device_status.run_sta = sta;
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- }
- turn_cnt = 0;
- rt_pin_write(TURN_ZP_R, OFF);
- rt_pin_write(TURN_ZP_L, OFF);
- Motor_shake(OFF, 0);
- HMI_WRITE("cangWei.rotateFlag.val=0");
- }
- /*************************************************
- Function: ctr_Motor_Driver
- Description: 步进电机驱动
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: 50000000
- Output: NULL
- Return: shake_sec
- Others: NULL
- *************************************************/
- void ctr_Motor_Driver(uint8_t EN, uint8_t DIR, rt_uint32_t pwm, rt_uint32_t time_out)
- {
- beep_init();
- rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
- rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
- rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
- rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
- if (EN == 0)
- {
- rt_pin_write(Motor_Power, 0);
- }
- else
- {
- rt_pin_write(Motor_EN, EN);
- }
- rt_pin_write(Motor_DIR, DIR);
- beep_set(pwm, pwm / 2); // 200kzh - 50%
- while (DIR == 1 && rt_pin_read(LIMIT_DOWN) == 1)
- {
- if (time_out == 0)
- {
- break;
- }
- rt_thread_delay(50);
- time_out--;
- }
- while (DIR == 0 && rt_pin_read(LIMIT_UP) == 1)
- {
- if (time_out == 0)
- {
- break;
- }
- rt_thread_delay(50);
- time_out--;
- }
- rt_pin_write(Motor_EN, OFF);
- if (device_status.autotakepic == 0)
- ctr_lamp(OFF, 1);
- beep_set(0, 0); // 200kzh - 50%
- }
- /*************************************************
- Function: ctr_Petroleum_jelly
- Description: 涂凡士林
- Calls:
- Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
- Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
- Input: NULL
- Output: NULL
- Return: NULL
- Others: NULL
- *************************************************/
- void ctr_Petroleum_jelly(rt_uint32_t delay)
- {
- beep_init();
- pwm_on(2, 50000);
- rt_thread_delay(delay * 1000);
- pwm_off(2, 0);
- rt_thread_delay(1000);
- pwm_on(3, 50000);
- rt_thread_delay(delay * 1000);
- pwm_off(3, 0);
- device_status.fsl_sw = 0;
- }
- // 1.0转仓
- void turnzp(void)
- {
- static uint16_t turn_timeout = 0;
- // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
- // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
- rt_pin_mode(CLEAR_R_LIMIT, PIN_MODE_INPUT);
- // rt_pin_write(CLEAR_R,OFF);
- // rt_pin_write(CLEAR_L,OFF);
- while (rt_pin_read(CLEAR_R_LIMIT) == 0)
- {
- rt_thread_delay(20);
- while (rt_pin_read(CLEAR_R_LIMIT) == 0)
- {
- // rt_pin_write(CLEAR_R,ON);
- // rt_pin_write(CLEAR_L,OFF);
- Motor_Juandai(ON);
- rt_thread_delay(50);
- turn_timeout++;
- if (turn_timeout == 600)
- {
- LOG_E("检测不到限位,电机强制停止");
- char *ctr_zp_limit_warn = makeJson_Warn("电流不足/限位超时", "转盘电机");
- DTU_Write("%s", ctr_zp_limit_warn);
- rt_free(ctr_zp_limit_warn);
- break;
- }
- }
- break;
- }
- while (rt_pin_read(CLEAR_R_LIMIT) == 1)
- {
- rt_thread_delay(20);
- while (rt_pin_read(CLEAR_R_LIMIT) == 1)
- {
- // rt_pin_write(CLEAR_R,ON);
- // rt_pin_write(CLEAR_L,OFF);
- Motor_Juandai(ON);
- rt_thread_delay(50);
- turn_timeout++;
- if (turn_timeout == 600)
- {
- LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
- char *ctr_zp_limit_warn = makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障", "转盘电机");
- DTU_Write("%s", ctr_zp_limit_warn);
- rt_free(ctr_zp_limit_warn);
- break;
- }
- }
- break;
- }
- while (rt_pin_read(CLEAR_R_LIMIT) == 0)
- {
- rt_thread_delay(20);
- if (rt_pin_read(CLEAR_R_LIMIT) == 0)
- {
- // rt_pin_write(CLEAR_R,OFF);
- // rt_pin_write(CLEAR_L,OFF);
- Motor_Juandai(OFF);
- break;
- }
- else
- {
- break;
- }
- }
- Motor_Juandai(OFF);
- // rt_pin_write(CLEAR_R,OFF);
- // rt_pin_write(CLEAR_L,OFF);
- turn_timeout = 0;
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- rt_thread_delay(1000);
- }
- // 清扫-常闭型限位开关
- // 新结构使用推杆电机做清扫
- uint8_t ctr_clear(uint16_t status_clear)
- {
- static uint16_t clear_num = 0;
- #if PWM_EN == 0
- rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
- rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
- #endif
- rt_pin_mode(CLEAR_R_LIMIT, PIN_MODE_INPUT);
- rt_pin_mode(CLEAR_L_LIMIT, PIN_MODE_INPUT);
- /*************************************************************外接清扫
- rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
- rt_pin_write(POWER_CLEAR,ON);
- rt_thread_delay(1000*100);
- rt_pin_write(POWER_CLEAR,OFF);
- ************************************************************/
- // 停止
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, OFF);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- if (status_clear == OFF || Read_Real_Voltage() / 100 < 12)
- return 0;
- rt_thread_delay(100);
- // 如果清扫位置在中间
- while (rt_pin_read(CLEAR_R_LIMIT) == 0 && rt_pin_read(CLEAR_L_LIMIT) == 0)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, OFF);
- #else
- Motor_Qingsao_R_PWM(ON);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_thread_delay(50);
- clear_num++;
- // 已到达检测位置
- if (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_thread_delay(2000);
- break;
- }
- if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
- {
- rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
- // DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_free(makeJson_Warn("Clear Motor ERR", "device"));
- if (Read_Real_Voltage() / 100 < 12)
- {
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- device_status.clear_status = 0;
- return 0;
- }
- break;
- }
- }
- clear_num = 0;
- // 如果清扫位置在左侧
- while (rt_pin_read(CLEAR_R_LIMIT) == 0)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, OFF);
- #else
- Motor_Qingsao_R_PWM(ON);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_thread_delay(50);
- clear_num++;
- if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
- {
- rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
- // DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_free(makeJson_Warn("Clear Motor ERR", "device"));
- if (Read_Real_Voltage() / 100 < 12)
- {
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- device_status.clear_status = 0;
- return 0;
- }
- break;
- }
- }
- clear_num = 0;
- while (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1 || (Read_Real_Voltage() / 100) < 12)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- if (Read_Real_Voltage() / 100 < 12)
- {
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- device_status.clear_status = 0;
- return 0;
- }
- rt_thread_delay(2000);
- break;
- }
- while (rt_pin_read(CLEAR_L_LIMIT) == 0)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(ON);
- #endif
- rt_thread_delay(50);
- clear_num++;
- if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
- {
- rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
- char *Clear_ERR = makeJson_Warn("Clear Motor ERR", "device");
- // DTU_Write("%s",Clear_ERR);
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_free(Clear_ERR);
- if (Read_Real_Voltage() / 100 < 12)
- {
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- device_status.clear_status = 0;
- return 0;
- }
- break;
- }
- }
- while (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_thread_delay(2000);
- break;
- }
- while (rt_pin_read(CLEAR_L_LIMIT) == 1 && rt_pin_read(CLEAR_R_LIMIT) == 1)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- if (device_status.version_type == 41)
- {
- rt_kprintf("Clear Motor Limit Not Access:%d", atoi(device_status.power));
- char *Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access", "device");
- // DTU_Write("%s",Clear_ERR);
- rt_free(Clear_ERR);
- }
- return 0;
- }
- clear_num = 0;
- rt_thread_delay(2000);
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- device_status.clear_status = 0;
- return 1;
- }
- // 路由器供电
- void ctr_router(uint8_t status_router)
- {
- rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
- if (device_status.version_type == 6)
- rt_pin_mode(ROUTER_P, PIN_MODE_OUTPUT);
- // rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
- if (status_router == ON)
- {
- rt_pin_write(ROUTER, ON);
- //
- #if LAMP_EN == 0
- if (device_status.version_type == 6)
- rt_pin_write(ROUTER_P, ON);
- #endif
- }
- else
- {
- rt_pin_write(ROUTER, OFF);
- //
- #if LAMP_EN == 0
- if (device_status.version_type == 6)
- rt_pin_write(ROUTER_P, OFF);
- #endif
- }
- }
- // 清扫-推杆电机
- void ctr_TG_Clear(uint16_t clear_timeout)
- {
- #if 0
- int current_clear[200];
- int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
- LOG_I("清扫电机待机:%d",Electric_current);
- #endif
- static uint16_t clear_count = 0;
- clear_count = clear_timeout;
- #if PWM_EN == 0
- rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
- rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
- #endif
- while (clear_count != 0)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, OFF);
- #else
- Motor_Qingsao_R_PWM(ON);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- clear_count--;
- rt_thread_delay(100);
- }
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- rt_thread_delay(3000);
- clear_count = 0;
- while (clear_timeout != clear_count)
- {
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, OFF);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(ON);
- #endif
- // if(clear_count<200)
- // current_clear[clear_count] = atoi(device_status.power);
- clear_count++;
- rt_thread_delay(100);
- }
- #if PWM_EN == 0
- rt_pin_write(CLEAR_R, ON);
- rt_pin_write(CLEAR_L, ON);
- #else
- Motor_Qingsao_R_PWM(OFF);
- Motor_Qingsao_L_PWM(OFF);
- #endif
- #if 0
- bubblesort(current_clear,200);
- if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
- {
- LOG_E("清扫电机电流不足:%d!",current_clear[199]);
- char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
- DTU_Write("%s",ctr_clear_warn);
- rt_free(ctr_clear_warn);
- }
- #endif
- rt_thread_delay(2000);
- device_status.clear_status = 0;
- HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
- HMI_WRITE("sysTest.switchClear.val=%d", 0);
- }
- // DTU,RTU供电
- void ctr_RTU_DTU(uint8_t status_rtu)
- {
- rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
- if (status_rtu == ON)
- {
- rt_pin_write(RTU_DTU, ON);
- }
- else
- {
- LOG_W("RTU电源复位!!!");
- rt_pin_write(RTU_DTU, OFF);
- }
- }
- // 海康拍照
- void Hk_Take_io(void)
- {
- rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
- rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
- rt_pin_write(HK_TAKE, 1);
- rt_pin_write(HK_IO, 0);
- if (device_status.dtype == 3)
- Beep_Tip(1000);
- if (device_status.dtype == 7)
- rt_thread_mdelay(1000);
- rt_pin_write(HK_TAKE, 0);
- rt_pin_write(HK_IO, 1);
- }
- /**
- * @brief 控制执行加热动作
- *
- * @param heat_time 加热时间(秒)
- */
- void calorstat(uint16_t heat_time)
- {
- // uint8_t heat_up_cnt = 0;
- uint16_t n = 0;
- uint16_t delay_heat = 60;
- FlagStatus heat_flg = RESET;
- device_status.heat_time_min = 0;
- device_status.run_sta = device_status.heattem; // 初始化加热实时温度
- ctr_Heat(ON);
- // UpLoad_Data(); //开始加热时的第一条数据
- // 恒温模式
- for (n = 0; n < heat_time; n++)
- {
- if (device_status.heattem > device_status.heatvalue && heat_flg == RESET)
- {
- heat_flg = SET;
- ctr_Heat(OFF);
- while (delay_heat != 0)
- {
- delay_heat--;
- rt_kprintf("正在恒温加热!!!:%d", delay_heat);
- HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"", delay_heat);
- rt_thread_delay(1000);
- if (device_status.heattem > device_status.run_sta + 1)
- {
- device_status.run_sta = device_status.heattem;
- }
- }
- delay_heat = 60;
- // 跳出FOR循环
- n = n + 60;
- }
- if (device_status.heattem < (device_status.heatvalue - 5) && heat_flg == SET)
- {
- device_status.run_sta = device_status.heattem;
- ctr_Heat(ON);
- }
- else if (device_status.heattem >= device_status.heatvalue && heat_flg == SET)
- {
- // if(heat_up_cnt==0)
- // {
- // UpLoad_Data(); //加热到设定温度的数据
- // heat_up_cnt = 1;
- // }
- device_status.run_sta = device_status.heattem;
- ctr_Heat(OFF);
- }
- if ((n % 60) == 0)
- {
- device_status.heat_time_min = device_status.heat_time_min + 1;
- // if(device_status.heat_time_min % 5 == 0)
- // {
- // UpLoad_Data(); //从加热开始每5分钟上传的数据
- // }
- }
- // 如果触发异常退出加热
- if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
- {
- rt_thread_delay(1000);
- if (device_status.bat_status == 1)
- {
- rt_kprintf("============================触发异常退出加热==========================");
- ctr_lamp(OFF, 1);
- ctr_Heat(OFF);
- break;
- }
- }
- if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
- {
- ctr_Heat(OFF);
- rt_kprintf("异常退出!!!\n");
- break;
- }
- rt_thread_delay(1000);
- rt_kprintf("=======正在加热======:%d-%d\n", n, heat_time);
- HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"", n, heat_time);
- }
- ctr_Heat(OFF);
- // UpLoad_Data(); //加热结束的数据
- }
- // 初始化所有控制驱动,关闭
- void HardWare_Init(uint8_t boot)
- {
- Beep_Tip(200);
- // 关闭上仓门
- ctr_cangmen_up(OFF);
- if (device_status.dtype == 3)
- {
- // 关闭下仓门电机
- ctr_cangmen_down(OFF);
- }
- // 关闭镇流器
- if (device_status.autotakepic == 0)
- ctr_lamp(OFF, 1);
- // 关闭震动电机
- ctr_shake(OFF, 0);
- // 关闭加热
- ctr_Heat(OFF);
- // 关闭补光灯
- ctr_led(OFF);
- // 关闭12V供电(海康相机,RTU)
- ctr_photo(OFF);
- }
- // 拍照
- void HK_TakePhoto(void)
- {
- // 打开补光灯
- DTU_Write("takephoto.mp3");
- rt_thread_delay(1000);
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s", takephotojson);
- rt_free(takephotojson);
- // 吸虫塔
- if (device_status.version_type != 6)
- {
- ctr_led(ON);
- if (device_status.version_type == 48)
- {
- rt_thread_delay(1000 * 60);
- }
- else
- {
- rt_thread_delay(1000 * 15);
- }
- }
- // 触发海康相机拍照
- Hk_Take_io();
- if (device_status.version_type != 6)
- {
- rt_thread_delay(1000 * 45);
- }
- else
- {
- ctr_led(ON);
- rt_thread_delay(1000 * 19);
- }
- ctr_led(OFF);
- }
- // 光控测试任务
- void SunTest(void)
- {
- rt_uint16_t ui_timeout_l = 0;
- // 未检测到光照,一秒扫描等待,超时30S
- while (Read_Light_Voltage() < 500)
- {
- ui_timeout_l++;
- rt_thread_delay(1000);
- if (ui_timeout_l == 30)
- break;
- }
- rt_thread_delay(3000);
- if (Read_Light_Voltage() < 500)
- {
- device_status.sun_status = 0; // 光控状态
- }
- if (Read_Light_Voltage() > 500)
- {
- rt_thread_delay(1000);
- }
- rt_thread_delay(3000);
- if (Read_Light_Voltage() > 500)
- {
- device_status.sun_status = 1;
- ctr_lamp(OFF, 1);
- }
- HMI_WRITE("sysTest.switchSun.val=%d", 0);
- device_status.sun_test = 0;
- device_status.work_status = 0;
- }
- /*上电初始化*/
- void ResetInit(void)
- {
- if (device_status.dtype == 7)
- {
- ctr_Motor_Driver(0, 0, 0, 0);
- // 关闭电磁阀
- ctr_shake(OFF, 0);
- // 关闭加热
- ctr_Heat(OFF);
- // 关闭制冷
- ctr_Cold(OFF);
- // 关闭补光灯
- ctr_led(OFF);
- // 转盘复位
- if (device_status.run_sta == 0)
- ctr_turn(0, 0);
- }
- if (device_status.version_type != 6 && device_status.version_type != vt_BZY && device_status.version_type != vt_BZY_JD)
- {
- device_status.work_done = 1;
- // 1.打开路由器供电
- if (device_status.power_status == 1)
- {
- ctr_router(ON);
- ctr_RTU_DTU(ON);
- // 2.打开相机供电
- ctr_photo(ON);
- }
- // 3.关闭镇流器
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- // 4.关闭震动电机
- ctr_shake(OFF, 0);
- // 5.关闭加热
- ctr_Heat(OFF);
- // 6.关闭补光灯
- ctr_led(OFF);
- if (device_status.bat_status == 1 || atoi(device_status.fuse_voltage) < 1)
- {
- LOG_W("欠压!");
- return;
- }
- // 7.关闭上仓门
- device_status.ctr_up_motor = 2;
- // while(device_status.ctr_up_motor!=0)
- // {
- // LOG_I("关闭上仓门...");
- // rt_thread_delay(100);
- // }
- // 8.关闭下仓门
- device_status.ctr_down_motor = 2;
- while (device_status.ctr_down_motor != 0)
- {
- LOG_I("关闭下仓门....");
- rt_thread_delay(100);
- }
- // 9.清扫
- if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
- {
- LOG_W("异常退出!!!\n");
- return;
- }
- #if LAMP_EN == 0
- ctr_Fan_PUT(OFF);
- ctr_Fan_IN(OFF);
- #endif
- if (device_status.version_type == 4 || device_status.version_type == 41)
- {
- device_status.clear_status = 1;
- }
- else if (device_status.version_type == 1)
- {
- turnzp();
- }
- rt_thread_delay(1000);
- }
- else if(device_status.version_type == vt_BZY_JD)
- {
- // 6.关闭补光灯
- ctr_led(OFF);
- }
- else
- {
- if (device_status.power_status == 1)
- {
- // 1.打开路由器供电
- ctr_router(ON);
- ctr_RTU_DTU(ON);
- // 2.打开相机供电
- ctr_photo(ON);
- }
- // 5.关闭加热
- // 6.关闭补光灯
- ctr_led(OFF);
- }
- }
- /*三色光源*/
- void Led_Check(uint8_t tp)
- {
- if (tp == 3)
- {
- if (device_status.light_over_tim > 2 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 1;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim > 3600 && device_status.light_over_tim < 7200)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 1;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim < 1 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 1;
- LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
- }
- }
- else if (tp == 6)
- {
- if (device_status.light_over_tim > 4 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 1;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim < 14400 && device_status.light_over_tim > 7200)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 1;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim < 7200)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 1;
- LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
- }
- }
- else if (tp == 9)
- {
- if (device_status.light_over_tim > 6 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 1;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim < 6 * 3600 && device_status.light_over_tim > 3 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 1;
- device_status.lamp2_status = 0;
- LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
- }
- else if (device_status.light_over_tim < 3 * 3600)
- {
- device_status.work_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 1;
- LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
- }
- }
- }
- // 出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
- void HardWare_Check(uint8_t boot)
- {
- if (boot == 0 && device_status.version_type != 6)
- {
- // 停止所有动作 -完成
- HardWare_Init(boot);
- }
- else
- {
- // 停止所有动作
- // 读取记录待机功耗(实测大概70mA)
- //(需减去屏幕的功耗大概120mA)
- // 动作上仓门,读取功率值保存
- // 动作下仓门,读取功率值保存
- // 动作清扫,读取功率值保存
- // 打开镇流器,读取功率值保存
- // 打开海康相机供电,读取功率值保存
- // 打开补光灯,读取功率值保存
- // 打开路由器/RTU供电,读取功率值保存
- // 打开加热,读取功率值保存
- }
- }
- // 工作状态检测
- void WorkCheck(void)
- {
- uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- // 雨控检测,温控检测,电池电压检测
- while (device_status.ds == 1 && device_status.rain_status == 0 && device_status.temp_status == 0 && device_status.bat_status == 0)
- {
- // 工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
- if (device_status.timeSwitch == 1)
- {
- LOG_I("***********时控*****************");
- // 如果开始和结束是同一天
- if (device_status.startBar < device_status.stopBar)
- {
- LOG_I("开始和结束是同一天");
- time_t now;
- time(&now);
- static struct tm nowtime; // 现在
- static struct tm starttime; // 开始
- static struct tm endtime; // 结束
- // 获取当前时间戳
- nowtime = *localtime(&now);
- nowtime.tm_hour = nowtime.tm_hour - 8;
- // 获取定时开始的时间戳
- starttime = *localtime(&now);
- starttime.tm_hour = device_status.startBar - 8;
- starttime.tm_min = 0;
- starttime.tm_sec = 0;
- // 获取定时结束的时间戳
- endtime = *localtime(&now);
- endtime.tm_hour = device_status.stopBar - 8;
- endtime.tm_min = 0;
- endtime.tm_sec = 0;
- LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***", mktime(&nowtime), mktime(&starttime), mktime(&endtime));
- // 如果当前时间大于开始时间且小于结束时间,且没有开始工作
- if ((difftime(mktime(&nowtime), mktime(&starttime)) >= 0) && (difftime(mktime(&nowtime), mktime(&endtime)) < 0))
- {
- LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
- device_status.work_status = 1;
- }
- // 如果当前时间小于开始时间
- else if (difftime(mktime(&nowtime), mktime(&starttime)) < 0)
- {
- LOG_I("当前时间小于开始时间,不工作!!!-%d-%d", mktime(&nowtime), mktime(&starttime));
- device_status.work_status = 0;
- }
- // 当前时间大于结束时间
- else
- {
- LOG_I("当前时间大于结束时间,不工作!!!-%d-%d", mktime(&nowtime), mktime(&starttime));
- device_status.work_status = 0;
- }
- #if LAMP_EN == 1
- // 如果当前时间超过20点,未到21点
- if ((difftime(mktime(&nowtime), mktime(&starttime)) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 3600) < 0))
- {
- LOG_I("3led:20~21");
- device_status.lamp_status = 1;
- device_status.lamp1_status = 0;
- device_status.lamp2_status = 0;
- }
- else if ((difftime(mktime(&nowtime), mktime(&starttime) + 3600) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 7200) < 0))
- {
- LOG_I("3led:21~22");
- device_status.lamp1_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp2_status = 0;
- }
- else if ((difftime(mktime(&nowtime), mktime(&starttime) + 7200) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 10800) < 0))
- {
- LOG_I("3led:22~23");
- device_status.lamp2_status = 1;
- device_status.lamp_status = 0;
- device_status.lamp1_status = 0;
- }
- #endif
- }
- // 如果结束时间是第二天
- else if (device_status.startBar > device_status.stopBar)
- {
- time_t now;
- time(&now);
- static struct tm nowtime; // 现在
- static struct tm starttime; // 开始
- static struct tm endtime; // 结束
- // 获取当前时间戳
- nowtime = *localtime(&now);
- nowtime.tm_hour = nowtime.tm_hour - 8;
- // 获取定时开始的时间戳
- starttime = *localtime(&now);
- starttime.tm_hour = device_status.startBar - 8;
- starttime.tm_min = 0;
- starttime.tm_sec = 0;
- // 获取定时结束的时间戳
- endtime = *localtime(&now);
- endtime.tm_hour = device_status.stopBar - 8;
- endtime.tm_min = 0;
- endtime.tm_sec = 0;
- LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!", mktime(&nowtime), mktime(&starttime), mktime(&endtime));
- // 如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
- if ((difftime(mktime(&nowtime), mktime(&starttime)) > 0))
- {
- // 获取定时结束的时间戳
- endtime = *localtime(&now); // 将获取到的时间转换为时间戳
- endtime.tm_hour = device_status.stopBar - 8; // 这里需减8用于时区转换
- endtime.tm_min = 0;
- endtime.tm_sec = 0;
- device_status.work_status = 1;
- LOG_I("当前前时间大于开始时间,且没有开始工作");
- }
- // 当前时间小于开始时间
- else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
- {
- // 获取定时结束的时间戳
- endtime = *localtime(&now); // 将获取到的时间转换为时间戳
- endtime.tm_hour = device_status.stopBar - 8; // 这里需减8用于时区转换
- endtime.tm_min = 0;
- endtime.tm_sec = 0;
- // 如果当前时间戳小于结束时间戳
- if (difftime(mktime(&nowtime), mktime(&endtime)) < 0)
- {
- LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
- device_status.work_status = 1;
- }
- else
- {
- LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
- device_status.work_status = 0; // 不在工作时间,待机
- }
- }
- }
- }
- else
- {
- LOG_I("光控定时模式!");
- /*
- time_t now;
- time(&now);
- static struct tm nowstamp;
- nowstamp =*localtime(&now);
- nowstamp.tm_hour = nowstamp.tm_hour - 8;
- static rt_uint32_t nowstamp_num = 0;
- nowstamp_num = mktime(&nowstamp);
- rt_kprintf("now stamp:%d\n",nowstamp_num);
- */
- if (device_status.sun_status == 0 && device_status.light_over_tim != 0)
- {
- device_status.light_over_tim--;
- #if LAMP_EN == 1
- Led_Check(device_status.sunBar);
- #else
- device_status.work_status = 1;
- ;
- LOG_I("光控定时,计时中>>>>>>>>>:%d", device_status.light_over_tim);
- #endif
- }
- else
- {
- if (device_status.test_flag == 0)
- {
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- }
- device_status.work_status = 0;
- if (device_status.light_over_tim == 0 && device_status.sun_status == 1)
- device_status.light_over_tim = device_status.sunBar * 3600;
- LOG_I("光控中,白天:%d!!!", device_status.sun_status);
- }
- }
- rt_thread_delay(1000);
- }
- if (chk_log_time)
- {
- LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d", device_status.rain_status, device_status.temp_status, device_status.bat_status);
- }
- device_status.work_status = 0;
- rt_thread_delay(1000);
- }
- /**
- * @brief 孢子仪工作线程
- *
- */
- void WorkTask_BZY(void)
- {
- if (device_status.ds == 1)
- {
- // 时间段判断
- // 先判断第一个时间段
- time_t now;
- time(&now);
- static struct tm now_stamp; // 现在
- static struct tm cul_sh1_stamp; // 开始1
- static struct tm cul_eh1_stamp; // 结束1
- static struct tm cul_sh2_stamp; // 开始2
- static struct tm cul_eh2_stamp; // 结束2
- static struct tm cul_sh3_stamp; // 开始3
- static struct tm cul_eh3_stamp; // 结束3
- now_stamp = *localtime(&now);
- // 获取定时开始的时间戳
- cul_sh1_stamp = *localtime(&now);
- cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
- cul_sh1_stamp.tm_min = 0;
- cul_sh1_stamp.tm_sec = 0;
- cul_sh2_stamp = *localtime(&now);
- cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
- cul_sh2_stamp.tm_min = 0;
- cul_sh2_stamp.tm_sec = 0;
- cul_sh3_stamp = *localtime(&now);
- cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
- cul_sh3_stamp.tm_min = 0;
- cul_sh3_stamp.tm_sec = 0;
- // 获取定时结束的时间戳
- cul_eh1_stamp = *localtime(&now);
- cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
- cul_eh1_stamp.tm_min = 0;
- cul_eh1_stamp.tm_sec = 0;
- cul_eh2_stamp = *localtime(&now);
- cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
- cul_eh2_stamp.tm_min = 0;
- cul_eh2_stamp.tm_sec = 0;
- cul_eh3_stamp = *localtime(&now);
- cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
- cul_eh3_stamp.tm_min = 0;
- cul_eh3_stamp.tm_sec = 0;
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
- // 当前时间戳小于第一段开始时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
- {
- time_t now;
- time(&now);
- cul_sh1_stamp = *localtime(&now);
- cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
- cul_sh1_stamp.tm_min = 0;
- cul_sh1_stamp.tm_sec = 0;
- now_stamp = *localtime(&now);
- 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);
- 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);
- LOG_D("run_sta:%d", device_status.run_sta);
- }
- // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
- {
- time_t now;
- time(&now);
- cul_sh2_stamp = *localtime(&now);
- cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
- cul_sh2_stamp.tm_min = 0;
- cul_sh2_stamp.tm_sec = 0;
- now_stamp = *localtime(&now);
- 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);
- 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);
- LOG_D("run_sta:%d", device_status.run_sta);
- }
- // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
- {
- // 转盘到涂凡士林位置
- if (device_status.run_sta == 0)
- {
- LOG_I("start to collect!!!");
- DTU_Write("collect.mp3");
- ctr_turn(90, 4);
- rt_thread_delay(2000);
- // 涂凡士林
- ctr_Petroleum_jelly(10);
- rt_thread_delay(5000);
- }
- /*转盘到采集位置*/
- if (device_status.run_sta == 4)
- ctr_turn(90, 1);
- // 只有开始和结束时刻不同的时间段,才有效
- if ((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0) || (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0))
- {
- if ((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0) && difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) > 0)
- {
- device_status.work_status = 1;
- ctr_Collect_Fan(ON);
- // 当前时间戳小于第一段结束时间戳
- while (difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)
- {
- time(&now);
- now_stamp = *localtime(&now);
- cul_eh1_stamp = *localtime(&now);
- cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
- cul_eh1_stamp.tm_min = 0;
- cul_eh1_stamp.tm_sec = 0;
- if (device_status.run_sta != 1)
- break;
- LOG_I("1===========采集风机启动,正在收集.....%d-%d", mktime(&now_stamp), mktime(&cul_eh1_stamp));
- rt_thread_mdelay(10000);
- }
- }
- else
- {
- device_status.work_status = 0;
- ctr_Collect_Fan(OFF);
- LOG_I("未到收集1时间!");
- }
- if (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0 && difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) > 0)
- {
- device_status.work_status = 1;
- ctr_Collect_Fan(ON);
- while (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0)
- {
- time(&now);
- now_stamp = *localtime(&now);
- cul_eh2_stamp = *localtime(&now);
- cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
- cul_eh2_stamp.tm_min = 0;
- cul_eh2_stamp.tm_sec = 0;
- if (device_status.run_sta != 1)
- break;
- LOG_I("2===========采集风机启动,正在收集.....%d-%d", mktime(&now_stamp), mktime(&cul_eh2_stamp));
- rt_thread_mdelay(10000);
- }
- }
- else
- {
- device_status.work_status = 0;
- ctr_Collect_Fan(OFF);
- LOG_I("未到收集2时间!");
- }
- }
- else
- {
- LOG_I("this collect time is 0s,The wait time cannot be negative!");
- }
- }
- if (device_status.run_sta == 2)
- {
- ctr_Collect_Fan(OFF);
- device_status.develop_flag = 1;
- device_status.work_status = 2;
- ctr_develop(); // 培养
- ctr_turn(90, 3);
- }
- if (device_status.run_sta == 3)
- {
- ctr_Collect_Fan(OFF);
- device_status.work_status = 3;
- device_status.autotakepic = 1; // 对焦拍照
- }
- // 在培养之前再次确认时间戳
- time(&now);
- now_stamp = *localtime(&now);
- cul_eh2_stamp = *localtime(&now);
- cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
- cul_eh2_stamp.tm_min = 0;
- cul_eh2_stamp.tm_sec = 0;
- // 当前时间戳大于收集结束时间戳并且run_sta==1
- if (device_status.run_sta == 1 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) > 0)
- {
- ctr_Collect_Fan(OFF);
- LOG_I("===============collect ok,turn to drop!!!");
- device_status.develop_flag = 1;
- device_status.work_status = 2; // 现在是培养
- DTU_Write("develop.mp3");
- if (device_status.run_sta == 1)
- ctr_turn(90, 2); /*转盘到培养位置*/
- rt_thread_delay(1000);
- ctr_shake(ON, device_status.shake_sec);
- rt_thread_delay(1000);
- ctr_develop(); // 培养
- if (device_status.run_sta == 2)
- ctr_turn(90, 3); /*转盘到拍照位置*/
- rt_thread_delay(1000);
- device_status.work_status = 3; // 现在是拍照
- device_status.autotakepic = 1; // 对焦拍照
- while (device_status.autotakepic == 0)
- {
- rt_thread_delay(1000);
- LOG_I("正在对焦拍照............");
- }
- device_status.work_status = 0; // 待机
- DTU_Write("wait.mp3");
- LOG_I("=====================work finished==================");
- }
- rt_thread_delay(1000);
- }
- device_status.work_status = 0; // 待机
- LOG_W("==================!!!设备已待机!!!===================");
- }
- /*********************↓ 胶带结构的孢子仪主工作流程 ↓************************/
- ///**
- // * @brief 检查是否到工作时间段
- // *
- // * @return uint8_t 0-未到 / 已到:时间段编号(1-2-3)
- // */
- // static uint8_t Confirm_time_period(void)
- //{
- // static uint8_t once_print = 0;
- //
- // uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
- // static int8_t log_en_cnt = -1;
- //
- // uint8_t time_period = 0;
- //
- // // 时间段判断
- // // 先判断第一个时间段
- // time_t now;
- // time(&now);
- // static struct tm now_stamp; // 现在
- // static struct tm cul_sh1_stamp; // 开始1
- // static struct tm cul_eh1_stamp; // 结束1
- // static struct tm cul_sh2_stamp; // 开始2
- // static struct tm cul_eh2_stamp; // 结束2
- // static struct tm cul_sh3_stamp; // 开始3
- // static struct tm cul_eh3_stamp; // 结束3
- // now_stamp = *localtime(&now);
- // // 获取定时开始的时间戳
- // cul_sh1_stamp = *localtime(&now);
- // cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
- // cul_sh1_stamp.tm_min = 0;
- // cul_sh1_stamp.tm_sec = 0;
- // cul_sh2_stamp = *localtime(&now);
- // cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
- // cul_sh2_stamp.tm_min = 0;
- // cul_sh2_stamp.tm_sec = 0;
- // cul_sh3_stamp = *localtime(&now);
- // cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
- // cul_sh3_stamp.tm_min = 0;
- // cul_sh3_stamp.tm_sec = 0;
- // // 获取定时结束的时间戳
- // cul_eh1_stamp = *localtime(&now);
- // cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
- // cul_eh1_stamp.tm_min = 0;
- // cul_eh1_stamp.tm_sec = 0;
- // cul_eh2_stamp = *localtime(&now);
- // cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
- // cul_eh2_stamp.tm_min = 0;
- // cul_eh2_stamp.tm_sec = 0;
- // cul_eh3_stamp = *localtime(&now);
- // cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
- // cul_eh3_stamp.tm_min = 0;
- // cul_eh3_stamp.tm_sec = 0;
- //
- //
- // if (once_print == 0)
- // {
- // 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);
- // 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);
- // 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);
- // 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);
- // 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);
- // 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);
- // once_print = 1;
- // }
- //
- // // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
- // // 当前时间戳小于第一段开始时间戳
- // if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
- // {
- // time_t now;
- // time(&now);
- // cul_sh1_stamp = *localtime(&now);
- // cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
- // cul_sh1_stamp.tm_min = 0;
- // cul_sh1_stamp.tm_sec = 0;
- // now_stamp = *localtime(&now);
- //
- // if (chk_log_time)
- // {
- // 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);
- // 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);
- // LOG_D("run_sta:%d", device_status.run_sta);
- // }
- //
- // time_period = 0;
- // }
- // // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
- // if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
- // {
- // time_t now;
- // time(&now);
- // cul_sh2_stamp = *localtime(&now);
- // cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
- // cul_sh2_stamp.tm_min = 0;
- // cul_sh2_stamp.tm_sec = 0;
- // now_stamp = *localtime(&now);
- // if (chk_log_time)
- // {
- // 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);
- // 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);
- // LOG_D("run_sta:%d", device_status.run_sta);
- // log_en_cnt = 0;
- // }
- //
- // time_period = 0;
- // }
- //
- // // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
- // if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) < 0)
- // {
- // time_period = 1;
- // }
- // else if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
- // {
- // time_period = 2;
- // }
- // else if (difftime(mktime(&now_stamp), mktime(&cul_sh3_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh3_stamp)) < 0)
- // {
- // time_period = 3;
- // }
- //
- // return time_period;
- //}
- #define test_min 40
- /**
- * @brief 检查是否到工作时间段
- *
- * @return uint8_t 0-未到 / 已到:时间段编号(1-2-3)
- */
- static uint8_t Confirm_time_period(void)
- {
- static uint8_t once_print = 0;
- uint8_t log_en_inr = LOG_INR * 3; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- uint8_t time_period = 0;
- // 时间段判断
- // 先判断第一个时间段
- time_t now;
- time(&now);
- static struct tm now_stamp; // 现在
- static struct tm cul_sh1_stamp; // 开始1
- static struct tm cul_eh1_stamp; // 结束1
- static struct tm cul_sh2_stamp; // 开始2
- static struct tm cul_eh2_stamp; // 结束2
- static struct tm cul_sh3_stamp; // 开始3
- static struct tm cul_eh3_stamp; // 结束3
- now_stamp = *localtime(&now);
- // 获取定时开始的时间戳
- cul_sh1_stamp = *localtime(&now);
- cul_sh1_stamp.tm_min = device_status.collecting_sh1 + test_min;
- //cul_sh1_stamp.tm_hour = 0;
- cul_sh1_stamp.tm_sec = 0;
- cul_sh2_stamp = *localtime(&now);
- cul_sh2_stamp.tm_min = device_status.collecting_sh2 + test_min;
- //cul_sh2_stamp.tm_hour = 0;
- cul_sh2_stamp.tm_sec = 0;
- cul_sh3_stamp = *localtime(&now);
- cul_sh3_stamp.tm_min = device_status.collecting_sh3 + test_min;
- //cul_sh3_stamp.tm_hour = 0;
- cul_sh3_stamp.tm_sec = 0;
- // 获取定时结束的时间戳
- cul_eh1_stamp = *localtime(&now);
- cul_eh1_stamp.tm_min = device_status.collecting_eh1 + test_min;
- //cul_eh1_stamp.tm_hour = 0;
- cul_eh1_stamp.tm_sec = 0;
- cul_eh2_stamp = *localtime(&now);
- cul_eh2_stamp.tm_min = device_status.collecting_eh2 + test_min;
- //cul_eh2_stamp.tm_hour = 0;
- cul_eh2_stamp.tm_sec = 0;
- cul_eh3_stamp = *localtime(&now);
- cul_eh3_stamp.tm_min = device_status.collecting_eh3 + test_min;
- //cul_eh3_stamp.tm_hour = 0;
- cul_eh3_stamp.tm_sec = 0;
- if (once_print == 0 || chk_log_time)
- {
- rt_kprintf("\n\n");
- 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);
- LOG_I("结束时间1-%04d-%02d-%02d %02d:%02d:%02d\n", 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);
- 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);
- 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);
- // 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);
- // 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);
- rt_kprintf("\n\n");
- once_print = 1;
- }
- // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
- // 当前时间戳小于第一段开始时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
- {
- if (chk_log_time)
- {
- uint32_t time_cache = cul_sh1_stamp.tm_hour * 3600 + cul_sh1_stamp.tm_min * 60 + cul_sh1_stamp.tm_sec;
- uint32_t time_now = now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec;
- uint32_t time_remainder = time_cache - time_now;
- uint8_t hour = time_remainder / 3600;
- uint8_t min = (time_remainder % 3600) / 60;
- uint8_t sec = time_remainder % 60;
- LOG_I(" ====== 未到收集时间 A :%04d-%02d-%02d %02d:%02d:%02d 剩余:%02d:%02d:%02d ====== run_sta %d",
- 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,
- hour,
- min,
- sec,
- device_status.run_sta);
- }
- time_period = 0;
- }
- // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
- {
- if (chk_log_time)
- {
- uint32_t time_cache = cul_sh2_stamp.tm_hour * 3600 + cul_sh2_stamp.tm_min * 60 + cul_sh2_stamp.tm_sec;
- uint32_t time_now = now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec;
- uint32_t time_remainder = time_cache - time_now;
- uint8_t hour = time_remainder / 3600;
- uint8_t min = (time_remainder % 3600) / 60;
- uint8_t sec = time_remainder % 60;
- LOG_I(" ====== 未到收集时间 B :%04d-%02d-%02d %02d:%02d:%02d 剩余:%02d:%02d:%02d ====== run_sta %d",
- 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,
- hour,
- min,
- sec,
- device_status.run_sta);
- }
- time_period = 0;
- }
- // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
- if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) < 0)
- {
- time_period = 1;
- }
- else if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
- {
- time_period = 2;
- }
- else if (difftime(mktime(&now_stamp), mktime(&cul_sh3_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh3_stamp)) < 0)
- {
- time_period = 3;
- }
- // if (chk_log_time)
- // rt_kprintf("time_period > %d %X %X\n", time_period, difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)), difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)));
- return time_period;
- }
- /**
- * @brief
- *
- * @param mot 电机选择
- * @param limit1 限位1选择
- * @param limit2 限位2选择(不需要的话填0)
- * @param mct 电机操作选择
- * @return Res_def 0-成功
- */
- Res_def Mtor_Control(Motor_type mot, Limit_type limit1, Limit_type limit2, Motor_Ctl_type mct, uint16_t timeout)
- {
- uint8_t res = res_OK;
- uint16_t Motor_L, Motor_R, Lim1, Lim2 = LIMIT_0;
- uint16_t wait_out = 0;
- switch (mot) // 电机选型
- {
- case mot_ZP:
- Motor_L = TURN_ZP_L;
- Motor_R = TURN_ZP_R;
- break;
- default:
- LOG_W("illegal Motor_type %d", mot);
- return res_Verifi;
- break;
- }
- switch (limit1) // 限位选型1
- {
- case lt_Angle_0:
- Lim1 = LIMIT_0;
- break;
- case lt_Angle_90:
- Lim1 = LIMIT_90;
- break;
- default:
- LOG_W("illegal limit1_type %d", limit1);
- return res_Verifi;
- break;
- }
- if (limit2 != 0)
- {
- switch (limit2) // 限位选型2
- {
- case lt_Angle_0:
- Lim2 = LIMIT_0;
- rt_pin_mode(Lim2, PIN_MODE_INPUT);
- break;
- case lt_Angle_90:
- Lim2 = LIMIT_90;
- rt_pin_mode(Lim2, PIN_MODE_INPUT);
- break;
- default:
- LOG_W("illegal limit2_type %d", limit2);
- return res_Verifi;
- break;
- }
- }
- rt_pin_mode(Motor_L, PIN_MODE_OUTPUT);
- rt_pin_mode(Motor_R, PIN_MODE_OUTPUT);
- rt_pin_mode(Lim1, PIN_MODE_INPUT);
- // 走出限位
- while((rt_pin_read(Lim1) == 0) && (wait_out * 1000 < timeout))
- {
- switch (mct)
- {
- case mct_Foreward:
- rt_pin_write(Motor_R, ON);
- rt_pin_write(Motor_L, OFF);
- break;
- case mct_Reversal:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, ON);
- break;
- case mct_Stop:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, OFF);
- break;
- default:
- LOG_W("illegal Motor_Ctl_type %d", mct);
- return res_Verifi;
- break;
- }
- wait_out++;
- rt_thread_mdelay(1000);
- rt_kprintf("wait exit limit %d/%d \n", wait_out , timeout / 1000);
- }
- // 参数校验完成 开始操作
- switch (mct)
- {
- case mct_Foreward:
- rt_pin_write(Motor_R, ON);
- rt_pin_write(Motor_L, OFF);
- break;
- case mct_Reversal:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, ON);
- break;
- case mct_Stop:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, OFF);
- break;
- default:
- LOG_W("illegal Motor_Ctl_type %d", mct);
- return res_Verifi;
- break;
- }
- if (mct == mct_Stop)
- {
- rt_thread_mdelay(10);
- return res;
- }
- res = res_Timeout;
- while ((wait_out * 100 < timeout) && (limit2 == 0))
- {
- switch (mct)
- {
- case mct_Foreward:
- rt_pin_write(Motor_R, ON);
- rt_pin_write(Motor_L, OFF);
- break;
- case mct_Reversal:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, ON);
- break;
- case mct_Stop:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, OFF);
- break;
- default:
- LOG_W("illegal Motor_Ctl_type %d", mct);
- return res_Verifi;
- break;
- }
- if (rt_pin_read(Lim1) == 0)
- {
- // LOG_W("lim1 TIG");
- res = res_OK;
- break;
- }
- wait_out++;
- rt_thread_mdelay(100);
- }
- while ((wait_out * 100 < timeout) && (limit2 != 0))
- {
- switch (mct)
- {
- case mct_Foreward:
- rt_pin_write(Motor_R, ON);
- rt_pin_write(Motor_L, OFF);
- break;
- case mct_Reversal:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, ON);
- break;
- case mct_Stop:
- rt_pin_write(Motor_R, OFF);
- rt_pin_write(Motor_L, OFF);
- break;
- default:
- LOG_W("illegal Motor_Ctl_type %d", mct);
- return res_Verifi;
- break;
- }
- if (rt_pin_read(Lim1) == 0 || rt_pin_read(Lim2) == 0)
- {
- // LOG_W("lim1 or 2 TIG");
- res = res_OK;
- break;
- }
- wait_out++;
- rt_thread_mdelay(100);
- }
- rt_pin_write(TURN_ZP_R, OFF);
- rt_pin_write(TURN_ZP_L, OFF);
- return res;
- }
- /**
- * @brief 控制转盘电机
- *
- * @param mct 控制操作
- * @return Res_def 执行结果
- */
- Res_def Mtor_Control_ZP(Motor_Ctl_type mct)
- {
- uint8_t res = Mtor_Control(mot_ZP, lt_Angle_0, 0, mct, 15000);
- rt_kprintf("Mtor_Control %d - %d\n", mct, res);
- return res;
- }
- /**
- * @brief 限位预警消息
- *
- */
- static void Report_Limit_Error(void)
- {
- char *turn_warn = makeJson_Warn("未检测到限位", "转盘");
- DTU_Write("%s", turn_warn);
- rt_free(turn_warn);
- }
- /**
- * @brief 获取当前时间
- *
- * @param now_stamp 存放时间戳的指针
- */
- static void Get_now_time(struct tm *now_stamp)
- {
- time_t now;
- time(&now);
- *now_stamp = *localtime(&now);
- }
- /**
- * @brief 检查是否处于工作时间段
- *
- * @param coll_ch 时间段通道
- * @return Temporal_list 检查结果
- */
- static Temporal_list Check_Work_time_period(uint8_t coll_ch)
- {
- static struct tm now_stamp = {0}; // 现在
- static struct tm cul_s_stamp = {0}; // 开始
- static struct tm cul_e_stamp = {0}; // 结束
- Get_now_time(&now_stamp);
- Get_now_time(&cul_s_stamp);
- Get_now_time(&cul_e_stamp);
- switch (coll_ch)
- {
- case 1:
- cul_s_stamp.tm_min = device_status.collecting_sh1 + test_min;
- //cul_s_stamp.tm_hour = 0;
- cul_s_stamp.tm_sec = 0;
- cul_e_stamp.tm_min = device_status.collecting_eh1 + test_min;
- //cul_e_stamp.tm_hour = 0;
- cul_e_stamp.tm_sec = 0;
- break;
- case 2:
- cul_s_stamp.tm_min = device_status.collecting_sh2 + test_min;
- //cul_s_stamp.tm_hour = 0;
- cul_s_stamp.tm_sec = 0;
- cul_e_stamp.tm_min = device_status.collecting_eh2 + test_min;
- //cul_e_stamp.tm_hour = 0;
- cul_e_stamp.tm_sec = 0;
- if (cul_s_stamp.tm_min == cul_e_stamp.tm_min) // 检查第二时间段是否有效
- {
- return tl_Error;
- }
- break;
- default:
- return tl_Verifi;
- break;
- }
- if (difftime(mktime(&now_stamp), mktime(&cul_s_stamp)) >= 0 && // 大于开始时间
- difftime(mktime(&now_stamp), mktime(&cul_e_stamp)) < 0) // 小于结束时间
- {
- return tl_Center;
- }
- if (difftime(mktime(&now_stamp), mktime(&cul_s_stamp)) < 0) // 小于开始时间
- {
- return tl_Front;
- }
- if (difftime(mktime(&now_stamp), mktime(&cul_e_stamp)) >= 0) // 大于结束时间
- {
- // rt_kprintf("now %02d:%02d:%02d start %02d:%02d:%02d end %02d:%02d:%02d\n" ,
- // now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec,
- // cul_s_stamp.tm_hour,cul_s_stamp.tm_min,cul_s_stamp.tm_sec,
- // cul_e_stamp.tm_hour,cul_e_stamp.tm_min,cul_e_stamp.tm_sec
- // );
- return tl_Back;
- }
- return tl_Verifi;
- }
- /**
- * @brief 写工作运行状态
- *
- * @param sta 要写入的值
- */
- static void Set_run_sta(run_sta_list sta)
- {
- device_status.run_sta = sta;
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- uint8_t check = 0;
- ef_get_env_blob("run_sta", &check, sizeof(device_status.run_sta), NULL);
- if (check != sta)
- {
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- }
- rt_kprintf("Set_run_sta > %d \n" , check);
- }
- void Set_runsta_reset(void)
- {
- Set_run_sta(rs_RESET);
- }
- MSH_CMD_EXPORT(Set_runsta_reset , Set_runsta_reset);
- /**
- * @brief 读工作运行状态
- *
- * @return run_sta_list 读出的值
- */
- static run_sta_list Get_run_sta(void)
- {
- ef_get_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta), NULL);
- return device_status.run_sta;
- }
- /**
- * @brief 获取剩余工作时间
- *
- * @param coll_ch 工作时间段通道号
- * @return uint8_t 百分比的值
- */
- static int8_t Get_remainder_time(uint8_t coll_ch)
- {
- static struct tm now_stamp = {0}; // 现在
- static struct tm cul_s_stamp = {0}; // 开始
- static struct tm cul_e_stamp = {0}; // 结束
- uint32_t dividend = 0, divisor = 0, quotient = 0;
- int8_t result = 0;
- Get_now_time(&now_stamp);
- Get_now_time(&cul_s_stamp);
- Get_now_time(&cul_e_stamp);
- switch (coll_ch)
- {
- case 1:
- cul_s_stamp.tm_min = device_status.collecting_sh1 + test_min;
- //cul_s_stamp.tm_hour = 0;
- cul_s_stamp.tm_sec = 0;
- cul_e_stamp.tm_min = device_status.collecting_eh1 + test_min;
- //cul_e_stamp.tm_hour = 0;
- cul_e_stamp.tm_sec = 0;
- break;
- case 2:
- cul_s_stamp.tm_min = device_status.collecting_sh2 + test_min;
- //cul_s_stamp.tm_hour = 0;
- cul_s_stamp.tm_sec = 0;
- cul_e_stamp.tm_min = device_status.collecting_eh2 + test_min;
- //cul_e_stamp.tm_hour = 0;
- cul_e_stamp.tm_sec = 0;
- if (cul_s_stamp.tm_min == cul_e_stamp.tm_min) // 检查第二时间段是否有效
- {
- return -1;
- }
- break;
- default:
- return -1;
- break;
- }
- dividend = (cul_e_stamp.tm_hour * 3600 + cul_e_stamp.tm_min * 60 + cul_e_stamp.tm_sec) - (cul_s_stamp.tm_hour * 3600 + cul_s_stamp.tm_min * 60 + cul_s_stamp.tm_sec);
- divisor = (cul_e_stamp.tm_hour * 3600 + cul_e_stamp.tm_min * 60 + cul_e_stamp.tm_sec) - (now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec);
- divisor *= 100;
- quotient = divisor / dividend;
- result = abs(100 - quotient);
- return result;
- }
- /**
- * @brief 孢子仪工作线程(胶带结构)
- *
- */
- void WorkTask_BZY_JD(void)
- {
- uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- /** 前置条件 **/
- if (device_status.ds != 1) // 检查设备是否开机
- {
- device_status.work_status = 0;
- if (chk_log_time)
- {
- LOG_I(" ==================!!!Device standby!!!===================");
- }
- return;
- }
- Get_run_sta();
- uint8_t coll_ch = Confirm_time_period();
- if ((coll_ch == 0) && (device_status.run_sta <= rs_COLL_B)) // 检查是否进入工作时间段
- {
- if (chk_log_time)
- {
- LOG_I(" ==================!!!Not entering working hours!!!===================");
- }
- return;
- }
- /** 前置条件 **/
- /** 正式工作逻辑 **/
- static int8_t coll_ch_recode = -1;
- if(coll_ch_recode != coll_ch)
- {
- rt_kprintf(" WorkTask_BZY_JD work in coll_ch > %d\n\n", coll_ch);
- coll_ch_recode = coll_ch;
- }
- switch (device_status.run_sta)
- {
- case rs_RESET: // 复位
- LOG_E("STEP%d > Positioning of the turntable", rs_RESET);
- if (Mtor_Control_ZP(mct_Foreward) == res_Timeout)
- {
- Report_Limit_Error();
- }
- Set_run_sta(rs_COLL_A);
- break;
- case rs_COLL_A: // 采集 A
- rt_kprintf("coll_ch %d time_period %d\n" , coll_ch , Check_Work_time_period(coll_ch));
- if (coll_ch != rs_COLL_A)
- {
- LOG_W("Verifi failed and jump to the next step > to %d",rs_COLL_B);
- Set_run_sta(rs_COLL_B);
- break;
- }
- if (Check_Work_time_period(coll_ch) == tl_Center)
- {
- DTU_Write("collect.mp3");
- LOG_E("STEP%d > start to collect A", rs_COLL_A);
- }
- while (Check_Work_time_period(coll_ch) == tl_Front) // 等待到开始时间
- {
- if (chk_log_time)
- {
- LOG_I("wait for rs_COLL_A Start ");
- }
- rt_thread_mdelay(1000);
- }
- while (Check_Work_time_period(coll_ch) == tl_Center) // 开风机等结束
- {
- device_status.work_status = 1;
- ctr_Collect_Fan(ON);
- if (chk_log_time)
- {
- LOG_I(" Collecting A...%d/%%", Get_remainder_time(coll_ch));
- }
- rt_thread_mdelay(1000);
- }
- ctr_Collect_Fan(OFF);
- Set_run_sta(rs_COLL_B);
- break;
- case rs_COLL_B: // 采集 B
- rt_thread_mdelay(1000);
- if(Check_Work_time_period(coll_ch) == tl_Front || coll_ch < rs_COLL_B || Get_remainder_time(coll_ch) == 1) // 等待到开始时间
- {
- if (chk_log_time)
- {
- LOG_I("wait for rs_COLL_B Start ");
- }
- rt_thread_mdelay(1000);
- return;
- }
- if ((Check_Work_time_period(coll_ch) == tl_Error) || (coll_ch != rs_COLL_B))
- {
- LOG_W("Verifi failed and jump to the next step > to %d",rs_Press_Tape);
- Set_run_sta(rs_Press_Tape);
- break;
- }
- LOG_E("STEP%d > start to collect B", rs_COLL_B);
- while (Check_Work_time_period(coll_ch) == tl_Center) // 开风机等结束
- {
- device_status.work_status = 1;
- ctr_Collect_Fan(ON);
- if (chk_log_time)
- {
- LOG_I(" Collecting B...%d/%%", Get_remainder_time(coll_ch));
- }
- rt_thread_mdelay(1000);
- }
- rt_kprintf("STEP2 Finsh > %d\n\n", Check_Work_time_period(coll_ch));
- ctr_Collect_Fan(OFF);
- Set_run_sta(rs_Press_Tape);
- break;
- case rs_Press_Tape: // 压带
- LOG_E("STEP%d > Press_Tape", rs_Press_Tape);
- ctr_Petroleum_jelly(10);
- rt_thread_mdelay(500);
- Set_run_sta(rs_Tape_Move);
- break;
- case rs_Tape_Move: // 转胶带
- LOG_E("STEP%d > Positioning of the turntable", rs_Tape_Move);
- if (Mtor_Control_ZP(mct_Foreward) == res_Timeout)
- {
- Report_Limit_Error();
- }
- Set_run_sta(rs_Take_Photo);
- break;
- case rs_Take_Photo: // 拍照
- LOG_E("STEP%d > Take_Photo", rs_Take_Photo);
- device_status.work_status = 3; // 现在是拍照
- device_status.autotakepic = 1; // 对焦拍照
- while (device_status.autotakepic == 1)
- {
- rt_thread_mdelay(5000);
- LOG_I("正在对焦拍照............");
- }
- device_status.work_status = 0; // 待机
- DTU_Write("wait.mp3");
- LOG_I("=====================work finished==================");
- Set_run_sta(rs_RESET);
- break;
- default:
- Set_run_sta(rs_RESET);
- break;
- }
- if (chk_log_time)
- {
- LOG_I(" Main working logic of turntable structure");
- LOG_I(" Run Mode %d", device_status.run_sta);
- }
- /** 正式工作逻辑 **/
- rt_thread_delay(1000);
- }
- void BZY_JD_AutoTest(void)
- {
- device_status.auto_test_sw = 1;
- HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
- // 转盘复位
- LOG_I(" 1. 转盘复位!!!\n");
- HMI_WRITE("sysTest.result.txt=\"一键测试1/6:转盘复位!\"");
- rt_thread_mdelay(2000);
- Mtor_Control_ZP(mct_Foreward);
- LOG_I(" 2. 采集,打开风机!!!\n");
- HMI_WRITE("sysTest.result.txt=\"一键测试2/6:采集,打开风机!\"");
- ctr_Collect_Fan(ON);
- rt_thread_mdelay(5000);
- LOG_I(" 3. 采集结束,关闭风机!!\n");
- HMI_WRITE("sysTest.result.txt=\"一键测试3/6:采集结束,关闭风机!\"");
- rt_thread_mdelay(2000);
- ctr_Collect_Fan(OFF);
- LOG_I(" 4. 传送胶带!!!\n");
- HMI_WRITE("sysTest.result.txt=\"一键测试4/6:传送胶带!\"");
- Mtor_Control_ZP(mct_Foreward);
- rt_thread_mdelay(2000);
- LOG_I(" 5. 打开补光灯!!\n!");
- HMI_WRITE("sysTest.result.txt=\"一键测试5/6:打开补光灯!\"");
- rt_thread_delay(2000);
- ctr_led(ON);
- LOG_I(" 6. 开始拍照!!!\n");
- HMI_WRITE("sysTest.result.txt=\"一键测试6/6:开始拍照!\"");
- device_status.autotakepic = 1;
- rt_thread_delay(2000);
- device_status.auto_test_sw = 0;
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- }
- /*********************↑ 胶带结构的孢子仪主工作流程 ↑************************/
- /**
- * @brief 孢子仪工作线程V2
- *
- */
- void WorkTask_BZYV2(void)
- {
- // 打开采集风机
- ctr_Collect_Fan(ON);
- // 打开胶带步进电机
- // 等待采集结束
- // 拍照
- // 打开相机供电
- // 打开补光灯
- // 滑台归位
- // 滑台启动
- }
- // 工作任务流程s
- void WorkTask(void)
- {
- static int clt_time = 0; // 收集时间差秒数
- static int heat_time = 0;
- uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- if (chk_log_time)
- {
- LOG_I("工作状态:%d", device_status.work_status);
- LOG_I("开关机状态:%d", device_status.ds);
- }
- 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)
- {
- device_status.work_done = 0;
- if (clt_time == 0)
- {
- #if 0
- if(device_status.version_type==41&&atoi(device_status.power)<350)
- {
- LOG_W("相机电流不足!");
- char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
- DTU_Write("%s",ctr_hk_p_warn);
- rt_free(ctr_hk_p_warn);
- }
- #endif
- #if LAMP_EN == 0
- ctr_Fan_PUT(ON);
- #endif
- DTU_Write("workstart.mp3");
- }
- // 1.打开灯管
- #if LAMP_EN == 1
- if (device_status.lamp_status == 1)
- {
- ctr_lamp(ON, 1);
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- }
- else if (device_status.lamp1_status == 1)
- {
- ctr_lamp(OFF, 1);
- ctr_lamp(ON, 2);
- ctr_lamp(OFF, 3);
- }
- else if (device_status.lamp2_status == 1)
- {
- ctr_lamp(OFF, 1);
- ctr_lamp(OFF, 2);
- ctr_lamp(ON, 3);
- }
- #else
- ctr_lamp(ON, 1);
- #endif
- LOG_I("打开灯管!!!");
- #if 0
- rt_thread_delay(2000);
- if(atoi(device_status.power)<450)
- {
- LOG_I("Current is:%d",atoi(device_status.power));
- if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
- {
- char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
- DTU_Write("%s",lamp_err_warn);
- rt_free(lamp_err_warn);
- }
- }
- #endif
- if (device_status.version_type != 5)
- {
- if (clt_time == 0)
- {
- rt_thread_delay(5000); // 待灯管启动再往下执行,否则会触发电机过流
- // 2.打开上仓门
- rt_kprintf("打开上仓门!!!\n");
- device_status.ctr_up_motor = 1;
- }
- // 3.收集
- clt_time = device_status.clt_time * 60;
- while (clt_time != 1)
- {
- #if LAMP_EN == 0
- ctr_Fan_IN(ON);
- #endif
- clt_time--;
- rt_thread_delay(1000);
- #if LAMP_EN == 0
- if (clt_time % 30 == 0)
- ctr_Fan_PUT(OFF);
- #endif
- rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n", device_status.clt_time, clt_time);
- HMI_WRITE("workSta.g0.txt=\"正在收集.....剩余时间:%d分-%d秒\"", device_status.clt_time, clt_time);
- // 如果触发异常
- if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
- {
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- #if LAMP_EN == 0
- ctr_Fan_IN(OFF);
- #endif
- rt_kprintf("异常退出!!!\n");
- HMI_WRITE("workSta.g0.txt=\"异常退出\"");
- break;
- }
- if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
- {
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- #if LAMP_EN == 0
- ctr_Fan_IN(OFF);
- #endif
- rt_kprintf("异常退出!!!\n");
- HMI_WRITE("workSta.g0.txt=\"异常退出\"");
- break;
- }
- }
- clt_time = 1;
- if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
- {
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- #if LAMP_EN == 0
- ctr_Fan_IN(OFF);
- #endif
- rt_kprintf("异常退出!!!\n");
- HMI_WRITE("workSta.g0.txt=\"异常退出\"");
- break;
- }
- if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
- {
- ctr_lamp(OFF, 1);
- #if LAMP_EN == 1
- ctr_lamp(OFF, 2);
- ctr_lamp(OFF, 3);
- #endif
- #if LAMP_EN == 0
- ctr_Fan_IN(OFF);
- #endif
- rt_kprintf("异常退出!!!\n");
- HMI_WRITE("workSta.g0.txt=\"异常退出\"");
- break;
- }
- #if LAMP_EN == 0
- ctr_Fan_IN(OFF);
- #endif
- // 4.关闭上仓门
- device_status.ctr_up_motor = 2;
- rt_kprintf("关闭上仓门!!!\n");
- HMI_WRITE("workSta.g0.txt=\"关闭上仓门!\"");
- while (device_status.ctr_up_motor != 0)
- {
- rt_thread_delay(100);
- LOG_I("等待上仓门关闭!!!");
- }
- // 5.加热
- if (device_status.heat_sw == 0)
- {
- calorstat(device_status.heattime * 60);
- }
- else
- {
- heat_time = device_status.heattime * 60;
- while (heat_time != 0)
- {
- heat_time--;
- LOG_I("正在加热状态!!!");
- rt_thread_delay(1000);
- }
- }
- // 6.打开下仓门
- if (device_status.rain_status == 0)
- {
- device_status.ctr_down_motor = 1;
- }
- else
- {
- device_status.ctr_down_motor = 2;
- device_status.ctr_up_motor = 2;
- }
- // 待下仓门完全打开
- while (device_status.ctr_down_motor != 0)
- {
- rt_thread_delay(100);
- rt_kprintf("等待下仓门打开!!!\n");
- HMI_WRITE("workSta.g0.txt=\"等待下仓门打开!\"");
- }
- rt_thread_delay(3000);
- // 关闭下仓门
- device_status.ctr_down_motor = 2;
- while (device_status.ctr_down_motor != 0)
- {
- rt_thread_delay(100);
- rt_kprintf("等待下仓门关闭!!!\n");
- HMI_WRITE("workSta.g0.txt=\"等待下仓门关闭!\"");
- }
- // 2022-04-12add:
- LOG_I("打开上仓门!!!");
- HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
- device_status.ctr_up_motor = 1;
- if (device_status.version_type == 4 || device_status.version_type == 41)
- {
- // 震动
- ctr_shake(ON, device_status.shake_sec);
- // 补光&&拍照
- LOG_I("拍照!!!");
- HMI_WRITE("workSta.g0.txt=\"拍照!\"");
- HK_TakePhoto();
- // 清扫
- device_status.clear_status = 1;
- // 清扫失效则使用震动
- // ctr_shake(ON, 100);
- }
- }
- else
- {
- // 打开高压
- ctr_Heat(ON);
- // 打开补光
- ctr_led(ON);
- LOG_I("打开补光!!");
- rt_pin_mode(CLEAR_L_LIMIT, PIN_MODE_INPUT);
- // 2.翻转清虫
- while (rt_pin_read(CLEAR_L_LIMIT) == 1)
- rt_thread_delay(20);
- rt_thread_delay(500);
- Hk_Take_io(); // 触发海康相机拍照
- rt_thread_delay(500);
- ctr_turnv5(); // 摆动清虫
- LOG_I("摆动清虫!");
- }
- }
- if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1 || device_status.ds == 0)
- {
- if (chk_log_time)
- {
- rt_kprintf("-------------------not work--------------------\n");
- }
- device_status.work_status = 0;
- }
- // 工作结束
- if (device_status.work_done == 0 && device_status.work_status == 0)
- {
- DTU_Write("workdone");
- HMI_WRITE("workSta.g0.txt=\"工作任务已完成!\"");
- ResetInit();
- }
- if (chk_log_time)
- {
- rt_kprintf(" ***not work-device status:%d\n", device_status.ds);
- }
- }
- /* 入口函数-工作状态检测 */
- /**
- * @brief 工作状态检测线程服务函数
- *
- * @param parameter -
- */
- static void Work_status_thread_entry(void *parameter)
- {
- static uint16_t sun_status_num = 120;
- // 如果是光控定时,进行光控监测的消抖
- if (device_status.timeSwitch == 0 && device_status.sun_status == 0)
- {
- rt_kprintf("光控定时!!!\n");
- while (sun_status_num != 0)
- {
- sun_status_num--;
- rt_thread_delay(1000);
- rt_kprintf("开机光控检测:%d\n", sun_status_num);
- }
- device_status.light_over_tim = device_status.sunBar * 3600;
- device_status.test_flag = 0;
- }
- while (1)
- {
- WorkCheck();
- }
- }
- /*入口函数-工作流程*/
- /**
- * @brief 工作流程线程服务函数
- *
- * @param parameter -
- */
- static void Work_Loop_thread_entry(void *parameter)
- {
- uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- rt_thread_delay(1000);
- ResetInit();
- while (1)
- {
- // rt_kprintf(" dtype = %d vtype = %d \n\n", device_status.dtype, device_status.version_type);
- if (device_status.dtype == dt_BZY) // dtype分类 孢子仪
- {
- switch (device_status.version_type)
- {
- case vt_BZY:
- {
- WorkTask_BZY(); // 孢子仪转盘结构
- }
- break;
- case vt_BZY_JD:
- {
- // if (chk_log_time)
- // {
- // LOG_I("WorkTask_BZY_JD");
- // }
- WorkTask_BZY_JD(); // 孢子仪胶带结构
- }
- break;
- default:
- WorkTask_BZY();
- break;
- }
- }
- else if (device_status.dtype == dt_CBD) // dtype分类 测报灯
- {
- switch (device_status.version_type)
- {
- case vt_XCT:
- {
- WorkTask_XCT();
- }
- break;
- default:
- WorkTask();
- break;
- }
- }
- rt_thread_delay(1000);
- }
- }
- /*入口函数清扫*/
- /**
- * @brief 控制清扫线程服务函数
- *
- * @param parameter -
- */
- static void Control_Clear_thread_entry(void *parameter)
- {
- while (1)
- {
- #if ROBOT_EN == 1
- ctr_Motor_Robot(ON);
- rt_thread_delay(100);
- #else
- #if Color_EN == 1
- /*复位*/
- if (Read_Color_Key(KEY_RESET) == 1)
- {
- ctr_Color_board(RESET, 1200);
- rt_thread_delay(5000);
- }
- #else
- if (device_status.clear_status == 1)
- {
- if (ctr_clear(1200) == 0)
- ctr_TG_Clear(400);
- }
- rt_thread_delay(100);
- #endif
- #endif
- }
- }
- /*入口函数加热*/
- /**
- * @brief 控制加热线程服务函数
- *
- * @param parameter -
- */
- static void Control_Heat_thread_entry(void *parameter)
- {
- uint16_t var_clear = 0;
- #if ROBOT_EN == 1
- static uint8_t key_on = 0;
- #else
- #if Color_EN == 0
- while (device_status.work_status == 0)
- {
- rt_thread_delay(1000);
- }
- #endif
- #endif
- while (1)
- {
- #if ROBOT_EN == 1
- // 磁悬浮供电
- // 监测磁悬浮限位位置`
- LOG_D("Read 磁悬浮:%d", device_status.heattem);
- // 等待10S
- if (device_status.heattem < 30 && Read_Real_Voltage() / 100 > 12) // 磁悬浮处于关闭状态
- {
- key_on = 0;
- // 发送触摸按钮信号
- rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
- rt_pin_write(EMS_Dir, 0);
- rt_thread_delay(50);
- rt_pin_write(EMS_Dir, 1);
- }
- else if (device_status.heattem < 30 && Read_Real_Voltage() / 100 < 12)
- {
- ctr_router(OFF);
- }
- if (device_status.heattem > 40)
- {
- key_on = 1;
- rt_thread_delay(1000);
- LOG_D("Read 磁悬浮已打开:%d", device_status.heattem);
- }
- // 磁悬浮供电
- // 监测磁悬浮限位位置
- // 根据位置确定是否 按下按钮+
- if (Read_Real_Voltage() / 100 < 12 && key_on == 1)
- {
- key_on = 0;
- rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
- rt_pin_write(EMS_Dir, 0);
- rt_thread_delay(50);
- rt_pin_write(EMS_Dir, 1);
- }
- #else
- #if Color_EN == 1
- /*黄板归位*/
- if (Read_Color_Key(KEY_BACK) == 1)
- {
- LOG_W("黄板归位!");
- ctr_Color_board(CLOSE, 300);
- rt_thread_delay(5000);
- }
- #else
- if (device_status.work_status == 1 && device_status.heat_sw == 1)
- {
- ctr_lamp(ON, 1);
- rt_thread_delay(10000);
- calorstat(device_status.heattime * 60);
- }
- else
- {
- LOG_I("Not calorstat!");
- }
- if (device_status.work_status == 1 && device_status.version_type == 5)
- {
- var_clear++;
- if (var_clear == 300)
- {
- var_clear = 0;
- ctr_cangmen_down(ON);
- rt_thread_mdelay(5000);
- ctr_cangmen_down(OFF);
- rt_thread_mdelay(500);
- ctr_cangmen_down(ON);
- rt_thread_mdelay(5000);
- ctr_cangmen_down(OFF);
- }
- }
- // //吸虫塔补光灯测试
- // while(device_status.vol!=200)
- // {
- // if(var_led==0) ctr_led(ON);
- // var_led++;
- // if(var_led>10)
- // {
- // ctr_led(OFF);
- // var_ledoff++;
- // if(var_ledoff>10)
- // {
- // var_led = 0;
- // var_ledoff = 0;
- // ctr_led(ON);
- // }
- // }
- // rt_thread_delay(1000);
- // }
- rt_thread_delay(1000);
- #endif
- #endif
- }
- }
- /*清扫线程*/
- /**
- * @brief 创建用于控制清扫操作的线程
- *
- * @return int -
- */
- int Control_clear(void)
- {
- /* 创建线程*/
- tid_ctr = rt_thread_create("Control_Clear_thread_entry",
- Control_Clear_thread_entry, RT_NULL,
- 2048, // 2048
- 24, // 23
- WORK_CHECK_THREAD_TIMESLICE); // 5
- if (tid_ctr != RT_NULL)
- {
- rt_thread_startup(tid_ctr);
- }
- return 0;
- }
- /*恒温加热线程*/
- /**
- * @brief 创建用于恒温加热操作的线程
- *
- * @return int -
- */
- int Control_heat(void)
- {
- /* 创建线程*/
- tid_heat = rt_thread_create("Control_Heat_thread_entry",
- Control_Heat_thread_entry, RT_NULL,
- 1024, // 2048
- 25, // 23
- WORK_CHECK_THREAD_TIMESLICE); // 5
- if (tid_heat != RT_NULL)
- {
- rt_thread_startup(tid_heat);
- }
- return 0;
- }
- /* 创建线程 -工作状态检测*/
- int Workstatus_check(void)
- {
- /* 创建线程*/
- tid_wkstc = rt_thread_create("work_status_check_thread",
- Work_status_thread_entry, RT_NULL,
- WORK_CHECK_THREAD_STACK_SIZE, // 1024
- WORK_CHECK_THREAD_PRIORITY, // 23
- WORK_CHECK_THREAD_TIMESLICE); // 5
- if (tid_wkstc != RT_NULL)
- {
- rt_thread_startup(tid_wkstc);
- }
- return 0;
- }
- /*工作流程线程*/
- int Work_Loop_Task(void)
- {
- /* 创建线程*/
- tid_workloop = rt_thread_create("work_loop_thread",
- Work_Loop_thread_entry, RT_NULL,
- WORK_LOOP_THREAD_STACK_SIZE, // 2048
- WORK_LOOP_THREAD_PRIORITY, // 12
- WORK_LOOP_THREAD_TIMESLICE); // 5
- #if Color_EN == 0
- if (tid_workloop != RT_NULL)
- {
- rt_thread_startup(tid_workloop);
- }
- #endif
- return 0;
- }
- MSH_CMD_EXPORT(HardWare_Check, HardWare_Check<ON | OFF>);
- MSH_CMD_EXPORT(ctr_lamp, ctr_lamp<ON | OFF>);
- MSH_CMD_EXPORT(ctr_clear, ctr_clear<ON | OFF>);
- MSH_CMD_EXPORT(ctr_led, sample : ctr_led<ON | OFF>);
|