Browse Source

Expose QTimer to host environment

Neal Wilson 10 years ago
parent
commit
26e60c9468
1 changed files with 41 additions and 0 deletions
  1. 41
    0
      src/unsupportedserial.w

+ 41
- 0
src/unsupportedserial.w View File

@@ -692,4 +692,45 @@ QScriptValue SerialPort_flush(QScriptContext *context, QScriptEngine *)
692 692
 	return QScriptValue();
693 693
 }
694 694
 
695
+@* Timers.
696
+
697
+\noindent While some devices will output a steady stream of measurements which
698
+can be continuously read as they come in, other devices must be polled for
699
+their current state. One approach is to poll the device immediately after
700
+reading the response from the previous polling, but there are times when we may
701
+want to limit the rate at which we poll the device. There are also devices
702
+which specify a length of time during which data should not be sent. For these
703
+cases, we expose |QTimer| to the host environment which allows us to wait. This
704
+is also useful for producing simulations to test features without needing to be
705
+connected to real hardware.
706
+
707
+<@Function prototypes for scripting@>=
708
+void setQTimerProperties(QScriptValue value, QScriptEngine *engine);
709
+QScriptValue constructQTimer(QScriptContext *context, QScriptEngine *engine);
710
+
711
+@ The host environment is informed of the constructor.
712
+
713
+@<Set up the scripting engine@>=
714
+constructor = engine->newFunction(constructQTimer);
715
+value = engine->newQMetaObject(&QTimer::staticMetaObject, constructor);
716
+engine->globalObject().setProperty("Timer", value);
717
+
718
+@ Everything that we are interested in here is a signal, slot, or property so
719
+there is little else to do.
720
+
721
+@<Functions for scripting@>=
722
+void setQTimerProperties(QScriptValue value, QScriptEngine *engine)
723
+{
724
+	setQObjectProperties(value, engine);
725
+}
726
+
727
+QScriptValue constructQTimer(QScriptContext *, QScriptEngine *engine)
728
+{
729
+	QScriptValue object = engine->newQObject(new QTimer);
730
+	setQTimerProperties(object, engine);
731
+	return object;
732
+}
733
+
734
+
735
+
695 736
 

Loading…
Cancel
Save