Touch UI example


#1

Anyone have an example of a Touch/Graphical UI where someone can click on a button drawn on the screen, and fire off some code. This would be a fun extension to the T-Deck or any touch enabled display.

I’m thinking a tutorial for a remote control where you click on buttons and it fires off emails/wifi api calls/ or logging of sensor data might be fun. Or list out mp3s on your sdcard and play them. I got mp3s playing on the t-deck in the past, but the library wasn’t compatible with the one that uLisp uses. If memory served one used C++ style calls while the other was C.


#2

There is an example of a set of functions for working with the touch panel:

https://github.com/molnija2/uLisp-touchscreen-example


#3

Some headers and libraries need to be included.

#if defined(ESP32_2432S028R)

#if defined(touchscreen_support)

#include <SPI.h>
#include <TFT_Touch.h> // Touchscreen driver chip

#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33
TFT_Touch tft_touch = TFT_Touch(XPT2046_CS, XPT2046_CLK, XPT2046_MOSI, XPT2046_MISO) ;

#endif // TOUCHSCREEN_DRIVERS
#endif // ESP32_2432S028R


#4

Oh, this is great!

It would be nice to add a library of common UI elements: Buttons (with a parameter of button text, and what function to fire off when pressed), a slider, radio button, check box, and perhaps some charts and graphs.


#5

Btw I got the touchscreen working on the t-deck, see this post for details.


#6

hasnOlife, thank you very much for the useful idea!


#7

Dear friends, good day!
I am trying to write a UI library with a touchscreen, using a simple object system proposed by David. It is planned to make it possible to automatically arrange the elements of the dialog in the window. Now the buttons and other elements are arranged automatically horizontally by line or by several lines. So far, only the message output has been written. (There was little time)

(Message '(string1 string2...) '(button1 button2 ...))

I wanted to add a function (kbhit) to check the key press.

object *fn_kbhit (object *args, object *env) {
  (void) env;

  if(Serial.available()>0) return tee ;

  return  nil;
}

const char string_kbhit[] = "kbhit" ;
const char doc_kbhit[] = "(kbhit) - test whether any keyboard keys
 hits.\n"
" Returns t if any char symbols are available"
"and otherwise returns nil.";

But for some reason it does not work normally. Perhaps UART has a built-in FIFO. So far I have not found a way to bypass this.

But even without this, the library works. The library and an example message on github.
https://github.com/molnija2/uLisp-touchscreen-example

For everyone who wants to, you can use it by adding your own functions. Perhaps you will have some ideas.


#8

Dear friends, good day

I guess what needs to be done for the function (kbhit) to work. Probably the ready flag is reset immediately after it is polled. I changed the code:

object *fn_kbhit (object *args, object *env) {
  (void) env;
  if(Serial.available()>0)  {
    LastChar = Serial.read();
    return tee ;
  }
  return  nil;
}

But so far I have no way to check it because the Arduino environment does not work after the update.
I also managed to find an analogue of this function in Common Lisp:

(listen [stream])

It is described in


and
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node195.html#SECTION002621000000000000000

The source on githab has been corrected by me for micro lisp 4.7. I plan to whip up horizontal and vertical scrollbars.

A lot of thanks to David for very useful backtrace system in the 4.7 version.


#9

Managed to debug (kbhit). It now looks like this

object *fn_kbhit (object *args, object *env) {
  (void) env;
  if(LastChar>0) return tee ;
  delay(200);
  if(Serial.available()>0)  {
      LastChar = Serial.read();
      return tee ;
  }
  return  nil;
}

I had to set the delay to 200 ms.

The dialog accepts both the touchscreen and the keyboard at the same time. The touchscreen allows you to press buttons, but you can move the focus (gray rectangle) with emacs arrows or “tab”, and select the desired buttons by pressing “enter”.
A full test was only on version 4.6 so far. Version 4.7 needs time to adapt it to the screen and touchscreen of my device. All codes are now improved on github for anyone who might find it useful.


#10

What is tee and where is it defined? I don’t see it anywhere in your github repo example.


#11

Nevermind, I believe it’s uLisp’s true.


#12

nanomonkey, excuse me, it’s really ulisp’s “true”