#include "app_ir_controller.h"
#include "app_motor.h"
#include "mw_ir_controller.h"
#include "public_diy.h"
// motor_state_stop = 0,
// motor_state_goAhead,
// motor_state_goBack,
// motor_state_turnLeft,
// motor_state_turnRight,
// motor_state_selfLeft,
// motor_state_selfRight,
// motor_state_NUM,


motor_state_ENUM app_IrToMotorState(IR_DECODE_ENUM e_val)
{
    motor_state_ENUM e_retVal;
    switch(e_val)
    {
        case ir_decode_up:
            e_retVal = motor_state_goAhead;
            break;
        case ir_decode_down:
            e_retVal = motor_state_goBack;
            break;
        case ir_decode_left:
            e_retVal = motor_state_turnLeft;
            break;
        case ir_decode_right:
            e_retVal = motor_state_turnRight;
            break;
        case ir_decode_ok:
            e_retVal = motor_state_stop;
            break;
        default:
            e_retVal = motor_state_NUM;
            break;

    }
    return e_retVal;
}

void app_irControllerProcess(void)
{
    IR_DECODE_ENUM e_ir_decode_val;
    motor_state_ENUM e_motor_val;
    // 接收函数循环
    mw_ir_comm_recv_loop();
    // 有数据
    if(mw_get_ir_controller_instruct(&e_ir_decode_val) == RET_OK)
    {
        e_motor_val = app_IrToMotorState(e_ir_decode_val);
        // 判断合法性                                                     
        if(e_motor_val < motor_state_NUM)
        {
            app_motor_changeState(e_motor_val);
        }
    }
}
