/*********************************************************************
*                     SEGGER Microcontroller GmbH                    *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2022  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************
----------------------------------------------------------------------
File        : ID_SCREEN_BUC_CONTROL_UPDATE_Slots.c
Purpose     : AppWizard managed file, function content could be changed
---------------------------END-OF-HEADER------------------------------
*/

#include "Application.h"
#include "../Generated/Resource.h"
#include "../Generated/ID_SCREEN_BUC_CONTROL.h"
#include "../Generated/ID_SCREEN_BUC_CONTROL_UPDATE.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "../utilities/fsl_debug_console.h"

/*** Begin of user code area ***/
/*** End of user code area ***/

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       cbID_SCREEN_BUC_CONTROL_UPDATE
*/
void cbID_SCREEN_BUC_CONTROL_UPDATE(WM_MESSAGE * pMsg) {
  GUI_USE_PARA(pMsg);
}

/*********************************************************************
*
*       ID_SCREEN_BUC_CONTROL_Copy__ID_EDIT_ATTENUTION_CTRL_VAL__WM_NOTIFICATION_VALUE_CHANGED__ID_EDIT_ATTENUTION_CTRL_VAL__APPW_JOB_SETVALUE
*/
void ID_SCREEN_BUC_CONTROL_Copy__ID_EDIT_ATTENUTION_CTRL_VAL__WM_NOTIFICATION_VALUE_CHANGED__ID_EDIT_ATTENUTION_CTRL_VAL__APPW_JOB_SETVALUE(APPW_ACTION_ITEM * pAction, WM_HWIN hScreen, WM_MESSAGE * pMsg, int * pResult) {
  GUI_USE_PARA(pAction);
  GUI_USE_PARA(hScreen);
  GUI_USE_PARA(pMsg);
  GUI_USE_PARA(pResult);
}

/*********************************************************************
*
*       ID_SCREEN_BUC_CONTROL_UPDATE__ID_BUTTON_ATTN_CTRL_UPDATE_SAVE__WM_NOTIFICATION_CLICKED
*/
void ID_SCREEN_BUC_CONTROL_UPDATE__ID_BUTTON_ATTN_CTRL_UPDATE_SAVE__WM_NOTIFICATION_CLICKED(APPW_ACTION_ITEM * pAction, WM_HWIN hScreen, WM_MESSAGE * pMsg, int * pResult) {
//	if(strcmp(Backup_gui_attenution_ctrl,"")==0)
//	{
//		PRINTF("\n String Matched NULL");
//		strcpy(Backup_gui_attenution_ctrl,"00");
//	}
	//PRINTF("gui_attenution_ctrl=%s",gui_attenution_ctrl);
//	PRINTF("gui_attenution_ctrl int =%d",atoi(gui_attenution_ctrl));
	//PRINTF("Backup_gui_attenution_ctrl =%s",Backup_gui_attenution_ctrl);

	APPW_GetText(ID_SCREEN_BUC_CONTROL_UPDATE, ID_EDIT_ATTENUTION_CTRL_VAL_UPDATE, gui_attenution_ctrl, sizeof(gui_attenution_ctrl));
	char *tok;
	int i=0,DigitCount=0;
	for(i=0;i<strlen(gui_attenution_ctrl);i++)
	{
		if(gui_attenution_ctrl[i]>='0' && gui_attenution_ctrl[i]<='9' || gui_attenution_ctrl[i]=='.')
		{
			DigitCount++;
		}
	}

	if(DigitCount==strlen(gui_attenution_ctrl))   // if gui_attenution_ctrl contains only digits
	{
				tok = strtok(gui_attenution_ctrl,".");
				if(atoi(tok)>=0 && atoi(tok)<=31)
				{
					//PRINTF("\n tok=%s",tok);
					//PRINTF("\n number");
					strcpy(gui_attenution_ctrl,tok);
					Buc_ctrl_RF_attn_ctrl_save_flag=1;
					APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, gui_attenution_ctrl);
					strcpy(Backup_gui_attenution_ctrl,gui_attenution_ctrl);
//					PRINTF("tok=%s",tok);
//					PRINTF("gui_attenution_ctrl=%s",gui_attenution_ctrl);
//					PRINTF("Backup_gui_attenution_ctrl=%s",Backup_gui_attenution_ctrl);
				}
	}
	else
	{
				//PRINTF("\n not number");
				APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, "");
				APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, Backup_gui_attenution_ctrl);
				if(strcmp(Backup_gui_attenution_ctrl,"")==0)
				{
					//PRINTF("\n NULL MATCHED");
					strcpy(Backup_gui_attenution_ctrl,gui_Screen_Param_Default_number);
					APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, "");
					APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, Backup_gui_attenution_ctrl);
				}
				strcpy(gui_attenution_ctrl,Backup_gui_attenution_ctrl);

	}

//	else
//	{
//		PRINTF("out range");
//		Buc_ctrl_RF_attn_ctrl_save_flag=0;
//		APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, "");
//		APPW_SetText(ID_SCREEN_BUC_CONTROL, ID_TEXT_ATTN_CTRL_DISP, Backup_gui_attenution_ctrl);
//	}

  GUI_USE_PARA(pAction);
  GUI_USE_PARA(hScreen);
  GUI_USE_PARA(pMsg);
  GUI_USE_PARA(pResult);
}

/*********************************************************************
*
*       ID_SCREEN_BUC_CONTROL_UPDATE__ID_BUTTON_BACK_ATTN_CTRL_UPDATE__WM_NOTIFICATION_CLICKED
*/
void ID_SCREEN_BUC_CONTROL_UPDATE__ID_BUTTON_BACK_ATTN_CTRL_UPDATE__WM_NOTIFICATION_CLICKED(APPW_ACTION_ITEM * pAction, WM_HWIN hScreen, WM_MESSAGE * pMsg, int * pResult) {
  GUI_USE_PARA(pAction);
  GUI_USE_PARA(hScreen);
  GUI_USE_PARA(pMsg);
  GUI_USE_PARA(pResult);
}

/*************************** End of file ****************************/
