#include "ut_pot.h" #include "..\..\src\logic\pot.h" static int ut_pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg, uint8_t exp_out) { uint8_t out = pot_mv_to_percent(value, cfg); printf("Value:%d Reference:%d Deadband:%d \n", value, cfg->reference, cfg->deadband); printf("Output:%d Expected:%d\n", out, exp_out); if(out==exp_out) { printf("PASS\n\n"); return 1; } else { printf("FAIL\n\n"); return 0; } } int ut_pot_mv_to_percent_test(void) { printf("******************************************************\n"); printf("uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg)\n"); int test_res; int pass = 1; uint16_t value; pot_cfg_t cfg; uint8_t exp_out; value = 0; cfg.deadband = 500; cfg.reference = 5000; exp_out = 0; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 499; cfg.deadband = 500; cfg.reference = 5000; exp_out = 0; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 500; cfg.deadband = 500; cfg.reference = 5000; exp_out = 0; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 1500; cfg.deadband = 500; cfg.reference = 5000; exp_out = 25; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 2500; cfg.deadband = 500; cfg.reference = 5000; exp_out = 50; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 3500; cfg.deadband = 500; cfg.reference = 5000; exp_out = 75; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 4500; cfg.deadband = 500; cfg.reference = 5000; exp_out = 100; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 4501; cfg.deadband = 500; cfg.reference = 5000; exp_out = 100; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; value = 5000; cfg.deadband = 500; cfg.reference = 5000; exp_out = 100; test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); if(!test_res) pass = 0; return pass; }