/* USER CODE BEGIN Header */
/****************************************************************************************
	* @author  尚知物理
	* @哔哩哔哩链接：https://shop598739109.taobao.com
	* @file           : Function.c
  * @brief          : Function 功能函数集合
  * @version V1.0
  * @date    06-26-2023
  * @LegalDeclaration ：本文档内容难免存在Bug，仅限于交流学习，禁止用于任何的商业用途
	* @Copyright   著作权尚知物理所有
  * @attention
  ******************************************************************************
  */
/* USER CODE END Header */

#include "stdio.h"
#include "function.h"//功能函数头文件
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"


uint16_t ADC_Value = 0;
float Ubat = 0;



void ADC_Get_Value()               //定义一个采样电压并计算，发送的函数
{
	HAL_ADC_Start(&hadc);                //开启ADC

	if (HAL_ADC_PollForConversion(&hadc,10) == HAL_OK)
	{
		ADC_Value = HAL_ADC_GetValue(&hadc);        //获得采样值
		Ubat = ADC_Value *1.8384 * 3.3/4096;	              //获得电压值
	}

	HAL_ADC_Stop(&hadc);			 //关闭ADC
}



void OLED_Init()
{
	LCD_Init();//LCD初始化
	LCD_Fill(0,0,LCD_W,LCD_H,BLACK);
	
	
//	LCD_DrawLine(35,35,204,204,WHITE);
//	LCD_DrawRectangle(35,35,204,204,WHITE);
	Draw_Circle(120,120,119,RED);
	Draw_Circle(120,120,118,RED);
	Draw_Circle(120,120,117,RED);
	Draw_Circle(120,120,116,RED);
	Draw_Circle(120,120,115,BLUE);
	Draw_Circle(120,120,114,BLUE);
	Draw_Circle(120,120,113,BLUE);
	Draw_Circle(120,120,112,BLUE);

//	LCD_ShowChinese(120,120,"中景园电子",RED,WHITE,32,0);
//	LCD_ShowString(32,80,"www.yyscience.cn",RED,WHITE,16,0);
//	LCD_ShowPicture(40,120,40,40,gImage_1);

}

void OLED_Show()
{
		LCD_ShowFloatNum1(100,20,Ubat,4,WHITE,BLACK,16);
		
		LCD_ShowIntNum(53,100,time.shi,2,WHITE,BLACK,32);
		LCD_ShowString(87,100,":",WHITE,BLACK,32,0);
		LCD_ShowIntNum(103,100,time.fen,2,WHITE,BLACK,32);
		LCD_ShowString(137,100,":",WHITE,BLACK,32,0);
		LCD_ShowIntNum(153,100,time.miao,2,WHITE,BLACK,32);
		
//		LCD_ShowIntNum(53,100,55,2,WHITE,BLACK,32);
//		LCD_ShowString(87,100,":",WHITE,BLACK,32,0);
//		LCD_ShowIntNum(103,100,55,2,WHITE,BLACK,32);
//		LCD_ShowString(137,100,":",WHITE,BLACK,32,0);
//		LCD_ShowIntNum(153,100,55,2,WHITE,BLACK,32);
}


Timer time;
void Timer_Init()
{
	time.shi  = 21;
	time.fen  = 52;
	time.miao = 0;
}

void Time()
{
	time.miao ++;
	if(time.miao >= 60)
	{
		time.miao = 0;
		time.fen ++;
		if(time.fen >= 60)
		{
			time.fen = 0;
			time.shi ++;
			if(time.shi >= 24)
			{
				time.shi = 0;
			}
		}
	}	
	
}


