summaryrefslogtreecommitdiff
path: root/lib/pale/multiplexedleddisplay.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pale/multiplexedleddisplay.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/multiplexedleddisplay.tcl142
1 files changed, 93 insertions, 49 deletions
diff --git a/lib/pale/multiplexedleddisplay.tcl b/lib/pale/multiplexedleddisplay.tcl
index 78976ad..8fcf042 100755..100644
--- a/lib/pale/multiplexedleddisplay.tcl
+++ b/lib/pale/multiplexedleddisplay.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _MULTIPLEXEDLEDDISPLAY_TCL ] } {
+set _MULTIPLEXEDLEDDISPLAY_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Implements PALE VHW component "Multiplexed LED display"
@@ -35,11 +40,12 @@ class MultiplexedLedDisplay {
inherit VirtualHWComponent
# Font: Font to be used in the panel -- bold
- common cb_font [font create \
- -weight bold -size -10 \
- -family {helvetica} \
+ common cb_font [font create \
+ -weight bold \
+ -size [expr {int(-10 * $::font_size_factor)}] \
+ -family {helvetica} \
]
- common COMPONENT_NAME "Multiplexed LED display" ;# Name of this component
+ common COMPONENT_NAME "Multiplexed LED Display" ;# Name of this component
common CLASS_NAME "MultiplexedLedDisplay" ;# Name of this class
common COMPONENT_ICON {mleddisplay} ;# Icon for this panel (16x16)
@@ -55,16 +61,17 @@ class MultiplexedLedDisplay {
{#5555AA #0000FF #5555FF}
{#AA55AA #8800FF #CC55FF}
}
+ common DIMMED_COLOR {#BBBBBB}
# Configuration menu
common CONFMENU {
{cascade {Common electrode} 7 "diode" .ca false 1 {
{radiobutton "Common anode" {}
::MultiplexedLedDisplay::cfg_common_anode 1
- "common_electrode_chanded" 7 ""}
- {radiobutton "Common catode" {}
+ "common_electrode_changed" 7 ""}
+ {radiobutton "Common cathode" {}
::MultiplexedLedDisplay::cfg_common_anode 0
- "common_electrode_chanded" 7 ""}
+ "common_electrode_changed" 7 ""}
}}
{cascade {Fade out interval} 5 "player_time" .dim false 1 {
{radiobutton "0" {}
@@ -126,7 +133,7 @@ class MultiplexedLedDisplay {
}}
{separator}
{command {All fade out} {} 0 "dim_all" {ledgray}
- "Dim all leds"}
+ "Dim all LEDs"}
{command {Show help} {} 5 "show_help" {help}
"Show brief help"}
{separator}
@@ -134,10 +141,15 @@ class MultiplexedLedDisplay {
"Save configuration into a file"}
{command {Load configuration} {} 0 "load_from" {fileopen}
"Load configuration from a file"}
+ {separator}
+ {checkbutton "Window always on top" {} {::MultiplexedLedDisplay::menu_keep_win_on_top}
+ 1 0 0 {keep_win_on_top_changed}
+ ""}
}
private variable conf_dim_interval 50 ;# Int: Interval to dim LED's in instruction cycles
private variable conf_led_color {red} ;# Color: Selected color for display segments
+ private variable keep_win_on_top 0 ;# Bool: Toplevel window
private variable leds ;# Array of CanvasObject (polygon): leds(display_num,segment_num) --> LED polygon
## Array of CanvasObject (line):
@@ -147,7 +159,7 @@ class MultiplexedLedDisplay {
private variable connection_port ;# Array of Int: Index is key number, value is port number or {-}
private variable connection_pin ;# Array of Int: Index is key number, value is bit number or {-}
private variable prev_state ;# List: Previous port states
- private variable common_anode 1 ;# Bool: 1 == common anode; 0 == common catode
+ private variable common_anode 1 ;# Bool: 1 == common anode; 0 == common cathode
private variable t_state ;# List: Transistor states
@@ -213,7 +225,7 @@ class MultiplexedLedDisplay {
# @return void
private method create_gui {} {
# Create panel window and canvas widget
- set win [toplevel .multiplexedleddisplay$count -class {Mult. LED Display} -bg {#EEEEEE}]
+ set win [toplevel .multiplexedleddisplay$count -class {Mult. LED Display} -bg ${::COMMON_BG_COLOR}]
set canvas_widget [canvas $win.canvas \
-bg white -width 0 -height 0 \
-highlightthickness 0 \
@@ -396,12 +408,12 @@ class MultiplexedLedDisplay {
# Create EntryBox for user note
$canvas_widget create text 40 210 \
- -text {Note} \
+ -text [mc "Note"] \
-font $cb_font \
-anchor e
- $canvas_widget create window 40 210 \
+ $canvas_widget create window 45 210 \
-window [ttk::entry $canvas_widget.usr_note \
- -validate all \
+ -validate key \
-validatecommand "$this set_modified" \
] \
-width 380 -anchor w
@@ -412,14 +424,25 @@ class MultiplexedLedDisplay {
pack $canvas_widget -fill both -expand 1
# Set window parameters
- wm geometry $win =425x225
+ wm minsize $win 430 225
wm iconphoto $win ::ICONS::16::$component_icon
- wm title $win "[mc $component_name] - [string trim $project {:}] - MCU 8051 IDE"
+ wm title $win "[mc $component_name] - [$project cget -projectName] - MCU 8051 IDE"
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW "$this close_window"
bindtags $win [list $win Toplevel all .]
}
+ ## Value of configuration menu variable "keep_win_on_top" has been changed
+ # @return void
+ public method keep_win_on_top_changed {} {
+ set keep_win_on_top $MultiplexedLedDisplay::menu_keep_win_on_top
+ if {$keep_win_on_top} {
+ wm attributes $win -topmost 1 -alpha 0.8
+ } else {
+ wm attributes $win -topmost 0 -alpha 1.0
+ }
+ }
+
## LED dim interval changed (meaningfull for multiplexed mode)
# @return void
public method dim_interval_changed {} {
@@ -427,14 +450,15 @@ class MultiplexedLedDisplay {
set_modified
}
- ## LED's common electrode chanded
+ ## LED's common electrode changed
# @return void
- public method common_electrode_chanded {} {
+ public method common_electrode_changed {} {
set common_anode ${::MultiplexedLedDisplay::cfg_common_anode}
if {$drawing_on} {
dim_all
- new_state [$project pale_get_true_state] 1
+ set state [$project pale_get_true_state]
+ new_state state 1
}
set_modified
}
@@ -445,12 +469,13 @@ class MultiplexedLedDisplay {
set conf_led_color ${::MultiplexedLedDisplay::color}
if {$drawing_on} {
- new_state [$project pale_get_true_state] 1
+ set state [$project pale_get_true_state]
+ new_state state 1
}
set_modified
}
- ## Dim all LED's and reset their prevoius states
+ ## Dim all LED's and reset their previous states
# @return void
public method dim_all {} {
for {set i 0} {$i < 8} {incr i} {
@@ -476,7 +501,7 @@ class MultiplexedLedDisplay {
if {$connection_pin($i) != {-}} {
set connection_pin($i) [expr {7 - $connection_pin($i)}]
}
- } {
+ } else {
set connection_port(T$i) [$canvas_widget.cb_t_p$i get]
set connection_pin(T$i) [$canvas_widget.cb_t_b$i get]
if {$connection_pin(T$i) != {-}} {
@@ -486,7 +511,8 @@ class MultiplexedLedDisplay {
# Change state of the device
if {$drawing_on} {
- new_state [$project pale_get_true_state] 1
+ set state [$project pale_get_true_state]
+ new_state state 1
}
# Set flag modified
@@ -711,7 +737,7 @@ class MultiplexedLedDisplay {
private method which_port_pin {type i} {
if {$type == {S}} {
return [list $connection_port($i) $connection_pin($i)]
- } {
+ } else {
return [list $connection_port(T$i) $connection_pin(T$i)]
}
}
@@ -732,13 +758,13 @@ class MultiplexedLedDisplay {
# @return void
public method mcu_changed {} {
# Refresh lists of possible values in port selection ComboBoxes
- set avaliable_ports [concat - [$project pale_get_avaliable_ports]]
+ set available_ports [concat - [$project pale_get_available_ports]]
# For segments ...
for {set i 0} {$i < 8} {incr i} {
- $canvas_widget.cb_p$i configure -values $avaliable_ports
+ $canvas_widget.cb_p$i configure -values $available_ports
- if {[lsearch -ascii -exact $avaliable_ports $connection_port($i)] == -1} {
+ if {[lsearch -ascii -exact $available_ports $connection_port($i)] == -1} {
$canvas_widget.cb_p$i current 0
set connection_port($i) {-}
}
@@ -746,9 +772,9 @@ class MultiplexedLedDisplay {
# For transistors ...
for {set i 0} {$i < 4} {incr i} {
- $canvas_widget.cb_t_p$i configure -values $avaliable_ports
+ $canvas_widget.cb_t_p$i configure -values $available_ports
- if {[lsearch -ascii -exact $avaliable_ports $connection_port(T$i)] == -1} {
+ if {[lsearch -ascii -exact $available_ports $connection_port(T$i)] == -1} {
$canvas_widget.cb_t_p$i current 0
set connection_port(T$i) {-}
}
@@ -757,18 +783,20 @@ class MultiplexedLedDisplay {
## Accept new state of ports
# @parm List state - Port states ( 5 x {8 x bit} -- {bit0 bit1 bit2 ... bit7} )
- # @parm Bool preserve_prvious_state = 0 - Preserve previous state of component
+ # @parm Bool preserve_prvious_state=0 - Preserve previous state of component
# @return void
#
# Possible bit values:
# '|' - High frequency
# 'X' - Access to external memory
# '?' - No volatge
- # '-' - Undeterminable value (some noise)
+ # '-' - Indeterminable value (some noise)
# '=' - High forced to low
# '0' - Logical 0
# '1' - Logical 1
- public method new_state {state {preserve_prvious_state 0}} {
+ public method new_state {_state {preserve_prvious_state 0}} {
+ upvar $_state state
+
# Determinate index of LED color in list COLORS
set color_idx [lsearch -ascii -exact \
{red orange yellow green blue purple} \
@@ -784,7 +812,7 @@ class MultiplexedLedDisplay {
if {[lindex $pp 0] == {-} || [lindex $pp 1] == {-}} {
set t_state($i) {}
# Connected
- } {
+ } else {
set t_state($i) [lindex $state $pp]
}
@@ -793,7 +821,7 @@ class MultiplexedLedDisplay {
{0} { ;# Logical 0
if {$common_anode} {
set t_state($i) 2
- } {
+ } else {
set t_state($i) 0
}
set wire_color {#FF0000}
@@ -801,7 +829,7 @@ class MultiplexedLedDisplay {
{1} { ;# Logical 1
if {$common_anode} {
set t_state($i) 0
- } {
+ } else {
set t_state($i) 2
}
set wire_color {#00FF00}
@@ -809,7 +837,7 @@ class MultiplexedLedDisplay {
{=} { ;# High forced to low
if {$common_anode} {
set t_state($i) 2
- } {
+ } else {
set t_state($i) 0
}
set wire_color {#00FF00}
@@ -842,7 +870,7 @@ class MultiplexedLedDisplay {
# Not connected
if {[lindex $pp 0] == {-} || [lindex $pp 1] == {-}} {
for {set j 0} {$j < 4} {incr j} {
- $canvas_widget itemconfigure $leds($j,$i) -fill {#555555}
+ $canvas_widget itemconfigure $leds($j,$i) -fill $DIMMED_COLOR -outline {#FFFFFF}
}
foreach item $wires($i) {
$canvas_widget itemconfigure $item -fill {#000000}
@@ -896,14 +924,14 @@ class MultiplexedLedDisplay {
set segment_color {0}
}
}
- } {
+ } else {
set segment_color {0}
}
}
{1} { ;# Logical 1
if {$common_anode} {
set segment_color {0}
- } {
+ } else {
switch -- $t_state($j) {
{2} {
set segment_color {2}
@@ -966,8 +994,8 @@ class MultiplexedLedDisplay {
# Determinate segment color (true color, not just number)
if {!$segment_color} {
- set segment_color {#555555}
- } {
+ set segment_color $DIMMED_COLOR
+ } else {
incr segment_color -1
set segment_color [lindex $COLORS [list $color_idx $segment_color]]
}
@@ -998,6 +1026,7 @@ class MultiplexedLedDisplay {
$conf_led_color \
$conf_dim_interval \
$common_anode \
+ $keep_win_on_top \
] \
]
}
@@ -1013,7 +1042,7 @@ class MultiplexedLedDisplay {
# Restore window geometry
if {[string length [lindex $state 2]]} {
- wm geometry $win [lindex $state 2]
+ wm geometry $win [regsub {^\=?\d+x\d+} [lindex $state 2] [join [wm minsize $win] {x}]]
}
# Load user note
@@ -1028,6 +1057,13 @@ class MultiplexedLedDisplay {
set common_anode 1
}
+ if {[lindex $state 7] != {}} {
+ set keep_win_on_top [lindex $state 7]
+ if {$keep_win_on_top} {
+ wm attributes $win -topmost 1 -alpha 0.8
+ }
+ }
+
## Restore state of ComboBoxes
# For segments ...
for {set i 0} {$i < 8} {incr i} {
@@ -1083,12 +1119,13 @@ class MultiplexedLedDisplay {
}
# Accept new state of ports
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
update
# Fail
}]} then {
- puts stderr "Unable to load config for $class_name"
+ puts stderr "Unable to load configuration for $class_name"
puts stderr $::errorInfo
return 0
@@ -1103,7 +1140,8 @@ class MultiplexedLedDisplay {
# @return void
public method reset {} {
dim_all
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
@@ -1117,6 +1155,7 @@ class MultiplexedLedDisplay {
set ::${class_name}::dim_interval $conf_dim_interval
set ::${class_name}::color $conf_led_color
set ::${class_name}::cfg_common_anode $common_anode
+ set ::${class_name}::menu_keep_win_on_top $keep_win_on_top
}
## This method is called after configuration menu has beed created
@@ -1135,7 +1174,7 @@ class MultiplexedLedDisplay {
#
# Note: There is defined text tag "tag_bold" in the text widget
public method show_help_special {text_widget} {
- $text_widget insert insert [mc "Virtual multiplexed LED display with common anode (default) or catode. Each segment can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes. Panel configuration can be saved to a file (with extension vhc). And can be loaded from that file later. LED fade out interval and LED colors are configurable\n\n"]
+ $text_widget insert insert [mc "Virtual Multiplexed LED Display with common anode (default) or cathode. Each segment can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes. Panel configuration can be saved to a file with extension vhc, and can be loaded from that file later. LED fade out interval and LED colors are configurable.\n\n"]
set color_idx [lsearch -ascii -exact \
{red orange yellow green blue purple} \
@@ -1145,7 +1184,7 @@ class MultiplexedLedDisplay {
$text_widget insert insert [mc "LED states:"]
$text_widget tag add tag_bold {insert linestart} {insert lineend}
$text_widget insert insert [mc "\n "]
- $text_widget window create insert -pady 1 -create "frame $text_widget.f0 -bd 1 -width 14 -height 16 -bg #888888"
+ $text_widget window create insert -pady 1 -create "frame $text_widget.f0 -bd 1 -width 14 -height 16 -bg $DIMMED_COLOR"
$text_widget insert insert [mc " Off\n "]
$text_widget window create insert -pady 1 -create "frame $text_widget.f1 -bd 1 -width 14 -height 16 -bg [lindex $COLORS [list $color_idx 0]]"
$text_widget insert insert [mc " Fast blinking\n "]
@@ -1172,8 +1211,13 @@ class MultiplexedLedDisplay {
}
}
}
- } {
- new_state [$project pale_get_true_state] 1
+ } else {
+ set state [$project pale_get_true_state]
+ new_state state 1
}
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard