Kiosk GUI Screens

I just tested Nuklear in a VM to see how it does. Not all of the demos compile as written, and if you're new to C, there will definitely be a lot to learn.

Code:
$ cd
$ mkdir -p work && cd work
$ git clone https://github.com/Immediate-Mode-UI/Nuklear.git
$ cd Nuklear/demo/x11
$ export CPATH=/usr/local/include && export LIBRARY_PATH=/usr/local/lib && make
$ ./bin/zahnrad

Screenshot at 2022-05-20 01-10-47.png
 
Well it took Jose offline pushing to get me going. I now have the visual part down now how do I assign command line actions to buttons?
Need to adjust font size.

Modified from centered example code.
Code:
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Flow.H>
#include <FL/Fl_Box.H>

int main()
{
  Fl_Double_Window win(480, 800);
  Fl_Flow flow(0, 0, win.w(), win.h());
  Fl_Button button1(0, 0, 400, 125, "Mapping");
  Fl_Button button2(0, 0, 400, 125, "Music");
  Fl_Button button3(0, 0, 400, 125, "Browser");
  Fl_Button button4(0, 0, 400, 125, "Video");
  Fl_Button button5(0, 0, 400, 150, "Shutdown");
  Fl_Box side(0, 0, 30, 1);
  side.color(FL_CYAN);
  side.box(FL_FLAT_BOX);

  flow.rule(side, "<=^");

  flow.rule(button1, "=<^");
  flow.rule(button2, "=<^");
  flow.rule(button3, "=<^");
  flow.rule(button4, "=<^");
  flow.rule(button5, "=<v");
  win.resizable(flow);
  win.show();

  return Fl::run();
}
fl_flow.jpg
 
In the same vein is there an FLTK runtime lib for the executable available so I don't have to install the whole toolkit on another box?
Is that possible?
Thinking smallest possible implementation. I know the toolkit is only 7MB it's just the thought.

What about FLTK 2.x. Its now offered but will it be backwards code compatible?
 
In the same vein is there an FLTK runtime lib for the executable available so I don't have to install the whole toolkit on another box?
Is that possible?
You should be able to link against the static FLTK library rather than dynamic.

Check out the -static (or -l:libfltk.a) flags when invoking the compiler.
 
I now have the visual part down now how do I assign command line actions to buttons?
You have to add a callback to your button.
Need to adjust font size.
Decent example of font handling here: https://github.com/fltk/fltk/blob/branch-1.3/examples/textdisplay-with-colors.cxx

What about FLTK 2.x. Its now offered but will it be backwards code compatible?
Yeah, that a little weird. Turns out 2.x is an ancient dead branch. New development will become 1.5. I don't know for sure about backwards compatibility, but lurking on their mailing list makes me think they'll do that. They're super helpful and user-focused.
 
After playing with examples and reading coursework I tackled it. FLTK without the crutches.
Thanks Jose for all the encouragment.

Code:
#include <stdlib.h>
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>

void b1cb(Fl_Widget *, void *) {
  system("foxtrotgps &");
  fflush(stdout);
}
void b2cb(Fl_Widget *, void *) {
  system("xcalc");
}
void b3cb(Fl_Widget *, void *) {
  system("xclock &");
}
void b4cb(Fl_Widget *, void *) {
  system("xterm && exit");
}
void b5cb(Fl_Widget *, void *) {
  system("shutdown -p now && exit");
}

int main(int argc, char ** argv) {
  Fl_Window *window = new Fl_Window(480,720);
  Fl_Box side(0, 0, 30, 720);
  side.color(FL_CYAN);
  side.box(FL_FLAT_BOX);

  Fl_Button *b1 = new Fl_Button(40, 10, 430, 130, "Mapping");
  b1->callback(b1cb,0);

  Fl_Button *b2 = new Fl_Button(40,140, 430, 130, "Music");
  b2->callback(b2cb,0);

  Fl_Button *b3 = new Fl_Button(40,270, 430, 130, "Browser");
  b3->callback(b3cb,0);

  Fl_Button *b4 = new Fl_Button(40,400, 430, 130, "Video");
  b4->callback(b4cb,0);

  Fl_Button *b5 = new Fl_Button(40,580, 430, 130, "Shutdown");
  b5->callback(b5cb,0);

  window->end();
  window->show(argc,argv);
  return Fl::run();
}
fltk-config --compile launch.cpp
I used the same exact layout from FL_Flow above so no need for a picture.
 
So step two is make it independent.

Work on button text and programs that run. Make them variables. Easier to reuse code for other projects. GPIO output'er maybe.

Sub Menus maybe.

Still trying to figure out what I want to do. Process die and spawn the app with button press or simply fade to background.
Maybe a hotkey to respawn it.
 
Decent example of font handling here
It turns out the magic feature here is called labelsize. I also colored Shutdown in a RED.

Code:
  Fl_Button *b5 = new Fl_Button(40,585, 430, 130, "Shutdown");
  b5->labelsize(30);
  b5->labelcolor(fl_rgb_color(162, 60, 20));
  b5->callback(b5cb,0);
 
This might be a dumb question but do we have support for compiling both:

Pre C++11 solution
and
C++11 solution

With base c++ compiler? Where is our C++ in regards to standards versions?
 
This might be a dumb question but do we have support for compiling both:

Pre C++11 solution
and
C++11 solution

With base c++ compiler? Where is our C++ in regards to standards versions?
Our base clang is pretty good with standards (we were a little behind when using our old 4.x gcc). You can specify via the -std=c++11 flag. You can find a list of supported standards in the manpage. 17 is supported and that is where the "cutting edge" in industry seems to be.

That said since, FLTK supports even C++98 and smart pointers were in 11 (tr1), going higher is often just adding a needless dependency to the project unless it truly makes the development experience magical :)
 
OK another FLTK related question.

How can I display FreeBSD sysctl values in a box? For example: sysctl dev.cpu.0.temperature
FL_Output ??
FL_Text_Display

How to read the sysctl?
popen method?

For this example a simple CPU temp display. No refresh. Just static.


I also want to display GPIO numerical values in a FLTK window. Lets say onewire temperatures.

I could pass it this way:

system(gpioctl -lv -f /dev/gpioc3/gpio06)

But it reports back to the console. Not in a FLTK window.

Is that the difference between the popen() method versus system()? There is also exec() and I don't know what I should be using.

This tuturial was quite enjoyable.
 
FLTK, C++ and C in one file. That will be a learning experience.
So the c++ compiler understands C.

sysctlbyname I have used before with much help on onewire rrd graphing program.

So really programmatically I can use both again within my FLTK projects.. libgpio and sysctlbyname.

That sounds like a start. Probably too complex but its something I need to learn.
 
Well I have been playing with FLUID. It seems the code is different..

Code:
// generated by Fast Light User Interface Designer (fluid) version 1.0310

#include "textbox.h"

Fl_Double_Window* make_window() {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = new Fl_Double_Window(100, 100);
    w = o; if (w) {/* empty */}
    { new Fl_Output(25, 25, 55, 55);
    } // Fl_Output* o
    o->end();
  } // Fl_Double_Window* o
  return w;
Some things like Double_Window compared to just FL_Window are different. I don't see that in most examples.
FLUID also writes header file instead of at top of code. Just learning so just one file better for now.
cmake is nightmare.

I scrounged some sysctl code from GIST but I need to fix it for microKelvin (or whatever is going on). Just something to get started.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/sysctl.h>

int main(void) {
  u_int val[3] = {0};
  char buf[256] = {""};
  size_t len = sizeof(val);
  size_t len2 = sizeof(buf);
  if (0 != (sysctlbyname("dev.cpu.0.temperature", &val, &len, NULL, 0))) {
    if (0 != (sysctlbyname("dev.aibs.0.%desc", buf, &len2, NULL, 0))) {
      puts("failed!");
      return EXIT_FAILURE;
    }
  }
  if (0 != (strcmp(buf, "")))
    printf("%s\n", buf);
  else
    printf("%lu\n", (unsigned long)val[0]);

  return EXIT_SUCCESS;
}
 
It is embarrassing to see the same question asked a different way over and over again when searching the forum.


If it makes any difference I am much further along than two years ago.... I have a path. I must learn three programming languages. FLTK, C++ and C
 
So if I am reading things right to have C code and C++ code used you use separate code files and compile the 'o' files individual and then link them? Using exernal() in the c++.
Am I on the right track?
 
On the libgpio side I have this non-working code I am working on. Just a stand in for now.

getconfig.c
Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <libgpio.h>
#include <strings.h>
#include <sys/types.h>
#include <err.h>

int
main(int argc, char *argv[])

{
      gpio_config_t cfg;
       cfg.g_pin = 32;
       gpio_pin_config(handle, &cfg);

};
Why don't this compile. Its straight from the handbook for libgpio.
cc getconfig.c -lgpio -o getconfig

How do I fit this square peg into the C++ hole?
 
Back
Top