Is there some Linux gurus here ?

Anything not related to STM32
Post Reply
Y@@J
Posts: 57
Joined: Mon Sep 28, 2020 8:51 pm

Is there some Linux gurus here ?

Post by Y@@J »

Hi, and happy new year !

I am just discovering Linux coding (on RasPi) because I wrote someting that runs on a STM32, and is displayed on a RasPi LCD. Bitmaps are sent by the STM32 to the RasPi over SPI (Roger's Core) in full duplex mode @16MHz (works GREAT !). These bitmaps (70 to 110/second) are blitted directly to the frame buffer (1st time ever with C on Linux...). Works great. Except that when exiting my Linux app, the desktop is not restored. I found no equivalent to the Windows APIs (invalidate rectangle, paint). Would be similar to Windows, would need 2 or 3 lines of code ! (but I couldn't write directly into the framebuffer)

Do you know of some magic formula I could send to the X server ? Saving the framebuffer before and restoring when the program ends is not the best solution.

There's another problem : this overlay "display port" (the area where the framebuffer is written) has an underlaying app displaying information (in a Chromium browser running in kyosk mode). Bitmaps are blitted fast enough to immediatly repaint (60fps, with 70-110 framebuffer updates per second). But it would be better not to have anything drawing underneath.

If I understand correctly, in Linux everything is files. Could the X Window output be temporarilly redirected to a NUL device (remember DOS...). It would be ideal !

I'm not asking for code, I'm just asking for some information I could use as keywords, or some links : most of the information I find is outdated, or irrelevant, or even absolute garbage ! And most of the time for Python. I will learn X, but for now I'm a bit in a hurry, and the documentation is HUGE. I think that being able to prevent display updates, and later reallow it would be a good starting point. Or something for those who want to do some coding for X-Window, and have a Win32 APIs background : some "bilingual dictionnary".
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Is there some Linux gurus here ?

Post by ag123 »

this is off-topic, but if you are using one of those ili9341 lcd
there is apparently a way to send video there directly on that too small little screen
https://www.raspberrypi.org/forums/view ... p?t=157618
https://www.youtube.com/watch?v=fPTaWHccljo
i've not tried though

if you are instead 'blitting' it to X on Rpi, my guess is you could read that data and display it using an ordinary X windows app? e.g. PyQt5 etc
Y@@J
Posts: 57
Joined: Mon Sep 28, 2020 8:51 pm

Re: Is there some Linux gurus here ?

Post by Y@@J »

It blit on the frame buffer, bare metal. Output being a HDMI 1024x600 LCD touchscreen.

Your answer is definitely NOT off topic ! It is exactly in topic.

The little app called xeyes ! I've seen this widget years ago, and didn't remember.

Now searching for the XEyes C source : it is EXACTLY what I need : drawing in a window with no borders (or borders, why not...) and "always on top", with events capture. I had to write my own bare metal bitblt function (for fat pixels)... Will draw in X, using XEyes as a template, with a BitBlt that uses GPU acceleration and that comes with X (no doubt it exists). I started to read the X manuals a couple days ago and gave up, reason why I coded my app bare metal. XEyes will probably teach more than I expect !

This will be my starting point with X. Shouldnt be too difficult to port my app to X (a guess), and it should solve my problem with desktop redraw (saving / restoring the framebuffer is just crappy, and drawing bare metal over a video window results in some flickering !). Most if not all the work is done (it's a daemon displaying what a OLED displays : a SPI SSD1306 emulator). If you are in 3D printing, it's a "Marlin Mode" for OctoPrint.

I googled "https://www.google.com/search?client=fi ... CAw&uact=5"

and for some reason, the first answer is "https://www.hanselman.com/blog/visual-c ... evelopment". I'm a very long time MS VisualC++ user and fanboy (since V1.0 beta). I discover now that there's an extension for Lunux and RasPi ?!?!? I started with Linux a few days ago, using Visual Studio on the PC (editing files remotely) and doing "make" in a terminal. I will test this extension !!!

Many thanks !

Will post a short video later. Difficult to explain with my limited vocabulary.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Is there some Linux gurus here ?

Post by ag123 »

for a quickstart you may want to explore PyQt5
https://build-system.fman.io/pyqt5-tutorial
or PyGTK
http://www.peteronion.org.uk/PyGobjectGtk+3/PyGtk.html
https://python-gtk-3-tutorial.readthedocs.io/en/latest/
it is a quick way to get started with some graphics, Qt5 and Gtk comes bundled with all the common widgets such as windows, buttons, list boxes, radio buttons, check boxes etc and using Python lets you experiment without needing to get into c/c++ codes

Raspberry Pi has some pretty good bindings with Python for gpio / spi etc.
https://www.raspberrypi.org/documentati ... /README.md
https://www.raspberrypi.org/documentati ... /README.md
Y@@J
Posts: 57
Joined: Mon Sep 28, 2020 8:51 pm

Re: Is there some Linux gurus here ?

Post by Y@@J »

No Python ! No QT ! And even more : no Qt with Python !

Want to stay as low level as possible, and avoid such a language. I'll have to use it at some point, but no need for now. Stopped using Basic 35 years ago, I will not use Python now : it's even worse.
Finally, I started with a "Hello World !", and it did it. A VERY old one, that starts this way :

Code: Select all

int main(argc,argv)
     int argc;
     char **argv;
hadn't seen such a declaration for ages (types outside) !

At this point, I've a daemon that opens a window when pushing a button, and the window displays a 1bpp bitmap using XCreateBitmapFromData() and XCopyPlane(). Had to write a conversion function because bits are in the opposite order in XBM bitmaps (the STM32 will do it soon so the RasPi will no more have to bother with). But the daemon can't close this window ! The window is still on the screen after closing everything programmatically. It closes only when clicking anywhere on the screen. Weird... Maybe something wrong in the event loop. Also, RasPi and malloc() seem not to work as usual (have to allocate 2.5MB, malloc() doen't like it...
I was extremely disapointed with X11 : no BitBlt equivalent. No viewports, no scaling, nothing. Only very basic functions. Time to see with OpenGL ? Maybe.
Y@@J
Posts: 57
Joined: Mon Sep 28, 2020 8:51 pm

Re: Is there some Linux gurus here ?

Post by Y@@J »

For now, it is tiny (128x64), but alive, in a "always on top" X11 window. Run as a daemon, no Title bar, as reactive as the OLED display, popping up and disapearing pressing a button, and zero flickering when over the video viewer.
In fact, it is not always on top : if Chromium browser is full screen, the browser is "more on top" than my Marlin Mode app. For now, this makes it unusable... And sometimes SPI gets out of sync (need STM32 reboot)

[EDIT] It seems there's no solution to the "no window over a full screen app". I tried many attributes with no success, and it's a known problem. But... I'm working with Pixel on the RasPi, while TouchUI for OctoPrint / Chromium normally runs in kiosk (full screen) mode on Matchbox window manager... It's made for full screen apps running on small touchscreens and it seems it allows that at least for dialogs ! @ag123 : do you know about Matchbox ? (I started reading and it seems doable...). Tomorrow, will reflash a standard OS with Matchbox and no desptop, and see what happens.
And at worst, it works with the framebuffer, with no risks of memory leaks. Just some cleaning, + belts and suspenders (should'nt crash a printer after a 20 hours of a 24 hours print !)
.
MarlinMode.JPG
MarlinMode.JPG (29.51 KiB) Viewed 4421 times
Y@@J
Posts: 57
Joined: Mon Sep 28, 2020 8:51 pm

Re: Is there some Linux gurus here ?

Post by Y@@J »

The app progressed a lot, but still unable to code for the Matchbox window manager (very little information, after hours on the web). And being an absolute newbie in Pi coding, I don't even know the "good" keywords. I attempted to subscribe to the RaspBerry forums, but for some reason it failed (no confirmation, maybe a typo in the email)... I gave up and will retry later...
This being said, I've something functionnal. Maybe a short video will help understanding the project. It is bare metal ( \m/ ) code, using no external libraries, meaning everybody will be able to compile and run without searching for libs (wirePi comes installed by default).

https://www.youtube.com/watch?v=vd2Wgo4UeBw

Maybe the most insteresting thing is that a STM32 allows for turning a RasPi into a SPI slave (slave mode is NOT implemented on the Pi).
Post Reply

Return to “Off topic”