Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 02 Oct 2014, 09:01
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Looking for a simple, fast routine to display text, images
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Author Message
linuph


Joined: 03 Jun 2012
Posts: 128
Location: Philippines

PostPosted: Fri 25 Jan 2013, 02:26    Post_subject:  Looking for a simple, fast routine to display text, images  

Attached a snapshot of a car GPS program that I'm working on. It runs on an old laptop with Dpup Exprimo 5.X.3.6 installed.

The program is a Bash (sh) script that makes extensive use of awk to read and process GPS text strings. Update of most of the white text and the GPS quality indicators (mode, sats, pdop) are updated synchronously with the GPS data, that is, every second. The system indicators (memory, disk, load) are updated every couple of minutes or so.
Top left is a live video from a webcam. All of it is on top of a static background picture. Not shown here are messages, e.g. lost GPS signal, that are shown on top of the video.
Last but not least: a video screen grabber runs in the background and saves everything live to disk.

The program is not yet operational: I still have to do a lot of additions, corrections and refinements but the principle works.

To display all dynamic text and indicators I use the dzen2 utility (see https://sites.google.com/site/gotmor/dzen). Several dzen2 instances run continuously in the background, called from awk:

Code:
awk -F","  '{
        if ( /\$GPGGA/) program stuff
            print stuff "dzen2 ........."
        else if (/\$GPRMC/) other program stuff
            print other stuff | "dzen2 ........."
            print other stuff | "dzen2 ........"
        else more program stuff
            print more program stuff | "dzen2........."
}' GPS_data


I use awk for a couple of reasons, the main ones being that it can do trigonometry and math (cos, sin, atan, sqrt to name a few) to calculate a.o. distances and bearings between geocoordinates, it is fast and small.

A complication however is that awk runs in it's own shell, making passing of variables to the bash shell and back rather 'awk'ward. It becomes more complicated because dzen2 requires a lot of arguments, like text, colors, font, geometry etc. leading to a lot of work and lots of mistakes, corrections when optimizing the layout of the display. And then, I don't need all the dzen2 options and I do not use the menu option. Of course, dzen2 was not designed for this (it's a taskbar/tray/menu application) but it is the only usable application that I could find.

Now to my question: can anyone advise on a small, fast program that can be called from awk and prints text and images as per the attached image? I guess something in C, but I don't know how to do that (I had quite some trouble already with the little C-routine that provides the background image....).

What I need to handle:
- text
- text fg color
- font/fontsize
- images
- screen position x,y

Optional:
- text bg color
- blinking text
- .....

Stuff should stay on display until refreshed or killed. Small footprint is needed because several instances have to run at the same time

Some notes:

I can't use the usual gtk kind solutions . Reason is that the car display is only 800x600 (no touch) and of limited resolution. A rather large font is used (DejaVu Sans Bold 24) for clear visibility when driving. There isn't room for frames, decorations, dialogs and the like.

It is surprising that awk can do all that processing in almost no time on my old P3 1GHz 512 Mb laptop. Also thanks to Puppy, of course.

dzen2 is a great little program. It is flexible and general purpose. Each instance requires only about 1.1Mb. I have 10 instances running in my program.

I look forward to ideas.
image.jpg
 Description   
 Filesize   69.57 KB
 Viewed   471 Time(s)

image.jpg

Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Fri 25 Jan 2013, 17:40    Post_subject:  

linuph.

This looks like an interesting project.

I wasn't really sure what you're after here.

A dedicated screen divided as shown or a single program that would look like your screen image.

If it's a divided screen, then as you know, there are many tiled window managers that you could use with conky or dzen. On the other hand, if you interested in a single program, that would be much more involved and in that case you might look at zoneminder here http://www.zoneminder.com/ . You many be able to adapt that to your needs.

Cheers,
s
Back to top
View user's profile Send_private_message 
linuph


Joined: 03 Jun 2012
Posts: 128
Location: Philippines

PostPosted: Fri 25 Jan 2013, 23:47    Post_subject:  

Seaside, thanks.

The image you see is dedicated and fully "handmade". There's no window manager involved. I did look into a tiled wm (like i3, I posted about that) but I found that it doesn't fit to my purpose.

There's a substantial difference in what my program and applications like Conky and Xmobar do:

-
Conky runs by it's own, backgrounded, picks up system data and displays them. What is displayed is initiated by Conky.

-
My program calls dzen2 to display data the very moment GPS data is available and processed, so everything is initiated by my program.

Theoretically I could have my program write processed GPS data to a file or memory and then have it picked up by Conky, however, that would lead to delays and, probably, other issues.

Here is a snippet of my code:

Code:

#!/bin/sh

awk -F"," -v dlati=$dlat -v dloni=$dlon -v hlati=$hlat -v hloni=$hlon '{
if ( $1 == "$GPGGA" && $7 == 0 ) {
   ############################################
   print "No valid GPS data. Wait or press 'Esc' to quit." | \
   "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-18-*-*-*-*-*\" \
   -fg red -bg black -h 18 -ta c -x 0 -y 342 -w 480" }
   ############################################
else if ( $1 == "$GPGGA" && $7 == 1 ) {
   #get GPS time
   gpshrs=substr($2,0,2)
   gpsmin=substr($2,3,2)
   gpssec=substr($2,5,2)
   if ( gpshrs > 15 ) gpshrs=0
      localtime=sprintf("%03s%03s%02s",gpshrs":", gpsmin":", gpssec)
      print localtime | \
      ###############################################
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -bg black -fg white -h 22 -ta r -x 600 -y 135 -w 180"
###############################################
   #convert current coordinates from decimal
   #into degrees, minutes, seconds and print
   clatd=int($3/100)
   clatm=int($3-clatd*100)
   clats=int(($3-clatd*100-clatm)*60)
   clatp=sprintf("%04s%03s%03s%1s", clatd"°",clatm"ʹ",clats"ʺ",$4)
   clond=int($5/100)
   clonm=int($5-clond*100)
   clons=int(($5-clond*100-clonm)*60)
   clonp=sprintf("%04s%03s%03s%1s", clond"°",clonm"ʹ",clons"ʺ",$6)         
   #get some more GPS data
   elev=int($10);sats=$8
   ############################################
   if ( sats < 2 ) {
      print clatp" "clonp | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg red -bg black -h 22 -ta l -x 5 -y 410 -w 345"
      print "████" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-18-*-*-*-*-*\" \
      -fg red -bg black -h 18 -ta l -x 609 -y 200 -w 100"
      print elev"m" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg red -bg black -h 22 -ta l -x 435 -y 410 -w 125" }
   else if ( sats == 2 ) {
      print clatp" "clonp | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg yellow -bg black -h 22 -ta l -x 5 -y 410 -w 345"
      print "████" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-18-*-*-*-*-*\" \
      -fg yellow -bg black -h 18 -ta l -x 609 -y 200 -w 100"
      print elev"m" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg yellow -bg black -h 22 -ta l -x 435 -y 410 -w 125" }
   else {
      print clatp" "clonp | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg white -bg black -h 22 -ta l -x 5 -y 410 -w 345"
      print "████" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-18-*-*-*-*-*\" \
      -fg green -bg black -h 18 -ta l -x 609 -y 200 -w 100"
      print elev"m" | \
      "dzen2 -fn \"-*-DejaVu Sans-*-r-*-*-22-*-*-*-*-*\" \
      -fg white -bg black -h 22 -ta l -x 435 -y 410 -w 125" }
###############################################
         
} }' /dev/rfcomm0


Between the long '####'s displaying of data takes place.

Maybe it explains better what I mean: I 'just' need a simple, fast and small routine to display text in position x,y with definable (large) font and color. Icons and transparency are nice options.
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Sat 26 Jan 2013, 13:47    Post_subject:  

linuph wrote:

Maybe it explains better what I mean: I 'just' need a simple, fast and small routine to display text in position x,y with definable (large) font and color. Icons and transparency are nice options.

linuph,

Interesting, it would seem that dzen is exactly what you want.

I guess gtk programs using svg files that you've experimented with are not up to the task? It seems that a one second refresh would be ok for even gtkdialog.

Cheers,
s
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2560
Location: New Zealand

PostPosted: Sat 26 Jan 2013, 14:53    Post_subject:  

So you are saying that dzen does what you want, but is more complex than you need, so you want a dzen replacement?

And you would prefer not to specify font/position etc from awk? Could you do it the other way round and call awk from the display program, so that you already define where you want the output of awk to appear before awk is running?

(forgive my ignorance - I am not a programmer. This just looks an interesting project).
Back to top
View user's profile Send_private_message 
linuph


Joined: 03 Jun 2012
Posts: 128
Location: Philippines

PostPosted: Sat 26 Jan 2013, 22:44    Post_subject:  

Yes, dzen2 does what I need but in some respects it's a bit cumbersome in the way I use it. And yes, I'm looking for something that is simpeler, programming wise.

In the mean time I looked into Cairo and Pango. A dedicated application can be written with it, but I quickly got lost in C programming Rolling Eyes I guess I have to get serious about learning C sometime...



greengeek:
Dzen2 does nothing by itself. It just displays stuff that you feed into it. It cannot call other programs.

To explain a bit more:

Every second a couple of comma separated strings arrive at the /dev/rfcomm0 port that must be parsed (read/processed). Awk is very efficient and fast in parsing such strings because it was designed to do exactly that.

Calling the awk routine from another program would be inefficient.

Mostly, GPSD and GPSPIPE are used to read GPS data. You can even use cat. The program structure would then be:

-read (gpspipe or cat)
-pipe
-process (awk)
-print (dzen2)

Directly with awk:
-parse
-print (dzen2)

GPSD and GPSPIPE are defacto standards. It is universal and allows various GPS hardware to communicate with various applications in various programming languages. However, I don't need it since I write a dedicated application.

BTW:
I use a Bluetooth GPS module. That's why you see '/dev/rfcomm0'. The rfcomm application takes care of the wireless connection with the Bluetooth GPS module and puts the GPS data stream on the serial port designated '/dev/rfcomm0'.
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Sun 27 Jan 2013, 00:57    Post_subject:  

linuph wrote:

BTW:
I use a Bluetooth GPS module. That's why you see '/dev/rfcomm0'. The rfcomm application takes care of the wireless connection with the Bluetooth GPS module and puts the GPS data stream on the serial port designated '/dev/rfcomm0'.

linuph,

Ah.... does the bluetooth device input data as a stream (continuously) or a discrete package. If it's a stream, you'll need to read a discrete block of data at a time.

Cheers,
s
Back to top
View user's profile Send_private_message 
linuph


Joined: 03 Jun 2012
Posts: 128
Location: Philippines

PostPosted: Sun 27 Jan 2013, 03:43    Post_subject:  

It's streamed packages, sort of.

Every second a comma separated string is sent. In each string are headers like $GPGGA or $GPRMC or $GPGSA (and more, depends on the GPS module). After the header follows particular data, ending with a \n.

So, yes, you have to separate the packages from the stream and process them. That's what awk is very good in.

The specification is according to the NMEA0183 standard. Here's documentation about that: http://aprs.gids.nl/nmea/
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Mon 28 Jan 2013, 11:21    Post_subject:  

linuph wrote:

So, yes, you have to separate the packages from the stream and process them. That's what awk is very good in.


linuph,

It appears that you know how to parse the data with awk. Another possibility I noticed in searching around for GPS data collection, was this video using python.
http://www.youtube.com/watch?v=d9hsQ_OhD20

Possibly the entire process could be done with python.

Cheers,
s

Edited_time_total
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2560
Location: New Zealand

PostPosted: Mon 28 Jan 2013, 15:49    Post_subject:  

seaside wrote:
linuph wrote:

So, yes, you have to separate the packages from the stream and process them. That's what awk is very good in.


linuph,

It appears that you know how to parse the data with awk. Another possibility I noticed in searching around for GPS data collection, was this video using python.
http://www.youtube.com/watch?v=d9hsQ_OhD20

Possibly the entire process could be done with python.

Cheers,
s

seaside - your post would not display because of an extra space at the end of the url
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Mon 28 Jan 2013, 16:22    Post_subject:  

greengeek wrote:

seaside - your post would not display because of an extra space at the end of the url


greengeek, Thanks, I was wondering what happened?
Now fixed.
s
Back to top
View user's profile Send_private_message 
linuph


Joined: 03 Jun 2012
Posts: 128
Location: Philippines

PostPosted: Mon 28 Jan 2013, 21:56    Post_subject:  

Yes, the process can be done entirely in Python. However, I stay away from it because such Python applications generally require large libraries. That doesn't do well on my old laptop with limited resources.

It's a hobby and challenge to do things off the beaten paths of Python, Java, Ruby, Lua, MatLab and what more. I would make an exception for C if I knew how.

The funny thing is that you can do relatively complex things on an outdated computer with your Puppy Linux as is, n.l. with bash and awk. But you can't display anything graphically. That's where dzen2 comes in as an extra.
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 30 Jan 2013, 03:17    Post_subject:  

you can generate svg images with text and other included images directly from awk or shell (pretty much anything really) and use this:
http://murga-linux.com/puppy/viewtopic.php?t=80352

I have posted a lot of svg generation tips here:
www.murga-linux.com/puppy/viewtopic.php?t=76431

_________________
Web Programming - Pet Packaging 100 & 101

Edited_time_total
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2560
Location: New Zealand

PostPosted: Wed 30 Jan 2013, 07:12    Post_subject:  

technosaurus wrote:
I have posted a lot of svg generation tips here: www.murga-linux.com/puppy/viewtopic.php?t=7643
Seems to be the wrong link? Typo?

EDIT: Looks like it should be topic 76431
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 30 Jan 2013, 22:47    Post_subject:  

Thanks, fixed.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1091s ][ Queries: 13 (0.0072s) ][ GZIP on ]