Exported tdUp(), tdDown() and tdStop() to the script engine

This commit is contained in:
Micke Prag 2011-02-24 10:20:12 +00:00
parent 18b56f2069
commit 75affe3f5c
3 changed files with 38 additions and 8 deletions

View file

@ -77,6 +77,30 @@ int TelldusCoreObject::turnOff(int deviceId) {
return retval; return retval;
} }
int TelldusCoreObject::up(int deviceId) {
int retval = tdUp( deviceId );
if (retval != TELLSTICK_SUCCESS) {
triggerError(deviceId, retval);
}
return retval;
}
int TelldusCoreObject::down(int deviceId) {
int retval = tdDown( deviceId );
if (retval != TELLSTICK_SUCCESS) {
triggerError(deviceId, retval);
}
return retval;
}
int TelldusCoreObject::stop(int deviceId) {
int retval = tdStop( deviceId );
if (retval != TELLSTICK_SUCCESS) {
triggerError(deviceId, retval);
}
return retval;
}
void TelldusCoreObject::triggerError(int deviceId, int errorId) { void TelldusCoreObject::triggerError(int deviceId, int errorId) {
char *errorString = tdGetErrorString( errorId ); char *errorString = tdGetErrorString( errorId );
QString message = QString::fromUtf8( errorString ); QString message = QString::fromUtf8( errorString );

View file

@ -10,7 +10,7 @@ class TelldusCoreObject : public QObject
public: public:
TelldusCoreObject( QObject * parent = 0 ); TelldusCoreObject( QObject * parent = 0 );
virtual ~TelldusCoreObject(); virtual ~TelldusCoreObject();
signals: signals:
void deviceChange( int deviceId, int eventId ); void deviceChange( int deviceId, int eventId );
void deviceEvent( int deviceId, int method, const QString &data ); void deviceEvent( int deviceId, int method, const QString &data );
@ -25,19 +25,22 @@ public slots:
int lastSentCommand( int deviceId, int methodsSupported ); int lastSentCommand( int deviceId, int methodsSupported );
QString lastSentValue( int deviceId ); QString lastSentValue( int deviceId );
int methods( int deviceId, int methodsSupported ); int methods( int deviceId, int methodsSupported );
int turnOn( int deviceId ); int turnOn( int deviceId );
int turnOff( int deviceId ); int turnOff( int deviceId );
int up( int deviceId );
int down( int deviceId );
int stop( int deviceId );
private: private:
void triggerError( int, int ); void triggerError( int, int );
static void WINAPI deviceChangeEventCallback(int deviceId, int eventId, int changeType, int callbackId, void *context); static void WINAPI deviceChangeEventCallback(int deviceId, int eventId, int changeType, int callbackId, void *context);
static void WINAPI deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context); static void WINAPI deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context);
int deviceEventId; int deviceEventId;
int deviceChangeEventId; int deviceChangeEventId;
}; };
#endif // TELLDUSCOREOBJECT_H #endif // TELLDUSCOREOBJECT_H

View file

@ -21,12 +21,15 @@ void TelldusCorePlugin::initialize ( const QString & key, QScriptEngine * engine
value.setProperty("TELLSTICK_BELL", TELLSTICK_BELL); value.setProperty("TELLSTICK_BELL", TELLSTICK_BELL);
value.setProperty("TELLSTICK_TOGGLE", TELLSTICK_TOGGLE); value.setProperty("TELLSTICK_TOGGLE", TELLSTICK_TOGGLE);
value.setProperty("TELLSTICK_DIM", TELLSTICK_DIM); value.setProperty("TELLSTICK_DIM", TELLSTICK_DIM);
value.setProperty("TELLSTICK_UP", TELLSTICK_UP);
value.setProperty("TELLSTICK_DOWN", TELLSTICK_DOWN);
value.setProperty("TELLSTICK_STOP", TELLSTICK_STOP);
value.setProperty("TELLSTICK_DEVICE_ADDED", TELLSTICK_DEVICE_ADDED); value.setProperty("TELLSTICK_DEVICE_ADDED", TELLSTICK_DEVICE_ADDED);
value.setProperty("TELLSTICK_DEVICE_CHANGED", TELLSTICK_DEVICE_CHANGED); value.setProperty("TELLSTICK_DEVICE_CHANGED", TELLSTICK_DEVICE_CHANGED);
value.setProperty("TELLSTICK_DEVICE_REMOVED", TELLSTICK_DEVICE_REMOVED); value.setProperty("TELLSTICK_DEVICE_REMOVED", TELLSTICK_DEVICE_REMOVED);
value.setProperty("TELLSTICK_DEVICE_STATE_CHANGED", TELLSTICK_DEVICE_STATE_CHANGED); value.setProperty("TELLSTICK_DEVICE_STATE_CHANGED", TELLSTICK_DEVICE_STATE_CHANGED);
engine->globalObject().property("com").property("telldus").setProperty("core", value); engine->globalObject().property("com").property("telldus").setProperty("core", value);
} }
} }