Wednesday, August 18, 2010

GUI Button State Machine

This post will share a design pattern that can be used in a serious GUI based application where several events must occur based on button presses. While LabView does have an event handling structure, this state machine can contain states based on button presses, but can also be extended to contain other cases (states) which execute in sequence as specified.

For this post, rather than show the details of every menu, here is the finished block diagram:

This follows the state machine design pattern. The state is tracked with a string via a shift register passed to the case structure each iteration of the while loop. The output tunnel will contain the state chosen for the next iteration. In this example, 4 buttons have been placed on the front panel, and there is a state called "Idle" which should be called when nothing is taking place. In the idle state, the 4 boolean buttons are built into an array which is searched for a "True". Since the Search 1D array function (found under the array menu) will return -1 if no "True" elements are found in the array, the "Idle" state continues until a button press is found (indicated by a search return value >= 0). When this happens, a new state is indexed from the string array constant and passed out of the Idle state on the output tunnel. You can place whatever code you like in the various states for your button presses.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers