Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

Buttons Plugin

Discussing issues that occur during plugin development.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Buttons Plugin

Post by _X7JAY7X_ »

This is what I am trying to do. I have created hardware that simply mimics the buttons from a Matrix Orbital lcd. I want to be able to hook these buttons up to the serial port and be able to use them with a parallel HD44780 Display.

I have a few years of C++ experience that may be helpful in writing plugins, however I do not know if a plugin would be possible for this or the right option.

I am trying to get most of the functionality of matrix orbital buttons in lcd smartie, however the backlight option will not work.

Can you point me in the right direction?

Thanks
Jason

clansley
Site Admin
Posts: 104
Joined: February 13th, 2005, 5:09 pm
Location: UK
Contact:

Post by clansley »

Although the plugin system isn't meant for implementing hardware support, I think it's possible to do what you want.

In LCD Smartie you would usually use $MObutton(X) in the event section to make use of key presses. What you could do is create a plugin that opens the serial port and reads from it (in it's own thread), and instead of using $MObutton, you could use $dll(yourdll,1,X,0) and your plugin could just check if the last key received from the serial port was X and return 1 if it was otherwise 0.

There's a basic sample C++ plugin available for download. On the palmorb site there's some basic serial code available for download.

Chris.

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

I get what your saying but, are you saying I can actually use the Actions menu with a dll? I cannot say

if $dll(....) > 1 then Playwinamp

it will not let me enter the dll string right after the if statement.

Can you post some example syntax for the plugin, so I can understand how to construct it.

Jason

clansley
Site Admin
Posts: 104
Joined: February 13th, 2005, 5:09 pm
Location: UK
Contact:

Post by clansley »

You should be able to type the $dll(...) stuff in after the if - when you say you can't what do you mean?

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

I have figured the if dll() part out.


However, I have got the plugin to read the serial port and return the value of the letter (i.e. Button A = 41 hex). The problem is is that smartie "hangs" while its waiting for an input from the serial port. Do you have any ideas?


Thanks
Jason

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

I dont know if this is the best way, but the only thing I could figure out is to repeatedly sending a byte to the computer from the buttons that tells it that it is there so it doesnt hang on the input.

Do you have a better idea?

Thanks
Jason

clansley
Site Admin
Posts: 104
Joined: February 13th, 2005, 5:09 pm
Location: UK
Contact:

Post by clansley »

The best method is to do the serial port reading in it's own thread.

A cheap and dirty idea would be to save the last key as a global int variable and look at that when your function1 is called. A better but harder method is to use a global buffer containing unread keypresses, with a critrical section guarding accesses to it.

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

Do you have any examples of this? I found this serial port code online and it uses the ReadLine command to get info from the serial port. This is what it is waiting on.

Are you good with C++? Can you look at the code or do you know of a good website with examples.

Thanks
Jason

clansley
Site Admin
Posts: 104
Joined: February 13th, 2005, 5:09 pm
Location: UK
Contact:

Post by clansley »

Reading from the serial port is usually a blocking thing - that's why you need to do it in it's own thread. I know C++ (that's what my job is doing) but not on Windows - I'm a unix programmer.

But it's not hard - you should be able to find examples of threading code on the web.

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

Ok I have created a thread that waits for a read of a buttons, if not it will time out after X amount of time. I think this will work, but here is the problem......... I have worked on the code a reguler .exe file and it works fine, however when I converted it to a dll it is giving me errors with functions. For example, I have

function 1 (x,x) (dll function 1, called as function 1 from smartie)
{

void Thread( void* pParams )
{ <-----

}

void main(void)
{ <----

}
}

it is giving me an error where the arrows are at, it is says:

error C2601: 'Thread' : local function definitions are illegal
error C2601: 'main' : local function definitions are illegal

is there a certain way to call function within .dll functions?

any ideas?

Thanks
Jason

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

I have figured it out, I got it to return the Hex Value of the button without locking Smartie up, and it seems to work fine. I disabled the "wait for so long" loop to read in a character and it works better.

With this loop enabled it was making the processor run at about 20%.

_X7JAY7X_
Hardware Genie - Plugin Author
Posts: 374
Joined: February 16th, 2005, 10:24 pm
Location: Michigan

Post by _X7JAY7X_ »

It is now completely done. I have added file support to change the Com port and to show plugin status. It is limited to basic output such as the time the plugin was started.

I have been using it now for the last few days. It works great.

penjuin
Hardware Genie - Plugin Author
Posts: 42
Joined: June 28th, 2005, 3:42 am
Location: Australia

Post by penjuin »

could you please post a link to it?

Post Reply