#include "global.h"
#include <fstream>

CfgCache g_cfg;
double target_speed;

double readDoubleFromFile(const std::string &filename)
{
    std::ifstream file(filename);
    double value = 0.0;
    if (file.is_open()) { file >> value; file.close(); }
    return value;
}

bool readFlag(const std::string &filename)
{
    std::ifstream file(filename);
    int flag = 0;
    if (file.is_open()) { file >> flag; file.close(); }
    return flag;
}

void cfg_load_all()
{
    g_cfg.speed       = readDoubleFromFile(speed_file);
    g_cfg.foresee     = readDoubleFromFile(foresee_file);
    g_cfg.zebrasee    = readDoubleFromFile(zebrasee_file);
    g_cfg.deadband    = readDoubleFromFile(deadband_file);
    g_cfg.steer_gain  = readDoubleFromFile(steer_gain_file);
    g_cfg.center_bias = readDoubleFromFile(center_bias_file);
    g_cfg.start       = readFlag(start_file);
    g_cfg.showImg     = readFlag(showImg_file);
    g_cfg.debug       = readFlag(debug_file);
}
