Browse Source

Expose device settings to device script

Neal Wilson 10 years ago
parent
commit
390acf167a
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      src/unsupportedserial.w

+ 15
- 0
src/unsupportedserial.w View File

372
 void JavaScriptDevice::start()
372
 void JavaScriptDevice::start()
373
 {
373
 {
374
 	QScriptValue object = scriptengine->newQObject(this);
374
 	QScriptValue object = scriptengine->newQObject(this);
375
+	@<Expose device settings as object property@>@;
375
 	QScriptContext *context = scriptengine->currentContext();
376
 	QScriptContext *context = scriptengine->currentContext();
376
 	QScriptValue oldThis = context->thisObject();
377
 	QScriptValue oldThis = context->thisObject();
377
 	context->setThisObject(object);
378
 	context->setThisObject(object);
381
 	context->setThisObject(oldThis);
382
 	context->setThisObject(oldThis);
382
 }
383
 }
383
 
384
 
385
+@ Device settings are only needed from the device script itself. As such, these
386
+are presented under a settings property available from the |this| object when
387
+the script is run.
388
+
389
+@<Expose device settings as object property@>=
390
+QScriptValue settingsObject = scriptengine->newObject();
391
+QVariantMap::const_iterator i = deviceSettings.constBegin();
392
+while(i != deviceSettings.constEnd())
393
+{
394
+	settingsObject.setProperty(i.key(), i.value().toString());
395
+	i++;
396
+}
397
+object.setProperty("settings", settingsObject);
398
+
384
 @ Currently we require wrapper functions to work with channels in the host
399
 @ Currently we require wrapper functions to work with channels in the host
385
 environment.
400
 environment.
386
 
401
 

Loading…
Cancel
Save