Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: michdan on October 30, 2014, 07:05:54 AM

Title: zhuravsky DIP switch with binary value
Post by: michdan on October 30, 2014, 07:05:54 AM
Hello

In a previous thread, zhuravsky modified a DIP switch so that all you needed to do was to move the PIN to the ON or OFF position in order to set it.

http://visguy.com/vgforum/index.php?topic=711.msg3193#msg3193

Is it possible to somehow show the binary value that the dip switches represent as a number?

For example:
If I set the dip switch 1 to ON and the others switches to OFF I will have the value 1.
If I set the dip switch 1 and 3 to ON and the others switches to OFF I will have the value 5 and so on

/michael
Title: Re: zhuravsky DIP switch with binary value
Post by: Yacine on October 30, 2014, 07:30:12 PM
Hello Michael,
a value for the switch can be displayed.
To answer you question, I added a user field to the shape that reads out the state of the individual switches and put the result in the shape text.
The text displayed is probably not yet exactly what you need, but at least it shows how this can be done.
Title: Re: zhuravsky DIP switch with binary value
Post by: michdan on October 31, 2014, 08:05:38 PM
Hello yacine
Thanks for your response, I will see if I can somehow convert the positions into a decimal value.

Regards
Michael
Title: Re: zhuravsky DIP switch with binary value
Post by: Yacine on October 31, 2014, 09:19:56 PM
Download the VSD.
Title: Re: zhuravsky DIP switch with binary value
Post by: michdan on November 04, 2014, 05:12:15 PM
Hello Yacine

I have downloaded your stencil, but I can not figure out how the position of the dip switch is being convertet into a '0' or '1'.

Is it a text box figure where you write your '0' and '1' ?

Could you explain in small steps how you made this?

I am totally newbie in shapesheets so any help is appreciated  :D

/michael
Title: Re: zhuravsky DIP switch with binary value
Post by: Yacine on November 04, 2014, 06:19:24 PM
Hi Michael,
Hope this is clear enough.
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 04, 2014, 06:56:31 PM
To convert to decimal you need to do to things to Yacine's formula in User.Row_13:
  1:  Change the "&" to "+"
  2:  Substitute the decimal equivalent value for each "1".  For example, at the far right of the formula, if switch 12 is high, value is "1" for both binary or decimal, but, for switch11 the "1" becomes a "2", the decimal value for binary binary position, and, switch10, the "1" converts to "4", etc.

That ought to do it.

Some options:  (1) Leave Row_13 formula unchanged, add a Row_14, copy formula, modify as above, and you have both binary and decimal available
                        (2) Using Insert field, change to custom formula to be =User.Row_13&CHAR(10)&"("&User.Row_14&")"  or enter directly in the shapesheet Text Fields section, in the value cell.  This will display both the binary and the decimal values.

HTH

Wapperdude
 
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 04, 2014, 09:59:29 PM
Oh, one other point of interest, normal binary is presented in groups of four digits, so, the row_13 formula could be modified to have a & " " & between the IF statements rather than the single "&" between the 4th & 5th and the 8th & 9th IF statements.

Wapp
Title: Re: zhuravsky DIP switch with binary value
Post by: Yacine on November 05, 2014, 05:27:16 PM
Hi Michael and Wapp,
I felt bored and played a little bit with the shape.
Use the new control points and let me know what you think about.
Title: Re: zhuravsky DIP switch with binary value
Post by: michdan on November 05, 2014, 05:54:09 PM
Hello Yacine

That was exactly what I was looking for, this is really nice.

I really have to work some more with this shapesheet programming :-)

Do you know any good books, websites, documentation etc. that can help a newbie like me to get started with understanding shapesheet programming?


/michael
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 05, 2014, 06:19:57 PM
@Yacine:  Yeah, that's basically it.  The only changes I'd suggest are the following:
  1.)  In binary, the reading goes from right to left, not left to right.  So, your binary word needs to be flipped.  You had it correct with your original reply.  Actually, decimal is the same way, right to left: 1's, 10's, 100's, 1000's, etc.
  2.)  How a user places the switches if somewhat arbitrary, but it would be less confusing if they also followed the conventional binary pattern.
  4.)  The trunk left is a nice feature.
  5.)  The switch identifier is nice
  5.)  I would still recommend adding the "space" every fourth digit, as that is also convention (well, mostly.  Does improve readability)
  6.)  The number of digits seems unnecessary, perhaps should be a displayable option
  7.)  Another possible option is to use the actions menu to let user select what's displayed:  binary, decimal, or both.  That's probably overkill at this point.


I had updated your original post to contain the my original modifications, I'll put it here, now, to illustrate what I mean.  Does not contain your enhancements.

Wapperdude
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 10, 2014, 01:18:58 AM
Major update to the zhuravsky DIP switch:
  1.)  Switches and binary digits are in correct right to left order
  2.)  Switch designator is shape data entry
  3.)  Binary digits are arranged in groups of 4.
  4.)  Binary and decimal values only represent number of switches shown.  Non-visible switches do not contribute to the binary and decimal values.
  5.)  Binary now truncs right, not left.

Wapperdude
Title: Re: zhuravsky DIP switch with binary value
Post by: Yacine on November 10, 2014, 07:30:38 AM
@Wapperdude, nice job.
Getting the value by "Controls.Row_1.Y>1 in" is however risky. If the main shape is too small, the formula interprets FALSE, where it should be TRUE.
Better would be to use a variable.
Cheers,
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 10, 2014, 10:22:05 AM
@Yacine:  You're absolutely right.  I was trying to keep the concept and implementation as close as possible to the original, and didn't think about the 1" issue.  The correct solution to allow better scaling, is to replace the "1 in."  with a height relative value, namely, "height*0.63".  With that change, then the size is not important.  But, the entire shape doesn't scale very well because the text isn't setup to scale.  In addition, at very small sizes, the line weight becomes an issue too.

Thanks for catching that though, there wasn't much margin at all!

Wapperdude
Title: Re: zhuravsky DIP switch with binary value
Post by: wapperdude on November 10, 2014, 05:04:42 PM
Updated: 
  1.  Fixed the controls value reference.   ???
  2.  Re-paired the text scaling that I had unintentionally disabled.   :o
  3.  Added some "group" coloring to the switches to make it a little more obvious what the physical groups of four are.   ::)

Wapperdude
Title: Re: zhuravsky DIP switch with binary value
Post by: zhuravsky on November 20, 2014, 11:11:31 AM
Thanks, guys!
I see my DIP switch still alive :)