-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
135 lines (102 loc) · 3.96 KB
/
main.py
File metadata and controls
135 lines (102 loc) · 3.96 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Main script
Do your stuff here, this file is similar to the loop() function on Arduino
Example on how to interact with a radio element
"""
# system packages
import time
# custom packages
from nextion import NexRadio, NexHardware
# define communication pins for Nextion display
tx_pin = 21
rx_pin = 22
# create Nextion hardware interface
nh = NexHardware(rx_pin=rx_pin, tx_pin=tx_pin)
# init nextion communication interface
nh.nexInit()
# create a radio instance
r0 = NexRadio(nh, 0, 1, "r0")
# ============================================================================
# ============================== Example values ==============================
# new values of radio
radio_state = 0
background_color_value = 63488 # red
font_color_value = 31 # blue
# ============================================================================
# ============================== Value functions =============================
# request the state of radio "r0"
print('Requesting radio "{}" value ...'.format(r0.name))
response = r0.getValue()
print('Radio "{}" value is: "{}"'.format(r0.name, response))
print()
time.sleep(1)
# modify radio "r0" being enabled by default
print('Set radio "{}" to "{}"'.format(r0.name, radio_state))
r0.setValue(radio_state)
print()
time.sleep(1)
# request the state of radio "r0" again
print('Requesting radio "{}" value ...'.format(r0.name))
response = r0.getValue()
print('Radio "{}" value is: "{}"'.format(r0.name, response))
print()
# sanity check
if response != radio_state:
print('WARNING: GET value did not match SET value')
time.sleep(1)
# ============================================================================
# =========================== Background functions ===========================
# request the background color of radio "r0"
print('Requesting background color of radio "{}" ...'.format(r0.name))
response = r0.Get_background_color_bco()
print('Background color of radio "{}" is: "{}"'.format(r0.name, response))
print()
time.sleep(1)
# modify the background color of radio "r0" to "red"
# search for RGB565 Colors. Red is "63488" at 65k colors
print('Set background color of radio "{}" to "{}"'.
format(r0.name, background_color_value))
r0.Set_background_color_bco(background_color_value)
print()
time.sleep(1)
# request the background color of radio "r0" again
print('Requesting background color of radio "{}" ...'.format(r0.name))
response = r0.Get_background_color_bco()
print('Background color of radio "{}" is: "{}"'.format(r0.name, response))
print()
# sanity check
if response != background_color_value:
print('WARNING: GET value did not match SET value')
time.sleep(1)
# ============================================================================
# ============================== Font functions ==============================
# request the font color of radio "r0"
print('Requesting font color of radio "{}" ...'.format(r0.name))
response = r0.Get_font_color_pco()
print('Font color of radio "{}" is: "{}"'.format(r0.name, response))
print()
time.sleep(1)
# enable radio "r0" again to make change in font color visible
r0.setValue(1)
# modify the font color of radio "r0" to "blue"
# search for RGB565 Colors. Blue is "31" at 65k colors
print('Set font color of radio "{}" to "{}"'.
format(r0.name, font_color_value))
r0.Set_font_color_pco(font_color_value)
print()
time.sleep(1)
# request the font color of radio "r0" again
print('Requesting font color of radio "{}" ...'.format(r0.name))
response = r0.Get_font_color_pco()
print('Font color of radio "{}" is: "{}"'.format(r0.name, response))
print()
# sanity check
if response != font_color_value:
print('WARNING: GET value did not match SET value')
# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')
# wait for 5 more seconds to safely finish the may still running threads
time.sleep(5)