Monday, July 31, 2017

Even More Life Changing Mouse Buttons

I recently wrote a post on how to change your life by changing a mouse button.  My life has been vastly improved since I added a delete button to my mouse.  My hair is growing thicker and fuller, my eyesight has improved, my lawn is greener, and I can delete things so much faster than before.  My life has been great, but I still felt like something was missing.

Easy access Delete
As a refresher, we at Endigit all use the Logitech M570 wireless trackball mouse.  With that mouse you can change the button settings.  I have assigned the forward button to be the delete button.  I rarely used the Forward button and often need to delete things.  This saves me from moving my hand from the mouse to the keyboard to hit the delete key.  Notice that I have the Back button still set as the Back task.  I use this often when navigating Windows Explorer and on the Interwebs.


Introducing: Quicker Quick Drop
I don't use the back button ever in LabVIEW though.  That makes that button worthless to me when developing software in LabVIEW.  I thought about it and talked about it with the other Endigiters and we thought it would be great to add ctrl-space for even quicker quick drop.  Now instead of wasting so much energy moving my pinkie finger all the way down the the control button and pushing space, I can gently press a mouse button and have quick drop open.  Take that Carpal Tunnel!



But wait there's more!
The middle mouse button is really useful for opening links in new tabs online, or opening a new instance of applications, but again, worthless to me in LabVIEW.  Another common task is cleaning up wires.  Clean Up Wire is normally the top option when you right-click on a wire so it is quick and easy.  However, I have modified my right-click menu so that Create Constant, Control, and Indicator are at the top.  (That is another great time saver.)  So I had to right-click and choose the 4th option down.

That is just too much work for me.  I started selecting the wire and then hitting ctrl-u to clean it up.  That was nice, except the U button is way on the right side of the keyboard.  I have to move my pinkie down to the Control button and then stretch way out to get the U key with my index finger.  That is exhausting!  Why not map the middle mouse button to ctrl-u to save me so much energy?  Unfortunately, the middle button cannot be configured for application specific behavior.  Luckily, AutoHotkey.com came to the rescue!  With AutoHotkey you can set specific keys to run scripts.  I have an AutoHotkey script that looks at the middle mouse button.  When it is pressed it checks if I am using LabVIEW.  If I am then it clicks and sends ctrl-u.  If I am not using LabVIEW it sends the normal middle click.  BOOM!  Now I have block diagram clean-up, and wire clean up with a quick easy push of the button.



What is next?
I have been thinking of other things that I can do to maximize my mouse and keyboard.  I think the next thing I am going to figure out is using the mouse buttons to copy and paste.  I am going to see if I can have ctrl modifier to have the Forward and Back buttons be copy and paste.

What ideas for mouse shortcuts do you want?
Comment your ideas on what you would like to have simplified with your mouse.  I would love to hear some new ideas.

Edit 8/10/2017:
Toggle between Front Panel and Block Diagram
I added so that when I press both the left and right mouse buttons at the same time it sends Ctrl-E to toggle between front panel and block diagram.



Monday, July 17, 2017

LabVIEW Queue for Loop Control; Elegant Hack or Abuse of the System?

After 10 years of LabVIEW development, I like to think of myself as fairly experienced. I’ve acquainted myself with a number of design patterns. When I encountered this, I assumed I was dealing with an event-based producer-consumer pattern.

Do you spot what’s wrong with this picture? Technically nothing, but it took me a minute to figure out what was really going on with that queue. That’s right, it’s not really a queue. It’s an elegant hack to control timing and shutdown of those parallel loops. My first reaction was, “this is wrong,” but the best I could do to justify that judgement was that this isn’t what queues are supposed to do. Problem 1: Readability. I didn’t understand what was going on as quickly as I would have with a more conventional use of a queue.
Weeks later, I was troubleshooting a problem with a similar implementation. Do you spot the problem here?

Kudos if you caught that the bottom “Status Loop” was gobbling up data intended for the Action loop. Someone took the pattern for timing and shutting down parallel loops and leveraged it to also carry data. Problem 2: Protection. There isn’t a guarantee that someone won’t mess with your queue.
Problem 3: When using this pattern, you must be sure to wire in a timeout value. Otherwise, your loop’s not gonna loop.
In the interest of continuous improvement, I thought we could add an improved version to our arsenal. One that solves all the problems. We call it Exitimer, and it’s just a class wrapped around the queue implementation.

Solution 1: With a little VI documentation, other developers understand what Exitimer’s being used for. It’s a timing and shutdown mechanism. They don’t even have to think about queues.
Solution 2: Because access scope to the queue is limited, nobody can try to misuse it to carry data.

Solution 3: Because the timing input is required and negative numbers are handled, there isn’t a risk of an infinite timeout.

Download the code from our website.  What do you think? Is this a pattern you've seen before? Elegant hack, or abuse of the system?