⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 healthmenstural.c

📁 mtk工具箱,计算器的详细设计,可以由此入手了解mtk的
💻 C
📖 第 1 页 / 共 5 页
字号:
        DecrementTime(myTime, incTime, &finaltime);

        g_mens_cntx->CurrYear = finaltime.nYear;
        g_mens_cntx->CurrMonth = finaltime.nMonth;
        g_mens_cntx->CurrDay = finaltime.nDay;

        g_mens_cntx->NumOfMon--;
        g_mens_cntx->IsAddToHistory = FALSE;

        EntryMensResult();
    }
    else
    {
        g_mens_cntx->IsAddToHistory = TRUE;
        MensDisplayBoundaryPopup();
    }
}


/*****************************************************************************
 * FUNCTION
 *  MensGoToNextWeek
 * DESCRIPTION
 *  Handle down arrow key when highlighting on last week of the month.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensGoToNextWeek(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mens_cntx->NumOfMon < MENS_MAX_NAVI_MON)
    {
        if (g_mens_cntx->CurrYear != 2030 || g_mens_cntx->CurrMonth != 12)
        {
            MYTIME myTime, incTime, finaltime;

            memset(&myTime, 0, sizeof(MYTIME));

            myTime.nDay = (U8) g_mens_cntx->CurrDay;
            myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
            myTime.nYear = (U16) g_mens_cntx->CurrYear;

            memset(&incTime, 0, sizeof(MYTIME));
            incTime.nDay = 7;
            IncrementTime(myTime, incTime, &finaltime);

            g_mens_cntx->CurrYear = finaltime.nYear;
            g_mens_cntx->CurrMonth = finaltime.nMonth;
            g_mens_cntx->CurrDay = finaltime.nDay;
            g_mens_cntx->NumOfMon++;
            g_mens_cntx->IsAddToHistory = FALSE;
            EntryMensResult();
            return;
        }
    }

    g_mens_cntx->IsAddToHistory = TRUE;
    MensDisplayBoundaryPopup();
}


/*****************************************************************************
 * FUNCTION
 *  MensGoToPreviousMonth
 * DESCRIPTION
 *  Side up key handler, go to the first day of previois month.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensGoToPreviousMonth(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mens_cntx->NumOfMon > 0)
    {
        MYTIME myTime, incTime, finaltime;

        memset(&myTime, 0, sizeof(MYTIME));

        myTime.nDay = 1;
        myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
        myTime.nYear = (U16) g_mens_cntx->CurrYear;

        memset(&incTime, 0, sizeof(MYTIME));
        incTime.nMonth = 1;

        DecrementTime(myTime, incTime, &finaltime);

        g_mens_cntx->CurrYear = finaltime.nYear;
        g_mens_cntx->CurrMonth = finaltime.nMonth;
        g_mens_cntx->CurrDay = finaltime.nDay;
        g_mens_cntx->NumOfMon--;
        g_mens_cntx->IsAddToHistory = FALSE;

        EntryMensResult();
    }
    else
    {
        g_mens_cntx->IsAddToHistory = TRUE;
        MensDisplayBoundaryPopup();
    }
}


/*****************************************************************************
 * FUNCTION
 *  MensGoToNextMonth
 * DESCRIPTION
 *  Side down key handler, go to the first day of next month.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensGoToNextMonth()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mens_cntx->NumOfMon < MENS_MAX_NAVI_MON)
    {
        if (g_mens_cntx->CurrYear != 2030 || g_mens_cntx->CurrMonth != 12)
        {
            MYTIME myTime, incTime, finaltime;

            memset(&myTime, 0, sizeof(MYTIME));

            myTime.nDay = 1;
            myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
            myTime.nYear = (U16) g_mens_cntx->CurrYear;

            memset(&incTime, 0, sizeof(MYTIME));
            incTime.nMonth = 1;
            IncrementTime(myTime, incTime, &finaltime);

            g_mens_cntx->NumOfMon++;
            g_mens_cntx->CurrYear = finaltime.nYear;
            g_mens_cntx->CurrMonth = finaltime.nMonth;
            g_mens_cntx->CurrDay = finaltime.nDay;
            g_mens_cntx->IsAddToHistory = FALSE;
            EntryMensResult();
            return;
        }
    }

    g_mens_cntx->IsAddToHistory = TRUE;
    MensDisplayBoundaryPopup();

}


/*****************************************************************************
 * FUNCTION
 *  MensDisplayBoundaryPopup
 * DESCRIPTION
 *  Display popup screen for out of boundary.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensDisplayBoundaryPopup(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DisplayPopup(
        (U8*) GetString(STR_CANNOT_NAVIGATE_FURTHER_MESSAGE),
        IMG_GLOBAL_WARNING,
        0,
        UI_POPUP_NOTIFYDURATION_TIME,
        (U8) WARNING_TONE);
}

#define MENS_PROBABILITY


/*****************************************************************************
 * FUNCTION
 *  MensCalcProbability
 * DESCRIPTION
 *  To calculate the probablity of ovulation.
 * PARAMETERS
 *  void
 * RETURNS
 *  probablity value
 *****************************************************************************/
S32 MensCalcProbability(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FLOAT prob;
    S16 DiffDays;
    MYTIME tmpDate;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&tmpDate, 0, sizeof(MYTIME));
    tmpDate.nDay = (U8) g_mens_cntx->CurrDay;
    tmpDate.nMonth = (U8) g_mens_cntx->CurrMonth;
    tmpDate.nYear = (U16) g_mens_cntx->CurrYear;

    DiffDays = MensGetDaysDifference(&tmpDate, &g_mens_cntx->InputDate);
    prob = (MensGetPregancyProb((S16) DiffDays, (S16) g_mens_cntx->AvgPeriod));

    return (S32) (prob * 100);
}


/*****************************************************************************
 * FUNCTION
 *  EntryMensProbability
 * DESCRIPTION
 *  Display probability screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryMensProbability(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *guiBuffer;  /* Buffer holding history data */
    S32 Prob;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    EntryNewScreen(SCR_ID_MENS_PROB, NULL, EntryMensProbability, NULL);

    guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_PROB);

    Prob = MensCalcProbability();

    ShowCategory72Screen(
        STR_SCR_HEALTH_MENSIS_PROBABILITY_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        0,
        0,
        (U8*) GetString(STR_SCR_HEALTH_MENSIS_PROBABILITY_MESSAGE),
        Prob,
        guiBuffer);

    SetLeftSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}

#define MENS_UTILITY


/*****************************************************************************
 * FUNCTION
 *  MensGetPregancyProb
 * DESCRIPTION
 *  This function is to calculate probability of pregnancy.
 * PARAMETERS
 *  DiffDay         [IN]        The number of diffenent dates between given date and menstrual date
 *  AvgPeriod       [IN]        Average perviods
 * RETURNS
 *  FLOAT    the probability of pregnancy
 *****************************************************************************/
FLOAT MensGetPregancyProb(S16 DiffDay, S16 AvgPeriod)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 i;
    S16 Nth;    /* the Nth day from menstrual date */
    S16 OD;     /* the estimated ovulated date */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; DiffDay < 0; i++)
    {
        DiffDay += AvgPeriod * i;
    }

    Nth = DiffDay % AvgPeriod;

    OD = AvgPeriod / 2;

    if (Nth < MENS_ZERO_PROB_PERIOD)
    {
        return (FLOAT) 0.01;
    }
    else if (Nth <= (OD + MENS_OVULATION_DAYS) && Nth >= (OD - MENS_OVULATION_DAYS))
    {
        return (FLOAT) 0.99;
    }
    else if (Nth < AvgPeriod / 2)
    {
        return (FLOAT) Nth *2 / AvgPeriod;
    }

    else
    {
        return (2 - (FLOAT) 2 * Nth / (AvgPeriod));
    }

}


/*****************************************************************************
 * FUNCTION
 *  MensGetDisplayColor
 * DESCRIPTION
 *  This function is to calculate which color to display of a given date.
 * PARAMETERS
 *  DiffDay         [IN]        The number of diffenent dates between given date and menstrual date
 *  AvgPeriod       [IN]        Average perviods
 * RETURNS
 *  enum MENS_COLOR_EMUM the color to be display
 *****************************************************************************/
MENS_COLOR_EMUM MensGetDisplayColor(S16 DiffDay, U8 AvgPeriod)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 i;
    S16 Nth;    /* the Nth day from menstrual date */
    S16 OD;     /* the estimated ovulated date */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; DiffDay < 0; i++)
    {
        DiffDay += AvgPeriod * i;
    }

    Nth = DiffDay % AvgPeriod;

    OD = AvgPeriod / 2;

    if (Nth < MENS_PERIOD)
    {
        return RED_COLOR;
    }
    else if (Nth == OD)
    {
        return ORANGE_COLOR;
    }
    else if (Nth <= (OD + MENS_OVULATION_DAYS) && Nth >= (OD - MENS_OVULATION_DAYS))
    {
        return YELLOW_COLOR;
    }
    else
    {
        return COLOR_NONE;
    }

}


/*****************************************************************************
 * FUNCTION
 *  MensGetDaysDifference
 * DESCRIPTION
 *  This function is to calculate number difference days between two date.
 * PARAMETERS
 *  t1      [IN]        Date to be computed
 *  t2      [IN]        Date to be computed
 * RETURNS
 *  Difference between t1 and t2 (t1 - t2).
 *****************************************************************************/

⌨️ 快捷键说明

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