/*
 * Main_APP.c
 *
 *  Created on: Aug 6, 2021
 *      Author: wuwenfeng
 */
#include "Main_APP.h"
#include "LCD.h"
#include "windows.h"
#include "touch.h"
#include "eeprom.h"
#include "key.h"
#include "buzzer.h"

#include "APP_colorcontrol.h"
#include "APP_keyboard.h"

extern TIM_HandleTypeDef htim4;
extern touch_device t0;

task run_loop;//主循环状态机




void main_app()
{

	HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_3);//启动n通道的pwm

	char str[64];
	LCDx_Init();
	EPPROM_SLOWWRITE_INIT();

	if(KEY1==0&&KEY3==0)
	{
		TP_adjustment(1);
	}else
	{
		TP_adjustment(0);
	}



	UI *ui=UI_Init(BLACK);

	//APP_blood_init(New_Window(ui,10,10,128,128,WHITE,"MAX30102"));

	//APP_IDcard_init(New_Window(ui,25,30,150,100,GREEN,"IDcard"));
	//New_Window(ui,80,80,60,90,YELLOW,"YELLOW");
	//New_Window(ui,120,90,70,60,MAGENTA,"MAGENTA");

	//APP_morsecode_init(New_Window(ui,25,30,200,150,CYAN,"Morse code"));

	APP_COLORCONTROL_init(New_Window(ui,20,30,300,64,CYAN,"COLORCONTROL"));
	APP_KEYBOARD_init(New_Window(ui,10,60,200,100,WHITE,"KEYBOARD"));
	ui->refresh_ui_flag=1;

	//add_a_note(1000,50,1000);
	//add_a_note(0,50,0);
	while(1)
	{
		//LCD_set_dot(t0.pix_x, t0.pix_y, RED);
		//sprintf(str,"%04d\n%04d\n%04d",t0.pix_x,t0.pix_y,t0.c);
		//LCD_ShowString(0, 0, &str, 16, RED, BLUE);
		/*
		switch(run_loop.sw)
		{


		}

*/

// 交叉编译测试
		//APP_blood_loop();
		//APP_IDcard_loop();
		//APP_morsecode_loop();
		APP_KEYBOARD_loop();
		GEI_BUTTON_CODE(&k1,KEY1);
		GEI_BUTTON_CODE(&k2,KEY2);
		GEI_BUTTON_CODE(&k3,KEY3);
		UI_Server(ui);
		TP_Server();
		EEPROM_SLOWWRITE_SERVER();
		buzzer_play_server();
	}

}

