Skip to content

Commit

Permalink
Merge pull request #13 from brainelectronics/feature/add-support-for-…
Browse files Browse the repository at this point in the history
…nextion-variable

Add support for nextion variable
  • Loading branch information
brainelectronics authored Jul 30, 2022
2 parents 4a6fade + 4e81254 commit 1c5e815
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 11 deletions.
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.10.0] - 2022-07-30
### Added
- Support `NexVariable` usage with
[`nextion_variable`](nextion/nextion_variable.py)

### Fixed
- Add full line comment between different section of all examples

## [0.9.0] - 2022-07-30
### Added
- Support GPIO usage with [`nextion_gpio`](nextion/nextion_gpio.py)
Expand Down Expand Up @@ -142,8 +150,9 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
- [Example HMI file](examples/everything.HMI) to be used for all examples

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.9.0...develop
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.10.0...develop

[0.10.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.10.0
[0.9.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.9.0
[0.8.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.8.0
[0.7.1]: https://github.com/brainelectronics/micropython-nextion/tree/0.7.1
Expand Down
36 changes: 28 additions & 8 deletions examples/basic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# init nextion communication interface
nh.nexInit()

# ============================================================================
# ============================== Text examples ===============================
# modify text field "t0" showing "newtxt" by default
print('Set text field "t0" to "asdf"')
cmd = 't0.txt="asdf"'
Expand All @@ -33,6 +35,8 @@

time.sleep(1)

# ============================================================================
# ============================= Number examples ==============================
# modify number field "n0" showing "0" by default
print('Set number field "n0" to "93"')
cmd = 'n0.val=93'
Expand All @@ -49,6 +53,8 @@

time.sleep(1)

# ============================================================================
# ============================= Button examples ==============================
# modify button "b0" showing "newtxt" by default
print('Set button "b0" to "btn txt"')
cmd = 'b0.txt="btn txt"'
Expand All @@ -57,6 +63,16 @@

time.sleep(1)

# modify dual state button "bt0" showing "newtxt" by default
print('Set dual state button "bt0" to "dsb txt"')
cmd = 'bt0.txt="dsb txt"'
nh.sendCommand(cmd)
print()

time.sleep(1)

# ============================================================================
# =========================== Progressbar examples ===========================
# modify progressbar "j0" showing "50%" by default
print('Set progressbar "j0" to "20"')
cmd = 'j0.val=20'
Expand All @@ -65,6 +81,8 @@

time.sleep(1)

# ============================================================================
# ============================= Slider examples ==============================
# modify slider "h0" showed in center position by default
print('Set slider "h0" to "80"')
cmd = 'h0.val=80'
Expand All @@ -73,14 +91,8 @@

time.sleep(1)

# modify button "bt0" showing "newtxt" by default
print('Set button "bt0" to "btn txt"')
cmd = 'bt0.txt="btn txt"'
nh.sendCommand(cmd)
print()

time.sleep(1)

# ============================================================================
# ============================ Checkbox examples =============================
# modify checkbox "c0" being checked by default
print('Set checkbox "c0" to "unchecked"')
cmd = 'c0.val=0'
Expand All @@ -89,6 +101,8 @@

time.sleep(1)

# ============================================================================
# ============================== Radio examples ==============================
# modify radio button "r0" being enabled by default
print('Set radio butto "r0" to "disabled"')
cmd = 'r0.val=0'
Expand All @@ -97,6 +111,8 @@

time.sleep(1)

# ============================================================================
# ============================== Gauge examples ==============================
# modify gauge "z0" pointing to the left by default
print('Set gauge "z0" to "135" (degree)')
cmd = 'z0.val=135'
Expand All @@ -105,13 +121,17 @@

time.sleep(1)

# ============================================================================
# ============================ Waveform examples =============================
# add several datapoints to waveform "s0"
print('Add several datapoints to waveform "s0"')
for x in range(0, 50):
cmd = 'add 14,0,{}'.format(x)
nh.sendCommand(cmd)
time.sleep(0.1)

# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')

# wait for 5 more seconds to safely finish the may still running threads
Expand Down
12 changes: 10 additions & 2 deletions examples/checkbox/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
# create a checkbox instance
c0 = NexCheckbox(nh, 0, 1, "c0")

# ============================================================================
# ============================== Example values ==============================
# new values of checkbox
checkbox_value = 0
background_color_value = 63488 # red
font_color_value = 31 # blue

# ============================================================================
# ============================== Value functions =============================
# request the value of checkbox "c0"
print('Requesting checkbox "{}" value ...'.format(c0.name))
response = c0.getValue()
Expand Down Expand Up @@ -60,6 +64,8 @@

time.sleep(1)

# ============================================================================
# =========================== Background functions ===========================
# request the background color of checkbox "c0"
print('Requesting background color of checkbox "{}" ...'.format(c0.name))
response = c0.Get_background_color_bco()
Expand Down Expand Up @@ -89,6 +95,8 @@

time.sleep(1)

# ============================================================================
# ============================== Font functions ==============================
# request the font color of checkbox "c0"
print('Requesting font color of checkbox "{}" ...'.format(c0.name))
response = c0.Get_font_color_pco()
Expand Down Expand Up @@ -119,8 +127,8 @@
if response != font_color_value:
print('WARNING: GET value did not match SET value')

time.sleep(1)

# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')

# wait for 5 more seconds to safely finish the may still running threads
Expand Down
12 changes: 12 additions & 0 deletions examples/gauge/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
# create a gauge instance
z0 = NexGauge(nh, 0, 1, "z0")

# ============================================================================
# ============================== Example values ==============================
# new values of gauge
gauge_value = randint(10, 350)
background_color_value = 63488 # red
font_color_value = 31 # blue
pointer_thickness = 5

# ============================================================================
# ============================== Value functions =============================
# request the value of gauge "z0"
print('Requesting gauge "{}" value ...'.format(z0.name))
response = z0.getValue()
Expand All @@ -60,6 +64,8 @@
if response != gauge_value:
print('WARNING: GET value did not match SET value')

# ============================================================================
# =========================== Background functions ===========================
# request the background color of gauge "z0"
print('Requesting background color of gauge "{}" ...'.format(z0.name))
response = z0.Get_background_color_bco()
Expand Down Expand Up @@ -89,6 +95,8 @@

time.sleep(1)

# ============================================================================
# ============================== Font functions ==============================
# request the font color of gauge "z0"
print('Requesting font color of gauge "{}" ...'.format(z0.name))
response = z0.Get_font_color_pco()
Expand Down Expand Up @@ -117,6 +125,8 @@

time.sleep(1)

# ============================================================================
# ============================ Pointer functions =============================
# request the pointer thickness of gauge "z0"
print('Requesting pointer thickness of gauge "{}" ...'.format(z0.name))
response = z0.Get_pointer_thickness_wid()
Expand All @@ -143,6 +153,8 @@
if response != pointer_thickness:
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
Expand Down
8 changes: 8 additions & 0 deletions examples/hardware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# init nextion communication interface
nh.nexInit()

# ============================================================================
# ============================ Brightness function ===========================
# decrease display brightness to 50%
display_brightness = 50
print('Decreasing display brightness to {}%...'.format(display_brightness))
Expand All @@ -34,6 +36,8 @@

time.sleep(1)

# ============================================================================
# ============================== Sleep function ==============================
# activate sleep mode of display
print('Activating display sleep mode for 5 seconds')
nh.sleep(True)
Expand All @@ -43,6 +47,8 @@

time.sleep(1)

# ============================================================================
# ============================ Hide/show function ============================
# manipulate display content to demonstrate display reset afterwards
print('Manipulating display content a little bit ...')
b0 = NexButton(nh, 0, 1, "b0")
Expand Down Expand Up @@ -71,6 +77,8 @@
b0.show()
print()

# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')

# wait for 5 more seconds to safely finish the may still running threads
Expand Down
4 changes: 4 additions & 0 deletions examples/page/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
page1 = NexPage(nh, 1, 0, "page1")
page2 = NexPage(nh, 2, 0, "page2")

# ============================================================================
# ============================== Page functions ==============================
# show the default page 0
print('Showing page "{}" ...'.format(page0.name))
page0.show()
Expand All @@ -56,6 +58,8 @@
page0.show()
print()

# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')

# wait for 5 more seconds to safely finish the may still running threads
Expand Down
10 changes: 10 additions & 0 deletions examples/progressbar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
# create a progressbar instance
j0 = NexProgressBar(nh, 0, 1, "j0")

# ============================================================================
# ============================== Example values ==============================
# new values of progressbar
# avoid something close to zero or close to 50
progressbar_value = choice([randint(5, 40), randint(60, 100)])
background_color_value = 63488 # red
font_color_value = 31 # blue

# ============================================================================
# ============================== Value functions =============================
# request the value of progressbar "j0" being 50 by default
print('Requesting progressbar "{}" value ...'.format(j0.name))
response = j0.getValue()
Expand Down Expand Up @@ -62,6 +66,8 @@

time.sleep(1)

# ============================================================================
# =========================== Background functions ===========================
# request the background color of progressbar "j0"
print('Requesting background color of progressbar "{}" ...'.format(j0.name))
response = j0.Get_background_color_bco()
Expand Down Expand Up @@ -93,6 +99,8 @@

time.sleep(1)

# ============================================================================
# ============================== Font functions ==============================
# request the font color of progressbar "j0"
print('Requesting font color of progressbar "{}" ...'.format(j0.name))
response = j0.Get_font_color_pco()
Expand Down Expand Up @@ -120,6 +128,8 @@
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
Expand Down
10 changes: 10 additions & 0 deletions examples/radio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
# 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()
Expand Down Expand Up @@ -60,6 +64,8 @@

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()
Expand Down Expand Up @@ -89,6 +95,8 @@

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()
Expand Down Expand Up @@ -119,6 +127,8 @@
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
Expand Down
Loading

0 comments on commit 1c5e815

Please sign in to comment.