WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: UI's with Framebuffer + python or lua  (Read 4055 times)

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
UI's with Framebuffer + python or lua
« on: October 09, 2015, 02:11:58 AM »
Been looking at ways to do simple UI's, for small LCDs etc

Framebuffer is the lowest level?

Make a file the same size the screen with 16 bit color ie rgb565.
cp file > /dev/fb0
Wanted to use python but it sucks for 2d arrays.
Found PIL, python imaging library but it is not a tcz:(

ffmpeg is useful for converting the raw file to a png you can see.
A Hexeditor is also useful to make sure you are writing the file correctly, high order byte then low order.

luajit might be better.

Dialog is not to bad for a simple UI.
Prototype a UI in dialog then cp /dev/fb0 ui.raw
Tweak the file then copy ui.raw back to /dev/fb0

Anyone got any other ideas?

Regards
Gavin

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 674
Re: UI's with Framebuffer + python or lua
« Reply #1 on: October 09, 2015, 04:50:13 AM »
Have you looked at lcd4linux??
That convert text to pixels, for example Digital Photo Frames.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: UI's with Framebuffer + python or lua
« Reply #2 on: October 11, 2015, 06:03:16 PM »
Hi patrikg,

Done character LCDs, mainly using the i2c pins.

Wanted to do Framebuffer for TFT LCD 2.4-7"
ie http://www.4dsystems.com.au/product/4DPi_24_HAT/
The smaller ones don't have many pixels so don't want to waste them on X11 windows borders etc.

There looks to be a trend to using HTML, CSSS, JS with acceleration using the GPU's for UI's.
might be one way to go.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: UI's with Framebuffer + python or lua
« Reply #3 on: October 12, 2015, 01:07:05 AM »
Found this
https://luapower.com/

Got some bitmap stuff plus lots of other useful stuff.
Running bitmap_test.lua now, averaging 33MB/s?
Goes from 6-250MB/s depending on pixel depth.
For rgb565 16 bit pixels = 48MB/s,  320x240 TFT LCD = 312 frames/sec on old Pi B.

Way more stuff than I need, but clues on how to do pixels,arrays etc.
1st method, Use external UI tools to make rgb565 bitmap = 115kb, file copy to fb then do pixel plotting over that. Time to cp 115kb file?
2nd method make rgb565 bitmap from lua code on the fly, time to write 115k fb from lua?
3rd method use shell/lua/micropython script to make bitmap from config file.

option 1 requires paint tool that makes rgb565 files, sorry MS Paint :'(
3rd method would allow for easy theming, just change colour in config script.


Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: UI's with Framebuffer + python or lua
« Reply #4 on: October 12, 2015, 08:06:03 PM »
A way to make a UI screen from script?

A simple lua script to write a single colour rgb565 bmp file.
MC has a hex viewer builtin which is nice.

For 1280x1024 it take 5.01 seconds in lua, 0.44 secs in luajit.
Smaller TFT LCD's 320x240 it becomes 0.44 lua and 0.04 seconds for luajit.
Very long time in shell script:0
Still to test micropython version.

UI button write into bmp at x,y,w,h button colour, should be quick as it is less data.
Plotting data is just writing single pixels?
Drawing lines =row/column of pixels.
Text overlay?
No idea yet how to put ui.bmp to /dev/fb0, cp method gets over written.

f = io.open('/home/tc/guibackground.bmp', 'wb')

x=1280
y=1024
lp=x * y

for i = 1, lp do
    f:write("\x15\x00")
end
f:flush()
f:close()