Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Read/Write Preferences in C++ (http://www.chiefdelphi.com/forums/showthread.php?t=138412)

rod@3711 10-05-2015 07:51 PM

Read/Write Preferences in C++
 
The 2015 SmartDashboard description gives a code example to set Preferences, then display them by adding a Robot Preferences widget.

Last year we made program changes for some timing and positioning variables that we would have preferred to set via the SmartDashboard and have them preserved.

I added the code to a Sample Robot project and can not get it to work.

The lines we added have // %rod comments in the following snippet.

////////////////////////////////////////////////////////////////////
class Robot: public SampleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick

Preferences *prefs; // %rod

public:
Robot() :
myRobot(0, 1), // these must be initialized in the same order
stick(0) // as they are declared above.
{
myRobot.SetExpiration(0.1);
prefs = Preferences::GetInstance(); // %rod
}

void RobotInit(){ // all new %rod
double x;
double y;
SmartDashboard::PutString("Version","1.1");
x = prefs->GetDouble("x Pref",33);
y = prefs->GetDouble("y Pref",66);
}
//////////////////////////////////////////////////////

The SmartDashboard will display the version 1.1 data, but when we add the Robot Preferences widget, it is blank.

I then spent several hours trying prefs->PutDouble, prefs->Save..., etc. and have now given up.

Is there a working example of C++ using Preferences?

rod@3711 10-13-2015 10:07 PM

Re: Read/Write Preferences in C++
 
Finally got back to looking at Preferences and found my mistake.

The string names for the Keys can not have spaces.

x = prefs->GetDouble("x Pref",33);

changed "x Pref" to "xPref" and everything worked as expected.


All times are GMT -5. The time now is 10:49 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi