Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

procrwil.h File Reference

#include <time.h>

Go to the source code of this file.

Compounds

struct  rwil_device

Typedefs

typedef void * rwil_handle
typedef void(* rwil_success_callback_t )(rwil_device)
 The type used for success callbacks. More...

typedef void(* rwil_failure_callback_t )(rwil_device, const char *)
 The type used for failure callbacks. More...


Functions

rwil_handle rwil_init ()
 Initialize the Real World Interface Library. More...

rwil_device rwil_create (rwil_handle rwilhandle, char house, int num)
 Create a device in the RWIL with the specified attributes. More...

void rwil_destroy (rwil_device handle)
 Destroy a device from the RWIL with the specified handle. More...

void rwil_on (rwil_device handle, time_t when)
 Turn a device on to full power. More...

void rwil_off (rwil_device handle, time_t when)
 Turn a device off. More...

void rwil_setbright (rwil_device handle, int brightness, time_t when)
 Set the brightness of a device. More...

void rwil_interpolatebright (rwil_device handle, int startbrightness, int endbrightness, time_t startwhen, time_t endwhen, int steps)
 Interpolate brightness between two values over a time interval. More...

int rwil_getbright (rwil_device handle)
 Get the brightness of a device now. More...

int rwil_ison (rwil_device handle)
 Determine whether the device is on now. More...

void rwil_success_callback (rwil_success_callback_t callback)
 Set the success callback. More...

void rwil_failure_callback (rwil_failure_callback_t callback)
 Set the failure callback. More...

void rwil_shutdown (rwil_handle rwilhandle)
 Shutdown the RWIL. More...


Typedef Documentation

typedef void(* rwil_failure_callback_t)(rwil_device, const char *)
 

The type used for failure callbacks.

This function takes as a parameter the device handle of the device that unsuccesfully executed, and a textual error message.

Definition at line 94 of file procrwil.h.

Referenced by rwil_failure_callback(), and rwil_getbright().

typedef void* rwil_handle
 

Definition at line 6 of file procrwil.h.

Referenced by main(), rwil_create(), rwil_getbright(), rwil_init(), and rwil_shutdown().

typedef void(* rwil_success_callback_t)(rwil_device)
 

The type used for success callbacks.

This function takes as a parameter the device handle of the device that succesfully executed.

Definition at line 81 of file procrwil.h.

Referenced by rwil_success_callback().


Function Documentation

rwil_device rwil_create rwil_handle    rwilhandle,
char    house,
int    num
 

Create a device in the RWIL with the specified attributes.

Parameters:
rwilhandle  The value returned from rwil_init()
house  The letter of the house address, a-p or A-P
num  The unit number address 1-16
Returns:
A handle to the device.

Definition at line 23 of file procrwil.cpp.

Referenced by main().

00024 {
00025   char buf[20];
00026   int val;
00027   RWIL *rwil = (RWIL*)rwilhandle;
00028   rwil_device device;
00029   val = (house << 16) + num;
00030   sprintf(buf, "%d", val);
00031   X10Device *dev = new X10Device(buf, rwil->output, house, num);
00032   rwil->AddDevice(dev);
00033   device.handle = rwilhandle;
00034   device.dev_handle = val;
00035   return device;
00036 }

void rwil_destroy rwil_device    handle
 

Destroy a device from the RWIL with the specified handle.

Parameters:
handle  Device to destroy.

Definition at line 39 of file procrwil.cpp.

Referenced by main().

00040 {
00041   RWIL *rwil = (RWIL*)handle.handle;
00042   char buf[20];
00043   sprintf(buf, "%d", handle.dev_handle);
00044   rwil->RemoveDevice(buf);
00045 }

void rwil_failure_callback rwil_failure_callback_t    callback
 

Set the failure callback.

Set the global failure callback.

Parameters:
callback  A function pointer to the callback function.

Definition at line 121 of file procrwil.cpp.

Referenced by main().

00122 {
00123   failure_call = callback;
00124 }

int rwil_getbright rwil_device    handle
 

Get the brightness of a device now.

Get the current brightness of a device.

Parameters:
handle  The device to check the brightness of.

Definition at line 95 of file procrwil.cpp.

References rwil_failure_callback_t, and rwil_handle.

Referenced by rwil_ison().

00096 {
00097   RWIL *rwil = (RWIL*)handle.handle;
00098   char buf[20];
00099   sprintf(buf, "%d", handle.dev_handle);
00100 
00101   X10Device* dev = (X10Device *)rwil->GetDevice(buf);
00102   return StringToInt(dev->GetStatus());
00103 }

rwil_handle rwil_init  
 

Initialize the Real World Interface Library.

Call this before any other functions.

Definition at line 12 of file procrwil.cpp.

00013 {
00014   RWIL *ptr = new RWIL;
00015   rwil_handle handle;
00016   ptr->Start();
00017   handle = ptr;
00018   ptr->output.SetAddCallback(rwil_callback);
00019   return handle;
00020 }

void rwil_interpolatebright rwil_device    handle,
int    startbrightness,
int    endbrightness,
time_t    startwhen,
time_t    endwhen,
int    steps
 

Interpolate brightness between two values over a time interval.

Callback is only called at completion or failure of last event.

Parameters:
handle  Device to set brightness of.
startbrightness  The starting brightness value
endbrightness  The ending brightness value
startwhen  The time to start inerpolating from startbrightness to endbrightness
endwhen  The time for the command to finish
steps  The number of steps to take in the interpolations.

Definition at line 72 of file procrwil.cpp.

Referenced by main().

00073 {
00074   RWIL *rwil = (RWIL*)handle.handle;
00075   char buf[20];
00076 
00077   time_t timedif = endwhen - startwhen;
00078   int brightdif = endbrightness - startbrightness;
00079 
00080   sprintf(buf, "%d", handle.dev_handle);
00081 
00082   int count = 0;
00083   for(count = 0; count < steps; count++)
00084   {
00085     Message msg(buf, "dim", startwhen + timedif * count / steps);
00086     msg.SetParam("percent", IntToString(startbrightness + brightdif * count / steps));
00087 
00088     //Ensure that the callback is only called by the last change in brightness
00089     if((count + 1)== steps)msg.SetParam("rwilhandle", IntToString((int)rwil));
00090     rwil->input.Add(msg);
00091   }
00092 }

int rwil_ison rwil_device    handle
 

Determine whether the device is on now.

Parameters:
handle  The device to check the status of.

Definition at line 106 of file procrwil.cpp.

00107 {
00108   if(rwil_getbright(handle)) return 1;
00109   return 0;
00110 }

void rwil_off rwil_device    handle,
time_t    when
 

Turn a device off.

Parameters:
handle  Device to turn off.
when  When to turn device off.

Definition at line 53 of file procrwil.cpp.

Referenced by main().

00054 {
00055   rwil_setbright(handle, 0, when);
00056 }

void rwil_on rwil_device    handle,
time_t    when
 

Turn a device on to full power.

Parameters:
handle  Device to turn on.
when  When to turn on.

Definition at line 48 of file procrwil.cpp.

Referenced by main().

00049 {
00050   rwil_setbright(handle, 100, when);
00051 }

void rwil_setbright rwil_device    handle,
int    brightness,
time_t    when
 

Set the brightness of a device.

Parameters:
handle  Device to set brightness on.
brightness  Level to set brightness to. @when When to set brightness

Definition at line 59 of file procrwil.cpp.

Referenced by rwil_off(), and rwil_on().

00060 {
00061   RWIL *rwil = (RWIL*)handle.handle;
00062   char buf[20];
00063   sprintf(buf, "%d", handle.dev_handle);
00064 
00065   Message msg(buf, "dim", when);
00066   msg.SetParam("percent", IntToString(brightness));
00067   msg.SetParam("rwilhandle", IntToString((int)rwil));
00068   rwil->input.Add(msg);
00069 }

void rwil_shutdown rwil_handle    rwilhandle
 

Shutdown the RWIL.

This function shuts down the rwil system, and waits for the shutdown to complete. This could take several seconds.

Parameters:
rwilhandle  Handle to the RWIL system as returned by rwil_init()

Definition at line 127 of file procrwil.cpp.

Referenced by main().

00128 {
00129   RWIL *rwil = (RWIL*)rwilhandle;
00130   rwil->Kill();
00131   rwil->Join();
00132   delete rwil;
00133 }

void rwil_success_callback rwil_success_callback_t    callback
 

Set the success callback.

Set the global success callback.

Parameters:
callback  A function pointer to the callback function.

Definition at line 115 of file procrwil.cpp.

Referenced by main().

00116 {
00117   success_call = callback;
00118 }


Generated on Thu Jan 17 15:51:20 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001