/**
 *  @file ins_ut_motor.c
 *  @details config unit test
 *
 */
 
#include <stdlib.h>
#include "unittest.h"
#include "unittest/device/ins_ut_motor.h"
#include "ins_mw_config.h"
#include "ins_pal_error_code.h"
#include "ins_comm_log.h"
#include "AmbaUtility.h"

#include "ins_dev_motor.h"

static int32_t InsUT_Device_MotorOpen(int32_t argc, char **argv)
{
	InsDev_Motor_t * motor_dev = InsDev_Motor_Init(0);
    int32_t part = 0;

#if 0
	if(argc > 0)
	{
		INSLOG_E("argc = %d\n", argc);
	    for(int i = 0; i < argc; i++)
	    {
	        INSLOG_E("argv[%d] = %s\n", i, argv[i]);
	    }
	}
#endif
	
    if(argc < 1)
    {
        INSLOG_W("Input para not enough!\n open 0 -> open motor function\n");
        return INSERR_NG;
    }
    part = atoi(argv[0]);

    return (int32_t)motor_dev->open((InsDev_Motor_HOOK_ID_e)part);
}

static int32_t InsUT_Device_MotorDbg(int32_t argc, char **argv)
{
	InsDev_Motor_t * motor_dev = InsDev_Motor_Init(0);

	#if 0
	if(argc > 0)
	{
		INSLOG_E("argc = %d\n", argc);
	    for(int i = 0; i < argc; i++)
	    {
	        INSLOG_E("argv[%d] = %s\n", i, argv[i]);
	    }
	}
	
    if(argc < 1)
    {
        INSLOG_W("Input para not enough!\n open 0\n");
        return INSERR_NG;
    }
	
	if (AmbaUtility_StringCompare(argv[0], "short_vib", 3U) == 0)
    {
        motor_dev->g_func->short_vib_work(AW_INDEX1, AW_GAIN_LEVEL_1, AW_LOOP1);
		//AmbaKAL_TaskSleep(2000);
		INSLOG_W("short_vib!");
    }
//	else if (AmbaUtility_StringCompare(argv[0], "ram_show", 3U) == 0)
//    {
//        motor_dev->g_func->ram_show();
//		//AmbaKAL_TaskSleep(2000);
//		INSLOG_W("ram_show!");
//    }
	else if (AmbaUtility_StringCompare(argv[0], "long_vib", 3U) == 0)
    {
        motor_dev->g_func->long_vib_work(AW_INDEX4, AW_MS_UINT*1000); // haptic_hv_long_vib_work
		//AmbaKAL_TaskSleep(AW_MS_UINT*1000);
		INSLOG_W("long_vib!");
    }
	else if (AmbaUtility_StringCompare(argv[0], "play_stop", 3U) == 0)
    {
        motor_dev->g_func->play_stop();
		INSLOG_W("play_stop!");
    }
//	else if (AmbaUtility_StringCompare(argv[0], "rtp_vib", 3U) == 0)
//    {
//        motor_dev->g_func->rtp_vib_work();
//		//AmbaKAL_TaskSleep(2000);
//		INSLOG_W("rtp_vib_work!");
//    }
	else if (AmbaUtility_StringCompare(argv[0], "f0_show", 3U) == 0)
    {
        motor_dev->g_func->f0_show();
		//AmbaKAL_TaskSleep(2000);
		INSLOG_W("f0_show!");
    }
	else if (AmbaUtility_StringCompare(argv[0], "cali_show", 3U) == 0)
    {
        motor_dev->g_func->cali_show();
		//AmbaKAL_TaskSleep(2000);
		INSLOG_W("cali_show!");
    }
//	else if (AmbaUtility_StringCompare(argv[0], "trig_mode_cfg", 3U) == 0)
//    {
//        motor_dev->g_func->trig_mode_cfg();
//		//AmbaKAL_TaskSleep(2000);
//		INSLOG_W("trig_mode_cfg!");
//    }
	else
	{
		INSLOG_W("dbg short_vib --> short vib!");
		INSLOG_W("dbg long_vib --> long vib!");
	}
	#else
	argc = argc;
	argv = argv;
	
    motor_dev->g_func->short_vib_work(AW_INDEX1, AW_GAIN_LEVEL_1, AW_LOOP1);
	AmbaKAL_TaskSleep(2000);
    motor_dev->g_func->ram_show();
	AmbaKAL_TaskSleep(2000);
	motor_dev->g_func->long_vib_work(AW_INDEX4, AW_MS_UINT*1000); // haptic_hv_long_vib_work
	AmbaKAL_TaskSleep(AW_MS_UINT*1000);
	motor_dev->g_func->play_stop();

	motor_dev->g_func->rtp_vib_work();
	AmbaKAL_TaskSleep(2000);
	motor_dev->g_func->f0_show();
	AmbaKAL_TaskSleep(2000);
	motor_dev->g_func->cali_show();
	AmbaKAL_TaskSleep(2000);
	motor_dev->g_func->trig_mode_cfg();
	AmbaKAL_TaskSleep(2000);
	#endif
	
    return (int32_t)INSERR_OK;
}

InsUT_Unittest_CmdInfo_t g_ut_cmd_motor[INSUT_CMDCNT_MOTOR] = 
{
    {InsUT_Device_MotorOpen,    0, NULL, "open",       "motor open"},
    {InsUT_Device_MotorDbg,    0, NULL, "dbg",       "motor dbg"},
};

