@(#) $Header: /usr/local/scalawags_cvs/Scalawags/Simulator2006/TogglecoObject.wc,v 1.5 2006/03/13 23:21:28 abrown Exp $
TogglecoObject simulates a toggle switch with a center off position. It drives two bits of digital output.
TogglecoObject will typically be used in either or both of TheOperatorInterface.tcl and TheRobot.tcl. TogglecoObject.tcl will typically be sourced in one of those files. The declarations for ::Toggleco::new will then be created in one or both of those files as needed. Warning: If you source it in TheOperatorInterface.tcl, you must not also source it also in TheRobot.tcl. Sourcing must happen only once.
| Horizontal |
    |
Vertical | ||||||
|
    |
|
||||||
::Toggleco::new plan3 .robot.switches.plan3 ::porthb \ 65 1 0 64 horizontal bit7 "#000000" "#7f8f7f" |
    |
::Toggleco::new plan3 .robot.switches.plan3 ::porthb \ 65 1 0 64 vertical bit7 "#000000" "#7f8f7f" ::Toggleco::new plan2 .robot.switches.plan2 ::portbb \ 130 128 0 2 vertical bit6 "#000000" "#7f8f7f" |
||||||
| When the baton is left, the digital output is 1 with mask 65. When the baton is right, the digital output is 64 with mask 65. When the baton is mid, the digital output is 0 with mask 65. In other words, this switch has been configured to only control bits 0 and 6. To invert the output of the switch you would replace "65 1 0 64" with "65 64 0 1". |
    |
When the baton on the left switch is up, the digital output is 1 with mask 65. When the baton is down, the digital output is 64 with mask 65. When the baton is mid, the digital output is 0 with mask 65. In other words, this switch has been configured to only control bits 0 and 6. |
There are two proc[edures] in TogglecoObject.tcl. We are only concerned with the first one. The first few lines of the proc lists the parameters required.
proc new { {TogglecoName} {NameOnCanv}
{variable} {mask} {upleft} {mid} {downright}
{shape} {text} {Fg} {Bg} } \
{
 # ToggleName and NameOnCanv must be unique names.
 # "variable" will be controlled by the digital output.
 # "mask", "upleft", "mid" and "downright" are numbers that control
 # how "variable" is controlled. Only the binary bits of "mask"
 # that are 1s will be changes. Other bits of "variable" are
 # untouched. If the baton is in the up or left position, then
 # variable takes on the value of "upleft". If the baton is in
 # down or right position, the variable takes on the value of
 # "downright". If it is in the middle position, the variable
 # takes on the values of "mid".
 # "shape" must be either "horizontal" or "vertical".
 # "text" is displayed above the toggle switch.
 # Fg and Bg = Foreground and Background colors.
The parameters TogglecoName and NameOnCanv are constants.
It is helpful to consider the values of "mask", "upleft", and "downright" in binary. If we want to control bit 5 and 0:
00100001 binary = 33 decimal
We can put two toggles side by side using code like this:
source {TogglecoObject.tcl}
::Toggleco::new plan3 .robot.switches.plan3 ::porthb \
65 1 0 64 vertical bit7 "#000000" "#7f8f7f"
::Toggleco::new plan2 .robot.switches.plan2 ::portbb \
130 128 0 2 vertical bit6 "#000000" "#7f8f7f"
pack .robot.switches.plan3 .robot.switches.plan2 -side left
The declaration above is in TheRobot.tcl. The double colons in front of each variable name makes them operate at the root namespace of the Tcl program.