#include"includes.h"
#include"gui.h"
#include"ILI93XX.h"
#include "adxl345.h"
#include "delay.h"

static OS_STK LcdTaskStk[LCD_TASK_STK_SIZE];



void taskLED(void *p_arg)
{
   (void)p_arg;
   
 //  OSTaskCreate(taskLcd,(void *)0,
   //             &LcdTaskStk[LCD_TASK_STK_SIZE - 1],LCD_TASK_PRIO);

   OSTaskCreate(taskAdxl345,(void *)0,
                &LcdTaskStk[ADXL345_TASK_STK_SIZE - 1],ADXL345_TASK_PRIO);
    LED_GPIO_Config();
    while(1)
    {
      LED1(ON);
      OSTimeDlyHMSM(0,0,0,500);
      LED1(OFF);    
      
      LED2(ON);
      OSTimeDlyHMSM(0,0,0,500);
      LED2(OFF);    
 

    }   
}

void taskLcd(void *p_arg)
{
   (void)p_arg;
   


    while(1)
    {
      LED1(ON);
      OSTimeDlyHMSM(0,0,0,500);
      LED1(OFF);    
      
      LED2(ON);
      OSTimeDlyHMSM(0,0,0,500);
      LED2(OFF);    
 

    }   
}

void taskAdxl345(void *p_arg)
{
   u8 static AdjustFlag=100; 
    //short angx,angy,angz; 
    short x,y,z; 
   (void)p_arg;
    LCDx_Init();
    GUI_Init();
    //GUI_DispString("Hello STemWin!");
    //GUI_DrawLine(50,50,200,200);  //画直线
   while(ADXL345_Init())   //3D加速度传感器初始化  
   {
     GUI_DispStringAt("ADXL345 ERROR",110,0);
       OSTimeDlyHMSM(0,0,0,100);
   }
    
   GUI_DispStringAt("ADXL345 OK   ",110,0);
   GUI_DispStringAt("X VAL:",110,10);
   GUI_DispStringAt("Y VAL:",110,20);
   GUI_DispStringAt("Z VAL:",110,30);

    while(1)
    {               
            //得到X,Y,Z轴的加速度值(原始值)
      ADXL345_Read_Average(&x,&y,&z,10);    //读取X,Y,Z三个方向的加速度值 
      Adxl_Show_Num(150,10,x,0);        //显示加速度原始值      
      Adxl_Show_Num(150,20,y,0);
      Adxl_Show_Num(150,30,z,0);
      if(!AdjustFlag)
       {
           ADXL345_AUTO_Adjust((char*)&x,(char*)&y,(char*)&z);//自动校准
		   AdjustFlag = 100;

       }
	  AdjustFlag--;
      OSTimeDlyHMSM(0,0,0,2);
    }   
}

