1 #*****************************************************************************
5 # Object Name : $RCSfile$
6 # Revision : $Revision$
9 # Created By : Robert Heller
10 # Created : Tue Jul 28 19:15:41 2015
11 # Last Modified : <150817.1413>
19 #*****************************************************************************
21 # Copyright (C) 2015 Robert Heller D/B/A Deepwoods Software
23 # Wendell, MA 01379-9728
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2 of the License, or
28 # (at your option) any later version.
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 #*****************************************************************************
44 package require SignalDriverMax72xx_Host;# Load low-level code
45 package require snit;# require the SNIT OO framework
48 ## @defgroup arduniomax72xx_signals Using an Ardunio Uno and a MAX72XX to Operate Signals
49 # @brief Classes to operate signals using an Ardunio Uno and a MAX72XX.
51 # The module contains code to operate various sorts of signals using
52 # the hardware and code in the ArdunioMAX72XX folder. See the
53 # documentation there for information on how things are wired, etc.
59 # @brief Basic signal colors.
60 # The four values are dark, red, yellow, and green.
63 ## Dark, all lamps off, implies red.
66 ## Red, generally stop or stop and proceed.
69 ## Yellow, generally approach.
72 ## Green, generally clear.
76 ## @typedef twoaspectlist
77 # @brief Aspects for one or two headed signals.
78 # This is a list of one or two aspect colors, the first element for the upper
79 # head (or only) and the second element for the lower head.
82 ## @brief One or two heads signals, 3 colors per head.
87 # # Load the low-level code
88 # package require SignalDriverMax72xx_Host
89 # # Connect to the Ardunio
90 # SignalDriverMax72xx controlpoint1 -portname /dev/ttyACM0
92 # arduniomax72xx_signals::OneTwoHead3Color CP1w2 -driver controlpoint1 -signal 0
93 # # Set aspect to Green over Red (clear)
94 # CP1w2 setaspect {green red}
97 # @author Robert Heller \<heller\@deepsoft.com\>
100 option -signal -readonly yes -
default 0 -type {snit::integer -min 0 -max 7}
101 option -driver -readonly yes -
default {} -type ::SignalDriverMax72xx
103 option -signalname -readonly yes -
default {}
106 ## @private The SignalDriverMax72xx object.
108 typemethod validate {
object} {
109 ## Type validating code
110 # Raises an error if object is not either the empty string or a
111 # OneTwoHead3Color type object.
112 # @param object Some object.
115 return $object;# Empty or
null objects are OK
116 } elseif {[
catch {$object info type} itstype]} {
117 error
"$object is not a $type";#
object is not a SNIT type
118 } elseif {$itstype eq $type} {
119 return $object;# Object is of our type.
121 error
"$object is not a $type";#
object is something
else
126 ## @brief Constructor: initialize the signal object.
128 # Create a low level actuator object and install it as a component.
130 # @param name Name of the signal object.
131 # @param ... Options:
132 # @arg -driver SignalDriverMax72xx object.
133 # @arg -signal Signal number on the MAX7200 board.
134 # @arg -signalname Name of the signal on the track work schematic.
137 # Prefetch the -driver option.
138 set options(-driver) [from args -driver]
139 if {$options(-driver) eq {}} {
140 error
"The -driver option is required!"
142 set driver $options(-driver)
145 typevariable aspectmap -array {
156 ## @private Aspect map.
158 method setaspect {aspect} {
159 ## Set signal aspect.
161 # @param aspect New aspect color.
164 set ap [join $aspect -]
165 if {![info exists aspectmap($ap)]} {
166 error
"Undefined aspect: $aspect"
168 $driver set [$self cget -signal] $aspectmap(ap)
169 set sig [$self cget -signalname]
170 if {$sig ne {}} {MainWindow ctcpanel setv $sig $aspect}
178 package provide ArdunioMAX72XX_Signals 1.0
One or two heads signals, 3 colors per head.
listtype onetwoaspectlist
signalcolors
Basic signal colors.
@ dark
Dark, all lamps off, implies red.
@ red
Red, generally stop or stop and proceed.
@ yellow
Yellow, generally approach.
@ green
Green, generally clear.