User avatar
JohnBeardmore
Posts: 211
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Naive and heretical questions about X11 on the Pi

Sat Dec 31, 2016 1:54 am

I’m trying to put together a public display to show the output power of a large PV system. The power measurement bit all works fine, so now I’m looking at the ‘minor’ matter of the public display. What I want to do is pretty simple. It’s just displaying some very big digits, possibly with a couple of logos and a small graph or two.

The idea is to mount the system high on a wall with no keyboard or mouse for user input. This is an output only program, taking a data feed via a file in /tmp. My hope is to plug an HDMI monitor into the Pi and use this as the display. (Access to the system for maintenance and development is by ssh and xrdp.)

Screen refresh will be every 15 seconds which hopefully won’t be too challenging, and this seems to be OK at the moment even on a Pi B.

I want to do this project on a Raspberry Pi so it will be cheap, and play nicely with the other open source energy bits and pieces I’m writing on the Pi.

Digging into the X documentation and online examples, my initial experiments have gone well, but all are based on examples which tell you how to do things the usual way, within windows, and on the display that’s in front of you. All the examples basically start XopenDisplay(), XcreateSimpleWindow(), then XmapWindow(). Subsequent calls to do useful things like write the text like XdrawString() take Display and Window as parameters. XnextEvent() is used to get things out of the message queue, with XcheckWindowEvent() called to see if there’s an event waiting. If there isn’t, I can check to see if the message I’m displaying needs updating, which matters to me far more than any of the standard X events, as in normal operation there shouldn’t be any.

At the moment I’ve got as far as an x11 application which runs in a window with lovely big digits, which I can see in my development environment over xrdp. See enclosed code.

There are a few things I need to know.

1)
Can I force this to run on the (virtual ?) display which will output to the HDMI monitor ?

2)
Do I need to do x11 graphics in the context of a window at all ? Is it possible to write directly to the display in the absence of any window ?

3)
Do I have to read the X event queue ? I tried only reading it when XcheckWindowEvent() said there was something, but it would still sometimes block on the subsequent call of XnextEvent() which stopped the program looking for data updates to display.

4)
To avoid the problem in 3) above, I’ve now taken out all references to the X event handling and the program seems to be doing pretty much what I need. Are there any downsides to this ? Will the program eventually become deranged if the event queue isn’t read ?

5)
If I can force the program to send its output to the HDMI display, can I also remove all the other screen furniture from this display (login prompts, backdrops etc).

6)
If 2) above isn’t possible, is it possible to make the window completely borderless so it can’t be differentiated from the background ?

Many thanks, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
topguy
Posts: 5882
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Naive and heretical questions about X11 on the Pi

Sat Dec 31, 2016 2:09 am

1:
If you have two x-servers running (one on HDMi and another as vncserver), you select which one by using the "-display" option.

Code: Select all

xeyes -display :0.0
or
xeyes -display :1.0
You can also set "DISPLAY" environment variable "export DISPLAY=:0.0"

2:
You could avoid anything X11 related by using SDL for example. You could have taken a look at "raylib" also. http://www.raylib.com/

5:
If you just start the X-server by just running "X" instead of "startx" you will get a barebones version without sessionmanager and windowmanager (which is the desktop stuff).
You can also google up "xinit" which also people use to start single application X sessions.

User avatar
JohnBeardmore
Posts: 211
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: Naive and heretical questions about X11 on the Pi

Tue Jan 03, 2017 10:11 pm

Thanks for the know how ! I'm setting up a new test machine with an HDMI monitor connected so I should be able to see what's going on shortly.

Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
Gavinmc42
Posts: 3874
Joined: Wed Aug 28, 2013 3:31 am

Re: Naive and heretical questions about X11 on the Pi

Thu Jan 05, 2017 3:51 am

I have used Python with Pygame on Raspbian desktop(X11) for solar panel etc 5 years ago.
Headless, I then moved to JavaFX, no need for X11.
I looked at tcl/tk but decided to move forwards not backwards :D

You are at where I was 4 years ago, I had to make a decision.
Use stuff that has been around for decades or learn the new stuff.
Probably not a good idea as my head nearly exploded with the learning?

Most on my solar monitoring stuff is now done via a Pi webserver running piCore/busybox-httpd.
To view the JS/HTML5 stuff I needed to use Raspbian with Chromium on the display unit.
Midnight Commander + ssh for maintenance.

As everyone now knows Linux/busybox is not secure so I am now moving to Ultibo.
The Sensomatic3000 example code is a good place to start as it shows text and graphics windows with plotting.
Ultibo also works fine with the 7" Pi display and even smaller LCDs.

Why Ultibo?
Well I got tired of filling up my hard drive with 8GB backup images.
In fact we had to put in a server to handle all the OS's backups, versions, software/Linux books, manuals etc
Sensormatic code folder is 12 files < 1MB source

Reason 2 is speed, Laz/FPC/Delphi is well known as RAD (Rapid Application Development) tools.
Ultibo is like the Arduino type IDE but for baremetal Pi's.
Coding can be done in minutes/hours/days instead of days/weeks/months.
The graphic stuff is just about usable now, lots still needs documentation and it is early days as it is only 1 year old.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Morphology
Posts: 36
Joined: Tue Jan 10, 2012 11:16 am
Contact: Website

Re: Naive and heretical questions about X11 on the Pi

Tue Jan 10, 2017 1:03 pm

+1 for RayLib

Comes with loads of examples for displaying text, graphics etc. no X / Pixel needed.

Morph.

User avatar
scruss
Posts: 2542
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Naive and heretical questions about X11 on the Pi

Tue Jan 10, 2017 2:03 pm

Some other possibilities:
  • Electron — an embedded JavaScipt/browser. I've seen this used to build really impressive UIs for embedded equipment that were just a Raspberry Pi + a small touchscreen.
  • Processing — a sketch with a very slow refresh rate, like once every few seconds, could read the file, parse it, and redraw the screen
  • Python/Tkinter — use root.after() at the end of your refresh subroutine to schedule a call to itself every few seconds.
  • Format the text in appropriate Pango markup, and use pango-view or ImageMagick to render it to an image. Display that image in a slideshow program that polls for changes in the image.
Processing would likely be the least work of all of these.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
Gavinmc42
Posts: 3874
Joined: Wed Aug 28, 2013 3:31 am

Re: Naive and heretical questions about X11 on the Pi

Sat Jan 14, 2017 12:22 am

Just been using the new ver 3 of Processing on the Pi's.
Slow on a B+ but usable on a Pi 3.
Ver 3 uses JavaFX which is hardware accelerated.

Been doing some network stuff from Windows or Linux to a Pi 3.
The network draw example was fun.
Processing is also quick to learn with a good library/extension management.

It proved so easy to use it got bumped to the top of the list for quick prototyping, one off apps.
It is being used to telnet to a Pi controller running Ultibo shell.
It will allow a Windows or Linux PC or a Pi3 to network control Pi based controllers :P
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Graphics programming”