menu.c

来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 588 行 · 第 1/2 页

C
588
字号
        if(--MenuTO)
        {
          return Result;
        }
      }
      else
      {
        return Result;
      }
    }
    /* Menu action  time out implement */
    while(pMenuActionChain->EventType)
    {
      if(pMenuActionChain->EventType != MenuEvent)
      {
        ++pMenuActionChain;
      }
      else
      {
        break;
      }
    }
    if (pMenuActionChain->MenuIndex)
    {
      if (MenuInd != pMenuActionChain->MenuIndex)
      {
        ShowUpdate = TRUE;
        MenuInd = pMenuActionChain->MenuIndex;
      }
    }
    if(pMenuActionChain->pVarArg != NULL)
    {
      ShowUpdate = TRUE;
      pSourceData = pMenuActionChain->pVarArg;
      while(*pSourceData)
      {
        *pDestData=*pSourceData;
        ++pSourceData;++pDestData;
      }
    }
    if (pMenuActionChain->MenuTO != MENU_TIME_OUT_NOT_UPADATE)
    {
      MenuTO = pMenuActionChain->MenuTO;
    }
    AnimType = pMenuActionChain->AnimationType;
    UserFunc1Hold = pMenuActionChain->UserFunc1;
    if(pMenuActionChain->UserFunc != NULL)
    {
      ShowUpdate = TRUE;
      pDestData = DataStr;
      pMenuActionChain->UserFunc(&pDestData,&MenuInd,&MenuTO,&AnimType);
    }
    if (ShowUpdate)
    {
      Result = MenuShow(pDestData,AnimType);
    }
  }
  return Result;
}

/*************************************************************************
 * Function Name: MenuGetInd
 * Parameters: none
 * Return: MENU_EVENT_TYPE_DEF
 *
 * Description: Return current menu index
 *
 *************************************************************************/
MENU_EVENT_TYPE_DEF MenuGetInd(void)
{
  return MenuInd;
}

/*************************************************************************
 * Function Name: MenuGetActionChain
 * Parameters: MEMU_IND_DEF MenuInd
 * Return: MENU_ACTION_SHAIN_DEF *
 *
 * Description: Return pointer to structure of action chain
 *
 *************************************************************************/
MENU_ACTION_SHAIN_DEF * MenuGetActionChain(MEMU_IND_DEF MenuInd)
{
  if (MenuInd > MENU_MAX_INDEX-1)
  {
    return (void *)0;
  }
  return (MENU_ACTION_SHAIN_DEF *)MenuActionChainAdd[MenuInd];
}

/*************************************************************************
 * Function Name: MenuGetVisualChain
 * Parameters:  MENU_LANG_TYPE_DEF Language,
 *              MEMU_IND_DEF MenuInd
 * Return:      MENU_VISUAL_DEF *
 *
 * Description: Return pointer to structure of visual chain
 *
 *************************************************************************/
MENU_VISUAL_DEF * MenuGetVisualChain(MENU_LANG_TYPE_DEF Language,MEMU_IND_DEF MenuInd)
{
  if ((MenuInd < MENU_MAX_INDEX) && (Language < MENU_LANGUAGE_NUMBER))
  {
    return (MENU_VISUAL_DEF *)(*MenuLanguageBaseAddTable[Language]+MenuInd);
  }
  return (MENU_VISUAL_DEF *)0;
}

/*************************************************************************
 * Function Name: MenuAnimation
 * Parameters: none
 *
 * Return: MENU_ERROR_CODE_DEF
 *
 * Description: makes animation
 *
 *************************************************************************/
MENU_ERROR_CODE_DEF MenuAnimation (void)
{
static Int16U i = 0;
MENU_ERROR_CODE_DEF Result = MENU_OK;

  if(++i < MenuAnimationSpeed)
  {
    return Result;
  }
  i = 0;
  if(MenuAnimationStep == 0)
  {
    return Result;
  }
  --MenuAnimationStep;
  switch (AnimationModeHold)
  {
  case MEMU_ANIMATION_LEFT:
    memmove(StrLine1Prev+1,StrLine1Prev,HD44780_HORIZONTAL_SIZE-1);
    StrLine1Prev[HD44780_HORIZONTAL_SIZE] = 0;
    StrLine1Prev[0] = StrLine1Next[MenuAnimationStep];
    memmove(StrLine2Prev+1,StrLine2Prev,HD44780_HORIZONTAL_SIZE-1);
    StrLine2Prev[HD44780_HORIZONTAL_SIZE] = 0;
    StrLine2Prev[0] = StrLine2Next[MenuAnimationStep];
    break;
  case MEMU_ANIMATION_RIGHT:
    memmove(StrLine1Prev,StrLine1Prev+1,HD44780_HORIZONTAL_SIZE-1);
    StrLine1Prev[HD44780_HORIZONTAL_SIZE-1] = StrLine1Next[HD44780_HORIZONTAL_SIZE-1 - MenuAnimationStep];
    memmove(StrLine2Prev,StrLine2Prev+1,HD44780_HORIZONTAL_SIZE-1);
    StrLine2Prev[HD44780_HORIZONTAL_SIZE-1] = StrLine2Next[HD44780_HORIZONTAL_SIZE-1 - MenuAnimationStep];
    break;
  default:
    strcpy(StrLine1Prev,StrLine1Next);
    strcpy(StrLine2Prev,StrLine2Next);
  }
  MEMU_STING_DEF *pData = StrLine1Prev;
  for(Int8U Y = 1; Y < 3; ++Y)
  {
    switch (HD44780_StrShow(1,Y,(Int8S *)pData))
    {
    case HD44780_BUSY_TO_ERROR:
    case HD44780_ERROR:
      Result =  MENU_SHOW_ERROR;
    case HD44780_OUT_OF_VISUAL:
      Result = MENU_SHOW_OUT_OF_VISUAL;
    }
    pData = StrLine2Prev;
  }

  if(MenuAnimationStep == 0)
  {
    if(UserFunc1Hold != NULL)
    {
      UserFunc1Hold(NULL,&MenuInd,&MenuTO,NULL);
    }
    return Result;
  }

  return(Result);
}

/*************************************************************************
 * Function Name: MenuInitAnimation
 * Parameters: Int8U X, Int8U Y,
 *             MEMU_STING_DEF *pData,
 *             MENU_ANIMATION_TYPE_DEF AnimationMode
 *
 * Return: HD44780_ERROR_CODE_DEF
 *
 * Description: Init the animation
 *
 *************************************************************************/
void  MenuInitAnimation(Int8U X, Int8U Y,MEMU_STING_DEF *pData, MENU_ANIMATION_TYPE_DEF AnimationMode)
{
  if(AnimationEnableFlag == FALSE)
  {
    AnimationMode = MEMU_ANIMATION_DIS;
  }
  AnimationModeHold = AnimationMode;
  switch (AnimationMode)
  {
  case MEMU_ANIMATION_LEFT:
  case MEMU_ANIMATION_RIGHT:
    MenuAnimationStep = HD44780_HORIZONTAL_SIZE;
    break;
  default:
    MenuAnimationStep = 1;
  }
  if(Y == 1)
  {
    strcpy(StrLine1Next,StrLine1Prev);
    for(;*pData; ++X)
    {
      StrLine1Next[X-1] = *pData++;
    }
  }
  else
  {
    strcpy(StrLine2Next,StrLine2Prev);
    for(; *pData; ++X)
    {
      StrLine2Next[X-1] = *pData++;
    }
  }
}

/*************************************************************************
 * Function Name: MenuGetAnimMode
 * Parameters: none
 *
 * Return: Boolean
 *
 * Description: Get current animation mode
 *
 *************************************************************************/
Boolean MenuGetAnimMode (void)
{
  return AnimationEnableFlag;
}

/*************************************************************************
 * Function Name: MenuSetAnimMode
 * Parameters: Boolean Flag
 *
 * Return: none
 *
 * Description: Set animation mode
 *
 *************************************************************************/
void MenuSetAnimMode (Boolean Flag)
{
  AnimationEnableFlag = Flag;
}


/*************************************************************************
 * Function Name: MenuGetAnimSpeed
 * Parameters: none
 *
 * Return: Int32U
 *
 * Description: Get current animation speed
 *
 *************************************************************************/
Int32U MenuGetAnimSpeed (void)
{
  return MenuAnimationSpeed;
}

/*************************************************************************
 * Function Name: MenuSetAnimSpeed
 * Parameters: Int32U Speed
 *
 * Return: none
 *
 * Description: Set animation mode
 *
 *************************************************************************/
void MenuSetAnimSpeed (Int32U Speed)
{
   MenuAnimationSpeed = Speed;
}

/*************************************************************************
 * Function Name: MenuGetAnimationProgress
 * Parameters: none
 *
 * Return:  Int16S
 *
 * Description: Return current animation steep
 *
 *************************************************************************/
Int16S MenuGetAnimationProgress (void)
{
   return MenuAnimationStep;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?