Beispiel #1
0
/**
  * @brief  Tamper callback 
  * @param  hrtc: RTC handle
  * @retval None
  */
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
{
  RTC_DateTypeDef sTimeStampDateget;
  RTC_TimeTypeDef sTimeStampget;
  
  /* Toggle LED4 */
  BSP_LED_Toggle(LED4);
  
#ifdef USE_LCD 
  HAL_RTCEx_GetTimeStamp(&RtcHandle, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BCD);
  /* Set the Back Color */
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  /* Set the Text Color */
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  BSP_LCD_DisplayStringAtLine(8, (uint8_t *)"TimeStamp Display");
  /* Display Time Stamp */
  RTC_Time_display(9, LCD_COLOR_BLACK , RTC_Get_Time(&sTimeStampget));
#else
    
  HAL_RTCEx_GetTimeStamp(&RtcHandle, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BIN);
  /* Display time Format : hh:mm:ss */
  sprintf((char*)aShowTimeStamp,"%0.2d:%0.2d:%0.2d", sTimeStampget.Hours, sTimeStampget.Minutes, sTimeStampget.Seconds);
  /* Display date Format : mm-dd */
  sprintf((char*)aShowDateStamp,"%0.2d-%0.2d-%0.2d", sTimeStampDateget.Month, sTimeStampDateget.Date, 2013); 
#endif /* USE_LCD */
}
Beispiel #2
0
/**
  * @brief  Displays the current time and date.
  * @param  None
  * @retval None
  */
static void RTC_CalendarShow(void)
{
  RTC_DateTypeDef sdatestructureget;
  RTC_TimeTypeDef stimestructureget;
  
#ifdef USE_LCD   
  /* Get the RTC current Time */
  HAL_RTC_GetTime(&RtcHandle, &stimestructureget, RTC_FORMAT_BCD);
  /* Get the RTC current Date */
  HAL_RTC_GetDate(&RtcHandle, &sdatestructureget, RTC_FORMAT_BCD);
  /* Set the Back Color */
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  /* Set the Text Color */
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  BSP_LCD_DisplayStringAtLine(6, (uint8_t *)"Current Time Display");

  RTC_Time_display(7, LCD_COLOR_BLACK , RTC_Get_Time(&stimestructureget));
#else
  /* Get the RTC current Time */
  HAL_RTC_GetTime(&RtcHandle, &stimestructureget, RTC_FORMAT_BIN);
  /* Get the RTC current Date */
  HAL_RTC_GetDate(&RtcHandle, &sdatestructureget, RTC_FORMAT_BIN);
  /* Display time Format : hh:mm:ss */
  sprintf((char*)aShowTime,"%0.2d:%0.2d:%0.2d", stimestructureget.Hours, stimestructureget.Minutes, stimestructureget.Seconds);
  /* Display date Format : mm-dd-yy */
  sprintf((char*)aShowDate,"%0.2d-%0.2d-%0.2d", sdatestructureget.Month, sdatestructureget.Date, 2000 + sdatestructureget.Year); 
#endif /* USE_LCD */
} 
Beispiel #3
0
/***********************************************************************
		module		:	[机器设置操作]
		function	:	[设置时间]
  		return		:	[0:成功
  						其它:失败]
		comment		:	[全局普通函数]
		machine		:	[EH-0818]
		language	:	[CHN]
 		keyword		:	[MAC_SET]
		date		:	[11/07/20]
 		author		:	[chen-zhengkai]
************************************************************************/
int setTime()
{
	typ_TIME	ttime;
	char	dBuf[40] = {0};
	const char	returnStr[] = "按任意键返回";
	const char	cueStr[] = "请输入时间:";
	int	ret = 0;
	int	hour = 0;
	int	minute = 0;
	int	second = 0;
	char	str1[20] = {0};
	char	str2[20] = {0};
	char	str3[20] = {0};
	
	
	RTC_Get_Time(&ttime);
	hour = ttime.hour;
	minute = ttime.min;
	second = ttime.sec;
		
	strcpy(str1,"时:");
	strcpy(str2,"分:");
	strcpy(str3,"秒:");
		
	while (1) {
//		sprintf(dBuf,"%02d:%02d:%02d",ttime.hour,ttime.min,ttime.sec);
//		DispStr_CE(0,0,dBuf,DISP_CENTER|DISP_CLRSCR);
		DispStr_CE(0,0,cueStr,DISP_CENTER|DISP_CLRSCR);
		DispStr_CE(0,4,str1,DISP_POSITION);
		DispStr_CE(0,8,str2,DISP_POSITION);
		DispStr_CE(0,12,str3,DISP_POSITION);
		
		ret = input_date_time(4,2,1,0,23,str1,&hour);
		if (ret == -1) {
			return ret;
		}
		ret = input_date_time(8,2,1,0,59,str2,&minute);	
		if (ret == -1) {
			continue;
		}
		ret = input_date_time(12,2,1,0,59,str3,&second);	
		if (ret != -1) {
			ttime.hour = hour;
			ttime.min = minute;
			ttime.sec = second;			
			RTC_Set_Time(&ttime);
			sprintf(dBuf,"%02d:%02d:%02d",hour,minute,second);						
			DispStr_CE(0,6,dBuf,DISP_CENTER|DISP_CLRSCR);
			DispStr_CE(0,10,returnStr,DISP_CENTER);
			delay_and_wait_key( 3, EXIT_KEY_ALL, 0 );
			return 0;
		}
	}
}
Beispiel #4
0
void printDebug4(void)
{
	RTCTime current_time;
	current_time = RTC_Get_Time();

	print_uart0("FCd4;");
	print_uart0("%d;%d;%d;",
		(int)current_time.RTC_Sec,
		(int)current_time.RTC_Min,
		(int)refreshCount / 10
	);
	print_uart0(";00#");
}
Beispiel #5
0
void printTelemetrie(void)
{

	//return;

	RTCTime current_time;
	current_time = RTC_Get_Time();

	print_uart0("FCt0;");
	print_uart0("%d;%d;%d;",
		(int)current_time.RTC_Min,
		(int)current_time.RTC_Sec,
		(int)lastCycleCount / 10);


	print_uart0("%d;%d;%d;%d;%d;%d;%d;%d;",
		//( AD0DR0 >> 6 ) & 0x3FF,
		(int)((float)ADC_runtime[ADC_NICK]-ADC_drift[ADC_NICK]),
		(int)((float)ADC_runtime[ADC_ROLL]-ADC_drift[ADC_ROLL]),
		(int)((float)ADC_runtime[ADC_PITCH]+ADC_drift[ADC_PITCH]),
		//( AD0DR3 >> 6 ) & 0x3FF,
		(signed int)ADC_runtime[ADC_ACCX] - ADC_standStill[ADC_ACCX],
		(signed int)ADC_runtime[ADC_ACCY] - ADC_standStill[ADC_ACCY],
		(int)ADC_runtime[ADC_ACCZ],
		(int)ADC_runtime[AIRPRESSURE],
		(int)(ADC_runtime[UBAT]/ubatDivider));


	print_uart0("%d;%d;%d;%d;",
		(int)PWMEngOut[0],
		(int)PWMEngOut[1],
		(int)PWMEngOut[2],
		(int)PWMEngOut[3]);

	print_uart0("%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d",
		(signed int)MM3_runtime.heading,
		(signed int)MM3_runtime.X_axis,
		(signed int)MM3_runtime.Y_axis,
		(signed int)MM3_runtime.Z_axis,
		(int)NMEAGPGGA.lat*10000,
		(int)NMEAGPGGA.lon*10000,
		(int)PWM_channel[PWM_N],
		(int)PWM_channel[PWM_G],
		(int)PWM_channel[PWM_POTI1],
		(int)PWM_channel[PWM_POTI2],
		//(signed int)hmcXvalue,//(int)PWM_channel[PWM_POTI2]+120,
		(int)PWM_channel[PWM_POTI3]);
	print_uart0(";00#");

}
Beispiel #6
0
void printDebug(void)
{

	RTCTime current_time;
	current_time = RTC_Get_Time();

	print_uart0("FCd0;");
	print_uart0("%d;%d;%d;",
		current_time.RTC_Sec,
		current_time.RTC_Min,
		refreshCount
	);
	print_uart0(";00#");
}
Beispiel #7
0
/**
  * @brief  Display the current time on the Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeShow(void)
{
    /* Get the current Time and Date */
    RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);

    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_WHITE);

    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_BLUE);
    LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"Current Time Display");

    /* Display the curent time and the sub second on the LCD */
    RTC_Time_display(LCD_LINE_5, Black , RTC_Get_Time(uwSecondfraction , &RTC_TimeStructure));
}
Beispiel #8
0
void printDebug1(void)
{

	RTCTime current_time;
	current_time = RTC_Get_Time();

	print_uart0("FCd1;");
	print_uart0("%d;%d;%d;",
		(int)current_time.RTC_Sec,
		(int)current_time.RTC_Min,
		(int)refreshCount / 10
	);

	print_uart0("%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
		(int)PWMEngOut[0],
		(int)PWMEngOut[1],
		(int)PWMEngOut[2],
		(int)PWMEngOut[3],
		(int)(ADC_runtime[ADC_NICK]-ADC_drift[ADC_NICK]),
		(int)(ADC_runtime[ADC_ROLL]-ADC_drift[ADC_ROLL]),
		(int)(ADC_runtime[ADC_PITCH]+ADC_drift[ADC_PITCH]),
		(int)ADC_runtime[ADC_ACCX],
		(int)ADC_runtime[ADC_ACCY],
		(int)ADC_runtime[ADC_ACCZ]);


	print_uart0("%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
		(int)ADC_runtime[AIRPRESSURE],
		(int)MM3_runtime.X_axis,
		(int)MM3_runtime.Y_axis,
		(int)MM3_runtime.Z_axis,
		(signed int)PWM_channel[0],
		(signed int)PWM_channel[1],
		(signed int)PWM_channel[2],
		(signed int)PWM_channel[3],
		(signed int)PWM_channel[4],
		(signed int)PWM_channel[5]);

	print_uart0("%d;%d",
		(signed int)PWM_channel[6],
		(signed int)(ADC_raw[UBAT] / ubatDivider)
	);

	print_uart0(";00#");
}
Beispiel #9
0
/**
  * @brief  Display the current TimeStamp (time and date) on the Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeStampShow(void)
{
    /* Get the current TimeStamp */
    RTC_GetTimeStamp(RTC_Format_BCD, &RTC_TimeStampStructure, &RTC_TimeStampDateStructure);

    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_WHITE);

    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_BLUE);
    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t *)"TimeStamp Display");

    /* Display the curent time and the sub second on the LCD */
    LCD_DisplayStringLine(LCD_LINE_9, (uint8_t *) " Time");
    RTC_Time_display(LCD_LINE_9, Black , RTC_Get_Time(uwSecondfraction , &RTC_TimeStampStructure));

    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_BLUE);
    LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *) " Date");
    RTC_Time_display(LCD_LINE_10, Black,  RTC_Get_Date( &RTC_TimeStampDateStructure));
}
/**
  * @brief  Display the current TimeStamp (time and date) on the Hyperterminal.
  * @param  None
  * @retval None
  */
static void RTC_TimeStampShow(void)
{
  RTC_TimeTypeDef  RTC_TimeStampStructure;
  RTC_DateTypeDef  RTC_TimeStampDateStructure;
  /* Get the current TimeStamp */
  RTC_GetTimeStamp(RTC_Format_BCD, &RTC_TimeStampStructure, &RTC_TimeStampDateStructure);

  /* Set the Back Color */
  LCD_SetBackColor(LCD_COLOR_WHITE);
  
  /* Set the Text Color */
  LCD_SetTextColor(LCD_COLOR_BLUE);
  LCD_SetFont(&Font16x24);
  LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"TimeStamp Display");
  /* Display the curent time and the sub second on the LCD */
  LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *) "Time");
  RTC_Time_display(LCD_LINE_5, Black , RTC_Get_Time(Secondfraction , &RTC_TimeStampStructure));
  /* Set the Text Color */
  LCD_SetTextColor(LCD_COLOR_BLUE);
  LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *) "Date");
  RTC_Time_display(LCD_LINE_6, Black,  RTC_Get_Date( &RTC_TimeStampDateStructure));
}
Beispiel #11
0
Status_t Do_Time(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
  FuncIN(DO_TIME);
  
  char String[32] = {0};
  RtcTime_t Time;
  
  RTC_Get_Time(&Time);
  
  if(argc > 0)
  {
    if(strstr(argv[0], "-a") != NULL)
      ASSERT(SUCCESS == Format_Time(2, &Time, String), -RTC_GENERAL_ERROR);
    else
      EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME);
  }
  else
    ASSERT(SUCCESS == Format_Time(1, &Time, String), -RTC_GENERAL_ERROR);
  
  printcmd("\r # %s\n", String);
  
  EXIT_SUCCESS_FUNC(DO_TIME);
}
Beispiel #12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 

  RTC_TimeTypeDef  RTC_TimeStruct;
  
  /* Initialize the LCD */
  STM320518_LCD_Init();      
    
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 1 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Red);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Red);
  LCD_DrawFullRect(31, 292,264,34);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  LCD_DrawFullRect(33, 290 ,260,30);
  
  /* Configure the external interrupt "RIGHT" and "LEFT" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT,BUTTON_MODE_EXTI);
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();
  
  /* Configure the RTC tamper register : To Clear all the Backup data register */
  RTC_TamperConfig();
  
  /* Set the LCD Text, Back Colors and Text size */
  LCD_SetTextColor(Black); 
  LCD_SetBackColor(Cyan);
  LCD_SetFont(&Font12x12);
  
  LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);
  
  LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3);
  
  /* Set text size */
  LCD_SetFont(&Font16x24);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  
  /* Initialize time Stucture */
  RTC_TimeStructInit(&RTC_TimeStruct); 

  /* Infinite loop */
  while (1)
  {
    /* Set the LCD Back Color and text size */
    LCD_SetFont(&Font16x24);
    LCD_SetBackColor(White);
    
    /* Check on the event 'start' */
    if(StartEvent != 0x0)
    {  
      /* Get the RTC sub second fraction */
      SecondFraction = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
      
      /* Get the Curent time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
      
      /* Refresh : Display the curent time and the sub second on the LCD  */
      RTC_Time_Display(37, Black , RTC_Get_Time(SecondFraction , &RTC_TimeStruct));
    }
    else
    {
      /* Re-initialize the Display time on the LCD */
      RTC_Time_InitDisplay();
    }  
  }
}
Beispiel #13
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{
  if((EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET) && (ubStartevent !=0) && (uwBackupindex < 11))
  {
    uint16_t Colorx;
    uint8_t index = 0;
    
    if (uwBackupindex < 10)
    {
      /* Increment counter */
      ubRTCCount++;
      
      /* Set LCD background color*/
      if((uint8_t)(ubRTCCount % 2) != 0)
      { 
        LCD_SetBackColor(Blue2);
        Colorx = White;
      }
      else
      {
        LCD_SetBackColor(Cyan);
        Colorx = Black;
      }
      
      /* Get the Current sub seconds and time */
      ubSSecondfraction = 1000 - ((uint32_t)((uint32_t)RTC_GetSubSecond() * 1000) / (uint32_t)0x3FF);
      RTC_GetTime(RTC_Format_BCD, &RTC_StampTimeStruct);
      
      LCD_SetFont(&Font12x12);
      
      /* Display result on the LCD */
      RTC_Time_display(LINE(7 + uwBackupindex), Colorx, RTC_Get_Time(ubSSecondfraction , &RTC_StampTimeStruct)); 
      
      /* Save time register  to Backup register (the first 10 registers are reserved for time) */
      RTC_WriteBackupRegister(aBKPDataReg[uwBackupindex],(uint32_t)RTC->TR);
      
      /* Save sub second time stamp register (the latest 10 registers are reserved for sub second) */
      RTC_WriteBackupRegister(aBKPDataReg[uwBackupindex + 10], ubSSecondfraction);
    }
    else
    {      
      /* Set the LCD Background Color */
      LCD_SetBackColor(White);
      LCD_SetFont(&Font12x12);
      
      /* Clear all LCD lines from 7 to 19 */
      for (index = 0; index < 13; index++)
      {
        LCD_ClearLine(LINE(7 + index));
      }
      
      /* Reset Counters */
      ubRTCCount = 0;
      uwBackupindex = 0 ;
      
      /* Enter to idle */
      ubStartevent =0;
      
      /* Set the time to 00h 00mn 00s AM */
      RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
      RTC_TimeStructure.RTC_Hours   = 0;
      RTC_TimeStructure.RTC_Minutes = 0;
      RTC_TimeStructure.RTC_Seconds = 0;  
      RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
      
      /* Disable the RTC Clock */
      RCC_RTCCLKCmd(DISABLE);
      LCD_SetFont(&Font16x24);
      
      /* Set the LCD Text Color */
      LCD_SetTextColor(Blue);
      
      /* Display message to the LCD */
      LCD_DisplayStringLine(LINE(5), (uint8_t *)MESSAGE1);
      
      /* Clear EXTI line 21 */
      EXTI_ClearITPendingBit(EXTI_Line21);
      
      /* Clear Tamper pin interrupt pending bit */
      RTC_ClearITPendingBit(RTC_IT_TAMP1);
    }  
    
    uwBackupindex++;
  }
  /* Clear the TAMPER EXTI pending bit */
  EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE);     
}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 

  RTC_TimeTypeDef  RTC_TimeStruct;   
  RTC_TimeTypeDef  RTC_TimeStructureInit;
  RTC_TimeTypeDef  RTC_StampTimeStruct;
  
  /* Configure the external interrupt "RIGHT" and "LEFT" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT,BUTTON_MODE_EXTI);
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();
  
  /* LCD Display init  */
  Display_Init();
  
  /* Configure the RTC tamper register : To Clear all the Backup data register */
  RTC_TamperConfig();

  /* Initialize time Stucture */
  RTC_TimeStructInit(&RTC_TimeStruct); 

  /* Infinite loop */
  while (1)
  {
    /* Set the LCD Back Color and text size */
    LCD_SetFont(&Font16x24);
    LCD_SetBackColor(White);
    
    /* Check on the event 'start' */
    if(StartEvent != 0x0)
    {  
      /* Get the RTC sub second fraction */
      SecondFraction = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
      
      /* Get the Curent time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
      
      /* Refresh : Display the curent time and the sub second on the LCD  */
      RTC_Time_Display(37, Black , RTC_Get_Time(SecondFraction , &RTC_TimeStruct));
    }
    else
    {
      /* Re-initialize the Display time on the LCD */
      RTC_Time_InitDisplay();
    }  
    
    /* Left button is pressed */
      if (Button_State == LEFT_ON)
      {
        /* Enable Tamper interrupt */
      RTC_ITConfig(RTC_IT_TAMP, ENABLE);
      /* Enabale the tamper 1 */
      RTC_TamperCmd(RTC_Tamper_1 , ENABLE);
      
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);
      
      /* Clear the LCD line 5 */
      LCD_ClearLine(Line5);
      
      /* Get the current time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructureInit);
      CurrentTimeSec = (RTC_TimeStructureInit.RTC_Hours * 3600) + (RTC_TimeStructureInit.RTC_Minutes * 60) +
        RTC_TimeStructureInit.RTC_Seconds;     
      
      /* start count */
      StartEvent = 0x1;
      /* Reinitialize Button_State variable */
      Button_State = 0; 
      }
    /* Right button is pressed */
      else if (Button_State == RIGHT_ON)
      {
        uint16_t Colorx;
      
      if (BackupIndex < 5)
      {
        if((uint8_t)(BackupIndex% 2) != 0x0)
        { 
          /* Set LCD backcolor*/
          LCD_SetBackColor(Blue2);
          Colorx = White;
        }
        else
        {
          /* Set LCD backcolor*/
          LCD_SetBackColor(Cyan);
          Colorx = Black;
        }
        SubSecFrac = 0;
        /* Get the Current sub second and time */
        SubSecFrac = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
        
        RTC_GetTime(RTC_Format_BIN, &RTC_StampTimeStruct);
        
        LCD_SetFont(&Font16x24);
        /* Display result on the LCD */
        RTC_Time_Display( LINE(3 + BackupIndex), Colorx, RTC_Get_Time(SubSecFrac , &RTC_StampTimeStruct) ); 
        
        if (BackupIndex < 2)
        {
          /* Save time register  to Backup register ( the first 5 register is reserved for time) */
          RTC_WriteBackupRegister(BKPDataReg[BackupIndex],(uint32_t)RTC->TR);
        
          /* Save sub second time stamp register ( the latest 6 register is reserved for time) */
          RTC_WriteBackupRegister(BKPDataReg[BackupIndex + 2], SubSecFrac);
        }
        
      }
      else
      {
        /* the backup register is full with 10trials */
        /* Set the LCD Back Color */
        LCD_SetBackColor(White);
        LCD_SetFont(&Font12x12);
        /* Set the LCD Text Color */
        LCD_SetTextColor(Red); 
        LCD_DisplayStringLine(LINE(16), (uint8_t *)MESSAGE4);
        LCD_DisplayStringLine(LINE(17), (uint8_t *)MESSAGE5);
        
      }  
      BackupIndex++;
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);  
      /* Reinitialize Button_State variable */
      Button_State = 0; 
      }
   
   /* TAMPER button is pressed */
   else if (Button_RTC == RTC_TAMP)
   {
     /* Set the LCD Back Color */
    LCD_SetBackColor(White);
    LCD_SetFont(&Font16x24);
    /* Clear LCD line 5 to 9 */
    for (i=0; i < 5; i++)
    {  
      /* Clear all the LCD lignes from 3 to 7 */
      LCD_ClearLine(LINE(3+i));
    }
    
    /* reset Counter */
    BackupIndex = 0 ;
    
    /* Enetr to idle */
    StartEvent =0x0;
    
    LCD_SetFont(&Font12x12);
    RTC_Time_InitDisplay();
    
    LCD_SetFont(&Font12x12);
    LCD_ClearLine(LINE(16));
    LCD_ClearLine(LINE(17));
    
    /* Enable Tamper interrupt */
    RTC_ITConfig(RTC_IT_TAMP, DISABLE);
    /* Enabale the tamper 1 */
    RTC_TamperCmd(RTC_Tamper_1 , DISABLE);
    /* Reinitialize Button_RTC variable */
    Button_RTC = 0; 
   }
  }
}
Beispiel #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  
  
  /* Initialize the LCD */
  STM324xG_LCD_Init(); 
  
  /* Clear the LCD */ 
  LCD_Clear(White);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
   
  /* Displays MESSAGE1 on line 1 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);

  /* RTC configuration  */
  RTC_Config();
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Red);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  
  /* Draw rectangle on the LCD */
  LCD_DrawRect(43, 300, 30, 260);

  /* Configure the external interrupt "WAKEUP" and "KEY" buttons */
  STM_EVAL_PBInit(BUTTON_WAKEUP,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_EXTI);
  
  /* Configure the RTC tamper register */
  RTC_TamperConfig();
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  
  /* Displays MESSAGE2 on line 5 */
  LCD_DisplayStringLine(LINE(5), (uint8_t *)MESSAGE2);
  
  /* Infinite loop */
  while (1)
  {
    /* Set The LCD font size */
    LCD_SetFont(&Font16x24);
     
    /* Set the LCD Back Color */
    LCD_SetBackColor(White);

    /* Check on the event 'start'*/
    if(Startevent != 0x0)
    {
       /* Get the RTC sub second fraction */
       Secondfraction = 1000 - ((uint32_t)((uint32_t)RTC_GetSubSecond() * 1000) / (uint32_t)0x3FF);
    }
    else
    {
      /* Idle */
      Secondfraction =0x0;
    }
    
    /* Get the Curent time */
    RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
    
    /* Display the curent time and the sub second on the LCD */
    RTC_Time_display(Line2, Black , RTC_Get_Time(Secondfraction , &RTC_TimeStruct));
  }
}
Beispiel #16
0
Status_t Menu_Set_Time(struct Menu_State_s *Menu_State_p, const uint32 Key, void *Ptr)
{
    FuncIN(MENU_SET_TIME);

    Status_t Status = GENERAL_ERROR;
    RtcTime_t Time_s;
    static uint32 EnterFlag = 0;

    if(EnterFlag == 0)
    {
        RTC_Get_Time(&Time_s);

        Hour = Time_s.Hour;
        Minute = Time_s.Minute;
        Second = Time_s.Second;
    }

    clrd();
    printd(1, "Set Time");
    printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
    Menu_Time_Update_Disp_Ptr_Pos();

    printc("(%s): Enter! Key = 0x%08X\n", __func__, Key);

    switch(Key)
    {
    case ENTER_KEY_EVENT:
        // First enter in this state
        if(EnterFlag == 0)
        {
            EnterFlag = 1;
            break;
        }

        Time_s.Hour = Hour;
        Time_s.Minute = Minute;
        Time_s.Second = Second;

        Status = RTC_Set_Time(&Time_s);
        VERIFY(Status, Status);

        if(Status == SUCCESS)
            printd(2, "%02u:%02u:%02u Time Set!", Hour, Minute, Second);
        else
            printd(2, "%02u:%02u:%02u ERROR!!!", Hour, Minute, Second);

        break;
    case CANCEL_KEY_EVENT:
        clrd();

        Hour = 0;
        Minute = 0;
        Second = 0;

        PointerPosition = 1;

        EnterFlag = 0;

        EXIT_SUCCESS_FUNC(MENU_SET_TIME);
    case UP_KEY_EVENT:
        Menu_Time_Increment_Ptr_Pos_Number();
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case DOWN_KEY_EVENT:
        Menu_Time_Decrement_Ptr_Pos_Number();
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case LEFT_KEY_EVENT:
        if(PointerPosition > 1)
        {
            PointerPosition--;
            Menu_Time_Update_Disp_Ptr_Pos();
        }
        break;
    case RIGHT_KEY_EVENT:
        if(PointerPosition < 6)
        {
            PointerPosition++;
            Menu_Time_Update_Disp_Ptr_Pos();
        }
        break;
    case EXIT_KEY_EVENT:
        clrd();

        Hour = 0;
        Minute = 0;
        Second = 0;

        PointerPosition = 1;

        EnterFlag = 0;

        EXIT_SUCCESS_FUNC(MENU_SET_TIME);
    case MENU_KEY_EVENT:
        clrd();

        Hour = 0;
        Minute = 0;
        Second = 0;

        PointerPosition = 1;

        EnterFlag = 0;

        EXIT_SUCCESS_FUNC(MENU_SET_TIME);
    case NUM1_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(1);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM2_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(2);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM3_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(3);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM4_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(4);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM5_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(5);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM6_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(6);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM7_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(7);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM8_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(8);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM9_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(9);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    case NUM0_KEY_EVENT:
        Menu_Time_Set_Ptr_Pos_Number(0);
        printd(2, "%02u:%02u:%02u", Hour, Minute, Second);
        break;
    default:
        Fatal_Abort(-INVALID_INPUT_PARAMETER);
    } // switch(Key)

    syncd();

    EXIT_SUCCESS_FUNC(MENU_SET_TIME);
}
U16 cgi_func (U8 *env, U8 *buf, U16 buflen, U32 *pcgi) {
  U16 len = 0;
	static FINFO file_info;
	static int file_number;
	char file_size[16];
	char currentTimeDate[20];
	ADMIN *admin;
	USER *user;
	
  switch (env[0]) {
    // directory.cgi
    case 'A':
			// List of files
			switch (env[2]) {
				case 'A':
					if (PCGIBUF(pcgi)->number == 0) {
						// First Call, set initial value for 'ffind' function.
						file_info.fileID = 0;
						file_number = 0;
						
						if (finit(NULL) != 0) {
							// No card or failed to initialize.
							break;
						}
					}
					
					switch (PCGIBUF(pcgi)->row) {
						case 0:
							if (ffind("*.*", &file_info) == 0) {
								file_size_format(file_info.size, file_size);
								
								len += sprintf((char *)buf+len, "<tr align='center' bgcolor='#DCDCDC'><td>%d.</td>"
																								"<td align='left'><a href='%s'>%s</a></td>"
																								"<td>%s</td>",
															(file_number + 1), // Number
															file_info.name, file_info.name, // Name
															file_size); // File size

								file_number++;
								PCGIBUF(pcgi)->row++;
								PCGIBUF(pcgi)->number++;
								len |= 0x8000;
							}
							break;
						default:
							len += sprintf((char *)buf+len, "<form method='post'><td><input type='submit' value='Delete'><input type='hidden' name='file_delete' value='%s'/></td></form></tr>",
															file_info.name); // Name

							PCGIBUF(pcgi)->row = 0;
							PCGIBUF(pcgi)->number++;
							len |= 0x8000;
							break;
					}
					break;
			}
      break;
		// index.cgi
		case 'B':
			switch (env[2]) {
				case 'A':
					if (PCGIBUF(pcgi)->number == 0) {
						// First Call, set initial value for 'ffind' function.
						file_info.fileID = 0;
						file_number = 0;
						
						if (finit(NULL) != 0) {
							// No card or failed to initialize.
							break;
						}
					}
					
					switch (PCGIBUF(pcgi)->row) {
						case 0:
							if (ffind("*.ani", &file_info) == 0) {
								file_size_format(file_info.size, file_size);
								
								len += sprintf((char *)buf+len, "<tr align='center'><td class=\"table_data_row\">%d.</td>"
																								"<td align='left' class=\"table_data_row\"><a href='%s'>%s</a></td>"
																								"<td class=\"table_data_row\">%s</td>"
																								"<td class=\"table_data_row\">%d</td>",
															(file_number + 1), // Number
															file_info.name, file_info.name, // Name
															file_size,	// File size
															(file_info.size / sizeof(LED_CUBE_Effect))); // Count

								file_number++;
								PCGIBUF(pcgi)->row++;
								PCGIBUF(pcgi)->number++;
								len |= 0x8000;
							}
							break;
						default:
							len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Delete'><input type='hidden' name='ani_file_delete' value='%s'/></td></form>", file_info.name);
						
							if (ANIMATION_PLAY && strcmp(AnimationFileName, (const char *)file_info.name) == 0) {
								len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Stop'><input type='hidden' name='animation_stop' value='yes'/></td></form></tr>");
							} else {
								len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Start'><input type='hidden' name='animation_start' value='%s'/></td></form></tr>", file_info.name);
							}
							
							PCGIBUF(pcgi)->row = 0;
							PCGIBUF(pcgi)->number++;
							len |= 0x8000;
							break;
					}
					break;
			}
			break;
		// time.cgi
		case 'C':
			switch (env[2]) {
				case 'A':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									strftime(currentTimeDate, sizeof(currentTimeDate), SETTINGS_DATA[TIME_FORMAT], RTC_Get_TimeInfo(RTC_Get_Time()));
									len += sprintf((char *)buf+len, (const char *)&env[8], currentTimeDate);
									break;
								case '1':
									strftime(currentTimeDate, sizeof(currentTimeDate), SETTINGS_DATA[DATE_FORMAT], RTC_Get_TimeInfo(RTC_Get_Time()));
									len += sprintf((char *)buf+len, (const char *)&env[8], currentTimeDate);
									break;
							}
							break;
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									len += sprintf((char *)buf+len, (const char *)&env[8], SETTINGS_DATA[TIME_FORMAT]);
									break;
								case '1':
									len += sprintf((char *)buf+len, (const char *)&env[8], SETTINGS_DATA[DATE_FORMAT]);
									break;
							}
							break;
						case '1': // Time zone offset
							switch (env[6]) {
								case '0':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -12) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -11) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -10) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -9) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -8) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '5': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -7) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '6': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -6) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '7': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -5) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '8': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -4) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '9': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -3) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
								case '1':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -2) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -1) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 0) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 1) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 2) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '5': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 3) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '6': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 4) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '7': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 5) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '8': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 6) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '9': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 7) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
								case '2':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 8) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 9) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 10) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 11) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 12) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
							}
							break;
					}
					break;
				case 'C':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[0]);
									break;
								case '1':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[1]);
									break;
								case '2':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[2]);
									break;
								case '3':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[3]);
									break;
								case '4':
									if(SNTP_Server_IP_1_WORKS) {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_green.png\" class=\"sntp_status_led\"/>");
									} else {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_red.png\" class=\"sntp_status_led\"/>");
									}
									break;
								case '5':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[0]);
									break;
								case '6':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[1]);
									break;
								case '7':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[2]);
									break;
								case '8':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[3]);
									break;
								case '9':
									if(SNTP_Server_IP_2_WORKS) {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_green.png\" class=\"sntp_status_led\"/>");
									} else {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_red.png\" class=\"sntp_status_led\"/>");
									}
									break;
							}
							break;
					}
					break;
			}
			break;
		// admins.cgi
		case 'D':
			switch (env[2]) {
				case 'A':
					// Repeat for all admins
					if(PCGIBUF(pcgi)->number < ADMINS_Count() && ADMINS_Count() > 0) {
						//admin = malloc(sizeof(ADMIN));
						admin = &Admins[PCGIBUF(pcgi)->number];

						switch (PCGIBUF(pcgi)->row) {
							case 0:
								len += sprintf((char *)buf+len, "<table class='table_data' style=\"cursor: pointer;\">"
																								"<tr align='left'><td class='table_data_header' onclick=\"toggleTable('table_admin_%d')\">ADMIN %d - %s</td></tr>"
																								"</table>", PCGIBUF(pcgi)->number,
																				(PCGIBUF(pcgi)->number+1), admin->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 1:
								len += sprintf((char *)buf+len, "<table class='table_data' id='table_admin_%d' style=\"display: none;\"><tr align='left'><form method='post'><td class='table_data_row' width='40%%'>Username *</td><td class='table_data_row'><input type='text' name='username' maxlength='%d' value='%s'/></td></tr>",
																PCGIBUF(pcgi)->number, ADMIN_USERNAME_MAX_LENGTH, admin->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 2:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Password *</td><td class='table_data_row'><input type='text' name='password' maxlength='%d' value='%s'/></td></tr>",
																ADMIN_PASSWORD_MAX_LENGTH, admin->Password);
								PCGIBUF(pcgi)->row++;
								break;
							case 3:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>E-mail *</td><td class='table_data_row'><input type='text' name='email' maxlength='%d' value='%s'/></td></tr>",
																ADMIN_EMAIL_MAX_LENGTH, admin->Email);
								PCGIBUF(pcgi)->row++;
								break;
							case 4: // save button
								len += sprintf((char *)buf+len, "<tr>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='save_admin' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 5:
								len += sprintf((char *)buf+len, "<input type='button' value='Save' onclick=\"confirmForm(this.form, 'Are you sure you want to save admin?')\"/>"
																								"</td></form></tr>");
								
								if(ADMINS_Count() > 1) {	
									PCGIBUF(pcgi)->row++;
								} else {
									PCGIBUF(pcgi)->row += 3;
								}
								break;
							case 6: // delete button
								len += sprintf((char *)buf+len, "<tr>"
																								"<form method='post'>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='delete_admin' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 7:
								len += sprintf((char *)buf+len, "<input type='button' value='Delete' onclick=\"confirmForm(this.form, 'Are you sure you want to delete admin?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							default:
								len += sprintf((char *)buf+len, "</table><br>");
								PCGIBUF(pcgi)->row = 0;
								PCGIBUF(pcgi)->number++;
								break;
						}

						len |= 0x8000;
						
						//free(admin);
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_USERNAME_MAX_LENGTH);
							break;
						case '1':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_PASSWORD_MAX_LENGTH);
							break;
						case '2':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_EMAIL_MAX_LENGTH);
							break;
					}
					break;
			}
			break;
		// users.cgi
		case 'E':
			switch (env[2]) {
				// Users list
				case 'A':				
					// Repeat for all users
					if (PCGIBUF(pcgi)->number < USERS_Count() && USERS_Count() > 0) {
						user = &Users[PCGIBUF(pcgi)->number];

						switch (PCGIBUF(pcgi)->row) {
							case 0:
								len += sprintf((char *)buf+len, "<table class='table_data' style=\"cursor: pointer;\">"
																								"<tr align='left'><td class='table_data_header' onclick=\"toggleTable('table_user_%d')\">USER %d - %s</td></tr>"
																								"</table>", PCGIBUF(pcgi)->number, (PCGIBUF(pcgi)->number+1), user->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 1:
								len += sprintf((char *)buf+len, "<table class='table_data' id='table_user_%d' style=\"display: none;\"><tr align='left'><form method='post'><td class='table_data_row' width='40%%'>Username *</td><td class='table_data_row'><input type='text' name='username' maxlength='%d' value='%s'/></td></tr>",
																PCGIBUF(pcgi)->number, USER_USERNAME_MAX_LENGTH, user->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 2:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Password *</td><td class='table_data_row'><input type='text' name='password' maxlength='%d' value='%s'/></td></tr>",
																USER_PASSWORD_MAX_LENGTH, user->Password);
								PCGIBUF(pcgi)->row++;
								break;
							case 3:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>First name *</td><td class='table_data_row'><input type='text' name='first_name' maxlength='%d' value='%s'/></th></tr>",
																sizeof(user->First_Name), user->First_Name);
								PCGIBUF(pcgi)->row++;
								break;
							case 4:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Last name *</td><td class='table_data_row'><input type='text' name='last_name' maxlength='%d' value='%s'/></td></tr>",
																sizeof(user->Last_Name), user->Last_Name);
								PCGIBUF(pcgi)->row++;
								break;
							case 5:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>E-mail *</td><td class='table_data_row'><input type='text' name='email' maxlength='%d' value='%s'/></td></tr>",
																sizeof(user->Email), user->Email);
								PCGIBUF(pcgi)->row++;
								break;
							case 6: // save button
								len += sprintf((char *)buf+len, "<tr>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='save_user' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 7:
								len += sprintf((char *)buf+len, "<input type='button' value='Save' onclick=\"confirmForm(this.form, 'Are you sure you want to save user?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							case 8: // delete button
								len += sprintf((char *)buf+len, "<tr>"
																								"<form method='post'>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='delete_user' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 9:
								len += sprintf((char *)buf+len, "<input type='button' value='Delete' onclick=\"confirmForm(this.form, 'Are you sure you want to delete user?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							default:
								len += sprintf((char *)buf+len, "</table><br>");
								PCGIBUF(pcgi)->row = 0;
								PCGIBUF(pcgi)->number++;
								break;
						}

						len |= 0x8000;
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_USERNAME_MAX_LENGTH);
							break;
						case '1':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_PASSWORD_MAX_LENGTH);
							break;
						case '2':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_FIRST_NAME_MAX_LENGTH);
							break;
						case '3':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_LAST_NAME_MAX_LENGTH);
							break;
						case '4':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_EMAIL_MAX_LENGTH);
							break;
					}
					break;
			}
			break;
		// Network Settings
		case 'F':
			switch (env[2]) {
				case '0':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.IpAdr[0],
                        LocM.IpAdr[1],LocM.IpAdr[2],LocM.IpAdr[3]);
					break;
				case '1':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.NetMask[0],
                        LocM.NetMask[1],LocM.NetMask[2],LocM.NetMask[3]);
					break;
				case '2':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.DefGW[0],
                        LocM.DefGW[1],LocM.DefGW[2],LocM.DefGW[3]);
					break;
				case '3':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.PriDNS[0],
                        LocM.PriDNS[1],LocM.PriDNS[2],LocM.PriDNS[3]);
					break;
				case '4':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.SecDNS[0],
                        LocM.SecDNS[1],LocM.SecDNS[2],LocM.SecDNS[3]);
					break;
			}
			break;
		// Footer
		case 'Z':
			if (http_get_user_id() == 0) { // Manufacturer
				len += sprintf((char *)buf+len, "<a href='index.cgi'>Home</a> &#149; "
																				"<a href='admins.cgi'>Admins Settings</a> &#149; "
																				"<a href='users.cgi'>Users Settings</a> &#149; "
																				"<a href='time.cgi'>Time Settings</a>  &#149; "
																				"<a href='network.cgi'>Network Settings</a>  &#149; "
																				"<a href='directory.cgi'>Directory</a><br>");
			} else if (http_get_user_id() > 0 && http_get_user_id() <= ADMINS_Count()) { // Admin
				len += sprintf((char *)buf+len, "<a href='index.cgi'>Home</a> &#149; "
																				"<a href='users.cgi'>Users Settings</a> &#149; "
																				"<a href='time.cgi'>Time Settings</a>  &#149; "
																				"<a href='network.cgi'>Network Settings</a><br>");
			}
			break;
  }

  return (len);
}