/*
 * File: TouchBoardXY_handle_4ms.c
 *
 * Code generated for Simulink model 'P417_SWTR_App'.
 *
 * Model version                  : 1.150
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Thu Dec 15 23:34:40 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "TouchBoardXY_handle_4ms.h"

/* Include model header file for global data */
#include "P417_SWTR_App.h"
#include "P417_SWTR_App_private.h"

/* System initialize for function-call system: '<S2>/TouchBoardXY_handle_4ms' */
void P4_TouchBoardXY_handle_4ms_Init(uint8_T *rty_XY_Touch_And_Below_1N_af_hd,
  B_TouchBoardXY_handle_4ms_P41_T *localB, DW_TouchBoardXY_handle_4ms_P4_T
  *localDW)
{
  /* SystemInitialize for Chart: '<S40>/Value_Debounce_Chart' */
  P417__Value_Debounce_Chart_Init(&localB->output,
    &localDW->sf_Value_Debounce_Chart);

  /* SystemInitialize for Chart: '<S15>/Slect_Touch' */
  localB->Sts_Control = 0U;

  /* SystemInitialize for Chart: '<S41>/Value_Debounce_Chart' */
  P417__Value_Debounce_Chart_Init(rty_XY_Touch_And_Below_1N_af_hd,
    &localDW->sf_Value_Debounce_Chart_c);
}

/* Output and update for function-call system: '<S2>/TouchBoardXY_handle_4ms' */
void P417_SW_TouchBoardXY_handle_4ms(uint8_T rtu_TouchBoard_XY_Sts_input,
  uint8_T rtu_Voice_Sts_Select, uint8_T rtu_Vol_Sts_Select, uint8_T
  rtu_Menu_Sts_Select, uint8_T rtu_XY_Touch_And_Below_1N, uint8_T
  *rty_TouchBoard_XY_Sts_after_han, uint8_T *rty_XY_Touch_And_Below_1N_af_hd,
  B_TouchBoardXY_handle_4ms_P41_T *localB, DW_TouchBoardXY_handle_4ms_P4_T
  *localDW)
{
  uint8_T rtb_Compare_oa;
  uint8_T rtb_Compare_eb;
  uint8_T rtb_Compare_ll;

  /* Chart: '<S40>/Value_Debounce_Chart' incorporates:
   *  RelationalOperator: '<S42>/FixPt Relational Operator'
   *  UnitDelay: '<S42>/Delay Input1'
   *
   * Block description for '<S42>/Delay Input1':
   *
   *  Store in Global RAM
   */
  P417_SWTR__Value_Debounce_Chart(rtu_TouchBoard_XY_Sts_input, (uint8_T)
    (rtu_TouchBoard_XY_Sts_input != localDW->DelayInput1_DSTATE),
    &localB->output, &localDW->sf_Value_Debounce_Chart, 3U);

  /* RelationalOperator: '<S36>/Compare' incorporates:
   *  Constant: '<S36>/Constant'
   */
  rtb_Compare_oa = (uint8_T)(rtu_Voice_Sts_Select > 0);

  /* RelationalOperator: '<S37>/Compare' incorporates:
   *  Constant: '<S37>/Constant'
   */
  rtb_Compare_eb = (uint8_T)(rtu_Vol_Sts_Select > 0);

  /* RelationalOperator: '<S38>/Compare' incorporates:
   *  Constant: '<S38>/Constant'
   */
  rtb_Compare_ll = (uint8_T)(rtu_Menu_Sts_Select > 0);

  /* Chart: '<S15>/Slect_Touch' incorporates:
   *  Constant: '<S35>/Constant'
   *  RelationalOperator: '<S35>/Compare'
   */
  /*  Die2_A_Position_Judgement */
  if ((rtb_Compare_oa == 0) && (rtb_Compare_eb == 0) && (rtb_Compare_ll == 0) &&
      (localB->output > 0)) {
    localB->Sts_Control = 1U;
  } else if ((rtb_Compare_oa == 1) && (rtb_Compare_eb == 0) && (rtb_Compare_ll ==
              0)) {
    localB->Sts_Control = 2U;
  } else if ((rtb_Compare_oa == 0) && (rtb_Compare_eb == 1) && (rtb_Compare_ll ==
              0)) {
    localB->Sts_Control = 3U;
  } else {
    if ((rtb_Compare_oa == 0) && (rtb_Compare_eb == 0) && (rtb_Compare_ll == 1))
    {
      localB->Sts_Control = 4U;
    }
  }

  /* End of Chart: '<S15>/Slect_Touch' */

  /* MultiPortSwitch: '<S15>/Multiport Switch' incorporates:
   *  Constant: '<S15>/Constant'
   *  UnitDelay: '<S15>/Unit Delay'
   */
  switch (localB->Sts_Control) {
   case 1:
    *rty_TouchBoard_XY_Sts_after_han = localB->output;
    break;

   case 2:
    *rty_TouchBoard_XY_Sts_after_han = rtu_Voice_Sts_Select;
    break;

   case 3:
    *rty_TouchBoard_XY_Sts_after_han = rtu_Vol_Sts_Select;
    break;

   case 4:
    *rty_TouchBoard_XY_Sts_after_han = rtu_Menu_Sts_Select;
    break;

   case 5:
    *rty_TouchBoard_XY_Sts_after_han = 0U;
    break;

   default:
    *rty_TouchBoard_XY_Sts_after_han = localDW->UnitDelay_DSTATE;
    break;
  }

  /* End of MultiPortSwitch: '<S15>/Multiport Switch' */

  /* Chart: '<S41>/Value_Debounce_Chart' incorporates:
   *  RelationalOperator: '<S44>/FixPt Relational Operator'
   *  UnitDelay: '<S44>/Delay Input1'
   *
   * Block description for '<S44>/Delay Input1':
   *
   *  Store in Global RAM
   */
  P417_SWTR__Value_Debounce_Chart(rtu_XY_Touch_And_Below_1N, (uint8_T)
    (rtu_XY_Touch_And_Below_1N != localDW->DelayInput1_DSTATE_a),
    rty_XY_Touch_And_Below_1N_af_hd, &localDW->sf_Value_Debounce_Chart_c, 12U);

  /* Update for UnitDelay: '<S42>/Delay Input1'
   *
   * Block description for '<S42>/Delay Input1':
   *
   *  Store in Global RAM
   */
  localDW->DelayInput1_DSTATE = rtu_TouchBoard_XY_Sts_input;

  /* Update for UnitDelay: '<S15>/Unit Delay' */
  localDW->UnitDelay_DSTATE = *rty_TouchBoard_XY_Sts_after_han;

  /* Update for UnitDelay: '<S44>/Delay Input1'
   *
   * Block description for '<S44>/Delay Input1':
   *
   *  Store in Global RAM
   */
  localDW->DelayInput1_DSTATE_a = rtu_XY_Touch_And_Below_1N;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
