#include "main.h"
#include "cmsis_os.h"
#include "adc.h"
#include "dma.h"
#include "usart.h"
#include "gpio.h"
#include "adc.h"
#include "dma.h"
#include "oled.h"
#include <stdint.h>
#include <stdio.h>  
#include "callback.h"  
#include "variables.h"
#include "led.h"
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if(huart->Instance==USART1)
	{
	
		//osDelay(1000);
	}
	
	
	
	if(huart->Instance==USART3)
	{
		led(7, 1);
		
		int i=0;
		while (i<9)
		{
			if (O2_sensor_receive[i]==0xFF)
			{
				
				int j=0,k=0,l=0;
				j=i+1;
				k=i+2;
				l=i+3;
					if(j>=9)
					{
						j=j-9;
					}
					if(k>=9)
					{
						k=k-9;
					}
					if(l>=9)
					{
						l=l-9;
					}
					if (O2_sensor_receive[j]==0x86)
					{		
						O2_H=O2_sensor_receive[k];
						O2_L=O2_sensor_receive[l];
					}
					break;
			}
		i=i+1;
		}
		//HAL_UART_Receive_DMA(&huart3, &O2_sensor_receive[0],9);
	/*int i=0;
	while (i<9)
	{
		
		if (O2_sensor_receive[i]!=0xFF)
		{
			i=i+1;
			continue;
		}
		if (O2_sensor_receive[i+1]!=0x86)
		{
			i=i+1;
			continue;
		}
		
	
    break;
	}

	if(i<9)
	{
	O2_H=O2_sensor_receive[i+2];
	O2_L=O2_sensor_receive[i+3];
	}
	*/	
		
		
	}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
		if(huart->ErrorCode & HAL_UART_ERROR_ORE)
		{
			//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
		}
}

