/*
 * Copyright 2022 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "board_init.h"
#include "driver_mpu6050_basic.h"

/*
 * Macros.
 */

#define APP_MPU6050_WAIT_TIME 1000u

/*
 * Variables.
 */

float app_mpu6050_g[3u];    /* save mpu6050 acceleration data. */
float app_mpu6050_dps[3u];  /* save mpu6050 angular gyro data. */
float app_mpu6050_d;        /* save mpu6050 temperature data. */

/*
 * Declerations.
 */

/*
 * Functions.
 */
int main(void)
{
    BOARD_Init();

    printf("libdriver_mpu6050_basic demo.\r\n");

    /* init */
    while(mpu6050_basic_init(BOARD_MPU6050_ADDR) != 0u)
    {
        mpu6050_interface_debug_print("mpu6050: mpu6050 init faild.\r\n");
        mpu6050_interface_delay_ms(APP_MPU6050_WAIT_TIME);
    }

    while(1)
    {
        /* read. */
        mpu6050_basic_read(app_mpu6050_g, app_mpu6050_dps);
        mpu6050_basic_read_temperature(&app_mpu6050_d);

        /* output. */
        mpu6050_interface_debug_print("mpu6050: acc x is %0.2fg.\r\n", (double)app_mpu6050_g[0]);
        mpu6050_interface_debug_print("mpu6050: acc y is %0.2fg.\r\n", (double)app_mpu6050_g[1]);
        mpu6050_interface_debug_print("mpu6050: acc z is %0.2fg.\r\n", (double)app_mpu6050_g[2]);
        mpu6050_interface_debug_print("mpu6050: gyro x is %0.2fdps.\r\n", (double)app_mpu6050_dps[0]);
        mpu6050_interface_debug_print("mpu6050: gyro y is %0.2fdps.\r\n", (double)app_mpu6050_dps[1]);
        mpu6050_interface_debug_print("mpu6050: gyro z is %0.2fdps.\r\n", (double)app_mpu6050_dps[2]);
        mpu6050_interface_debug_print("mpu6050: temperature %0.2fC.\r\n", (double)app_mpu6050_d);

        /* delay. */
        mpu6050_interface_delay_ms(APP_MPU6050_WAIT_TIME);

    }

}

/* EOF. */
