text: /*
   * @Author: ELEGOO
   * @Date: 2019-10-22 11:59:09
   * @LastEditTime: 2020-06-12 16:36:20
   * @LastEditors: Changhua
   * @Description: SmartRobot robot tank
   * @FilePath: 
   */
  #include "DeviceDriverSet_xxx0.h"
  #include "Arduino.h"
  
  /*Motor control*/
  void DeviceDriverSet_Motor::DeviceDriverSet_Motor_Init(void)
  {
  	pinMode(PIN_Motor_PWMA, OUTPUT);
    pinMode(PIN_Motor_PWMB, OUTPUT);
    pinMode(PIN_Motor_AIN_1, OUTPUT);
    pinMode(PIN_Motor_BIN_1, OUTPUT);
    pinMode(PIN_Motor_STBY, OUTPUT);
  }
  
  
  /*ITR20001 Detection*/
  bool DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_Init(void)
  {
    pinMode(PIN_ITR20001xxxL, INPUT);
    pinMode(PIN_ITR20001xxxM, INPUT);
    pinMode(PIN_ITR20001xxxR, INPUT);
    return false;
  }
  float DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_L(void)
  {
    return analogRead(PIN_ITR20001xxxL);
  }
  float DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_M(void)
  {
    return analogRead(PIN_ITR20001xxxM);
  }
  float DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_R(void)
  {
    return analogRead(PIN_ITR20001xxxR);
  }
  #if _Test_DeviceDriverSet
  void DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_Test(void)
  {
    Serial.print("\tL=");
    Serial.print(analogRead(PIN_ITR20001xxxL));
  
    Serial.print("\tM=");
    Serial.print(analogRead(PIN_ITR20001xxxM));
  
    Serial.print("\tR=");
    Serial.println(analogRead(PIN_ITR20001xxxR));
  }
  #endif
  
  /*
   Motor_control：AB / 方向、速度
  */
  void DeviceDriverSet_Motor::DeviceDriverSet_Motor_control(boolean direction_A, uint8_t speed_A, //A组电机参数
                                                            boolean direction_B, uint8_t speed_B, //B组电机参数
                                                            boolean controlED                     //AB使能允许 true
                                                            )                                     //电机控制
  {
  
    if (controlED == control_enable) //使能允许？
    {
      digitalWrite(PIN_Motor_STBY, HIGH);
      { //A...Right
  
        switch (direction_A) //方向控制
        {
        case direction_just:
          digitalWrite(PIN_Motor_AIN_1, HIGH);
          analogWrite(PIN_Motor_PWMA, speed_A);
          break;
        case direction_back:
  
          digitalWrite(PIN_Motor_AIN_1, LOW);
          analogWrite(PIN_Motor_PWMA, speed_A);
          break;
        case direction_void:
          analogWrite(PIN_Motor_PWMA, 0);
          digitalWrite(PIN_Motor_STBY, LOW);
          break;
        default:
          analogWrite(PIN_Motor_PWMA, 0);
          digitalWrite(PIN_Motor_STBY, LOW);
          break;
        }
      }
  
      { //B...Left
        switch (direction_B)
        {
        case direction_just:
          digitalWrite(PIN_Motor_BIN_1, HIGH);
  
          analogWrite(PIN_Motor_PWMB, speed_B);
          break;
        case direction_back:
          digitalWrite(PIN_Motor_BIN_1, LOW);
          analogWrite(PIN_Motor_PWMB, speed_B);
          break;
        case direction_void:
          analogWrite(PIN_Motor_PWMB, 0);
          digitalWrite(PIN_Motor_STBY, LOW);
          break;
        default:
          analogWrite(PIN_Motor_PWMB, 0);
          digitalWrite(PIN_Motor_STBY, LOW);
          break;
        }
      }
    }
    else
    {
      digitalWrite(PIN_Motor_STBY, LOW);
      return;
    }
  }
  