/** * If we write a new networktables.ini with some sample values, test that * we get those same values back using the Preference class. */ TEST(PreferencesTest, ReadPreferencesFromFile) { NetworkTable::Shutdown(); std::remove(kFileName); std::ofstream preferencesFile(kFileName); preferencesFile << "[NetworkTables Storage 3.0]" << std::endl; preferencesFile << "string \"/Preferences/testFileGetString\"=\"Hello, preferences file\"" << std::endl; preferencesFile << "double \"/Preferences/testFileGetInt\"=1" << std::endl; preferencesFile << "double \"/Preferences/testFileGetDouble\"=0.5" << std::endl; preferencesFile << "double \"/Preferences/testFileGetFloat\"=0.25" << std::endl; preferencesFile << "boolean \"/Preferences/testFileGetBoolean\"=true" << std::endl; preferencesFile << "double \"/Preferences/testFileGetLong\"=1000000000000000000" << std::endl; preferencesFile.close(); NetworkTable::Initialize(); Preferences* preferences = Preferences::GetInstance(); EXPECT_EQ("Hello, preferences file", preferences->GetString("testFileGetString")); EXPECT_EQ(1, preferences->GetInt("testFileGetInt")); EXPECT_FLOAT_EQ(0.5, preferences->GetDouble("testFileGetDouble")); EXPECT_FLOAT_EQ(0.25f, preferences->GetFloat("testFileGetFloat")); EXPECT_TRUE(preferences->GetBoolean("testFileGetBoolean")); EXPECT_EQ(1000000000000000000ll, preferences->GetLong("testFileGetLong")); }
/* * Load preferences from config file */ void PrefsDialog::LoadPreferences(void) { Preferences* pPrefs = ((MyApp*)wxTheApp)->GetPrefs(); assert(pPrefs != NULL); /* * Load preferences. */ mConfigFile = ((MyApp*)wxTheApp)->GetConfigFileName(); pPrefs->GetDouble("gamma", &mGammaCorrection); pPrefs->GetString("debugger", /*ref*/ mDebugger); pPrefs->GetString("valgrinder", /*ref*/ mValgrinder); pPrefs->GetBool("auto-power-on", &mAutoPowerOn); pPrefs->GetBool("enable-sound", &mEnableSound); pPrefs->GetBool("enable-fake-camera", &mEnableFakeCamera); }
// Read data from the Preferences Panel void getPreferences() { kLeftP = prefs->GetDouble("kLeftP", 0.025); kLeftI = prefs->GetDouble("kLeftI", 0.0); kLeftD = prefs->GetDouble("kLeftD", 0.2); kLeftF = prefs->GetDouble("kLeftF", 0.03); kLeftLowRPM = prefs->GetDouble("kLeftLowRPM", -1000.0); kLeftHighRPM = prefs->GetDouble("kLeftHighRPM", -2400.0); kRightP = prefs->GetDouble("kRightP", 0.025); kRightI = prefs->GetDouble("kRightI", 0.0); kRightD = prefs->GetDouble("kRightD", 0.2); kRightF = prefs->GetDouble("kRightF", 0.03); kRightLowRPM = prefs->GetDouble("kRightLowRPM", 1000.0); kRightHighRPM = prefs->GetDouble("kRightHighRPM", 2400.0); kLaunchP = prefs->GetDouble("kLaunchP", 0.2); kLaunchI = prefs->GetDouble("kLaunchI", 0.004); kLaunchD = prefs->GetDouble("kLaunchD", 0.5); kLaunchF = prefs->GetDouble("kLaunchF", 0.0); kGatherP = prefs->GetDouble("kGatherP", 0.05); kGatherI = prefs->GetDouble("kGatherI", 0.0); kGatherD = prefs->GetDouble("kGatherD", 0.1); kGatherF = prefs->GetDouble("kGatherF", 0.0); kTurnP = prefs->GetDouble("kTurnP", 0.025); kTurnI = prefs->GetDouble("kTurnI", 0.004); kTurnD = prefs->GetDouble("kTurnD", 0.06); kTurnF = prefs->GetDouble("kTurnF", 0.0); kGatherAngle = prefs->GetDouble("kGatherAngle", 113.0); kLaunchMinAngle = prefs->GetDouble("kLaunchMinAngle", 23.5); kLaunchMaxAngle = prefs->GetDouble("kLaunchMaxAngle", 36.7); kLaunchAngle = prefs->GetDouble("kLaunchAngle", 30.0); kCoeff0 = prefs->GetDouble("kCoeff0", 0.144); kCoeff1 = prefs->GetDouble("kCoeff1", 19.8); kLogLevel = prefs->GetString("kLogLevel", "INFO"); Log::SetLevel(Log::FromString(kLogLevel)); LOGGER(INFO) << "[getPreferences] LeftRPM:" << kLeftHighRPM << " RightRPM: " << kRightHighRPM; }