Subject: Home-Brewed Glass Panel
From: Rotary Engine
Date: 11/29/2011, 8:32 PM
To: AAA Put this in the To box


Paul:

Reading all your posts on EFI systems and GPS intefacing has kept me
thinking about what might be the best operating system to use if one
wanted to create an entire home-brewed glass-panel display.

I ran the idea past my wife's cousin, who is now retired from a position
as a programmer for some Silicon Valley hardware developer.  He
suggested a look at TCL (pronouced: Tickle)

see:
http://en.labs.wikimedia.org/wiki/Tcl_Programming/Introduction#So_what_is_Tcl.3F

He sparked my interest so I've been hacking around with it for the last
couple of day.  The weather has been snowy/rainy and we occasionally
have up to 3 dogs and 8 grandchildren under 8 years of age ramming
around the house, so hiding in my office is often prudent behavior :)

I first explored methods using TCL GUI tools to draw the panel
instrument (which I've done with the vertical gauges on the bottom of my
panel).  I  then decided that displaying images of real instruments was
a faster/prettier way to do it. I can now simulate the appearance of
most anything on the screen.

I now need to figure out how TCL can be used to read an external
data-source.
I will probably test it by having it read test-numbers from a simple
external data file, but according to claims from online sites, I should
be able to read data from most any data port as well.  That is my next
project.

This is one of my most recent panel displays.

Robin Berglund


Robin,
This is very impressive and very nice appearance.

SUGGESTION: include an attitude indicator, and layout the "clocks" in the
standard T layout.

Philippe CHENEVIER

Can TCL be used to program a Honeycomb tablet?
Tablets have build in gyro's.

Paul Lamar

===================================================

According to various web sites Tcl is cross-platform, "available for Mac, Unix, Windows, ..."
I've been experimenting with it using Linux (Ubuntu 10.04)
Tcl is part of the standard Ubuntu install, though mine came with Tcl 8.4. installed
Various web sites recommended upgrading to 8.5, which I did through the package-manager.
Tcl has many add-on packages which can be installed; many "widgets" as they are called, can make Tcl more powerful.
I upgraded the "Tk" add-on package too (Tcl 8.5-kwidgets), which is rather standard, and allows one to use GUI tools
People often refer to Tcl as Tcl/tk.
Working with images of jpg and other image formats, requires the Img package, which I downloaded from
  http://packages.ubuntu.com/search?keywords=libtk-img

There are quite a few example Tcl sripts out the the web,
but most of them are either too simple or too complex for my needs; I wasted a lot of time getting my first panel to run.
Tcl programmers use a variety of styles, but one can write Tcl so that it appears much like BASIC.
Subroutines are known as procedures and some of the syntax is quite different, but of someone can read a BASIC program they can probably read a Tcl script and modigy it without killing it.
Some of the features that I've figured out are that variable names are defined on-the-fly
(ex:  Set diam 140) is equivalent to 'diam=140' and it does not need to know about the variable 'diam' ahead of time.
But when one wants to use the variable in an expression one must put a $ in front of the variable name
(ex:   set r1 [expr {$diam/2}] is equivalent to 'r1=diam/2'

Very little punctuation is used, spaces are important, language is case-sensitive. Comment lines start with a # character.
Just when to use the "(", "{, or "[" still has me totally confused.
Also ... how various GUI windows are referenced in procedures is still a mystery to me,
and I am just starting to get a handle on how "local variables" within procedures are shared globally by other parts of the program script.

The following Tcl script will display the oil-temperature gauges on the screen. Since it uses the 'canvas' GUI function, one must have the Tk package installed.

I created the script using the Ubuntu gedit text editor and saved it to a directory/folder on my hard-drive,
giving the script a name (ie 'sample'.tkl')
To run it one just opens a terminal window, types the name of the Tcl interpreter being used, followed by the script name
( ie 'wish sample.tkl' ), For some reason the Tcl version 8.5 calls the Tcl interpreter "wish".
(The default interpreter was called "tclsh")


****************************************
# These lines of code were cut out of my demonstration program but will run on their own



set VGBorderColor white ;# these variable define look of vertical gauges
set VGLoColor blue      ;# gauge color when reading is low
set VGHiColor red       ;# gauge color when reading is high
set VGOKColor green     ;# gauge color when reading is in
operating-range
set GaugeColor yellow   ;#



# min & max are gauge extremes, low and hi are gauge color-change
# threshold values, dispvalue is gauge reading

proc vgauge { w vlabel x1 y1 x2 y2 min max lowlevel hilevel dispvalue
vglabel} {
eval global [info globals]

  set y3 [expr {$y1 + ($y2 - $y1)*($max - $dispvalue)/($max - $min)}]


  if {$dispvalue < $lowlevel} {set GaugeColor $VGLoColor} elseif
{$dispvalue > $hilevel} {set GaugeColor $VGHiColor} else {set GaugeColor
$VGOKColor}

  $w create rectangle $x1 $y1 $x2 $y2  -fill DarkGray
  $w create rectangle $x1 $y3 $x2 $y2  -fill $GaugeColor
  $w create text $x1 [expr $y1 - 12 ] -anchor nw -font {Courier 10
bold}  -fill white -text $vglabel
  $w create text $x1 [expr $y2 + 5 ] -anchor nw -font {Courier 10 bold}
-fill white -text $dispvalue


}



pack [canvas .c -bg black -width 1024 -height 768]

.c create text 30 550 -anchor nw -font {Courier 18 bold}  -fill orange
-text Oil
vgauge .c gauge 20 600 40 700 0 100 50 80 55 PSI

# When deployed, the reading '55' would come from engine sensor


vgauge .c gauge 60 600 80 700 0 300 120 220 115 TMP

************************

Have fun

R Berglund






BTW ... I forgot to mention ... the following is an excerpt from one of
the web sites mentioned in my original email



First steps
To see whether your installation works, you might save the following
text to a file hello.tcl and run it (type tclsh hello.tcl at a console
on Linux, double-click on Windows):


package require Tk
pack [label .l -text "Hello world!"]


It should bring up a little grey window with the greeting.

To make a script directly executable (on Unix/Linux, and Cygwin on
Windows), use this first line (the # being flush left):


#!/usr/bin/env tclsh


or (in an older, deprecated tricky style):


#! /bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}


This way, the shell can determine which executable to run the script
with.

An even simpler way, and highly recommended for beginners as well as
experienced users, is to start up tclsh or wish interactively. You will
see a % prompt in the console, can type commands to it, and watch its
responses. Even error messages are very helpful here, and don't cause a
program abort - don't be afraid to try whatever you like! Example:


$ tclsh
% info patchlevel
8.4.12
% expr 6*7
42
% expr 42/0
divide by zero


You can even write programs interactively, best as one-liners:


% proc ! x {expr {$x<=2? $x: $x*[! [incr x -1]]}}
% ! 5
120
...


R Berglund

-- 
The Rotary Engine NewsLetter. Powered by Linux.
ACRE NL web site. http://www.rotaryeng.net
Youtube key word PaulLamar2
Copyright 1998-2011 All world wide rights reserved.