/* ********************************************************************************************************* * xmk guide * huali xmk guide process * * (c) Copyright 2016-2020, hualijidian.com * All Rights Reserved * * File : hardware.c * By : eric * Date : 2018��7��10�� * Version : V0.0.1 ********************************************************************************************************* */ #include "stdlib.h" #include "env.h" #include "hardware.h" #include "iocfg.h" #define DBG_TAG "hard" #define DBG_LVL DBG_INFO #include #define CHECK_INPUT(in, v) \ do{ \ if(preI.in && (v)){ \ I.in = 1; \ } \ preI.in = (v); \ }while(0) rt_inline uint8_t checkWithPre(uint8_t input, uint8_t cnt) { static uint8_t pre[64]; if(pre[cnt] && input){ return 1; } pre[cnt] = input; return 0; } rt_inline void checkInput(void) { uint8_t i = 0; I.BtnRun = checkWithPre(!IN_RUN, i++); I.BtnRev = checkWithPre(!IN_REV, i++); I.BtnEStop = checkWithPre(IN2, i++); I.BtnCStop = checkWithPre(!IN3, i++); I.BtnLiftUp = checkWithPre(!IN4, i++); I.BtnLiftDown = checkWithPre(!IN5, i++); I.RmcStart = checkWithPre(!RMC_IN1, i++); I.RmcEStop = checkWithPre(RMC_IN2, i++); I.RmcForward = checkWithPre(!RMC_IN3, i++); I.RmcBackward = checkWithPre(!RMC_IN4, i++); I.RmcDriftLeft = checkWithPre(!RMC_IN6, i++); I.RmcDriftRight = checkWithPre(!RMC_IN5, i++); I.RmcRoteLeft = checkWithPre(!RMC_IN7, i++); I.RmcRoteRight = checkWithPre(!RMC_IN8, i++); I.RmcLiftUp = checkWithPre(!RMC_IN9, i++); I.RmcLiftDown = checkWithPre(!RMC_IN10, i++); I.RmcStop = checkWithPre(!RMC_IN11, i++); I.OBS1In1 = checkWithPre(!OBS1_IN1, i++); I.OBS1In2 = checkWithPre(!OBS1_IN2, i++); I.OBS1In3 = checkWithPre(!OBS1_IN3, i++); I.OBS1In4 = checkWithPre(!OBS1_IN4, i++); I.OBS2In1 = checkWithPre(!OBS2_IN1, i++); I.OBS2In2 = checkWithPre(!OBS2_IN2, i++); I.OBS2In3 = checkWithPre(!OBS2_IN3, i++); I.OBS2In4 = checkWithPre(!OBS2_IN4, i++); I.OBS3In1 = checkWithPre(!OBS3_IN1, i++); I.OBS3In2 = checkWithPre(!OBS3_IN2, i++); I.OBS3In3 = checkWithPre(!OBS3_IN3, i++); I.OBS3In4 = checkWithPre(!OBS3_IN4, i++); I.OBS4In1 = checkWithPre(!OBS4_IN1, i++); I.OBS4In2 = checkWithPre(!OBS4_IN2, i++); I.OBS4In3 = checkWithPre(!OBS4_IN3, i++); I.OBS4In4 = checkWithPre(!OBS4_IN4, i++); I.Npn1 = checkWithPre(!NPN1_IN1, i++); I.Npn2 = checkWithPre(!NPN1_IN2, i++); I.Npn3 = checkWithPre(!NPN2_IN3, i++); I.Npn4 = checkWithPre(!NPN2_IN4, i++); I.Npn5 = checkWithPre(!NPN3_IN5, i++); I.Npn6 = checkWithPre(!NPN3_IN6, i++); I.Npn7 = checkWithPre(!NPN4_IN7, i++); I.Npn8 = checkWithPre(!NPN4_IN8, i++); I.Npn9 = checkWithPre(!NPN5_IN9, i++); I.Npn10 = checkWithPre(!NPN5_IN10, i++); I.Lft1InTop = checkWithPre(NPN1_IN1, i++); I.Lft1InBottom = checkWithPre(NPN1_IN2, i++); I.Lft2InTop = checkWithPre(!NPN2_IN3, i++); I.Lft2InBottom = checkWithPre(!NPN2_IN4, i++); I.Motor1DET = checkWithPre(!MOTOR1_DET1, i++); I.Motor2DET = checkWithPre(!MOTOR2_DET2, i++); } void HWProcess(void *param) { uint8_t i; while(1) { checkInput(); rt_thread_mdelay(100); i++; if(i>20) { i = 0; LOG_I("OBS1 [%d %d %d %d]",I.OBS1In1,I.OBS1In2,I.OBS1In3,I.OBS1In4); LOG_I("OBS2 [%d %d %d %d]",I.OBS2In1,I.OBS2In2,I.OBS2In3,I.OBS2In4); LOG_I("OBS3 [%d %d %d %d]",I.OBS3In1,I.OBS3In2,I.OBS3In3,I.OBS3In4); LOG_I("OBS4 [%d %d %d %d]",I.OBS4In1,I.OBS4In2,I.OBS4In3,I.OBS4In4); LOG_I("Npn1 [%d %d %d %d %d]",I.Npn1,I.Npn2,I.Npn3,I.Npn4,I.Npn5); LOG_I("Npn6 [%d %d %d %d %d]",I.Npn6,I.Npn7,I.Npn8,I.Npn9,I.Npn10); LOG_I("Lft1 [%d %d] Lft2 [%d %d]",I.Lft1InTop,I.Lft1InBottom,I.Lft2InTop,I.Lft2InBottom); } } } int HWInit(void) { rt_thread_t tid; // thread tid = rt_thread_create("hw", HWProcess, RT_NULL, 512, RT_THREAD_PRIORITY_MAX - 5, 10); if (tid != RT_NULL) { rt_thread_startup(tid); } return RT_EOK; } INIT_APP_EXPORT(HWInit); //void Battery_Process(void) { // S.BatteryVolt = S.Driver1Volt; // if (Cfg.MainPower == CFG_MAIN_POWER_24V) { // S.BatteryVolt = S.Driver1Volt; // return; // } //}