Embedded C GUI for Raspberry PI & Arduino In developing my custom telemetry robot controller with a touchscreen TFT LCD display, I needed to design a GUI library in C to support menus, buttons, text and images. GUIslice is a lightweight C library intended to work with the Raspberry Pi and Arduino. GUIslice Touchscreen GUI in C Custom Telemetry Menu Screen GUIslice C Library Features GUIslice provides an open source (free), lightweight platform-independent library that enables embedded GUI menus and displays in C. Processor Hardware Support: This library was intended for use on the Raspberry Pi and Arduino, but also runs on ARM Cortex M0 (Adafruit Feather M0). It can easily be compiled for other targets as well. Display Hardware Support: GUIslice can drive a wide range of displays from 2" TFT LCD displays using a SPI interface (such as PiTFT), parallel, OLED to HDMI. It also supports direct LINUX framebuffer graphics (via SDL1.2). See latest testing for compatibility. Touchscreen Support: To facilitate embedded touchscreen GUI designs, optional support is provided for resistive and capacitive touch devices. Lightweight GUI library: Dependencies for LINUX: SDL 1.2 (optional TTF_Font) or SDL2 -- no need for Python or XWindows / X11! Dependencies for Arduino: Adafruit-GFX, graphics lib (eg. ILI9341) and optional touch lib (eg. STMPE610). Enhancements to support GUI elements in Flash memory for RAM-constained devices such as Arduino (ATmega328) Written in pure C with no dynamic memory allocation within GUIslice Graphic elements: Buttons, Checkboxes, Radio buttons, Text areas, Progress bars, Bitmap images, basic drawing primitives, etc. Both text and image-based buttons are supported. Event mechanism with callbacks. Extensions for custom widget creation. Window paging: Support for multiple display pages and switching between them. Font support: For LINUX: Wide variety of TrueType fonts supported via TTF_Font. Permissive License: GUIslice has been released as open source with the very permissive MIT License. It is free to use for personal or commercial use. Download GUIslice The source code is now available in the following GitHub repository: Repository: GUIslice for Raspberry Pi & Arduino (GitHub) (previously: microSDL) git clone https://github.com/ImpulseAdventure/GUIslice Documentation: GUIslice wiki API Reference Guide: please download GUIslice_ref.pdf from the latest release Direct download link: GUIslice download (.ZIP) Email support: I gladly welcome any code contributions (pull requests), feedback or suggestions for new features / hardware support! Screenshots of Embedded GUI applications Raspberry Pi touchscreen GUI Touchscreen GUI for Arduino Examples of GUIslice on Arduino Please see the GUIslice for Arduino page for more details Installation of GUIslice on Raspberry Pi Please see the Installation guide for Raspberry Pi Latest Updates The following is a brief summary of features or changes have been made recently to the GUIslice library. For more details, please see the detailed release notes. v0.9: Add radial gauges, scrolling textbox / terminal window, scrolling graph / plot. Add filled triangles, quads. Support for polar coordinate line drawing. Fixed-point LUT emulation for trig functions on Arduino. v0.8.7: Add filled circle primitive. Enhancements to SDL touch & mouse handling. v0.8.6: Touch controls more responsive. Fixes for Beaglebone Black. v0.8.5: Add support for ST7735 (eg. 0.96" OLED 128x64) & SSD1306 (eg. 1.44" SPI 128x128) v0.8.4: Add support for FT6206 (capacitive touch) on Arduino. Add line primitive. Touch axis swap and flip for Arduino. Add detailed config guide. How to use GUIslice The GUIslice library includes a number of example programs demonstrating basic functionality as well as more complex drawing callbacks and compound elements. For more details, please refer to the GUIslice wiki. Example touchscreen C GUI code with Button and Event Loop The following program displays an image-based button and tracks any touch-presses, highlighting the button while hovering on it. Releasing the button ends the program through a callback. #include "GUIslice.h" #include "GUIslice_drv.h" // Instantiate the GUI #define MAX_PAGE 1 #define MAX_ELEM_PG_MAIN 5 gslc_tsGui m_gui; gslc_tsDriver m_drv; gslc_tsPage m_asPage[MAX_PAGE]; gslc_tsElem m_asPageElem[MAX_ELEM_PG_MAIN]; bool m_bQuit = false; // Button callback bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY) { if (eTouch == GSLC_TOUCH_UP_IN) { m_bQuit = true; } return true; } int main( int argc, char* args[] ) { gslc_tsElem* pElem = NULL; // Initialize gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)); // Build the main page gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPageElem,MAX_ELEM_PG_MAIN); // Background flat color gslc_SetBkgndColor(&m_gui,GSLC_COL_GRAY_DK2); // Create background box pElem = gslc_ElemCreateBox(&m_gui,E_ELEM_BOX,E_PG_MAIN,(gslc_tsRect){10,50,300,150}); gslc_ElemSetCol(pElem,GSLC_COL_WHITE,GSLC_COL_BLACK,GSLC_COL_BLACK); // Create Quit button with image label and callback pElem = gslc_ElemCreateBtnImg(&m_gui,E_ELEM_BTN_QUIT,E_PG_MAIN,(gslc_tsRect){258,70,32,32}, gslc_GetImageFromFile("btn-exit.bmp",GSLC_IMGREF_FMT_BMP16), gslc_GetImageFromFile("btn-exit-sel.bmp",GSLC_IMGREF_FMT_BMP16), &CbBtnQuit); // Start up display on main page gslc_SetPageCur(&m_gui,E_PG_MAIN); // Main event loop m_bQuit = false; while (!m_bQuit) { // Update GUI gslc_Update(&m_gui); } // Close down display gslc_Quit(&m_gui); return 0; } Example Code Example code is provided in the GUIslice repository in the following subdirectories: LINUX: /tests/ Arduino sketches: /arduino/ Supported Devices The following CPUs, boards and hardware devices have been tested to work with GUIslice: Processors Raspberry Pi / Pi 2 / Pi 3 Arduino (see GUIslice for Arduino) Arduino Pro Mini ATmega328P / Arduino UNO R3 ATmega2560 ARM Cortex Cortex M0 (Adafruit Feather M0 - ATSAMD21) BeagleBone Black AM335x 1GHz ARM Cortex-A8 Tested soon: STM32 (STM32F103C8T6) ESP8266 (ESP-12) Displays Adafruit 2.2" 18-bit color TFT LCD with microSD card breakout Adafruit 2.8" TFT Touch shield for Arduino (resistive screen) PiTFT Plus 2.8" TFT 320x240 + Capacitive Touchscreen for Raspberry Pi PiTFT 3.5" TFT 480x320 + Resistive Touchscreen for Raspberry Pi Waveshare 3.5" 320x480 TFT LCD 0.96" SPI 128x64 OLED LCD 1.44" 128x128 SPI TFT LCD Tested soon: 2.4" SPI TFT Serial LCD Touch Panel 1.8" SPI TFT 128x160 Graphic driver chips ILI9341 / ILI9340 ST7735 SSD1306 XPT2046 (via SDL) HX8357-D (via SDL) Touch driver chips STMPE610 FT6206 FT6X06 (via SDL) Tested soon: ADS7843

Embedded C GUI for Raspberry PI & Arduino

In developing my custom telemetry robot controller with a touchscreen TFT LCD display, I needed to design a GUI library in C to support menus, buttons, text and images. GUIslice is a lightweight C library intended to work with the Raspberry Pi and Arduino.
GUIslice Touchscreen GUI in C
Custom Telemetry Menu Screen

GUIslice C Library Features

GUIslice provides an open source (free), lightweight platform-independent library that enables embedded GUI menus and displays in C.
  • Processor Hardware Support: This library was intended for use on the Raspberry Pi and Arduino, but also runs on ARM Cortex M0 (Adafruit Feather M0). It can easily be compiled for other targets as well.
  • Display Hardware Support: GUIslice can drive a wide range of displays from 2" TFT LCD displays using a SPI interface (such as PiTFT), parallel, OLED to HDMI. It also supports direct LINUX framebuffer graphics (via SDL1.2). See latest testing for compatibility.
  • Touchscreen Support: To facilitate embedded touchscreen GUI designs, optional support is provided for resistive and capacitive touch devices.
  • Lightweight GUI library:
    • Dependencies for LINUXSDL 1.2 (optional TTF_Font) or SDL2 -- no need for Python or XWindows / X11!
    • Dependencies for ArduinoAdafruit-GFX, graphics lib (eg. ILI9341) and optional touch lib (eg. STMPE610).
    • Enhancements to support GUI elements in Flash memory for RAM-constained devices such as Arduino (ATmega328)
    • Written in pure C with no dynamic memory allocation within GUIslice
  • Graphic elements: Buttons, Checkboxes, Radio buttons, Text areas, Progress bars, Bitmap images, basic drawing primitives, etc. Both text and image-based buttons are supported. Event mechanism with callbacks. Extensions for custom widget creation.
  • Window paging: Support for multiple display pages and switching between them.
  • Font support: For LINUX: Wide variety of TrueType fonts supported via TTF_Font.
  • Permissive License: GUIslice has been released as open source with the very permissive MIT License. It is free to use for personal or commercial use.

Download GUIslice

The source code is now available in the following GitHub repository:
I gladly welcome any code contributions (pull requests), feedback or suggestions for new features / hardware support!

Screenshots of Embedded GUI applications

Raspberry Pi touchscreen GUI Touchscreen GUI for Arduino

Examples of GUIslice on Arduino

Please see the GUIslice for Arduino page for more details

Installation of GUIslice on Raspberry Pi

Latest Updates

The following is a brief summary of features or changes have been made recently to the GUIslice library. For more details, please see the detailed release notes.
  • v0.9: Add radial gauges, scrolling textbox / terminal window, scrolling graph / plot. Add filled triangles, quads. Support for polar coordinate line drawing. Fixed-point LUT emulation for trig functions on Arduino.
  • v0.8.7: Add filled circle primitive. Enhancements to SDL touch & mouse handling.
  • v0.8.6: Touch controls more responsive. Fixes for Beaglebone Black.
  • v0.8.5: Add support for ST7735 (eg. 0.96" OLED 128x64) & SSD1306 (eg. 1.44" SPI 128x128)
  • v0.8.4: Add support for FT6206 (capacitive touch) on Arduino. Add line primitive. Touch axis swap and flip for Arduino. Add detailed config guide.

How to use GUIslice

The GUIslice library includes a number of example programs demonstrating basic functionality as well as more complex drawing callbacks and compound elements. For more details, please refer to the GUIslice wiki.

Example touchscreen C GUI code with Button and Event Loop

The following program displays an image-based button and tracks any touch-presses, highlighting the button while hovering on it. Releasing the button ends the program through a callback.
#include "GUIslice.h"
#include "GUIslice_drv.h"

// Instantiate the GUI
#define MAX_PAGE            1
#define MAX_ELEM_PG_MAIN    5
gslc_tsGui                  m_gui;
gslc_tsDriver               m_drv;
gslc_tsPage                 m_asPage[MAX_PAGE];
gslc_tsElem                 m_asPageElem[MAX_ELEM_PG_MAIN];

bool m_bQuit = false;

// Button callback
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
{
  if (eTouch == GSLC_TOUCH_UP_IN) {
    m_bQuit = true;
  }
  return true;
}


int main( int argc, char* args[] )
{
  gslc_tsElem*  pElem = NULL;

  // Initialize
  gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0));
  
  // Build the main page
  gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPageElem,MAX_ELEM_PG_MAIN);  
  
  // Background flat color
  gslc_SetBkgndColor(&m_gui,GSLC_COL_GRAY_DK2);

  // Create background box
  pElem = gslc_ElemCreateBox(&m_gui,E_ELEM_BOX,E_PG_MAIN,(gslc_tsRect){10,50,300,150});
  gslc_ElemSetCol(pElem,GSLC_COL_WHITE,GSLC_COL_BLACK,GSLC_COL_BLACK);

  // Create Quit button with image label and callback
  pElem = gslc_ElemCreateBtnImg(&m_gui,E_ELEM_BTN_QUIT,E_PG_MAIN,(gslc_tsRect){258,70,32,32},
          gslc_GetImageFromFile("btn-exit.bmp",GSLC_IMGREF_FMT_BMP16),
          gslc_GetImageFromFile("btn-exit-sel.bmp",GSLC_IMGREF_FMT_BMP16),
          &CbBtnQuit);

  // Start up display on main page
  gslc_SetPageCur(&m_gui,E_PG_MAIN);

  // Main event loop
  m_bQuit = false;
  while (!m_bQuit) {
    // Update GUI
    gslc_Update(&m_gui);
  }

  // Close down display
  gslc_Quit(&m_gui);
  return 0;
}

Example Code

Example code is provided in the GUIslice repository in the following subdirectories:
  • LINUX: /tests/
  • Arduino sketches: /arduino/

Supported Devices

The following CPUs, boards and hardware devices have been tested to work with GUIslice:
  • Processors
  • Displays
    • Adafruit 2.2" 18-bit color TFT LCD with microSD card breakout
    • Adafruit 2.8" TFT Touch shield for Arduino (resistive screen)
    • PiTFT Plus 2.8" TFT 320x240 + Capacitive Touchscreen for Raspberry Pi
    • PiTFT 3.5" TFT 480x320 + Resistive Touchscreen for Raspberry Pi
    • Waveshare 3.5" 320x480 TFT LCD
    • 0.96" SPI 128x64 OLED LCD
    • 1.44" 128x128 SPI TFT LCD
    • Tested soon:
      • 2.4" SPI TFT Serial LCD Touch Panel
      • 1.8" SPI TFT 128x160
  • Graphic driver chips
    • ILI9341 / ILI9340
    • ST7735
    • SSD1306
    • XPT2046 (via SDL)
    • HX8357-D (via SDL)
  • Touch driver chips
    • STMPE610
    • FT6206
    • FT6X06 (via SDL)
    • Tested soon:
      • ADS7843
SHARE

Oscar perez

Arquitecto especialista en gestion de proyectos si necesitas desarrollar algun proyecto en Bogota contactame en el 3006825874 o visita mi pagina en www.arquitectobogota.tk

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comentarios:

Publicar un comentario