Skip to content

Commit a660fe0

Browse files
kaladinstorm84Matt Anderson
andauthored
Add Squareline Studio example project (#132)
* new file: Examples/Projects/Squareline/CMakeLists.txt new file: Examples/Projects/Squareline/Squareline.ino new file: Examples/Projects/Squareline/components/ui_comp_hook.c new file: Examples/Projects/Squareline/filelist.txt new file: Examples/Projects/Squareline/ui.c new file: Examples/Projects/Squareline/ui.h new file: Examples/Projects/Squareline/ui_Screen1.c new file: Examples/Projects/Squareline/ui_comp_hook.c new file: Examples/Projects/Squareline/ui_events.h new file: Examples/Projects/Squareline/ui_helpers.c new file: Examples/Projects/Squareline/ui_helpers.h * Delete Examples/Projects/Squareline/ui/autosave directory * Delete Examples/Projects/Squareline/SquareLine_Project.sll * Delete Examples/Projects/Squareline/SquareLine_Project.spj * Delete Examples/Projects/Squareline/CMakeLists.txt * Delete Examples/Projects/Squareline/filelist.txt --------- Co-authored-by: Matt Anderson <[email protected]>
1 parent 408f38f commit a660fe0

File tree

9 files changed

+651
-0
lines changed

9 files changed

+651
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
#include <Arduino.h>
3+
#include <TFT_eSPI.h>
4+
#include <XPT2046_Touchscreen.h>
5+
#include <lvgl.h>
6+
7+
8+
#include "ui.h"
9+
10+
//LV_CONF LV_COLOR_DEPTH must be set to 16
11+
12+
/*Set to your screen resolution*/
13+
static const uint16_t screenWidth = 320;
14+
static const uint16_t screenHeight = 240;
15+
//set up screen
16+
static lv_disp_draw_buf_t draw_buf;
17+
static lv_color_t buf[ screenWidth * screenHeight / 10 ];
18+
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
19+
20+
// set up touch
21+
#define TIRQ_PIN 2
22+
#define XPT2046_IRQ 36
23+
#define XPT2046_MOSI 32
24+
#define XPT2046_MISO 39
25+
#define XPT2046_CLK 25
26+
#define XPT2046_CS 33
27+
SPIClass mySpi = SPIClass(HSPI);
28+
XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
29+
30+
31+
void my_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p )
32+
{
33+
log_i("Flushing");
34+
uint32_t w = ( area->x2 - area->x1 + 1 );
35+
uint32_t h = ( area->y2 - area->y1 + 1 );
36+
37+
tft.startWrite();
38+
tft.setAddrWindow( area->x1, area->y1, w, h );
39+
tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
40+
tft.endWrite();
41+
lv_disp_flush_ready( disp_drv );
42+
}
43+
boolean wastouched = true;
44+
void my_touchpad_read( lv_indev_drv_t * indev_drv, lv_indev_data_t * data )
45+
{
46+
uint16_t touchX, touchY;
47+
48+
bool touched = (ts.tirqTouched() && ts.touched());
49+
50+
if( !touched )
51+
{
52+
data->state = LV_INDEV_STATE_REL;
53+
}
54+
else
55+
{
56+
TS_Point p = ts.getPoint();
57+
touchX = map(p.x,200,3700,1,screenWidth); /* Touchscreen X calibration */
58+
touchY = map(p.y,240,3800,1,screenHeight); /* Touchscreen X calibration */
59+
data->state = LV_INDEV_STATE_PR;
60+
61+
/*Set the coordinates*/
62+
data->point.x = touchX;
63+
data->point.y = touchY;
64+
// tft.print("touched");
65+
Serial.print( "Data x " );
66+
Serial.println( touchX );
67+
68+
Serial.print( "Data y " );
69+
Serial.println( touchY );
70+
}
71+
}
72+
int pollInterval = 15;
73+
void setup() {
74+
75+
Serial.begin(115000);
76+
// put your setup code here, to run once:
77+
lv_init();
78+
79+
tft.init(); /* TFT init */
80+
tft.setRotation( 1 ); /* Landscape orientation, flipped */
81+
mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); /* Start second SPI bus for touchscreen */
82+
ts.begin(mySpi); /* Touchscreen init */
83+
ts.setRotation( 1 ); /* Landscape orientation, flipped */
84+
tft.fillScreen(TFT_BLACK);
85+
86+
87+
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 10 );
88+
89+
/*Initialize the display*/
90+
static lv_disp_drv_t disp_drv;
91+
lv_disp_drv_init( &disp_drv );
92+
/*Change the following line to your display resolution*/
93+
disp_drv.hor_res = screenWidth;
94+
disp_drv.ver_res = screenHeight;
95+
disp_drv.flush_cb = my_disp_flush;
96+
disp_drv.draw_buf = &draw_buf;
97+
lv_disp_drv_register( &disp_drv );
98+
99+
/*Initialize the (dummy) input device driver*/
100+
static lv_indev_drv_t indev_drv;
101+
lv_indev_drv_init( &indev_drv );
102+
indev_drv.type = LV_INDEV_TYPE_POINTER;
103+
indev_drv.read_cb = my_touchpad_read;
104+
lv_indev_drv_register( &indev_drv );
105+
106+
ui_init();
107+
108+
}
109+
110+
111+
void loop() {
112+
113+
114+
lv_timer_handler();
115+
//allow stuff to happen
116+
delay(10);
117+
}
118+
119+
// put function definitions here:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+

Examples/Projects/Squareline/ui.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+
6+
#include "ui.h"
7+
#include "ui_helpers.h"
8+
9+
///////////////////// VARIABLES ////////////////////
10+
11+
12+
// SCREEN: ui_Screen1
13+
void ui_Screen1_screen_init(void);
14+
lv_obj_t * ui_Screen1;
15+
lv_obj_t * ui_Panel1;
16+
lv_obj_t * ui_Label1;
17+
lv_obj_t * ui_Slider1;
18+
lv_obj_t * ui_Label2;
19+
lv_obj_t * ui____initial_actions0;
20+
21+
///////////////////// TEST LVGL SETTINGS ////////////////////
22+
#if LV_COLOR_DEPTH != 16
23+
#error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
24+
#endif
25+
#if LV_COLOR_16_SWAP !=0
26+
#error "LV_COLOR_16_SWAP should be 0 to match SquareLine Studio's settings"
27+
#endif
28+
29+
///////////////////// ANIMATIONS ////////////////////
30+
31+
///////////////////// FUNCTIONS ////////////////////
32+
33+
///////////////////// SCREENS ////////////////////
34+
35+
void ui_init(void)
36+
{
37+
lv_disp_t * dispp = lv_disp_get_default();
38+
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
39+
false, LV_FONT_DEFAULT);
40+
lv_disp_set_theme(dispp, theme);
41+
ui_Screen1_screen_init();
42+
ui____initial_actions0 = lv_obj_create(NULL);
43+
lv_disp_load_scr(ui_Screen1);
44+
}

Examples/Projects/Squareline/ui.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+
6+
#ifndef _SQUARELINE_PROJECT_UI_H
7+
#define _SQUARELINE_PROJECT_UI_H
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#if defined __has_include
14+
#if __has_include("lvgl.h")
15+
#include "lvgl.h"
16+
#elif __has_include("lvgl/lvgl.h")
17+
#include "lvgl/lvgl.h"
18+
#else
19+
#include "lvgl.h"
20+
#endif
21+
#else
22+
#include "lvgl.h"
23+
#endif
24+
25+
#include "ui_helpers.h"
26+
#include "ui_events.h"
27+
// SCREEN: ui_Screen1
28+
void ui_Screen1_screen_init(void);
29+
extern lv_obj_t * ui_Screen1;
30+
extern lv_obj_t * ui_Panel1;
31+
extern lv_obj_t * ui_Label1;
32+
extern lv_obj_t * ui_Slider1;
33+
extern lv_obj_t * ui_Label2;
34+
extern lv_obj_t * ui____initial_actions0;
35+
36+
37+
38+
39+
void ui_init(void);
40+
41+
#ifdef __cplusplus
42+
} /*extern "C"*/
43+
#endif
44+
45+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+
6+
#include "ui.h"
7+
8+
void ui_Screen1_screen_init(void)
9+
{
10+
ui_Screen1 = lv_obj_create(NULL);
11+
lv_obj_clear_flag(ui_Screen1, LV_OBJ_FLAG_SCROLLABLE); /// Flags
12+
13+
ui_Panel1 = lv_obj_create(ui_Screen1);
14+
lv_obj_set_width(ui_Panel1, lv_pct(90));
15+
lv_obj_set_height(ui_Panel1, lv_pct(90));
16+
lv_obj_set_align(ui_Panel1, LV_ALIGN_CENTER);
17+
lv_obj_clear_flag(ui_Panel1, LV_OBJ_FLAG_SCROLLABLE); /// Flags
18+
19+
ui_Label1 = lv_label_create(ui_Panel1);
20+
lv_obj_set_width(ui_Label1, lv_pct(100));
21+
lv_obj_set_height(ui_Label1, lv_pct(100));
22+
lv_obj_set_align(ui_Label1, LV_ALIGN_CENTER);
23+
lv_label_set_text(ui_Label1, "UI Loaded!\n\nDrop your UI in the UI Directory\n\n");
24+
25+
ui_Slider1 = lv_slider_create(ui_Screen1);
26+
lv_obj_set_width(ui_Slider1, 242);
27+
lv_obj_set_height(ui_Slider1, 10);
28+
lv_obj_set_x(ui_Slider1, 4);
29+
lv_obj_set_y(ui_Slider1, 80);
30+
lv_obj_set_align(ui_Slider1, LV_ALIGN_CENTER);
31+
32+
33+
ui_Label2 = lv_label_create(ui_Screen1);
34+
lv_obj_set_width(ui_Label2, LV_SIZE_CONTENT); /// 1
35+
lv_obj_set_height(ui_Label2, LV_SIZE_CONTENT); /// 1
36+
lv_obj_set_x(ui_Label2, -8);
37+
lv_obj_set_y(ui_Label2, 44);
38+
lv_obj_set_align(ui_Label2, LV_ALIGN_CENTER);
39+
lv_label_set_text(ui_Label2, "Touch Test");
40+
lv_label_set_recolor(ui_Label2, "true");
41+
42+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file was generated by SquareLine Studio
2+
// SquareLine Studio version: SquareLine Studio 1.3.4
3+
// LVGL version: 8.3.6
4+
// Project name: SquareLine_Project
5+
6+
#ifndef _UI_EVENTS_H
7+
#define _UI_EVENTS_H
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#ifdef __cplusplus
14+
} /*extern "C"*/
15+
#endif
16+
17+
#endif

0 commit comments

Comments
 (0)