-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication_Template.spin2
114 lines (94 loc) · 3.76 KB
/
Application_Template.spin2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
Propeller2_GUI
Application Template
Author: José Rullán
Date: January 10, 2023
}
CON
_clkfreq = 200_000_000
''+--------------------------------------------------------------------------+
'' GUI application constants
''+--------------------------------------------------------------------------+
''Buttons
#0, P_BTN, MAX_BUTTONS
OBJ
''+--------------------------------------------------------------------------+
'' GUI framework objects
''+--------------------------------------------------------------------------+
'' CODE VARIABLES
color : "Colors" '160 bytes 4 bytes
util : "Utilities"
graphics : "Graphics"
gui : "GUI" '6204 bytes 732 bytes
button[MAX_BUTTONS] : "Button" '1040 bytes 68 bytes
DAT
''+--------------------------------------------------------------------------+
'' GUI images files (Inkscape + Processsing)
'' Must be RGB 565 in BGR order (R is byte 0)
''+--------------------------------------------------------------------------+
'Images
'logo_black FILE "logo_black.p2"
VAR
WORD BACKGROUND_COLOR
PUB main()
BACKGROUND_COLOR := color.black
init_gui()
debug("Finished init_gui()")
gui.draw()
debug("Finished drawing")
repeat
'Continous logic here...
'GUI scan (handle touch events and updates)
gui.scan()
''+--------------------------------------------------------------------+
'' GUI initialization and configuration
''+--------------------------------------------------------------------+
PUB init_gui()
''Initialization of the GUI object, screens and widgets
'Set pins for TFT and touchscreen
gui.set_TFT_pins(25,23,24,27,26,23,-1,-1) '(ce, rst, dc, sda, clk, led, v3, gnd)
gui.set_TS_pins(26,29,27,28,30) '(clk, cs, din, do, irq)
'Initialize the gui element and driver
gui.init(BACKGROUND_COLOR, color.white, color.green, gui.PORTRAIT, false) '(bg, fg, ol, o, cal?)
gui.set_screen_saving(10) 'Set screen saving time in seconds
debug("Initialized GUI")
'GUI Areas example configuration
gui.set_vertical_layout(40,160,40)
gui.set_horizontal_layout(40,160,40)
gui.set_area_bg(gui.TOP_LEFT, color.yellow)
gui.set_area_bg(gui.TOP_CENTER, color.blue)
gui.set_area_bg(gui.TOP_RIGHT, color.GREEN)
gui.set_area_bg(gui.MIDDLE_LEFT, color.white)
gui.set_area_bg(gui.MIDDLE_CENTER, color.darken(color.cyan,8))
gui.set_area_bg(gui.MIDDLE_RIGHT, color.white)
gui.set_area_bg(gui.BOTTOM_LEFT, color.cyan)
gui.set_area_bg(gui.BOTTOM_CENTER, color.blue)
gui.set_area_bg(gui.BOTTOM_RIGHT, color.purple)
'Button example configuration
button[P_BTN].configure(P_BTN,70,100,100,40,color.grey,color.black,color.grey) '(i, xt, yt, w, h, bg, fg, ol)
button[P_BTN].set_mode(button.TOGGLE_MODE)
button[P_BTN].set_contents(String("P"))
button[P_BTN].set_font_size(2)
button[P_BTN].set_border_width(2)
button[P_BTN].set_enable(true)
button[P_BTN].set_event_handler(@button_event_handler)
gui.add_widget(@button[P_BTN].set_enable, @button[P_BTN].draw, @button[P_BTN].check_event)
''+--------------------------------------------------------------------+
'' WIDGETS EVENT HANDLING METHODS
''+--------------------------------------------------------------------+
''Button example event handler
''This method could be use for multiple buttons
''that can be identified by the id parameter
''returned by the button.
PUB button_event_handler(id,val)
if (id == P_BTN)
'Do something....
if val
debug("True value")
button[P_BTN].set_invert(true)
'Do something....
else
debug("False value")
button[P_BTN].set_invert(false)
'Do something....
button[P_BTN].draw()