-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample Keypad.spin2
112 lines (92 loc) · 3.89 KB
/
Example Keypad.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
{
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
DAT
banner FILE "demo_banner_simple.p2"
OBJ
''+--------------------------------------------------------------------------+
'' GUI framework objects
''+--------------------------------------------------------------------------+
'' CODE VARIABLES
color : "Colors" '160 bytes 4 bytes
util : "Utilities"
graphics : "Graphics"
gui : "GUI" '6204 bytes 732 bytes
terminal : "Multiline_Display"
keypad : "Keypad"
banner_image : "Image"
VAR
WORD BACKGROUND_COLOR
PUB main()| x, inc
BACKGROUND_COLOR := color.lighten(color.grey,15)
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(0) 'Set screen saving time in seconds
debug("Initialized GUI")
'GUI Areas example configuration
gui.set_vertical_layout(40,280,0)
gui.set_horizontal_layout(240,0,0)
gui.set_area_bg(gui.TOP_LEFT, color.darken(color.cyan,8))
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)
banner_image.set_image(@banner,240,40)
banner_image.configure(0,0,0,BACKGROUND_COLOR,color.black,color.grey)
banner_image.enable_events(false)
banner_image.set_enable(true)
gui.add_widget(@banner_image.set_enable, @banner_image.draw, @banner_image.check_event)
debug("Added banner image")
terminal.configure(0, 0, 40, 239, 140, color.darken(color.grey,9), color.lighten(color.set_color(50,190,255),8), color.grey)'color.lighten(INVISION_SOLAR_ORANGE), color.grey)
terminal.set_order(1)
terminal.set_contents(String("P2GUI Demo"))
terminal.set_align(0)
terminal.set_border_width(2)
terminal.set_font_size(2)
terminal.set_invert(true)
terminal.set_enable(true)
gui.add_widget(@terminal.set_enable, @terminal.draw, @terminal.check_event)
debug("Added terminal")
keypad.configure(0, 0, 210, color.white, color.blue, color.grey)
keypad.set_event_handler(@button_event_handler)
keypad.set_enable(true)
gui.add_widget(@keypad.set_enable, @keypad.draw, @keypad.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,ptr)
terminal.writeln(ptr)