Quellcode durchsuchen

Expose channel settings to device script

Neal Wilson vor 10 Jahren
Ursprung
Commit
7c8e57cb57
1 geänderte Dateien mit 25 neuen und 2 gelöschten Zeilen
  1. 25
    2
      src/unsupportedserial.w

+ 25
- 2
src/unsupportedserial.w Datei anzeigen

373
 {
373
 {
374
 	QScriptValue object = scriptengine->newQObject(this);
374
 	QScriptValue object = scriptengine->newQObject(this);
375
 	@<Expose device settings as object property@>@;
375
 	@<Expose device settings as object property@>@;
376
+	@<Expose channels and channel settings to device script@>@;
376
 	QScriptContext *context = scriptengine->currentContext();
377
 	QScriptContext *context = scriptengine->currentContext();
377
 	QScriptValue oldThis = context->thisObject();
378
 	QScriptValue oldThis = context->thisObject();
378
 	context->setThisObject(object);
379
 	context->setThisObject(object);
396
 }
397
 }
397
 object.setProperty("settings", settingsObject);
398
 object.setProperty("settings", settingsObject);
398
 
399
 
400
+@ While channels are available to the device script through the same
401
+|getChannel()| interface used outside of the device script for integration
402
+purposes, it is more convenient to have an array of channels with channel
403
+specific settings as properties of the channel.
404
+
405
+@<Expose channels and channel settings to device script@>=
406
+QScriptValue channelsArray = scriptengine->newArray(channelCount());
407
+for(int i = 0; i < channelCount(); i++)
408
+{
409
+	QScriptValue channelObject = scriptengine->newQObject(getChannel(i));
410
+	QScriptValue channelSettingsObject = scriptengine->newObject();
411
+	QVariantMap::const_iterator j = channelSettings.at(i).constBegin();
412
+	while(j != channelSettings.at(i).constEnd())
413
+	{
414
+		channelSettingsObject.setProperty(j.key(), j.value().toString());
415
+		j++;
416
+	}
417
+	channelObject.setProperty("settings", channelSettingsObject);
418
+	channelsArray.setProperty(i, channelObject);
419
+}
420
+object.setProperty("channels", channelsArray);
421
+
399
 @ Currently we require wrapper functions to work with channels in the host
422
 @ Currently we require wrapper functions to work with channels in the host
400
 environment.
423
 environment.
401
 
424
 
493
 			QStringList channelValues;
516
 			QStringList channelValues;
494
 			for(int j = 0; j < channelConfigData.size(); j++)
517
 			for(int j = 0; j < channelConfigData.size(); j++)
495
 			{
518
 			{
496
-				node = channelConfigData.at(i).toElement();
519
+				node = channelConfigData.at(j).toElement();
497
 				if(node.attribute("name") == "keys")
520
 				if(node.attribute("name") == "keys")
498
 				{
521
 				{
499
 					QString data = node.attribute("value");
522
 					QString data = node.attribute("value");
514
 					}
537
 					}
515
 					channelValues = data.split(", ");
538
 					channelValues = data.split(", ");
516
 				}
539
 				}
517
-				else if(node.attribute("nane") == "hidden")
540
+				else if(node.attribute("name") == "hidden")
518
 				{
541
 				{
519
 					hiddenState.append(node.attribute("value") == "true");
542
 					hiddenState.append(node.attribute("value") == "true");
520
 				}
543
 				}

Laden…
Abbrechen
Speichern