22 ******************************************************************************
33 *
44 * @file serialplugin.cpp
5- * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
5+ * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6+ * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
67 * @addtogroup GCSPlugins GCS Plugins
78 * @{
89 * @addtogroup SerialPlugin Serial Connection Plugin
@@ -65,16 +66,14 @@ void SerialEnumerationThread::stop()
6566 }
6667}
6768
68- SerialConnection::SerialConnection () :
69+ SerialConnection::SerialConnection (SerialPluginConfiguration *config ) :
6970 serialHandle(NULL ),
7071 enablePolling(true ),
7172 m_enumerateThread(this ),
72- m_deviceOpened(false )
73+ m_deviceOpened(false ),
74+ m_config(config)
7375{
74- m_config = new SerialPluginConfiguration (" Serial Telemetry" , this );
75- m_config->restoreSettings ();
76-
77- m_optionspage = new SerialPluginOptionsPage (m_config, this );
76+ m_optionsPage = new SerialPluginOptionsPage (m_config, this );
7877
7978
8079 // Experimental: enable polling on all OS'es since there
@@ -90,8 +89,8 @@ SerialConnection::SerialConnection() :
9089// this, SLOT(onEnumerationChanged()));
9190// #else
9291 // Other OSes do not send such signals:
93- QObject::connect (&m_enumerateThread, SIGNAL (enumerationChanged ()),
94- this , SLOT (onEnumerationChanged ()));
92+ QObject::connect (&m_enumerateThread, SIGNAL (enumerationChanged ()), this , SLOT ( onEnumerationChanged ()));
93+ QObject::connect (m_optionsPage, SIGNAL ( availableDevChanged ()), this , SLOT (onEnumerationChanged ()));
9594 m_enumerateThread.start ();
9695// #endif
9796}
@@ -224,27 +223,54 @@ void SerialConnection::resumePolling()
224223 enablePolling = true ;
225224}
226225
227- SerialPlugin::SerialPlugin () : m_connection(0 )
226+ SerialPlugin::SerialPlugin () : m_connection(0 ), m_config( 0 )
228227{}
229228
230229SerialPlugin::~SerialPlugin ()
231230{
232- removeObject (m_connection->Optionspage ());
233- }
234-
235- void SerialPlugin::extensionsInitialized ()
236- {
237- addAutoReleasedObject (m_connection);
231+ removeObject (m_connection->optionsPage ());
238232}
239233
240234bool SerialPlugin::initialize (const QStringList &arguments, QString *errorString)
241235{
242236 Q_UNUSED (arguments);
243237 Q_UNUSED (errorString);
244- m_connection = new SerialConnection ();
238+
239+ Core::ICore::instance ()->readSettings (this );
240+
241+ m_connection = new SerialConnection (m_config);
242+
245243 // must manage this registration of child object ourselves
246244 // if we use an autorelease here it causes the GCS to crash
247245 // as it is deleting objects as the app closes...
248- addObject (m_connection->Optionspage ());
246+ addObject (m_connection->optionsPage ());
247+
248+ // FIXME this is really a contrived way to save the settings...
249+ // needs to be done centrally from
250+ QObject::connect (m_connection, &SerialConnection::availableDevChanged,
251+ [this ]() { Core::ICore::instance ()->saveSettings (this ); }
252+ );
253+
249254 return true ;
250255}
256+
257+ void SerialPlugin::extensionsInitialized ()
258+ {
259+ addAutoReleasedObject (m_connection);
260+ }
261+
262+ void SerialPlugin::readConfig (QSettings &settings, Core::UAVConfigInfo *configInfo)
263+ {
264+ Q_UNUSED (configInfo);
265+
266+ m_config = new SerialPluginConfiguration (" SerialConnection" , settings, this );
267+ }
268+
269+ void SerialPlugin::saveConfig (QSettings &settings, Core::UAVConfigInfo *configInfo) const
270+ {
271+ Q_UNUSED (configInfo);
272+
273+ if (m_config) {
274+ m_config->saveConfig (settings);
275+ }
276+ }
0 commit comments