Page 1 of 1

PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by peec
PKJ Tellstick GUI
PKJ Tellstick GUI is a new tool under development and it's getting developed as we speak.

It's very basic and lightweight right now, it does not really add more features then the TelldusCenter is bringing you, but I will focus more on adding advanced features later on.

The project is hosted on Google Code: http://code.google.com/p/javatellstick/

A little screenshot.
Image

Tellstick DUO
This API is created for the Tellstick DUO (that is going to be released soon ... )

Key features
- API is smart, detects different devices and it's properties, such as DimmableDevice, Device, BellDevice.

Key focus:
I will focus of maintainability and make it easy to maintain.
You can also use this library to develop new tellstick applications in Java.

SVN & Download
Checkout: http://javatellstick.googlecode.com/svn/trunk/apps/
See config.cnf and run client.jar.

More info
http://code.google.com/p/javatellstick/


Technical information
- It's built with Java, and therefor you will need JAVA runtime to use it!
- If you have telldus center installed as 32bit you will need to run 32bit java(!)
I used libraries such as:
- JNA, makes the application able to communicate with the TellstickCore.
- SWT , a wrapper around Swing, it means that if you run the app on windows it will look like a windows application, on linux it would look as a linux application. This makes it faster because it uses the operative system to generate the GUI components.


Ideas
Since this is a brand new development, I ask for ideas, what do you want to see being implemented?

Re: PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
Two notes.

Since you have an API for Duo you need to run our betas. The current one is 2.0.104 and ships 64-bit libraries on all platforms (Windows, Linux and Mac OS X). So it should be possible to build and use this JAVA library with a 64 bit JAVA as well.

In the latest version we also included support for groups. That means a device (group) can be both "bellable" and "on/off-able". Groups simply combines all methods from the devices in the group. You can check for a group with the function tdGetDeviceType(). It returns either TELLSTICK_TYPE_DEVICE or TELLSTICK_TYPE_GROUP.

Re: PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
One more thing. I see you hardcoded the supported methods in TellstickDevice::getDevice(). This is up to the end application to tell the library which metods it supports.
Why? Let me explain with an example.

Bob has only switches and dimmers. He writes an application using your library and get DimmableDevice and Device objects back from TellstickDevice::getDevices(). He successfully implements these objects and then sends the application to his friend Eddie.
Eddie has switches and bells. The application then get BellDevice and Device objects from TellstickDevice::getDevices(). Since BellDevices isn't implemented in Bob's application it would behave strange. It could perhaps crash or display an empty interface. Either way, his bell wouldn't work for Eddie.

My suggestion is that Bob sends its supported methods to TellstickDevice::getDevices(). In this example it is JNA.CLibrary.TELLSTICK_TURNOFF | JNA.CLibrary.TELLSTICK_TURNON | JNA.CLibrary.TELLSTICK_DIM. The application will behave the same for Bob but when he sends it to Eddie his "bellable" device will be returned as a normal Device-object from TellstickDevice::getDevices() and the application will still work.

The interface might not be the most optimal for Eddie but he will at least be able to use it without missing any features.

If it is inconvenient to send the methods at every call to TellstickDevice::getDevice() and TellstickDevice::getDevices() it could be set when the application loads the library. You can then reuse it when appropriate. If you don't want the application to send more methods to your library than you have implemented it is easy to mask them off like this:

Code: Select all

public TellstickDevice(int deviceId, int supportedMethods){
  int maskedMethods = supportedMethods & (JNA.CLibrary.TELLSTICK_BELL | JNA.CLibrary.TELLSTICK_TURNOFF | JNA.CLibrary.TELLSTICK_TURNON | JNA.CLibrary.TELLSTICK_DIM | JNA.CLibrary.TELLSTICK_TOGGLE | JNA.CLibrary.TELLSTICK_LEARN);
  /We use "maskedMethods" from now on. It can never contian more methods than bell, turnoff, turnon, dim, toggle and learn.

  // Get last status ( EMULATED 2 way communication ) Works with TS DUO
  this.status = JNA.CLibrary.INSTANCE.tdLastSentCommand(deviceId, maskedMethods);              
}

Re: PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by peec
First of all thanks for the informative messages! This helps me creating the API much more convenient.

I have done the following in order to get your ideas implemented.
Since you have an API for Duo you need to run our betas. The current one is 2.0.104 and ships 64-bit libraries on all platforms (Windows, Linux and Mac OS X). So it should be possible to build and use this JAVA library with a 64 bit JAVA as well.
Yes, this is already possible to do, the only thing one have to do is to change path to telldus in trunk/apps/config.cnf to the 64bit install. And when it comes to running it from eclipse, it's just about changing the native library path and JRE to the 64 bit paths.
In the latest version we also included support for groups. That means a device (group) can be both "bellable" and "on/off-able". Groups simply combines all methods from the devices in the group. You can check for a group with the function tdGetDeviceType(). It returns either TELLSTICK_TYPE_DEVICE or TELLSTICK_TYPE_GROUP.
Thanks for this information, I overlooked this feature, and have now implemented two more classes actually. GroupDevice (collection of types of devices such as BellDevice, Device and DimmableDevice) and SceneDevice (execute and stop) From what I see SceneDevice is not implemented yet ? Still I have implemented it so that this library will have ready feature for Scene execution / stopping.

Here is a sample of the new GUI: As you can see the gray item is a "GroupDevice" and contains methods supported. (in this case BellDevice and Device aswell as isLearnable() flag)
Image
One more thing. I see you hardcoded the supported methods in TellstickDevice::getDevice(). This is up to the end application to tell the library which metods it supports.
Why? Let me explain with an example
... snip ...
I see what you mean here, and i found a quite neat solution. It seemed like an OK solution, I implemented a new Exception in this case and static methods.

This is required before any construct or getting of devices is possible:

Code: Select all

 // Set supported methods for this app.
                // THIS IS REQUIRED.
                TellstickDevice.setSupportedMethods(
                                JNA.CLibrary.TELLSTICK_BELL |
                                JNA.CLibrary.TELLSTICK_TURNOFF |
                                JNA.CLibrary.TELLSTICK_TURNON |
                                JNA.CLibrary.TELLSTICK_DIM |
                                JNA.CLibrary.TELLSTICK_LEARN |
                                JNA.CLibrary.TELLSTICK_EXECUTE |
                                JNA.CLibrary.TELLSTICK_STOP
                );
and this means that people will need to add try / catch block in order to run methods:

Code: Select all

try{

TellstickDevice device = TellstickDevice.getDevice(1);

// Do stuff.
ArrayList<TellstickDevice> alldevices = TellstickDevice.getDevices();

// Do stuff.

}catch(SupportedMethodsException e){
	e.printStackTrace();
}

Change log of this:
http://code.google.com/p/javatellstick/ ... etail?r=26


Thanks again!

Re: PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
peec wrote:Thanks for this information, I overlooked this feature, and have now implemented two more classes actually. GroupDevice (collection of types of devices such as BellDevice, Device and DimmableDevice) and SceneDevice (execute and stop) From what I see SceneDevice is not implemented yet ? Still I have implemented it so that this library will have ready feature for Scene execution / stopping.
You are right. Scenes are not implemented yet. When they are implemented they are only having the "execute" method though. The "stop" method makes no sense for scenes. It is made for projector-screens. They have the methods up, down, and stop.
I implemented a new Exception in this case and static methods.

This is required before any construct or getting of devices is possible:

Code: Select all

 // Set supported methods for this app.
                // THIS IS REQUIRED.
                TellstickDevice.setSupportedMethods(
                                JNA.CLibrary.TELLSTICK_BELL |
                                JNA.CLibrary.TELLSTICK_TURNOFF |
                                JNA.CLibrary.TELLSTICK_TURNON |
                                JNA.CLibrary.TELLSTICK_DIM |
                                JNA.CLibrary.TELLSTICK_LEARN |
                                JNA.CLibrary.TELLSTICK_EXECUTE |
                                JNA.CLibrary.TELLSTICK_STOP
                );
I think this is a good solution!

Btw, TellStick is spelled with a capital S. But now I am picky... ;)

Re: PKJ Tellstick GUI [java]

Posted: Fri Mar 17, 2023 9:45 am
by peec
Thanks for info.

Just to announce it.

I have bounced of a new project based on this API.

A web server solution, that incorporates all the new stuff of DUO (basically).
The design is not slick, i created this design fast, but it uses fine libraries such as jQuery and AJAX to do calls.

I think the best thing with this server is that it's built using Play! Framework and is highly customizable and enterprise ready ( believe it or not ).

Project URL of the web server.
http://code.google.com/p/javatellstick-webserver/

I created a youtube video for show the interaction with the library.
http://www.youtube.com/watch?v=dvGIKlyRI0o