//
// Created by dell on 25-1-7.
//

#include "gd60914.h"

void gd60914_get_object_tempture(void) {
    #ifdef SOFTWARE_IIC
    soft_i2c_config();
    #else
    i2c_config();
    #endif

    static uint8_t sensor_validation_data[2];
    extern uint8_t g_temperature_uint8[2];

#ifdef SOFTWARE_IIC
    soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
#else
    i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, sensor_validation_data);
#endif

    if (sensor_validation_data[0] != 0xAA || sensor_validation_data[1] != 0x55) {
#ifdef DEBUG_VERBOES
        printf("sensor error\r\n");
#endif
        return;
    }

    delay_ms(350);

#ifdef SOFTWARE_IIC
    soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
#else
    i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
#endif

    // printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]);
}

void gd60914_read_temp(void) {

    uint8_t value[2] = {0};
    #ifdef SOFTWARE_IIC
    soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, value);
    #else
    i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, value);
    #endif

    printf("%x %x\r\n", value[1], value[0]);
}