/*
 * WESPION_Def.h
 *
 *  Created on: Jul 8, 2023
 *      Author: JuHyung
 */

#ifndef INC_WESPION_DEF_H_
#define INC_WESPION_DEF_H_

// ── FW 빌드 정보 (Live Expression: FW_Build) ──
typedef struct {
  const char* version;   // "1.0.2-pi"
  const char* commit;    // git short hash
  const char* date;      // __DATE__
  const char* time;      // __TIME__
} FW_BuildInfo_t;
extern FW_BuildInfo_t FW_Build;

/* Private includes */


/* USER Private includes */


/* USER Private defines */


/* USER Private structure */
/* ************************************************************************************
 *                                Common Number Types                                 *
 * ************************************************************************************/
typedef enum
{
  Inv_Off        = 0,
  Inv_Init       = 1,
  Inv_Ready      = 2,
  Inv_VbyFCtrl   = 3,
  Inv_IbyFCtrl   = 4,
  Inv_TorqueCtrl = 5,
  Inv_TorqueWeakCtrl = 6,
  Inv_SpeedCtrl  = 7,
  Inv_Fault      = 8,
} WP_Status;

typedef enum
{
  Debug = 0,
  EncInit = 1,
  Calibration = 2,
  RunGym = 3,
} WP_DriveStatus;

typedef enum
{
  NotDone = 0,
  Done = 1,
  Error = 9,
//  Error1 = 91,
//  Error2 = 92,
//  Error3 = 93,
} WP_GeneralStatus;

typedef enum
{
  Drv_NoMotor = 0,
  Drv_Motor1 = 1,
  Drv_Motor2 = 2,
  Drv_BothMotor = 3,
} WP_ActiveMotorStat;

typedef enum
{
  WP_OK = 0U,
  WP_ERR = !WP_OK
} WP_ErrorStatus;

typedef enum
{
  WP_STOP = 0U,
  WP_RUN = !WP_STOP
} WP_RunStatus;

//  HSW (23.12.16)
typedef enum
{
  Normal     = 0,
  Eccentric  = 1,
  Elastic    = 2,
  Isokinetic = 3,
  Hydraulic  = 4
} WP_WeightMode;

typedef enum
{
//  MOTOR_L = 0,
//  MOTOR_R = 1,
//  MOTOR_BOTH = 2,
  L = 0,
  R = 1,
  LR = 2,
} WP_MotorSide;

typedef enum
{
  KG0P5 = 1,
  KG5P0 = 2,
} WP_WeightCtrl;
typedef enum
{
  UP = 1,
  DOWN = 2,
  STOP = 0
} WP_DirStatus;

typedef enum
{
  ON = 1,
  OFF = 0
} WP_WeightStatus;

typedef enum
{
  Block = -1,
  Ground = 0,
  Base = 1,
  Idle = 2,
  LoSoft = 3,
  RoM = 4,
  HiSoft = 5,
  Over = 6
} WP_RegionStatus;


/* ************************************************************************************
 *                                   Basic Structures                                 *
 * ************************************************************************************/
typedef struct
{
  uint8_t scheduler1msflag;
  uint8_t scheduler2msflag;
  uint8_t scheduler5msflag;
  uint8_t scheduler10msflag;
  uint8_t scheduler10ms_1flag;
  uint8_t scheduler50msflag;
  uint8_t scheduler100msflag;
  uint8_t scheduler500msflag;
  uint8_t scheduler1sflag;
}timetask;

typedef struct
{
  uint16_t _1ms;
  uint16_t _2ms;
  uint16_t _5ms;
  uint16_t _10ms;
  uint16_t _10ms_1;
  uint16_t _50ms;
  uint16_t _100ms;
  uint16_t _500ms;
  uint16_t _1s;
  uint16_t _10s;
  uint16_t _60s;
}timecnt;

typedef struct
{
  uint16_t rtc;
  uint16_t exti0;
  uint16_t dma1_St6;
  uint16_t adc;
  uint16_t tim1_brk_tim9;
  uint16_t tim1_up_tim10;
  uint16_t tim1_trg_com_timm11;
  uint16_t tim2;
  uint16_t tim4;
  uint16_t i2c1_ev;
  uint16_t i2c1_er;
  uint16_t spi1;
  uint16_t usart2;
  uint16_t usart3;
  uint16_t exti15_10;
  uint16_t tim8_up_tim13;
  uint16_t tim8_trg_com_tim14;
  uint16_t dma2_St0;
}IRQcnt;


/* ************************************************************************************
 *                              Motor Control Structures                              *
 * ************************************************************************************/
typedef struct __WP_MotorDQAxisTypeDef
{
  float d;
  float q;
} WP_MotorDQTypeDef;

typedef struct __WP_Motor3PhaseTypeDef
{
  float U;
  float V;
  float W;
} WP_Motor3PhaseTypeDef;

typedef struct __WP_MotorAxisTypeDef
{
  WP_Motor3PhaseTypeDef I3;     // 3Phase Feedback Current
  WP_MotorDQTypeDef Is;         // Stationary-axis Feedback Current
  WP_MotorDQTypeDef Ie;         // Rotationary-axis Feedback Current
  float Iphase;                 // Current Vector Scalar value
  WP_MotorDQTypeDef VeRef;      // Rotationary-axis calculated Voltage(After PI Controller)
  WP_MotorDQTypeDef VeSet;      // Rotationary-axis calculated Voltage(After ref limit)
  WP_MotorDQTypeDef VsSet;      // Stationary-axis calculated Voltage(After ref limit)
  WP_Motor3PhaseTypeDef V3Set;  // 3Phase calculated Voltage(After ref limit)
  WP_Motor3PhaseTypeDef Vdead;  // Dead time compensation value
  WP_Motor3PhaseTypeDef V3;     // 3Phase calculated Voltage(After phase limit)(Real Output)
  WP_MotorDQTypeDef Vs;         // Stationary-axis calculated Voltage(After phase limit)
  WP_MotorDQTypeDef Ve;         // Rotationary-axis calculated Voltage(After phase limit)
  float VphaseRef;
  float VphaseFil;
  float VphaseSet;
  float Dutyratio[3];
  uint32_t PWMcnt[3];
} WP_MotorAxisTypeDef;

typedef struct __WP_MotorCmdTypeDef
{
  WP_MotorDQTypeDef Icmd;
  WP_MotorDQTypeDef Iref;
  float IsCmd;
  float IsBeta;
  float RpmCmd;
  float RpmRef;
  float XbyF_Freq;
  WP_MotorDQTypeDef Vfcmd;
} WP_MotorCmdTypeDef;

typedef struct __WP_MotorMrSinCosUTypeDef
{
  uint16_t Sin;
  uint16_t Cos;
} WP_MotorMrSinCosUTypeDef;

typedef struct __WP_MotorMrSinCosSTypeDef
{
  int16_t Sin;
  int16_t Cos;
} WP_MotorMrSinCosSTypeDef;

typedef struct __WP_MotorMrSinCosFTypeDef
{
  float Sin;
  float Cos;
} WP_MotorMrSinCosFTypeDef;

typedef struct __WP_MotorMrAngleTypeDef
{
  WP_MotorMrSinCosUTypeDef Raw;
  WP_MotorMrSinCosUTypeDef Min;
  WP_MotorMrSinCosUTypeDef Max;
  WP_MotorMrSinCosUTypeDef Mid;
  WP_MotorMrSinCosFTypeDef Gain;
  WP_MotorMrSinCosFTypeDef Scaled;
} WP_MotorMrAngleTypeDef;

typedef struct __WP_MotorAngleTypeDef
{
  // Parameter Variables
  float AngleElecOffset;
  uint16_t EncPulse;
  float AngleScale;
  uint8_t PolePair;
  float SpeedScale;

  // Encoder Position Variables
  uint16_t Pulse;
  uint16_t PulseOld;
  int32_t diffL;
  float diffF;

  // Encoder Speed Variables
  uint8_t _1msCnt;
  uint8_t _1msFlg;    // Speed Control Flag
  uint16_t mnew;
  uint16_t mold;
  int32_t diffM;

  // Motor Angle Variables
  float AngleMech;
  float AngleMechAll;
  float AngleElec;
  float radElec;
  float XbyFAngle;

  // Motor Speed Variables
  float Rpm;
  float RpmFil;
  float RpmLim;
  float SpdCtrlOutLim;
  float WeFil;

  // Transform Angle
  float Tr_Sin;
  float Tr_Cos;

  WP_MotorMrAngleTypeDef MR;

} WP_MotorAngleTypeDef;

typedef struct __WP_GainTypeDef
{
  // Gain Parameter Variables
  float Kp;
  float Ki;
  float Kaw;

  float Kd;       ///somebp 2024.02.07

} WP_GainTypeDef;

typedef struct __WP_PITypeDef
{
  // Gain Parameter Variables
  float Err;
  float Pterm;
  float Iterm;

  float Dterm;    ///somebp 2024.02.07

  float PIterm;
  float Ff;
  float AW; // Anti-windup
  float Out;
} WP_PITypeDef;

typedef struct __WP_MotorParameterTypeDef
{
  // Motor Parameter Variables
  uint8_t Pole;
  uint8_t PolePair;
  float Rs;
  float Ld;
  float Lq;
  float PhaiF;
} WP_MotorParameterTypeDef;

typedef struct __WP_MotorContrlTypeDef
{
  WP_MotorCmdTypeDef Cmd;
  WP_MotorAxisTypeDef Fb;
  WP_GainTypeDef GainCurD;
  WP_GainTypeDef GainCurQ;
  WP_GainTypeDef GainSpd;
  WP_GainTypeDef GainFweak;
  WP_PITypeDef PiCurD;    // D Current Control PI
  WP_PITypeDef PiCurQ;    // Q Current Control PI
  WP_PITypeDef PiSpd;     // Speed Control PI
  WP_PITypeDef PiFweak;   // Field Weak Control PI
  WP_MotorParameterTypeDef Para;
} WP_MotorContrlTypeDef;

typedef struct __WP_MotorControllerErrorTypeDef
{
  // Error Variables
  WP_ErrorStatus OverCurrentU;
  WP_ErrorStatus OverCurrentV;
  WP_ErrorStatus OverCurrentW;
  WP_ErrorStatus OverCurrentD;
  WP_ErrorStatus OverCurrentQ;
  WP_ErrorStatus CurrentSensorShortU;
  WP_ErrorStatus CurrentSensorShortV;
  WP_ErrorStatus CurrentSensorShortW;
  WP_ErrorStatus CurrentSensorOpenU;
  WP_ErrorStatus CurrentSensorOpenV;
  WP_ErrorStatus CurrentSensorOpenW;
  WP_ErrorStatus CurrentSensorOffsetU;
  WP_ErrorStatus CurrentSensorOffsetV;
  WP_ErrorStatus CurrentSensorOffsetW;
  WP_ErrorStatus OverSpd;
  WP_ErrorStatus Angle;
  WP_ErrorStatus Speed;

  WP_ErrorStatus PWM;
} WP_MotorControllerErrorTypeDef;

/* ************************************************************************************
 *                                Inverter Structures                                 *
 * ************************************************************************************/
typedef struct __WP_ControllerTypeDef
{
  WP_Status Mode;
  WP_ActiveMotorStat ActiveMotor;
  uint8_t AdOffsetFlg;
  uint16_t AdOffsetCnt;
  uint8_t MrOffsetFlg;
  uint8_t Motor1Pwm;
  uint8_t Motor2Pwm;
} WP_ControllerTypeDef;

typedef struct __WP_ControllerErrorTypeDef
{
  // Error Variables
  WP_MotorControllerErrorTypeDef Motor1;
  WP_MotorControllerErrorTypeDef Motor2;

  WP_ErrorStatus UnderV;
  WP_ErrorStatus OverV;
  WP_ErrorStatus AdOffset;

} WP_ControllerErrorTypeDef;

typedef struct __WP_ErrorValueTypeDef
{
  // Error Variables
  float OverVoltage;
  float UnderVoltage;
  float OverCurrent;
  float OverSpeed;
  float IsensorShort;
  float IsensorOpen;
  float IsensorOffsetMax;
  float IsensorOffsetMin;
} WP_ErrorValueTypeDef;

typedef struct __WP_InverterParameterTypeDef
{
  float HwAdcScale;
  float HwVdcScale;
  float HwiScale;
  float VdcScale;
  float iScale;

  float VdcMargin;

  float Tsamp;
  float PWM_Mid;
  float PWM_Max;
} WP_InverterParameterTypeDef;

typedef struct __WP_InverterAdOffsetTypeDef
{
  WP_Motor3PhaseTypeDef iRaw;
  WP_Motor3PhaseTypeDef iOffset;
}WP_InverterAdOffsetTypeDef;

typedef struct __WP_InverterControlTypeDef
{
  float Vdc;
  float VdcFil;
  float VphaseLim;        // d-q Voltage limit
  float VphLim;           // 3 Phase Voltage Limit
  float Vdc_2;
  float _Vdc_2;
  float PWM_Scale;

  float VdcLimFweak;
  float VlimFweak;
  float IlimFweak;

  WP_InverterAdOffsetTypeDef AD1;
  WP_InverterAdOffsetTypeDef AD2;
} WP_InverterControlTypeDef;

typedef struct __WP_InverterTypeDef
{
  WP_InverterControlTypeDef Ctrl;
  WP_InverterParameterTypeDef Para;

} WP_InverterTypeDef;

typedef struct __WP_InverterADrawdataTypeDef
{
  uint16_t Raw[3][4];
}WP_InverterADrawdataTypeDef;

typedef struct __WP_InverterLpfTypeDef
{
//#define LPF(out, in, b1)  out = out-in>0 ? b1*(out-in)+ in :-b1*(in-out)+ in
//#define LpfFACTOR(fc, fs, fct)  fct =  fs/(fc*TWO_PI+fs)
  float fc;     // Cutoff Freqeucny
  float fs;     // Sampling Frequency
  float fct;    // LPF Constant
}WP_InverterLpfTypeDef;

typedef struct __WP_InverterComAdRawListTypeDef
{
  uint16_t VU0;   // ADC3 IN4
  uint16_t VU1;   // ADC3 IN5
  uint16_t NTC0;  // ADC3 IN6
  uint16_t NTC1;  // ADC3 IN7
  uint16_t EXT1;  // ADC3 IN8
  uint16_t EXT2;  // ADC3 IN9
  uint16_t EXT3;  // ADC3 IN14
  uint16_t EXT4;  // ADC3 IN15
} WP_InverterComAdRawListTypeDef;

typedef struct __WP_InverterComAdScaleListTypeDef
{
  float VU0;   // ADC3 IN4
  float VU1;   // ADC3 IN5
  float NTC0;  // ADC3 IN6
  float NTC1;  // ADC3 IN7
  float EXT1;  // ADC3 IN8
  float EXT2;  // ADC3 IN9
  float EXT3;  // ADC3 IN14
  float EXT4;  // ADC3 IN15
} WP_InverterComAdScaleListTypeDef;

typedef struct __WP_InverterComAdTypeDef
{
  uint8_t Flg;
  WP_InverterComAdRawListTypeDef Raw;
  WP_InverterComAdScaleListTypeDef Data;
}WP_InverterComAdTypeDef;

/* ************************************************************************************
 *                            Software Version Structures                             *
 * ************************************************************************************/
typedef struct __WP_SwVersionTypeDef
{
  uint8_t VerMajer;
  uint8_t VerMiner;
  uint8_t VerSub;
  uint8_t VerPre;     // Pre-release: 0=정식, N=dev.N
  uint16_t VerYear;
  uint8_t VerMonth;
  uint8_t VerDate;
}WP_SwVersionTypeDef;

/* ************************************************************************************
 *                            GymManagement  Structures                             *
 * ************************************************************************************/

typedef struct __WP_MachineTypeDef
{
  float SensorGearRatio;
  float SensorGearRatioInv;
  float SpoolDiameter;   // [mm]
  uint16_t CableMaxLength;
  float MaxWeight;
  float MaxCurrent;

  float SoftWindingHeight;
  float DefaultWeight;
  float FrictionWeight;
  float FrictionCoeff;    // 마찰 계수
  float FrictionSpeedPlus;
  float FrictionSpeedMinus;

  float Scale_Weight2Current;
  float Scale_Current2Weight;

} WP_MachineTypeDef;

typedef struct __WP_RegionTypeDef
{
  int16_t H_LoSoft[2];
  int16_t RangeLo[2];
  int16_t RangeHi[2];
  int16_t H_HiSoft[2];

  int16_t H_gnd;
  int16_t H_base;
  int16_t H_shock;

  int16_t L_soft;      //  [mm]
  float L_soft_inv;
  int16_t L_RangeMin;

  uint8_t RangeError;
} WP_RegionTypeDef;

typedef struct __WP_GymTypeDef    // HSW (23.11.20)
{
  uint8_t WeightMode[2];
  uint8_t WeightModeError;    //  □ WeightMode 구조체에 넣어야겠다
  float WeightBLE[2];
  float WeightSet[2];
  int16_t Position[2];
  int32_t PositionFine[2]; // PositionFine : 0.05mm 단위
  int32_t PositionFine2[2];
  int8_t RegionCurr[2];
  WP_RegionTypeDef Region;

  float CalibDeg[2];
  float Speed[2];

  float F_stop;
  float F_min;
  float F_shock;
  float F_idle;

  float F_EccSet;
//  uint8_t F_Ecc_Percentage[2];
  float F_EccSet_Temp[2];    // 3/19 프로토콜 업데이트 하면서 임시로 중복 존재
  float F_EccLimit;
  uint8_t F_Ecc_ErrorCode;
  float EccSpdUp;
  float EccSpdDown;

  float AutoWeightRatio[2];

} WP_GymTypeDef;

/*  ISR 수행시간 프로파일링 (v1.0.2)
 *  DWT Cycle Counter로 ISR 진입~종료 사이클 측정.
 *  180MHz 기준: cycles / 180 = µs
 */
typedef struct __ISR_ProfileTypeDef
{
  volatile uint32_t last;       // 직전 ISR 사이클 수
  volatile uint32_t max;        // 최대값 (리셋까지 유지)
  volatile uint32_t avg;        // 이동평균 (α=1/16)
  volatile uint32_t count;      // ISR 호출 횟수
} ISR_ProfileTypeDef;

/*  ISR → Scheduler 지연 알림 플래그 (v1.0.2 리팩토링)
 *  ISR에서 직접 UART/Return_ 호출 대신 플래그만 세팅하고,
 *  스케줄러(5ms)에서 ISR_DeferredNotify()가 실제 전송 수행.
 */
typedef struct __ISR_DeferredTypeDef
{
  // WeightOnOff 완료 알림
  volatile uint8_t WeightOnOff_Ready;      // 0=없음, 1=전송 필요
  uint8_t WeightOnOff_Status;              // ON or OFF

  // MotionAutoWeight 발동 알림
  volatile uint8_t MotionAuto_Ready;       // 0=없음, 1=전송 필요
  uint8_t MotionAuto_StatusL;
  uint8_t MotionAuto_StatusR;

  // ClampEccWeight 변경 알림
  volatile uint8_t EccClamp_Ready;         // 0=없음, 1=전송 필요
  uint8_t EccClamp_L;
  uint8_t EccClamp_R;
  uint8_t EccClamp_Err;

} ISR_DeferredTypeDef;

typedef struct __WP_WeightCtrlTypeDef
{
  float Nominal[2];  // 유저세팅(WP_Gym.WeightSet)으로부터 정하는 구간별 무게값
  float Target[2];   // 모드에 따른 실시간 무게 지령
  float Temp[2];     // 시간에 따라 지령을 쫓아가기 위한 실시간 무게 지령
  float Valid[2];
  float Ecc[2];

  uint8_t MotionAutoActive;
  uint8_t MotionAutoStatus; // 모션오토 기능의 동작 상태
  uint8_t OnOffStatus[2];   // 무게의 온오프 상태
  float OnOffScale[2];
  float OnOffStep;

} WP_WeightCtrlTypeDef;

//typedef struct __WP_DirectionTypeDef
//{
////  int8_t Status[2];
////  int16_t Cnt[2];     // 방향 지속시간을 쓰고 싶을 경우 살리자
//} WP_DirectionTypeDef;

typedef struct __WP_FfScaleTypeDef
{
  float RefSpeed;
  float RefSpeed_Inv;
  float Min;
  float Max;
  float Step;
  float Temp[2];
} WP_FfScaleTypeDef;

typedef struct __WP_WeightTypeDef
{
  WP_WeightCtrlTypeDef Ctrl;
//  General Parameters
  float RefSpdMove;
  float RefSpdStop;
  float RefTimeStable;   // 무게를 바꾸고 있는데 이정도 버티면 잘 버티고 있으니 더 빠르게 바꿔도 되겠다고 판단하는 기준
  float RefTimeVeryStable;

  float Ecc_Step;

//  WP_DirectionTypeDef Dir;

////  WeightChanger
//  float ChangePeriod;
//  uint32_t ChangeTimeOld;
//  uint32_t ChangeTimeNew;
//  uint32_t ChangeTimeGap;
//  float DiffSmall;
//  float DiffLarge;
//  float ChangeMin;
//  float ChangeMax;
//  float ChangeMinPerSec;      // 무게 변경 단위의 최소
//  float ChangeMidPerSec;      // 중간
//  float ChangeMaxPerSec;      // 최대
//  float ChangeMinStep;
//  float ChangeMidStep;
//  float ChangeMaxStep;
//  int32_t ChangeCnt[2];

////  AutoToggle
//  uint32_t ManagerTime_new;
//  uint32_t ManagerTime_old;
//  uint32_t ManagerTime_Gap;
//  uint32_t ManagerTime_Consumption;

  //  WeightFeel - FeedForward
  WP_FfScaleTypeDef FfScale;

  //  모드별 파라미터 (하위 구조체)
  struct {
    float Vref;       // 기준속도 (mm/s)
    float Vmax;       // 최대속도 cap (mm/s)
    float n;          // 속도 지수 (1.0=선형, 2.0=2차)
    float minRatio;   // 최소 텐션 비율 (0.1 = 10%)
  } Hydro;

  struct {
    float Vtarget;    // 목표속도 (mm/s)
    float Kp;         // 비례 게인 (즉각 응답)
    float Ki;         // 적분 게인 (정상상태 오차 제거)
    float DecayRate;  // 하강 시 힘 감쇠 속도 (kg/s), 기본 20
    float Fmin;       // 최소 부하 (kg), 하강 시에도 이 이하로 안 떨어짐
    float Fmax;       // 최대 부하 (kg), 브레이킹 상한. 0=TargetWeight 사용
  } Iso;

  struct {
    float Freq;         // 주파수 (Hz), 10~100
    float AmplitudeKg;  // 진폭 (kg), 0.5~15
    float MaxRatio;     // 비율 상한 (0~1), 기본 0.30
  } Vib;

  //  공통 안전장치
  struct {
    float IqLimit;          // 소프트 Iq 상한 (A), 0=비활성
    float SlewRate_kgPerSec; // 토크 변화율 상한 (kg/s)
  } Safety;

} WP_WeightTypeDef;

typedef struct __WP_UserSettingTypeDef
{
  uint16_t TimeCali;
  uint16_t TimeSafetyOFF;

} WP_UserSettingTypeDef;

typedef struct __WP_RegenRTypeDef
{
  uint8_t DebugStatus;
  uint8_t Status;

  float Vdc_Limit;
  float Vdc_Off;
  float Vdc_margin_Inv;

  float Idc_Charge_Limit;
  float Idc_Off;
  float Idc_margin_Inv;

  float Vdc_debug;
  float Idc_debug;

  float Vdc_raw;
  float Idc_raw;

  float Vdc_ref;
  float Idc_ref;

  float Vdc_filtered;
  float Idc_filtered;

  float diff_Vdc;
  float diff_Idc;

  float alpha_Vdc;
  float alpha_Idc;

  float RegenScale_Vdc;
  float RegenScale_Idc;
  uint16_t PWM_Vdc;
  uint16_t PWM_Idc;
  uint16_t PWM;
  uint16_t PWM_fin;

} WP_RegenRTypeDef;



typedef struct __WP_DeratingTypeDef
{
  uint8_t DebugStatus;    // 개발 시 임시 코드 구현을 위한 값
  int cnt;
  uint8_t Status;   // Derating 여부, 발동 요인을 구별하기 위한 값


  int16_t Iq_x10_cont[2];
  int16_t Iq_x10[2];
  int16_t Iq_x10_Debug[2];
  int16_t Iq_x10_Debug_Derated[2];

  int32_t P_loss[2];
  int32_t P_diss[2];
  int32_t deltaT[2];
  int32_t deltaT_ON;
  int32_t deltaT_max;

  uint8_t DeratingScale[2];
  float Iq_Lim[2];
  uint8_t Iq_x10_Lim_Min;


//  온도가 상승하여 디레이팅이 필요하다고 판단하는 로직은 위와 같은데
//  얼마의 시간을 유지해야 충분히 냉각됐다 판단하고 해제할 지는 아직 모름.
}WP_DeratingTypeDef;

typedef struct __WP_LEDCtrlTypeDef
{
  uint8_t R;
  uint8_t G;
  uint8_t B;

  int8_t MotionAutoWeight;
  int8_t BLEDisconnection;

}WP_LEDCtrlTypeDef;

typedef struct __WP_EncInitTypeDef   // 엔코더 초기화 (250703 추가)
{
  WP_GeneralStatus Flag;
  WP_GeneralStatus Status[2];
  uint32_t Step[2];
  uint8_t CurrentLevel[2];
  uint8_t AngleStep[2];
  uint32_t StartTime[2];
  uint32_t StepTime[2];
  float StartAngle[2];

} WP_EncInitTypeDef;

typedef struct __WP_ForcedCaliTypeDef
{
  WP_GeneralStatus Flag;
  uint8_t Status[2];           // L/R 상태 (NotDone/Done/Error)
  uint8_t Step[2];             // L/R 진행 단계 (0=미시작, 1=진행중)
  uint32_t StartTime[2];       // 시작 시간
  uint32_t StopTime[2];        // 정지 시작 시간
  uint8_t CurrentLevel[2];     // 전류 단계 (0=0.8A, 1=1.0A, 2=0.5A)
  float StartAngle[2];         // 시작 기계각
  float StartPosition[2];      // 시작 위치
  uint8_t WasRotating[2];      // 이전 회전 상태
} WP_ForcedCaliTypeDef;


/* USER Private extern function */

/* USER Private extern variables */

#endif /* INC_WESPION_DEF_H_ */
