#include "main_thread0.h"
#include "debug_uart/bsp_debug_uart.h"
#include "led/bsp_led.h"
#include "gpt/bsp_gpt_pwm_output.h"
#include "hs3003/bsp_hw_i2c.h"
#include "hs3003/bsl_hs3003.h"
#include "bsp_esp8266/bsp_wifi_esp8266.h"
#include "VL53L0X/bsl_vl53l0x.h"

/* Main Thread entry function */
/* pvParameters contains TaskHandle_t */
void main_thread0_entry(void *pvParameters)
{
    char tcpSendData[100] = {0};
    s_Hs300xDataType humi_temp;
    uint16_t higValue = 0;
    uint16_t catValue = 0;
    FSP_PARAMETER_NOT_USED (pvParameters);
    vTaskDelay(10000);

    /* TODO: add your own code here */
    while (1)
    {
        LED1_ON;
        vTaskDelay(1000);
        LED1_OFF;
        R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_SECONDS);

        humi_temp = Hs300x_ReadData();
        printf("MLJ+TH=%03ld,%03ld\r\n", (uint32_t)humi_temp.temp, (uint32_t)humi_temp.humi);
        sprintf(tcpSendData, "MLJ+TH=%03ld,%03ld\r\n\0", (uint32_t)humi_temp.temp, (uint32_t)humi_temp.humi);
        ESP8266_AT_Send(tcpSendData);   //发送温湿度
        vTaskDelay(1000);
        higValue = bsl_vl53l0x_hig_single();
        printf("MLJ+FEED=%04d\r\n", higValue);
        sprintf(tcpSendData, "MLJ+FEED=%04d\r\n\0", higValue);
        ESP8266_AT_Send(tcpSendData);   //发送温湿度
        vTaskDelay(1000);
        catValue = bsl_vl53l0x_cat_single();
        printf("MLJ+CAT=%04d\r\n", catValue);
        sprintf(tcpSendData, "MLJ+CAT=%04d\r\n\0", catValue);
        ESP8266_AT_Send(tcpSendData);   //发送温湿度
    }
}
