├── Pictures ├── 0aabb3b8-45ac-4089-8034-bd3b26065207.jpg ├── Image.PNG ├── Text box.PNG ├── af27046c-2f33-44af-a220-e1cf2456dcb5.jpg ├── fa314fcf-e02c-4a30-bb53-9c6628b62733.jpg ├── main menu.PNG ├── menu.jpg ├── modal dialog.PNG ├── paint.jpg └── plot.jpg ├── README.md ├── examples ├── current-sensor │ ├── .gitignore │ ├── User_Setup.h │ ├── current-sensor.ino │ ├── data │ │ ├── about.bmp │ │ ├── btn.bmp │ │ ├── cross.bmp │ │ ├── cross16px.bmp │ │ ├── folder.bmp │ │ ├── label.bmp │ │ ├── magic.bmp │ │ ├── msg.bmp │ │ ├── no.bmp │ │ ├── ok.bmp │ │ ├── ok59.bmp │ │ └── pic.bmp │ ├── emGUIGlue.cpp │ ├── emGUIGlue.h │ └── src │ │ ├── FIR-filter-class │ │ ├── README │ │ ├── filt.cpp │ │ └── filt.h │ │ ├── GUI │ │ ├── GUI.cpp │ │ ├── GUI.h │ │ ├── WindowMain.h │ │ ├── WindowPack.cpp │ │ ├── WindowPack.h │ │ ├── WindowPaint.h │ │ └── WindowPlot.h │ │ ├── TFT │ │ ├── Fonts │ │ │ ├── Custom │ │ │ │ ├── Orbitron_Light_24.h │ │ │ │ ├── Orbitron_Light_32.h │ │ │ │ ├── Roboto_Thin_24.h │ │ │ │ ├── Satisfy_24.h │ │ │ │ └── Yellowtail_32.h │ │ │ ├── Font16.c │ │ │ ├── Font16.h │ │ │ ├── Font32rle.c │ │ │ ├── Font32rle.h │ │ │ ├── Font64rle.c │ │ │ ├── Font64rle.h │ │ │ ├── Font72rle.c │ │ │ ├── Font72rle.h │ │ │ ├── Font7srle.c │ │ │ ├── Font7srle.h │ │ │ ├── GFXFF │ │ │ │ ├── FreeMono12pt7b.h │ │ │ │ ├── FreeMono18pt7b.h │ │ │ │ ├── FreeMono24pt7b.h │ │ │ │ ├── FreeMono9pt7b.h │ │ │ │ ├── FreeMonoBold12pt7b.h │ │ │ │ ├── FreeMonoBold18pt7b.h │ │ │ │ ├── FreeMonoBold24pt7b.h │ │ │ │ ├── FreeMonoBold9pt7b.h │ │ │ │ ├── FreeMonoBoldOblique12pt7b.h │ │ │ │ ├── FreeMonoBoldOblique18pt7b.h │ │ │ │ ├── FreeMonoBoldOblique24pt7b.h │ │ │ │ ├── FreeMonoBoldOblique9pt7b.h │ │ │ │ ├── FreeMonoOblique12pt7b.h │ │ │ │ ├── FreeMonoOblique18pt7b.h │ │ │ │ ├── FreeMonoOblique24pt7b.h │ │ │ │ ├── FreeMonoOblique9pt7b.h │ │ │ │ ├── FreeSans12pt7b.h │ │ │ │ ├── FreeSans18pt7b.h │ │ │ │ ├── FreeSans24pt7b.h │ │ │ │ ├── FreeSans9pt7b.h │ │ │ │ ├── FreeSansBold12pt7b.h │ │ │ │ ├── FreeSansBold18pt7b.h │ │ │ │ ├── FreeSansBold24pt7b.h │ │ │ │ ├── FreeSansBold9pt7b.h │ │ │ │ ├── FreeSansBoldOblique12pt7b.h │ │ │ │ ├── FreeSansBoldOblique18pt7b.h │ │ │ │ ├── FreeSansBoldOblique24pt7b.h │ │ │ │ ├── FreeSansBoldOblique9pt7b.h │ │ │ │ ├── FreeSansOblique12pt7b.h │ │ │ │ ├── FreeSansOblique18pt7b.h │ │ │ │ ├── FreeSansOblique24pt7b.h │ │ │ │ ├── FreeSansOblique9pt7b.h │ │ │ │ ├── FreeSerif12pt7b.h │ │ │ │ ├── FreeSerif18pt7b.h │ │ │ │ ├── FreeSerif24pt7b.h │ │ │ │ ├── FreeSerif9pt7b.h │ │ │ │ ├── FreeSerifBold12pt7b.h │ │ │ │ ├── FreeSerifBold18pt7b.h │ │ │ │ ├── FreeSerifBold24pt7b.h │ │ │ │ ├── FreeSerifBold9pt7b.h │ │ │ │ ├── FreeSerifBoldItalic12pt7b.h │ │ │ │ ├── FreeSerifBoldItalic18pt7b.h │ │ │ │ ├── FreeSerifBoldItalic24pt7b.h │ │ │ │ ├── FreeSerifBoldItalic9pt7b.h │ │ │ │ ├── FreeSerifItalic12pt7b.h │ │ │ │ ├── FreeSerifItalic18pt7b.h │ │ │ │ ├── FreeSerifItalic24pt7b.h │ │ │ │ ├── FreeSerifItalic9pt7b.h │ │ │ │ ├── TomThumb.h │ │ │ │ ├── gfxfont.h │ │ │ │ ├── license.txt │ │ │ │ └── print.txt │ │ │ ├── TrueType │ │ │ │ └── Not_yet_supported.txt │ │ │ └── glcdfont.c │ │ ├── TFT_ILI9341_ESP.cpp │ │ └── TFT_ILI9341_ESP.h │ │ ├── TouchWrapper │ │ ├── TouchWrapper.cpp │ │ └── TouchWrapper.h │ │ └── UTF8-fonts │ │ ├── MyriadPro_Bold9pt8b.h │ │ ├── MyriadPro_Regular12pt8b.h │ │ ├── MyriadPro_Regular24pt8b.h │ │ ├── MyriadPro_Regular9pt8b.h │ │ ├── Roboto-Bold.ttf.9pt.RUS.h │ │ ├── Roboto-Bold.ttf.9pt.h │ │ ├── Roboto-Regular.ttf.12pt.RUS.h │ │ ├── Roboto-Regular.ttf.12pt.h │ │ ├── Roboto-Regular.ttf.24pt.RUS.h │ │ ├── Roboto-Regular.ttf.24pt.h │ │ ├── Roboto-Regular.ttf.9pt.RUS.h │ │ ├── Roboto-Regular.ttf.9pt.h │ │ └── customfonts.h ├── demo-menu-due │ └── demo-menu-due.ino └── demo-menu │ ├── GUI.cpp │ ├── GUI.h │ ├── User_Setup.h │ ├── data │ ├── about.bmp │ ├── folder.bmp │ ├── label.bmp │ ├── magic.bmp │ ├── no.bmp │ ├── ok.bmp │ └── pic.bmp │ ├── demo-menu.ino │ ├── emGUIGlue.cpp │ ├── emGUIGlue.h │ └── src │ └── TFT │ ├── Fonts │ ├── Custom │ │ ├── Orbitron_Light_24.h │ │ ├── Orbitron_Light_32.h │ │ ├── Roboto_Thin_24.h │ │ ├── Satisfy_24.h │ │ └── Yellowtail_32.h │ ├── Font16.c │ ├── Font16.h │ ├── Font32rle.c │ ├── Font32rle.h │ ├── Font64rle.c │ ├── Font64rle.h │ ├── Font72rle.c │ ├── Font72rle.h │ ├── Font7srle.c │ ├── Font7srle.h │ ├── GFXFF │ │ ├── FreeMono12pt7b.h │ │ ├── FreeMono18pt7b.h │ │ ├── FreeMono24pt7b.h │ │ ├── FreeMono9pt7b.h │ │ ├── FreeMonoBold12pt7b.h │ │ ├── FreeMonoBold18pt7b.h │ │ ├── FreeMonoBold24pt7b.h │ │ ├── FreeMonoBold9pt7b.h │ │ ├── FreeMonoBoldOblique12pt7b.h │ │ ├── FreeMonoBoldOblique18pt7b.h │ │ ├── FreeMonoBoldOblique24pt7b.h │ │ ├── FreeMonoBoldOblique9pt7b.h │ │ ├── FreeMonoOblique12pt7b.h │ │ ├── FreeMonoOblique18pt7b.h │ │ ├── FreeMonoOblique24pt7b.h │ │ ├── FreeMonoOblique9pt7b.h │ │ ├── FreeSans12pt7b.h │ │ ├── FreeSans18pt7b.h │ │ ├── FreeSans24pt7b.h │ │ ├── FreeSans9pt7b.h │ │ ├── FreeSansBold12pt7b.h │ │ ├── FreeSansBold18pt7b.h │ │ ├── FreeSansBold24pt7b.h │ │ ├── FreeSansBold9pt7b.h │ │ ├── FreeSansBoldOblique12pt7b.h │ │ ├── FreeSansBoldOblique18pt7b.h │ │ ├── FreeSansBoldOblique24pt7b.h │ │ ├── FreeSansBoldOblique9pt7b.h │ │ ├── FreeSansOblique12pt7b.h │ │ ├── FreeSansOblique18pt7b.h │ │ ├── FreeSansOblique24pt7b.h │ │ ├── FreeSansOblique9pt7b.h │ │ ├── FreeSerif12pt7b.h │ │ ├── FreeSerif18pt7b.h │ │ ├── FreeSerif24pt7b.h │ │ ├── FreeSerif9pt7b.h │ │ ├── FreeSerifBold12pt7b.h │ │ ├── FreeSerifBold18pt7b.h │ │ ├── FreeSerifBold24pt7b.h │ │ ├── FreeSerifBold9pt7b.h │ │ ├── FreeSerifBoldItalic12pt7b.h │ │ ├── FreeSerifBoldItalic18pt7b.h │ │ ├── FreeSerifBoldItalic24pt7b.h │ │ ├── FreeSerifBoldItalic9pt7b.h │ │ ├── FreeSerifItalic12pt7b.h │ │ ├── FreeSerifItalic18pt7b.h │ │ ├── FreeSerifItalic24pt7b.h │ │ ├── FreeSerifItalic9pt7b.h │ │ ├── TomThumb.h │ │ ├── gfxfont.h │ │ ├── license.txt │ │ └── print.txt │ ├── TrueType │ │ └── Not_yet_supported.txt │ └── glcdfont.c │ ├── SPI9.cpp │ ├── SPI9.h │ ├── TFT_ILI9341_ESP.cpp │ └── TFT_ILI9341_ESP.h ├── keywords.txt ├── library.properties └── src ├── emGUI.h ├── emGUI ├── .gitignore ├── Changelog.md ├── Draw │ ├── Draw.c │ └── Draw.h ├── Readme.md ├── Widgets │ ├── Button.c │ ├── Button.h │ ├── Console.c │ ├── Console.h │ ├── KeyBoard.c │ ├── KeyBoard.h │ ├── KeyRow.c │ ├── KeyRow.h │ ├── Label.c │ ├── Label.h │ ├── ModalDialog.c │ ├── ModalDialog.h │ ├── PictureStack.c │ ├── PictureStack.h │ ├── Plot.c │ ├── Plot.h │ ├── ProgressBar.c │ ├── ProgressBar.h │ ├── StatusBar.c │ ├── StatusBar.h │ ├── Widget.c │ ├── Widget.h │ ├── Window.c │ ├── Window.h │ ├── WindowManager.c │ └── WindowManager.h ├── cpp │ ├── Button.hpp │ ├── DisposableWindow.hpp │ ├── Label.hpp │ ├── PictureStack.hpp │ ├── Widget.hpp │ └── WindowHeader.hpp ├── emGUI.h ├── emGUI.hpp └── options │ ├── opts.c │ └── opts.h ├── emGUI_port_opts.h ├── gfxfont.h └── glcdfont.c /Pictures/0aabb3b8-45ac-4089-8034-bd3b26065207.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/0aabb3b8-45ac-4089-8034-bd3b26065207.jpg -------------------------------------------------------------------------------- /Pictures/Image.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/Image.PNG -------------------------------------------------------------------------------- /Pictures/Text box.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/Text box.PNG -------------------------------------------------------------------------------- /Pictures/af27046c-2f33-44af-a220-e1cf2456dcb5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/af27046c-2f33-44af-a220-e1cf2456dcb5.jpg -------------------------------------------------------------------------------- /Pictures/fa314fcf-e02c-4a30-bb53-9c6628b62733.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/fa314fcf-e02c-4a30-bb53-9c6628b62733.jpg -------------------------------------------------------------------------------- /Pictures/main menu.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/main menu.PNG -------------------------------------------------------------------------------- /Pictures/menu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/menu.jpg -------------------------------------------------------------------------------- /Pictures/modal dialog.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/modal dialog.PNG -------------------------------------------------------------------------------- /Pictures/paint.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/paint.jpg -------------------------------------------------------------------------------- /Pictures/plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/Pictures/plot.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | emGUI v1.0.0 2 | ===== 3 | 4 | C GUI Library for Arduino. 5 | 6 | Some photos 7 | 8 | 9 | ![Main menu](Pictures/fa314fcf-e02c-4a30-bb53-9c6628b62733.jpg)![Another photo](Pictures/af27046c-2f33-44af-a220-e1cf2456dcb5.jpg) 10 | 11 | 12 | This lib could work not only with Arduino, so we made an [example with visual studio](https://github.com/libEmGUI/emGUI-example) (will be submited soon) 13 | ![Example on PC: main menu](Pictures/main%20menu.PNG)![Example on PC: modal dialog](Pictures/modal%20dialog.PNG)![Example on PC: Big colorful image](Pictures/Image.PNG)![Example on PC: Multiline textbox with left allign](Pictures/Text%20box.PNG) 14 | 15 | // Russian 16 | 17 | Библиотека делает ГУЙ. Главная сущность в ней - виджет (Widget). 18 | Это базовая струткура, отражающая логическую единицу интерфейса, содержащая такую информацию 19 | как расположение, размер, обработчик дейсвтия при нажатии. Она служит предком для 20 | всех остальных сущностей: Window, Label, Button, StatusBar и т.д. 21 | (Вы можете описать свои сущности, если в этом есть необходимость) 22 | 23 | Виджеты вкладываются друг в друга, образуя иерархию. Главным виджетом выступает 24 | едиснвтенный экземпляр структуры типа Interface, который заполняется окнами (Windows) 25 | Окна создаются в момент вызыва функции `pxWindowCreate(eWindow)`. Функция принимает в качестве 26 | аргумента название окна (типа enum). Далее окно становится невидимм и вызывается функцией 27 | `vInterfaceOpenWindow(eWindow)` 28 | 29 | В библиотеке реализован стек окон. В разумных пределах можно открывать сколько 30 | угодно окон и не бояться за порядок их откртия/закрытя 31 | 32 | Вызов функции 33 | 34 | `bool bInterfaceCheckTouchScreenEvent(xTouchEvent *pxTouchScreenEv);` 35 | 36 | Приведет к вызову обработчика, который вы можете назначить на любой виджет. 37 | 38 | В библиотеке реализовано закрытие активного окна при нажатии на крестик в статусбаре. 39 | Обработчик может задаваться как в конструкторе, так и отдельной функцией (подробнее смотрите в исходном коде к библиотеке) 40 | 41 | Getting started 42 | 43 | Для начала работы необходимо определить виртуальные функции отрисовки примитовов: 44 | - Прямоугольник 45 | - Вертикальная линия 46 | - Горизонтальная линия 47 | - Символ(в библиотеке пристуствуют два шрифта) 48 | - Изображение 49 | 50 | В примере вы можете ознакомиться с тем, как определить эти функции 51 | 52 | Вы можете также переопределить формат хранения изображений. В этом случае 53 | вам необходимо (!) переопределить изображения, которые используются в 54 | библиотеке. А так же переопределить методы для нахождения высоты и 55 | ширины изображения (см файл Draw.h) 56 | 57 | Файл opts.h опредляет значения макросов по-умолчанию (НЕ МЕНЯЙТЕ ЭТОТ ФАЙЛ!) 58 | Для определения своих значений используйте файл emGUI_opts.h 59 | 60 | В этом файле можно определить основные константы (таткие как размер экрана) 61 | А так же переопределить цвета, шрифты, изображения, типы изображений 62 | 63 | 64 | -------------------------------------------------------------------------------- /examples/current-sensor/.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ 2 | -------------------------------------------------------------------------------- /examples/current-sensor/User_Setup.h: -------------------------------------------------------------------------------- 1 | // USER DEFINED SETTINGS V16 2 | // Set fonts to be loaded, pins used and SPI control method 3 | 4 | // ################################################################################## 5 | // 6 | // Define the pins that are used to interface with the display here 7 | // 8 | // ################################################################################## 9 | 10 | // We must use hardware SPI 11 | // Typical setup for NodeMCU ESP-12 is : 12 | // 13 | // Display SDO/MISO to NodeMCU pin D6 14 | // Display LED to NodeMCU pin VIN (5V) 15 | // Display SCK to NodeMCU pin D5 16 | // Display SDI/MOSI to NodeMCU pin D7 17 | // Display DC to NodeMCU pin D3 18 | // Display RESET to NodeMCU pin D4 19 | // Display CS to NodeMCU pin D8 20 | // Display GND to NodeMCU pin GND (0V) 21 | // Display VCC to NodeMCU pin VIN (5V) 22 | 23 | // ###### EDIT THE PIN NUMBERS IN THE 3 LINES FOLLOWING TO SUIT YOUR SETUP ###### 24 | 25 | // LinkSpriteTouchScreen 26 | //#define TFT_DC D4 // Data Command control pin 27 | 28 | 29 | 30 | /* 31 | 32 | http://www.forward.com.au/pfod/ESP8266/GPIOpins/index.html 33 | 34 | 35 | static const uint8_t D0 = 16; - встроенный PULL-DOWN 36 | static const uint8_t D1 = 5; - *cs TOUCH* 37 | static const uint8_t D2 = 4; - *cs TFT* 38 | static const uint8_t D3 = 0; - [BOOT]*SDA_PIN* 39 | static const uint8_t D4 = 2; - [BOOT] На старте должен быть HIGH *SCK_PIN* 40 | static const uint8_t D5 = 14; - [SPI] SCK 41 | static const uint8_t D6 = 12; - [SPI] MOSI 42 | static const uint8_t D7 = 13; - [SPI] MOSI 43 | static const uint8_t D8 = 15; - [BOOT] на старте должен быть LOW *DC* 44 | static const uint8_t D9 = 3; - [UART] rx 45 | static const uint8_t D10 = 1; - [UART] tx 46 | 47 | */ 48 | // Topfoison 49 | #define TFT_DC 15 // Data Command control pin 50 | #define TFT_CS 4 51 | #define TOUCH_CS 5 52 | #define TFT_RST -1 53 | 54 | //#define INTR_TOUCH 10 55 | 56 | 57 | #define SDA_PIN 0 58 | #define SCK_PIN 2 59 | #define INTR_SYS -1 60 | #define INTR_NFC -1 61 | 62 | #define UART_RX 3 63 | 64 | // ################################################################################## 65 | // 66 | // Define the fonts that are to be used here 67 | // 68 | // ################################################################################## 69 | 70 | // Comment out the #defines below with // to stop that font being loaded 71 | // The ESP8366 had plenty of memory so commenting out fonts is not normally necessary 72 | // If all fonts are loaded the extra FLASH space required is about 17000 bytes... 73 | // To save FLASH space only enable the fonts you need! 74 | 75 | //#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH 76 | //#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters 77 | //#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters 78 | //#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm 79 | //#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:. 80 | //#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. 81 | 82 | // ################################################################################## 83 | // 84 | // Define use of 9bit SPI use for displays without D/C pin, TFT_DC pin still needed 85 | // 86 | // ################################################################################## 87 | 88 | //#define USE_SPI9 89 | 90 | // ################################################################################## 91 | // 92 | // Other speed up options 93 | // 94 | // ################################################################################## 95 | 96 | // Define the SPI clock frequency (40MHz works OK) 80MHz sometimes fails 97 | 98 | // #define SPI_FREQUENCY 20000000 99 | // #define SPI_FREQUENCY 40000000 100 | #define SPI_FREQUENCY 40000000 101 | // #define SPI_FREQUENCY 16000000 102 | 103 | 104 | // Comment out the following #define if "SPI Transactions" do not need to be 105 | // supported. Tranaction support is required if other SPI devices are connected. 106 | // When commented out the code size will be smaller and sketches will 107 | // run slightly faster, so leave it commented out unless you need it! 108 | // Transaction support is needed to work with SD library but not needed with TFT_SdFat 109 | 110 | // #define SUPPORT_TRANSACTIONS 111 | 112 | -------------------------------------------------------------------------------- /examples/current-sensor/current-sensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * main file 3 | * 4 | * TFT configs are in User_Setup.h 5 | * fbits.tech 2018 // Roman Savrulin, Mikhail Natalenko 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "src/GUI/GUI.h" 13 | #include "emGUIGlue.h" 14 | #include "src/GUI/WindowPack.h" 15 | #include "src/TouchWrapper/TouchWrapper.h" 16 | #include 17 | #include "src/FIR-filter-class/filt.h" 18 | 19 | extern "C" { 20 | #include "user_interface.h" 21 | } 22 | #include "User_Setup.h" 23 | 24 | // Signal filter 25 | Filter lpf(LPF, 51, AFE_DATA_RATE / 1000.f, 0.05); 26 | // Current (and voltage in high side) monitor 27 | Adafruit_INA219 monitor; 28 | TouchWrapper touch; 29 | 30 | void setup() { 31 | // Init serial and start firmware 32 | if(digitalRead(UART_RX) == 1) { 33 | if(!Serial){ 34 | Serial.begin(115200); 35 | while (!Serial){ 36 | delay(100); 37 | } 38 | } 39 | } 40 | 41 | Serial.println(F("Ready")); 42 | SPIFFS.begin(); 43 | 44 | Wire.begin(SDA_PIN, SCK_PIN); 45 | touch.init(); 46 | 47 | // Setup emGUI 48 | vGUIGlueInit(); 49 | // Start GUI 50 | GUIInit(); 51 | 52 | // setup and start INA219 current monitor 53 | monitor.begin(); 54 | monitor.setCalibration_32V_1A(); 55 | } 56 | 57 | // To reduce noise in signal we use filter 58 | void handleData(float data) { 59 | auto window = WindowPlot::getInstance(false); 60 | auto fData = lpf.do_sample(data); 61 | if (window) window->update(data); 62 | } 63 | 64 | void loop() { 65 | touch.handleTouch(true); 66 | // emGUI loop 67 | vWindowManagerDraw(); 68 | 69 | handleData(monitor.getCurrent_mA()); 70 | Serial.printf("I(mA): %2f, V(mV): %2f, P(mW):%2f \n", monitor.getCurrent_mA(), monitor.getBusVoltage_V(), monitor.getPower_mW()); 71 | } 72 | -------------------------------------------------------------------------------- /examples/current-sensor/data/about.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/about.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/btn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/btn.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/cross.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/cross.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/cross16px.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/cross16px.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/folder.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/folder.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/label.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/label.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/magic.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/magic.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/msg.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/msg.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/no.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/no.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/ok.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/ok.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/ok59.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/ok59.bmp -------------------------------------------------------------------------------- /examples/current-sensor/data/pic.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libEmGUI/emGUI-arduino/9a6628d1b3007af264334eb759a0c1f6c857a2d2/examples/current-sensor/data/pic.bmp -------------------------------------------------------------------------------- /examples/current-sensor/emGUIGlue.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFT_WRAPPER_H_ 2 | #define _TFT_WRAPPER_H_ 3 | 4 | #include 5 | 6 | 7 | 8 | void TFTSleep(); 9 | 10 | void TFTWake(); 11 | 12 | void vGUIGlueInit(); 13 | 14 | xFont xGetDefaultFont(); 15 | void vGUIGlueSetCtx(void *); 16 | 17 | 18 | #endif -------------------------------------------------------------------------------- /examples/current-sensor/src/FIR-filter-class/README: -------------------------------------------------------------------------------- 1 | BUILDING 2 | 3 | The included Makefile makes the executable "devel". The file 4 | devel.cpp is an example of using the filtering class. The 5 | documentation for the class is in filt.h, and the class itself is 6 | implemented in filt.cpp. 7 | 8 | TESTING and USAGE 9 | 10 | The file cut.wav is about 8 seconds of an advertisement. The file 11 | cut.raw is the same 8 seconds with the 44 byte wav header removed. 12 | The program devel.cpp is hard coded to filter the file cut.raw. The 13 | filtered output ends up in a file filtered.raw. 14 | 15 | If you want to hear the results of the filtering, you need to add a 16 | wav header to filtered.raw. I use the freeware program "sox" to do 17 | this (the sampling rate is 44.1Khz, there is 1 channel, and the data 18 | is in a signed integer 16 bit format). 19 | 20 | As a shortcut, if you are in a Unix/Linux environment you can just use 21 | the command 22 | 23 | cat hdr.dat filtered.raw > filtered.wav 24 | 25 | -------------------------------------------------------------------------------- /examples/current-sensor/src/FIR-filter-class/filt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FIR filter class, by Mike Perkins 3 | * 4 | * a simple C++ class for linear phase FIR filtering 5 | * 6 | * For background, see the post http://www.cardinalpeak.com/blog?p=1841 7 | * 8 | * Copyright (c) 2013, Cardinal Peak, LLC. http://www.cardinalpeak.com 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * 1) Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * 2) Redistributions in binary form must reproduce the above 18 | * copyright notice, this list of conditions and the following 19 | * disclaimer in the documentation and/or other materials provided 20 | * with the distribution. 21 | * 22 | * 3) Neither the name of Cardinal Peak nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 29 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 30 | * CARDINAL PEAK, LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 33 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 36 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | */ 39 | 40 | #include "filt.h" 41 | #define _USE_MATH_DEFINES 42 | #include 43 | #define ECODE(x) {m_error_flag = x; return;} 44 | 45 | // Handles LPF and HPF case 46 | Filter::Filter(filterType filt_t, int num_taps, double Fs, double Fx) 47 | { 48 | m_error_flag = 0; 49 | m_filt_t = filt_t; 50 | m_num_taps = num_taps; 51 | m_Fs = Fs; 52 | m_Fx = Fx; 53 | m_lambda = M_PI * Fx / (Fs/2); 54 | 55 | if( Fs <= 0 ) ECODE(-1); 56 | if( Fx <= 0 || Fx >= Fs/2 ) ECODE(-2); 57 | if( m_num_taps <= 0 || m_num_taps > MAX_NUM_FILTER_TAPS ) ECODE(-3); 58 | 59 | m_taps = m_sr = NULL; 60 | m_taps = (double*)malloc( m_num_taps * sizeof(double) ); 61 | m_sr = (double*)malloc( m_num_taps * sizeof(double) ); 62 | if( m_taps == NULL || m_sr == NULL ) ECODE(-4); 63 | 64 | init(); 65 | 66 | if( m_filt_t == LPF ) designLPF(); 67 | else if( m_filt_t == HPF ) designHPF(); 68 | else ECODE(-5); 69 | 70 | return; 71 | } 72 | 73 | // Handles BPF case 74 | Filter::Filter(filterType filt_t, int num_taps, double Fs, double Fl, 75 | double Fu) 76 | { 77 | m_error_flag = 0; 78 | m_filt_t = filt_t; 79 | m_num_taps = num_taps; 80 | m_Fs = Fs; 81 | m_Fx = Fl; 82 | m_Fu = Fu; 83 | m_lambda = M_PI * Fl / (Fs/2); 84 | m_phi = M_PI * Fu / (Fs/2); 85 | 86 | if( Fs <= 0 ) ECODE(-10); 87 | if( Fl >= Fu ) ECODE(-11); 88 | if( Fl <= 0 || Fl >= Fs/2 ) ECODE(-12); 89 | if( Fu <= 0 || Fu >= Fs/2 ) ECODE(-13); 90 | if( m_num_taps <= 0 || m_num_taps > MAX_NUM_FILTER_TAPS ) ECODE(-14); 91 | 92 | m_taps = m_sr = NULL; 93 | m_taps = (double*)malloc( m_num_taps * sizeof(double) ); 94 | m_sr = (double*)malloc( m_num_taps * sizeof(double) ); 95 | if( m_taps == NULL || m_sr == NULL ) ECODE(-15); 96 | 97 | init(); 98 | 99 | if( m_filt_t == BPF ) designBPF(); 100 | else ECODE(-16); 101 | 102 | return; 103 | } 104 | 105 | Filter::~Filter() 106 | { 107 | if( m_taps != NULL ) free( m_taps ); 108 | if( m_sr != NULL ) free( m_sr ); 109 | } 110 | 111 | void 112 | Filter::designLPF() 113 | { 114 | int n; 115 | double mm; 116 | 117 | for(n = 0; n < m_num_taps; n++){ 118 | mm = n - (m_num_taps - 1.0) / 2.0; 119 | if( mm == 0.0 ) m_taps[n] = m_lambda / M_PI; 120 | else m_taps[n] = sin( mm * m_lambda ) / (mm * M_PI); 121 | } 122 | 123 | return; 124 | } 125 | 126 | void 127 | Filter::designHPF() 128 | { 129 | int n; 130 | double mm; 131 | 132 | for(n = 0; n < m_num_taps; n++){ 133 | mm = n - (m_num_taps - 1.0) / 2.0; 134 | if( mm == 0.0 ) m_taps[n] = 1.0 - m_lambda / M_PI; 135 | else m_taps[n] = -sin( mm * m_lambda ) / (mm * M_PI); 136 | } 137 | 138 | return; 139 | } 140 | 141 | void 142 | Filter::designBPF() 143 | { 144 | int n; 145 | double mm; 146 | 147 | for(n = 0; n < m_num_taps; n++){ 148 | mm = n - (m_num_taps - 1.0) / 2.0; 149 | if( mm == 0.0 ) m_taps[n] = (m_phi - m_lambda) / M_PI; 150 | else m_taps[n] = ( sin( mm * m_phi ) - 151 | sin( mm * m_lambda ) ) / (mm * M_PI); 152 | } 153 | 154 | return; 155 | } 156 | 157 | void 158 | Filter::get_taps( double *taps ) 159 | { 160 | int i; 161 | 162 | if( m_error_flag != 0 ) return; 163 | 164 | for(i = 0; i < m_num_taps; i++) taps[i] = m_taps[i]; 165 | 166 | return; 167 | } 168 | 169 | /*int 170 | Filter::write_taps_to_file( char *filename ) 171 | { 172 | FILE *fd; 173 | 174 | if( m_error_flag != 0 ) return -1; 175 | 176 | int i; 177 | fd = fopen(filename, "w"); 178 | if( fd == NULL ) return -1; 179 | 180 | fprintf(fd, "%d\n", m_num_taps); 181 | for(i = 0; i < m_num_taps; i++){ 182 | fprintf(fd, "%15.6f\n", m_taps[i]); 183 | } 184 | fclose(fd); 185 | 186 | return 0; 187 | } 188 | 189 | // Output the magnitude of the frequency response in dB 190 | #define NP 1000 191 | int 192 | Filter::write_freqres_to_file( char *filename ) 193 | { 194 | FILE *fd; 195 | int i, k; 196 | double w, dw; 197 | double y_r[NP], y_i[NP], y_mag[NP]; 198 | double mag_max = -1; 199 | double tmp_d; 200 | 201 | if( m_error_flag != 0 ) return -1; 202 | 203 | dw = M_PI / (NP - 1.0); 204 | for(i = 0; i < NP; i++){ 205 | w = i*dw; 206 | y_r[i] = y_i[i] = 0; 207 | for(k = 0; k < m_num_taps; k++){ 208 | y_r[i] += m_taps[k] * cos(k * w); 209 | y_i[i] -= m_taps[k] * sin(k * w); 210 | } 211 | } 212 | 213 | for(i = 0; i < NP; i++){ 214 | y_mag[i] = sqrt( y_r[i]*y_r[i] + y_i[i]*y_i[i] ); 215 | if( y_mag[i] > mag_max ) mag_max = y_mag[i]; 216 | } 217 | 218 | if( mag_max <= 0.0 ) return -2; 219 | 220 | fd = fopen(filename, "w"); 221 | if( fd == NULL ) return -3; 222 | 223 | for(i = 0; i < NP; i++){ 224 | w = i*dw; 225 | if( y_mag[i] == 0 ) tmp_d = -100; 226 | else{ 227 | tmp_d = 20 * log10( y_mag[i] / mag_max ); 228 | if( tmp_d < -100 ) tmp_d = -100; 229 | } 230 | fprintf(fd, "%10.6e %10.6e\n", w * (m_Fs/2)/M_PI, tmp_d); 231 | } 232 | 233 | fclose(fd); 234 | return 0; 235 | } 236 | */ 237 | void 238 | Filter::init() 239 | { 240 | int i; 241 | 242 | if( m_error_flag != 0 ) return; 243 | 244 | for(i = 0; i < m_num_taps; i++) m_sr[i] = 0; 245 | 246 | return; 247 | } 248 | 249 | double 250 | Filter::do_sample(double data_sample) 251 | { 252 | int i; 253 | double result; 254 | 255 | if( m_error_flag != 0 ) return(0); 256 | 257 | for(i = m_num_taps - 1; i >= 1; i--){ 258 | m_sr[i] = m_sr[i-1]; 259 | } 260 | m_sr[0] = data_sample; 261 | 262 | result = 0; 263 | for(i = 0; i < m_num_taps; i++) result += m_sr[i] * m_taps[i]; 264 | 265 | return result; 266 | } 267 | -------------------------------------------------------------------------------- /examples/current-sensor/src/FIR-filter-class/filt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FIR filter class, by Mike Perkins 3 | * 4 | * a simple C++ class for linear phase FIR filtering 5 | * 6 | * For background, see the post http://www.cardinalpeak.com/blog?p=1841 7 | * 8 | * Copyright (c) 2013, Cardinal Peak, LLC. http://www.cardinalpeak.com 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * 1) Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * 2) Redistributions in binary form must reproduce the above 18 | * copyright notice, this list of conditions and the following 19 | * disclaimer in the documentation and/or other materials provided 20 | * with the distribution. 21 | * 22 | * 3) Neither the name of Cardinal Peak nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 29 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 30 | * CARDINAL PEAK, LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 33 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 36 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | */ 39 | 40 | /* 41 | * 42 | * PURPOSE: 43 | * This object designs digital filters and filters digital data streams 44 | * 45 | * USAGE: 46 | * Invoke an object of type Filter. Two constructors are available. 47 | * One is used for LPF and HPF filters, one is used for BPFs. 48 | * The arguments to the constructors are as follows: 49 | * 50 | * // For LPF or HPF only 51 | * Filter(filterType filt_t, int num_taps, double Fs, double Fx); 52 | * // For BPF only 53 | * Filter(filterType filt_t, int num_taps, double Fs, double Fl, double Fu); 54 | * 55 | * filt_t: is LPF, HPF or BPF 56 | * num_taps: is the number of taps you want the filter to use 57 | * Fs: is the sampling frequency of the digital data being filtered 58 | * Fx: is the "transition" frequency for LPF and HPF filters 59 | * Fl, Fu: are the upper and lower transition frequencies for BPF filters 60 | * 61 | * Once the filter is created, you can start filtering data. Here 62 | * is an example for 51 tap lowpass filtering of an audio stream sampled at 63 | * 44.1Khz (the CD sampling rate), where the goal is to create a signal 64 | * of "telephone" bandwidth (4Khz): 65 | * 66 | * Filter *my_filter; 67 | * 68 | * my_filter = new Filter(LPF, 51, 44.1, 4.0) 69 | * if( my_filter->get_error_flag() != 0 ) // abort in an appropriate manner 70 | * 71 | * while(data_to_be_filtered){ 72 | * next_sample = // Get the next sample from the data stream somehow 73 | * filtered_sample = my_filter->do_sample( next_sample ); 74 | * . 75 | * . 76 | * . 77 | * } 78 | * delete my_filter; 79 | * 80 | * Several helper functions are provided: 81 | * init(): The filter can be re-initialized with a call to this function 82 | * get_taps(double *taps): returns the filter taps in the array "taps" 83 | * write_taps_to_file(char *filename): writes the filter taps to a file 84 | * write_freqres_to_file(char *filename): output frequency response to a file 85 | * 86 | * Finally, a get_error_flag() function is provided. Recommended usage 87 | * is to check the get_error_flag() return value for a non-zero 88 | * value after the new Filter object is created. If it is non-zero, print 89 | * out the non-zero value and look at the following table to see the 90 | * error: 91 | * -1: Fs <= 0 92 | * -2: Fx <= 0 or Fx >= Fs/2 93 | * -3: num_taps <= 0 or num_taps >= MAX_NUM_FILTER_TAPS 94 | * -4: memory allocation for the needed arrays failed 95 | * -5: an invalid filterType was passed into a constructor 96 | * -10: Fs <= 0 (BPF case) 97 | * -11: Fl >= Fu 98 | * -12: Fl <= 0 || Fl >= Fs/2 99 | * -13: Fu <= 0 || Fu >= Fs/2 100 | * -14: num_taps <= 0 or num_taps >= MAX_NUM_FILTER_TAPS (BPF case) 101 | * -15: memory allocation for the needed arrays failed (BPF case) 102 | * -16: an invalid filterType was passed into a constructor (BPF case) 103 | * 104 | * Note that if a non-zero error code value occurs, every call to do_sample() 105 | * will return the value 0. write_taps_fo_file() will fail and return a -1 (it 106 | * also returns a -1 if it fails to open the tap file passed into it). 107 | * get_taps() will have no effect on the array passed in if the error_flag 108 | * is non-zero. write_freqres_to_file( ) returns different error codes 109 | * depending on the nature of the error...see the function itself for details. 110 | * 111 | * The filters are designed using the "Fourier Series Method". This 112 | * means that the coefficients of a Fourier Series approximation to the 113 | * frequency response of an ideal filter (LPF, HPF, BPF) are used as 114 | * the filter taps. The resulting filters have some ripple in the passband 115 | * due to the Gibbs phenomenon; the filters are linear phase. 116 | */ 117 | 118 | #ifndef _FILTER_H 119 | #define _FILTER_H 120 | 121 | #define MAX_NUM_FILTER_TAPS 1000 122 | 123 | #include 124 | #include 125 | #include 126 | //#include 127 | #include 128 | #include 129 | 130 | enum filterType {LPF, HPF, BPF}; 131 | 132 | class Filter{ 133 | private: 134 | filterType m_filt_t; 135 | int m_num_taps; 136 | int m_error_flag; 137 | double m_Fs; 138 | double m_Fx; 139 | double m_lambda; 140 | double *m_taps; 141 | double *m_sr; 142 | void designLPF(); 143 | void designHPF(); 144 | 145 | // Only needed for the bandpass filter case 146 | double m_Fu, m_phi; 147 | void designBPF(); 148 | 149 | public: 150 | Filter(filterType filt_t, int num_taps, double Fs, double Fx); 151 | Filter(filterType filt_t, int num_taps, double Fs, double Fl, double Fu); 152 | ~Filter( ); 153 | void init(); 154 | double do_sample(double data_sample); 155 | int get_error_flag(){return m_error_flag;}; 156 | void get_taps( double *taps ); 157 | int write_taps_to_file( char* filename ); 158 | int write_freqres_to_file( char* filename ); 159 | }; 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "GUI.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace emGUI; 7 | 8 | static xStatusBar * statusbar; 9 | static WindowHeader::uniquePtr header; 10 | static xButton * crossButton; 11 | 12 | bool MainWindowCloseRequestHdl(xWidget *); 13 | 14 | // Action on interface creating 15 | // Init statusbar and open main window 16 | bool bGUIonWindowManagerCreateHandler(xWidget *) { 17 | vWindowManagerSetKeypressHandler([](int iID, uint16_t uEv){ 18 | (void)iID; 19 | if(uEv = 1) 20 | vWindowManagerCloseActiveWindow(); 21 | 22 | return true; 23 | }); 24 | 25 | //Status bar 26 | statusbar = pxWindowManagerGetStatusBar(); 27 | auto usY = (usWidgetGetH(statusbar) - pxDrawHDL()->usFontGetH(getSmallFont())) / 2; 28 | auto usW = usWidgetGetW(statusbar) * 50 / 100; 29 | auto usX = usWidgetGetW(statusbar) / 2 - usW / 2; 30 | 31 | header = std::make_unique(usX, usY, usW, 0, getSmallFont(), EMGUI_WINDOW_HEADER_LENGTH, statusbar); 32 | 33 | // You should use R5G6B5 bmp (just put it in SPIFFS) I prefer to use GIMP to convert bmp. 34 | usX = usWidgetGetW(statusbar) - pxDrawHDL()->usGetPictureW("/cross.bmp") - 1 ; 35 | usY = 1; 36 | 37 | crossButton = pxButtonCreateFromImage(usX, usY, "/cross.bmp", statusbar); 38 | vButtonSetOnClickHandler((xWidget*)crossButton, 39 | [](xWidget *) { 40 | vWindowManagerCloseActiveWindow(); 41 | return true; 42 | }); 43 | 44 | WindowMain::getInstance()->open(); 45 | return true; 46 | } 47 | 48 | void GUIInit() { 49 | pxWindowManagerCreate(bGUIonWindowManagerCreateHandler); 50 | } 51 | -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/GUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../../emGUIGlue.h" 6 | #include "WindowPack.h" 7 | 8 | void GUIInit(); 9 | -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/WindowMain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "WindowPack.h" 4 | 5 | class WindowMain : public DisposableWindow { 6 | public: 7 | void create() { 8 | vWindowSetHeader(xThis, "Main menu"); 9 | uint8_t offset = 20; 10 | uint8_t btnWidth = 120; 11 | uint8_t btnHeight = 120; 12 | uint8_t row1 = offset; 13 | uint8_t column1 = offset; 14 | uint8_t column2 = EMGUI_LCD_WIDTH - offset - btnWidth; 15 | 16 | auto paintBtn = pxButtonCreateFromText(column1, row1, btnWidth, btnHeight, "Paint", xThis); 17 | vButtonSetOnClickHandler(paintBtn, 18 | [](xWidget *) { 19 | WindowPaint::getInstance()->open(); 20 | return true; 21 | }); 22 | auto plotBtn = pxButtonCreateFromText(column2, row1, btnWidth, btnHeight, "Plot", xThis); 23 | vButtonSetOnClickHandler(plotBtn, 24 | [](xWidget *) { 25 | WindowPlot::getInstance()->open(); 26 | return true; 27 | }); 28 | } 29 | 30 | bool onCloseRequest() { 31 | return false; //allow window close 32 | } 33 | }; -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/WindowPack.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "WindowPack.h" 3 | #include "./../TFT/Fonts/GFXFF/FreeSans9pt7b.h" 4 | #include "./../TFT/Fonts/GFXFF/FreeSansBold9pt7b.h" 5 | #include "./../TFT/Fonts/GFXFF/FreeSans24pt7b.h" 6 | #include "./../UTF8-fonts/customfonts.h" 7 | 8 | const GFXfont * bigFont[] = { &Roboto_Regular24pt7b , &Roboto_Regular24pt8bRUS, NULL }; 9 | const GFXfont * smallFont[] = { &Roboto_Regular9pt7b , &Roboto_Regular9pt8bRUS, NULL }; 10 | const GFXfont * boldFont[] = { &Roboto_Bold9pt7b , &Roboto_Bold9pt8bRUS, NULL }; 11 | 12 | 13 | xFont getBigFont(){ 14 | return bigFont; 15 | } 16 | xFont getSmallFont(){ 17 | return smallFont; 18 | } 19 | xFont getBoldFont(){ 20 | return boldFont; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/WindowPack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "emGUI/emGUI.hpp" 4 | //#include "emGUI/emGUI.h" 5 | #include 6 | #include "../../emGUIGlue.h" 7 | 8 | typedef enum { 9 | WINDOW_MENU, 10 | WINDOW_PAINT, 11 | WINDOW_PLOT 12 | }eWindows; 13 | 14 | xFont getBigFont(); 15 | xFont getSmallFont(); 16 | xFont getBoldFont(); 17 | 18 | #include "WindowPlot.h" 19 | #include "WindowPaint.h" 20 | #include "WindowMain.h" -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/WindowPaint.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "WindowPack.h" 5 | 6 | class WindowPaint: public DisposableWindow { 7 | public: 8 | void create() { 9 | 10 | vWindowSetFullScreen(xThis, true); 11 | 12 | vWidgetSetClickable(xThis, true); 13 | xThis->pxCheckTSRoutine = [] (xWidget *pxW, xTouchEvent_t * xEv) -> bool { 14 | auto x = xEv->x; 15 | auto y = xEv->y; 16 | auto rectSize = 2; 17 | x = (x >= rectSize)?x-rectSize:x; 18 | y = (y >= rectSize)?y-rectSize:y; 19 | pxDrawHDL()->vRectangle(x, y, x + rectSize, y + rectSize, 0, true); 20 | return false; 21 | }; 22 | } 23 | bool onDrawUpdate() { 24 | pxDrawHDL()->vHLine(0, EMGUI_LCD_HEIGHT/2, EMGUI_LCD_WIDTH, EMGUI_COLOR_GRAY); 25 | pxDrawHDL()->vVLine(EMGUI_LCD_WIDTH/2, 0, EMGUI_LCD_HEIGHT, EMGUI_COLOR_GRAY); 26 | return true; 27 | } 28 | uint16_t prvGetNextColor() { 29 | static std::vector colors = { 30 | EMGUI_COLOR_WHITE, 31 | EMGUI_COLOR_RED, 32 | EMGUI_COLOR_GREEN, 33 | EMGUI_COLOR_BLUE, 34 | EMGUI_COLOR_BLACK 35 | 36 | }; 37 | 38 | if (++colorNum >= colors.size()) 39 | colorNum = 0; 40 | return colors[colorNum]; 41 | } 42 | 43 | bool onKeypress(uint16_t uEv) { 44 | if (uEv == 0) { 45 | vWidgetSetBgColor(xThis, prvGetNextColor(), false); 46 | return true; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | protected: 53 | unsigned int colorNum = 0; 54 | }; 55 | -------------------------------------------------------------------------------- /examples/current-sensor/src/GUI/WindowPlot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "WindowPack.h" 4 | using namespace emGUI; 5 | 6 | class WindowPlot : public DisposableWindow { 7 | public: 8 | xPlotData_t plotLead; 9 | void create() { 10 | vWindowSetHeader(xThis, "Plot, mA"); 11 | plotLead.bDataFilled = false; 12 | plotLead.bWriteEnabled = false; 13 | plotLead.sDataDCOffset = -500; 14 | plotLead.sName = "Test"; 15 | plotLead.ulElemCount = AFE_DATA_RATE * 10; 16 | plotLead.psData = (short *)malloc(sizeof(*plotLead.psData)*plotLead.ulElemCount); 17 | memset(plotLead.psData, 0, sizeof(*plotLead.psData)*plotLead.ulElemCount); 18 | plotLead.ulWritePos = 0; 19 | 20 | Serial.println("Create window"); 21 | plot = pxPlotCreate(0, 0, EMGUI_LCD_WIDTH, EMGUI_LCD_HEIGHT - EMGUI_STATUS_BAR_HEIGHT -20, xThis, &plotLead); 22 | vPlotSetScale(plot, 250); // Size of grid cell (yval) 23 | 24 | currentMonitorHeader = pxLabelCreate(0, EMGUI_LCD_HEIGHT - EMGUI_STATUS_BAR_HEIGHT - 20, 100, 20, "I (mA):", xGetDefaultFont(), 100, xThis); 25 | vLabelSetTextAlign(currentMonitorHeader, LABEL_ALIGN_RIGHT); 26 | vLabelSetVerticalAlign(currentMonitorHeader, LABEL_ALIGN_MIDDLE); 27 | 28 | currentMonitor = pxLabelCreate(100, EMGUI_LCD_HEIGHT - EMGUI_STATUS_BAR_HEIGHT - 20, 100, 20, "0", xGetDefaultFont(), 100, xThis); 29 | vLabelSetTextAlign(currentMonitor, LABEL_ALIGN_LEFT); 30 | vLabelSetVerticalAlign(currentMonitor, LABEL_ALIGN_MIDDLE); 31 | } 32 | 33 | xPlot * plot; 34 | 35 | xLabel * currentMonitor; 36 | xLabel * currentMonitorHeader; 37 | short data; 38 | short passDelay = 60; 39 | bool onClose(){ 40 | free(plotLead.psData); 41 | return false; 42 | }; 43 | void update(float data) { 44 | this->data = (short)(data * 10); 45 | vPlotAddValue(&plotLead, data); 46 | //long data = plotLead.psData[plotLead.ulWritePos]; 47 | } 48 | 49 | bool onDrawUpdate(){ 50 | static char textBuffer[80]; 51 | static auto lastMillis = millis(); 52 | 53 | if (millis() - lastMillis > passDelay) { 54 | sprintf (textBuffer, "%d\0", data / 10); 55 | pcLabelSetText(currentMonitor, textBuffer); 56 | lastMillis = millis(); 57 | } 58 | return false; 59 | } 60 | 61 | }; -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/Font16.h: -------------------------------------------------------------------------------- 1 | #include "Font16.c" 2 | 3 | #define nr_chrs_f16 96 4 | #define chr_hgt_f16 16 5 | #define baseline_f16 13 6 | #define data_size_f16 8 7 | #define firstchr_f16 32 8 | 9 | extern const unsigned char widtbl_f16[96]; 10 | extern const unsigned char* const chrtbl_f16[96]; 11 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/Font32rle.h: -------------------------------------------------------------------------------- 1 | #include "Font32rle.c" 2 | 3 | #define nr_chrs_f32 96 4 | #define chr_hgt_f32 26 5 | #define baseline_f32 19 6 | #define data_size_f32 8 7 | #define firstchr_f32 32 8 | 9 | extern const unsigned char widtbl_f32[96]; 10 | extern const unsigned char* const chrtbl_f32[96]; 11 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/Font64rle.h: -------------------------------------------------------------------------------- 1 | #include "Font64rle.c" 2 | 3 | #define nr_chrs_f64 96 4 | #define chr_hgt_f64 48 5 | #define baseline_f64 36 6 | #define data_size_f64 8 7 | #define firstchr_f64 32 8 | 9 | extern const unsigned char widtbl_f64[96]; 10 | extern const unsigned char* const chrtbl_f64[96]; 11 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/Font72rle.h: -------------------------------------------------------------------------------- 1 | #include "Font72rle.c" 2 | 3 | #define nr_chrs_f72 96 4 | #define chr_hgt_f72 75 5 | #define baseline_f72 73 6 | #define data_size_f72 8 7 | #define firstchr_f72 32 8 | 9 | extern const unsigned char widtbl_f72[96]; 10 | extern const unsigned char* const chrtbl_f72[96]; 11 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/Font7srle.h: -------------------------------------------------------------------------------- 1 | #include "Font7srle.c" 2 | 3 | #define nr_chrs_f7s 96 4 | #define chr_hgt_f7s 48 5 | #define baseline_f7s 47 6 | #define data_size_f7s 8 7 | #define firstchr_f7s 32 8 | 9 | extern const unsigned char widtbl_f7s[96]; 10 | extern const unsigned char* const chrtbl_f7s[96]; 11 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/GFXFF/gfxfont.h: -------------------------------------------------------------------------------- 1 | // Adopted by Bodmer to support TFT_HX8357_Due library. 2 | 3 | // Font structures for newer Adafruit_GFX (1.1 and later). 4 | // Example fonts are included in 'Fonts' directory. 5 | // To use a font in your Arduino sketch, #include the corresponding .h 6 | // file and pass address of GFXfont struct to setFont(). Pass NULL to 7 | // revert to 'classic' fixed-space bitmap font. 8 | 9 | #ifndef _GFXFONT_H_ 10 | #define _GFXFONT_H_ 11 | 12 | #ifdef LOAD_GFXFF 13 | 14 | typedef struct { // Data stored PER GLYPH 15 | uint16_t bitmapOffset; // Pointer into GFXfont->bitmap 16 | uint8_t width, height; // Bitmap dimensions in pixels 17 | uint8_t xAdvance; // Distance to advance cursor (x axis) 18 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner 19 | } GFXglyph; 20 | 21 | typedef struct { // Data stored for FONT AS A WHOLE: 22 | uint8_t *bitmap; // Glyph bitmaps, concatenated 23 | GFXglyph *glyph; // Glyph array 24 | uint8_t first, last; // ASCII extents 25 | uint8_t yAdvance; // Newline distance (y axis) 26 | } GFXfont; 27 | 28 | #endif // LOAD_GFXFF 29 | 30 | #endif // _GFXFONT_H_ 31 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/GFXFF/license.txt: -------------------------------------------------------------------------------- 1 | This TFT_ILI9341_ESP library has been developed from the Adafruit_GFX library: 2 | 3 | https://github.com/adafruit/Adafruit-GFX-Library 4 | 5 | It has been modified extensively to improve rendering speed on 6 | ESP8266 processors. There follows the original library license text. 7 | 8 | 9 | Original text follows: 10 | 11 | Software License Agreement (BSD License) 12 | 13 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | 18 | - Redistributions of source code must retain the above copyright notice, 19 | this list of conditions and the following disclaimer. 20 | - Redistributions in binary form must reproduce the above copyright notice, 21 | this list of conditions and the following disclaimer in the documentation 22 | and/or other materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/GFXFF/print.txt: -------------------------------------------------------------------------------- 1 | #define TT1 TomThumb 2 | 3 | #define FF1 FreeMono9pt7b 4 | #define FF2 FreeMono12pt7b 5 | #define FF3 FreeMono18pt7b 6 | #define FF4 FreeMono24pt7b 7 | 8 | #define FF5 FreeMonoBold9pt7b 9 | #define FF6 FreeMonoBold12pt7b 10 | #define FF7 FreeMonoBold18pt7b 11 | #define FF8 FreeMonoBold24pt7b 12 | 13 | #define FF9 FreeMonoBoldOblique9pt7b 14 | #define FF10 FreeMonoBoldOblique12pt7b 15 | #define FF11 FreeMonoBoldOblique18pt7b 16 | #define FF12 FreeMonoBoldOblique24pt7b 17 | 18 | #define FF13 FreeMonoOblique9pt7b 19 | #define FF14 FreeMonoOblique12pt7b 20 | #define FF15 FreeMonoOblique18pt7b 21 | #define FF16 FreeMonoOblique24pt7b 22 | 23 | #define FF17 FreeSans9pt7b 24 | #define FF18 FreeSans12pt7b 25 | #define FF19 FreeSans18pt7b 26 | #define FF20 FreeSans24pt7b 27 | 28 | #define FF21 FreeSansBold9pt7b 29 | #define FF22 FreeSansBold12pt7b 30 | #define FF23 FreeSansBold18pt7b 31 | #define FF24 FreeSansBold24pt7b 32 | 33 | #define FF25 FreeSansBoldOblique9pt7b 34 | #define FF26 FreeSansBoldOblique12pt7b 35 | #define FF27 FreeSansBoldOblique18pt7b 36 | #define FF28 FreeSansBoldOblique24pt7b 37 | 38 | #define FF29 FreeSansOblique9pt7b 39 | #define FF30 FreeSansOblique12pt7b 40 | #define FF31 FreeSansOblique18pt7b 41 | #define FF32 FreeSansOblique24pt7b 42 | 43 | #define FF33 FreeSerif9pt7b 44 | #define FF34 FreeSerif12pt7b 45 | #define FF35 FreeSerif18pt7b 46 | #define FF36 FreeSerif24pt7b 47 | 48 | #define FF37 FreeSerifBold9pt7b 49 | #define FF38 FreeSerifBold12pt7b 50 | #define FF39 FreeSerifBold18pt7b 51 | #define FF40 FreeSerifBold24pt7b 52 | 53 | #define FF41 FreeSerifBoldItalic9pt7b 54 | #define FF42 FreeSerifBoldItalic12pt7b 55 | #define FF43 FreeSerifBoldItalic18pt7b 56 | #define FF44 FreeSerifBoldItalic24pt7b 57 | 58 | #define FF45 FreeSerifItalic9pt7b 59 | #define FF46 FreeSerifItalic12pt7b 60 | #define FF47 FreeSerifItalic18pt7b 61 | #define FF48 FreeSerifItalic24pt7b 62 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/TrueType/Not_yet_supported.txt: -------------------------------------------------------------------------------- 1 | TO DO: Add support for converted True Type fonts in an RLE format. -------------------------------------------------------------------------------- /examples/current-sensor/src/TFT/Fonts/glcdfont.c: -------------------------------------------------------------------------------- 1 | // Original Adafruit_GFX 5x7 font 2 | 3 | #ifndef FONT5X7_H 4 | #define FONT5X7_H 5 | 6 | #include 7 | 8 | // Standard ASCII 5x7 font 9 | 10 | static const unsigned char font[] PROGMEM = { 11 | 0x00, 0x00, 0x00, 0x00, 0x00, 12 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 13 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 14 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 15 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 16 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 17 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 18 | 0x00, 0x18, 0x3C, 0x18, 0x00, 19 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 20 | 0x00, 0x18, 0x24, 0x18, 0x00, 21 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 22 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 23 | 0x26, 0x29, 0x79, 0x29, 0x26, 24 | 0x40, 0x7F, 0x05, 0x05, 0x07, 25 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 26 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 27 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 28 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 29 | 0x14, 0x22, 0x7F, 0x22, 0x14, 30 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 31 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 32 | 0x00, 0x66, 0x89, 0x95, 0x6A, 33 | 0x60, 0x60, 0x60, 0x60, 0x60, 34 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 35 | 0x08, 0x04, 0x7E, 0x04, 0x08, 36 | 0x10, 0x20, 0x7E, 0x20, 0x10, 37 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 38 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 39 | 0x1E, 0x10, 0x10, 0x10, 0x10, 40 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 41 | 0x30, 0x38, 0x3E, 0x38, 0x30, 42 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x5F, 0x00, 0x00, 45 | 0x00, 0x07, 0x00, 0x07, 0x00, 46 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 47 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 48 | 0x23, 0x13, 0x08, 0x64, 0x62, 49 | 0x36, 0x49, 0x56, 0x20, 0x50, 50 | 0x00, 0x08, 0x07, 0x03, 0x00, 51 | 0x00, 0x1C, 0x22, 0x41, 0x00, 52 | 0x00, 0x41, 0x22, 0x1C, 0x00, 53 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 54 | 0x08, 0x08, 0x3E, 0x08, 0x08, 55 | 0x00, 0x80, 0x70, 0x30, 0x00, 56 | 0x08, 0x08, 0x08, 0x08, 0x08, 57 | 0x00, 0x00, 0x60, 0x60, 0x00, 58 | 0x20, 0x10, 0x08, 0x04, 0x02, 59 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 60 | 0x00, 0x42, 0x7F, 0x40, 0x00, 61 | 0x72, 0x49, 0x49, 0x49, 0x46, 62 | 0x21, 0x41, 0x49, 0x4D, 0x33, 63 | 0x18, 0x14, 0x12, 0x7F, 0x10, 64 | 0x27, 0x45, 0x45, 0x45, 0x39, 65 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 66 | 0x41, 0x21, 0x11, 0x09, 0x07, 67 | 0x36, 0x49, 0x49, 0x49, 0x36, 68 | 0x46, 0x49, 0x49, 0x29, 0x1E, 69 | 0x00, 0x00, 0x14, 0x00, 0x00, 70 | 0x00, 0x40, 0x34, 0x00, 0x00, 71 | 0x00, 0x08, 0x14, 0x22, 0x41, 72 | 0x14, 0x14, 0x14, 0x14, 0x14, 73 | 0x00, 0x41, 0x22, 0x14, 0x08, 74 | 0x02, 0x01, 0x59, 0x09, 0x06, 75 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 76 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 77 | 0x7F, 0x49, 0x49, 0x49, 0x36, 78 | 0x3E, 0x41, 0x41, 0x41, 0x22, 79 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 80 | 0x7F, 0x49, 0x49, 0x49, 0x41, 81 | 0x7F, 0x09, 0x09, 0x09, 0x01, 82 | 0x3E, 0x41, 0x41, 0x51, 0x73, 83 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 84 | 0x00, 0x41, 0x7F, 0x41, 0x00, 85 | 0x20, 0x40, 0x41, 0x3F, 0x01, 86 | 0x7F, 0x08, 0x14, 0x22, 0x41, 87 | 0x7F, 0x40, 0x40, 0x40, 0x40, 88 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 89 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 90 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 91 | 0x7F, 0x09, 0x09, 0x09, 0x06, 92 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 93 | 0x7F, 0x09, 0x19, 0x29, 0x46, 94 | 0x26, 0x49, 0x49, 0x49, 0x32, 95 | 0x03, 0x01, 0x7F, 0x01, 0x03, 96 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 97 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 98 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 99 | 0x63, 0x14, 0x08, 0x14, 0x63, 100 | 0x03, 0x04, 0x78, 0x04, 0x03, 101 | 0x61, 0x59, 0x49, 0x4D, 0x43, 102 | 0x00, 0x7F, 0x41, 0x41, 0x41, 103 | 0x02, 0x04, 0x08, 0x10, 0x20, 104 | 0x00, 0x41, 0x41, 0x41, 0x7F, 105 | 0x04, 0x02, 0x01, 0x02, 0x04, 106 | 0x40, 0x40, 0x40, 0x40, 0x40, 107 | 0x00, 0x03, 0x07, 0x08, 0x00, 108 | 0x20, 0x54, 0x54, 0x78, 0x40, 109 | 0x7F, 0x28, 0x44, 0x44, 0x38, 110 | 0x38, 0x44, 0x44, 0x44, 0x28, 111 | 0x38, 0x44, 0x44, 0x28, 0x7F, 112 | 0x38, 0x54, 0x54, 0x54, 0x18, 113 | 0x00, 0x08, 0x7E, 0x09, 0x02, 114 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 115 | 0x7F, 0x08, 0x04, 0x04, 0x78, 116 | 0x00, 0x44, 0x7D, 0x40, 0x00, 117 | 0x20, 0x40, 0x40, 0x3D, 0x00, 118 | 0x7F, 0x10, 0x28, 0x44, 0x00, 119 | 0x00, 0x41, 0x7F, 0x40, 0x00, 120 | 0x7C, 0x04, 0x78, 0x04, 0x78, 121 | 0x7C, 0x08, 0x04, 0x04, 0x78, 122 | 0x38, 0x44, 0x44, 0x44, 0x38, 123 | 0xFC, 0x18, 0x24, 0x24, 0x18, 124 | 0x18, 0x24, 0x24, 0x18, 0xFC, 125 | 0x7C, 0x08, 0x04, 0x04, 0x08, 126 | 0x48, 0x54, 0x54, 0x54, 0x24, 127 | 0x04, 0x04, 0x3F, 0x44, 0x24, 128 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 129 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 130 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 131 | 0x44, 0x28, 0x10, 0x28, 0x44, 132 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 133 | 0x44, 0x64, 0x54, 0x4C, 0x44, 134 | 0x00, 0x08, 0x36, 0x41, 0x00, 135 | 0x00, 0x00, 0x77, 0x00, 0x00, 136 | 0x00, 0x41, 0x36, 0x08, 0x00, 137 | 0x02, 0x01, 0x02, 0x04, 0x02, 138 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 139 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 140 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 141 | 0x38, 0x54, 0x54, 0x55, 0x59, 142 | 0x21, 0x55, 0x55, 0x79, 0x41, 143 | 0x21, 0x54, 0x54, 0x78, 0x41, 144 | 0x21, 0x55, 0x54, 0x78, 0x40, 145 | 0x20, 0x54, 0x55, 0x79, 0x40, 146 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 147 | 0x39, 0x55, 0x55, 0x55, 0x59, 148 | 0x39, 0x54, 0x54, 0x54, 0x59, 149 | 0x39, 0x55, 0x54, 0x54, 0x58, 150 | 0x00, 0x00, 0x45, 0x7C, 0x41, 151 | 0x00, 0x02, 0x45, 0x7D, 0x42, 152 | 0x00, 0x01, 0x45, 0x7C, 0x40, 153 | 0xF0, 0x29, 0x24, 0x29, 0xF0, 154 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 155 | 0x7C, 0x54, 0x55, 0x45, 0x00, 156 | 0x20, 0x54, 0x54, 0x7C, 0x54, 157 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 158 | 0x32, 0x49, 0x49, 0x49, 0x32, 159 | 0x32, 0x48, 0x48, 0x48, 0x32, 160 | 0x32, 0x4A, 0x48, 0x48, 0x30, 161 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 162 | 0x3A, 0x42, 0x40, 0x20, 0x78, 163 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 164 | 0x39, 0x44, 0x44, 0x44, 0x39, 165 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 166 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 167 | 0x48, 0x7E, 0x49, 0x43, 0x66, 168 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 169 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 170 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 171 | 0x20, 0x54, 0x54, 0x79, 0x41, 172 | 0x00, 0x00, 0x44, 0x7D, 0x41, 173 | 0x30, 0x48, 0x48, 0x4A, 0x32, 174 | 0x38, 0x40, 0x40, 0x22, 0x7A, 175 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 176 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 177 | 0x26, 0x29, 0x29, 0x2F, 0x28, 178 | 0x26, 0x29, 0x29, 0x29, 0x26, 179 | 0x30, 0x48, 0x4D, 0x40, 0x20, 180 | 0x38, 0x08, 0x08, 0x08, 0x08, 181 | 0x08, 0x08, 0x08, 0x08, 0x38, 182 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 183 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 184 | 0x00, 0x00, 0x7B, 0x00, 0x00, 185 | 0x08, 0x14, 0x2A, 0x14, 0x22, 186 | 0x22, 0x14, 0x2A, 0x14, 0x08, 187 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 188 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 189 | 0x00, 0x00, 0x00, 0xFF, 0x00, 190 | 0x10, 0x10, 0x10, 0xFF, 0x00, 191 | 0x14, 0x14, 0x14, 0xFF, 0x00, 192 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 193 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 194 | 0x14, 0x14, 0x14, 0xFC, 0x00, 195 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 196 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 197 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 198 | 0x14, 0x14, 0x17, 0x10, 0x1F, 199 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 200 | 0x14, 0x14, 0x14, 0x1F, 0x00, 201 | 0x10, 0x10, 0x10, 0xF0, 0x00, 202 | 0x00, 0x00, 0x00, 0x1F, 0x10, 203 | 0x10, 0x10, 0x10, 0x1F, 0x10, 204 | 0x10, 0x10, 0x10, 0xF0, 0x10, 205 | 0x00, 0x00, 0x00, 0xFF, 0x10, 206 | 0x10, 0x10, 0x10, 0x10, 0x10, 207 | 0x10, 0x10, 0x10, 0xFF, 0x10, 208 | 0x00, 0x00, 0x00, 0xFF, 0x14, 209 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 210 | 0x00, 0x00, 0x1F, 0x10, 0x17, 211 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 212 | 0x14, 0x14, 0x17, 0x10, 0x17, 213 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 214 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 215 | 0x14, 0x14, 0x14, 0x14, 0x14, 216 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 217 | 0x14, 0x14, 0x14, 0x17, 0x14, 218 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 219 | 0x14, 0x14, 0x14, 0xF4, 0x14, 220 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 221 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 222 | 0x00, 0x00, 0x00, 0x1F, 0x14, 223 | 0x00, 0x00, 0x00, 0xFC, 0x14, 224 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 225 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 226 | 0x14, 0x14, 0x14, 0xFF, 0x14, 227 | 0x10, 0x10, 0x10, 0x1F, 0x00, 228 | 0x00, 0x00, 0x00, 0xF0, 0x10, 229 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 230 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 231 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 232 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 233 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 234 | 0x38, 0x44, 0x44, 0x38, 0x44, 235 | 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 236 | 0x7E, 0x02, 0x02, 0x06, 0x06, 237 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 238 | 0x63, 0x55, 0x49, 0x41, 0x63, 239 | 0x38, 0x44, 0x44, 0x3C, 0x04, 240 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 241 | 0x06, 0x02, 0x7E, 0x02, 0x02, 242 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 243 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 244 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 245 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 246 | 0x30, 0x48, 0x78, 0x48, 0x30, 247 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 248 | 0x3E, 0x49, 0x49, 0x49, 0x00, 249 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 250 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 251 | 0x44, 0x44, 0x5F, 0x44, 0x44, 252 | 0x40, 0x51, 0x4A, 0x44, 0x40, 253 | 0x40, 0x44, 0x4A, 0x51, 0x40, 254 | 0x00, 0x00, 0xFF, 0x01, 0x03, 255 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 256 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 257 | 0x36, 0x12, 0x36, 0x24, 0x36, 258 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 259 | 0x00, 0x00, 0x18, 0x18, 0x00, 260 | 0x00, 0x00, 0x10, 0x10, 0x00, 261 | 0x30, 0x40, 0xFF, 0x01, 0x01, 262 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 263 | 0x00, 0x19, 0x1D, 0x17, 0x12, 264 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 265 | 0x00, 0x00, 0x00, 0x00, 0x00 266 | }; 267 | 268 | #endif // FONT5X7_H 269 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TouchWrapper/TouchWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "TouchWrapper.h" 2 | 3 | void TouchWrapper::init(bool debug) 4 | { 5 | Serial.println("configuring touch"); 6 | begin(); 7 | 8 | bTouchInt = false; 9 | alreadyPoped = true; 10 | 11 | lastTouched = false; 12 | } 13 | 14 | bool TouchWrapper::handleTouch(bool flag) 15 | { 16 | currentTouch.eventTime = millis(); 17 | bool touchFlag = touched(); 18 | 19 | if (touchFlag) 20 | { 21 | alreadyPoped = false; 22 | uint16_t xptr; 23 | uint16_t yptr; 24 | 25 | TS_Point p = getPoint(); 26 | 27 | currentTouch.x = 320 - ((p.x - 300) * 10 / 115); // * xCompensationA / mul + xCompensationB; 28 | currentTouch.y = (p.y - 300) * 10 / 154; // * yCompensationA / mul + yCompensationB; 29 | 30 | if (!lastTouched) 31 | { 32 | currentTouch.event = pushTs; 33 | //Serial.printf(F_WRP("push x: %d; y: %d; m: %d;\n"), currentTouch.x, currentTouch.y, currentTouch.eventTime); 34 | } 35 | else 36 | { 37 | currentTouch.event = updateTs; 38 | //Serial.printf(F_WRP("upd x: %d; y: %d; m: %d;\n"), currentTouch.x, currentTouch.y, currentTouch.eventTime); 39 | } 40 | bWindowManagerCheckTouchScreenEvent((xTouchEvent *)¤tTouch); 41 | } 42 | else if (!alreadyPoped) 43 | { 44 | currentTouch.event = popTs; 45 | alreadyPoped = true; 46 | Serial.printf(F_WRP("pop x: %d; y: %d; m: %d;\n"), currentTouch.x, currentTouch.y, currentTouch.eventTime); 47 | bWindowManagerCheckTouchScreenEvent((xTouchEvent *)¤tTouch); 48 | } 49 | 50 | bTouchInt = false; 51 | lastTouched = touchFlag; 52 | 53 | return touchFlag; 54 | } 55 | -------------------------------------------------------------------------------- /examples/current-sensor/src/TouchWrapper/TouchWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../emGUIGlue.h" 6 | #include "../../User_Setup.h" 7 | 8 | class TouchWrapper : XPT2046_Touchscreen { 9 | public: 10 | TouchWrapper() : XPT2046_Touchscreen(TOUCH_CS) {} 11 | 12 | void init(bool debug = false); 13 | bool handleTouch(bool flag); 14 | 15 | protected: 16 | volatile xTouchEvent currentTouch; 17 | volatile bool bTouchInt = false; 18 | bool alreadyPoped = true; 19 | bool lastTouched = false; 20 | }; 21 | -------------------------------------------------------------------------------- /examples/current-sensor/src/UTF8-fonts/customfonts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Roboto-Bold.ttf.9pt.h" 4 | #include "Roboto-Bold.ttf.9pt.RUS.h" 5 | 6 | #include "Roboto-Regular.ttf.9pt.h" 7 | #include "Roboto-Regular.ttf.9pt.RUS.h" 8 | #include "Roboto-Regular.ttf.12pt.h" 9 | #include "Roboto-Regular.ttf.12pt.RUS.h" 10 | #include "Roboto-Regular.ttf.24pt.h" 11 | #include "Roboto-Regular.ttf.24pt.RUS.h" 12 | -------------------------------------------------------------------------------- /examples/demo-menu/GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "GUI.h" 2 | 3 | #include 4 | 5 | using namespace emGUI; 6 | 7 | bool MainWindowCloseRequestHdl(xWidget *); 8 | 9 | class TPTest: public DisposableWindow { 10 | public: 11 | void create() { 12 | 13 | vWindowSetFullScreen(xThis, true); 14 | 15 | vWidgetSetClickable(xThis, true); 16 | xThis->pxCheckTSRoutine = [] (xWidget *pxW, xTouchEvent * xEv) -> bool { 17 | auto x = xEv->x; 18 | auto y = xEv->y; 19 | auto rectSize = 2; 20 | x = (x >= rectSize)?x-rectSize:x; 21 | y = (y >= rectSize)?y-rectSize:y; 22 | pxDrawHDL()->vRectangle(x, y, x + rectSize, y + rectSize, 0, true); 23 | return false; 24 | }; 25 | } 26 | 27 | bool onDrawUpdate() { 28 | pxDrawHDL()->vHLine(0, EMGUI_LCD_HEIGHT/2, EMGUI_LCD_WIDTH, EMGUI_COLOR_GRAY); 29 | pxDrawHDL()->vVLine(EMGUI_LCD_WIDTH/2, 0, EMGUI_LCD_HEIGHT, EMGUI_COLOR_GRAY); 30 | return true; 31 | } 32 | 33 | uint16_t prvGetNextColor() { 34 | 35 | static std::vector colors = { 36 | EMGUI_COLOR_WHITE, 37 | EMGUI_COLOR_RED, 38 | EMGUI_COLOR_GREEN, 39 | EMGUI_COLOR_BLUE, 40 | EMGUI_COLOR_BLACK 41 | 42 | }; 43 | if (++colorNum >= colors.size()) 44 | colorNum = 0; 45 | return colors[colorNum]; 46 | } 47 | 48 | bool onKeypress(uint16_t uEv) { 49 | if (uEv == 0) { 50 | vWidgetSetBgColor(xThis, prvGetNextColor(), false); 51 | return true; 52 | } 53 | 54 | return false; 55 | } 56 | 57 | protected: 58 | int colorNum = 0; 59 | }; 60 | 61 | 62 | class WindowHWTest: public emGUI::DisposableWindow { 63 | public: 64 | 65 | void create() { 66 | 67 | vWindowSetHeader(xThis, "HW Test"); 68 | 69 | auto spacing = 2; 70 | auto h = 10; 71 | auto y = spacing / 2; 72 | auto x = 5; 73 | auto w = 130; 74 | auto len = 20; 75 | 76 | l1 = pxLabelCreate(x, y, w, 110, F_WRP(""), NULL, 100, xThis); 77 | 78 | bLabelSetMultiline(l1, true); 79 | y += usWidgetGetH(l1) + spacing; 80 | 81 | l2 = pxLabelCreate(x, y, 230, 50, F_WRP(""), NULL, 100, xThis); 82 | bLabelSetMultiline(l2, true); 83 | 84 | x = 150; 85 | y = 10; 86 | w = 80; 87 | h = 40; 88 | spacing = 10; 89 | 90 | draw = std::make_unique