diff --git a/changelog.md b/changelog.md index 96f3275..1437b03 100644 --- a/changelog.md +++ b/changelog.md @@ -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) @@ -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 -[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 diff --git a/examples/basic/main.py b/examples/basic/main.py index 66236dd..918b05d 100644 --- a/examples/basic/main.py +++ b/examples/basic/main.py @@ -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"' @@ -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' @@ -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"' @@ -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' @@ -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' @@ -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' @@ -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' @@ -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' @@ -105,6 +121,8 @@ time.sleep(1) +# ============================================================================ +# ============================ Waveform examples ============================= # add several datapoints to waveform "s0" print('Add several datapoints to waveform "s0"') for x in range(0, 50): @@ -112,6 +130,8 @@ 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 diff --git a/examples/checkbox/main.py b/examples/checkbox/main.py index 45c36fb..9023a84 100644 --- a/examples/checkbox/main.py +++ b/examples/checkbox/main.py @@ -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() @@ -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() @@ -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() @@ -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 diff --git a/examples/gauge/main.py b/examples/gauge/main.py index 309b889..0c8a47e 100644 --- a/examples/gauge/main.py +++ b/examples/gauge/main.py @@ -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() @@ -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() @@ -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() @@ -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() @@ -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 diff --git a/examples/hardware/main.py b/examples/hardware/main.py index ea72d71..8232465 100644 --- a/examples/hardware/main.py +++ b/examples/hardware/main.py @@ -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)) @@ -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) @@ -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") @@ -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 diff --git a/examples/page/main.py b/examples/page/main.py index 24114f1..d72500a 100644 --- a/examples/page/main.py +++ b/examples/page/main.py @@ -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() @@ -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 diff --git a/examples/progressbar/main.py b/examples/progressbar/main.py index 61db912..29035bf 100644 --- a/examples/progressbar/main.py +++ b/examples/progressbar/main.py @@ -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() @@ -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() @@ -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() @@ -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 diff --git a/examples/radio/main.py b/examples/radio/main.py index 235bd8a..9d310f5 100644 --- a/examples/radio/main.py +++ b/examples/radio/main.py @@ -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() @@ -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() @@ -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() @@ -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 diff --git a/examples/text/main.py b/examples/text/main.py index 723e5b4..5dc36e5 100644 --- a/examples/text/main.py +++ b/examples/text/main.py @@ -28,6 +28,8 @@ # create a textfield instance t0 = NexText(nh, 0, 1, "t0") +# ============================================================================ +# ============================== Example values ============================== # new values of text textfield_text = "other txt" background_color_value = 63488 # red @@ -35,6 +37,8 @@ x_offset = 20 y_offset = 20 +# ============================================================================ +# ============================== Text functions ============================== # request the text of textfield "t0" print('Requesting textfield "{}" text ...'.format(t0.name)) response = t0.getText() @@ -62,6 +66,8 @@ time.sleep(1) +# ============================================================================ +# =========================== Background functions =========================== # request the background color of textfield "t0" print('Requesting background color of textfield "{}" ...'.format(t0.name)) response = t0.Get_background_color_bco() @@ -91,6 +97,8 @@ time.sleep(1) +# ============================================================================ +# ============================== Font functions ============================== # request the font color of textfield "t0" print('Requesting font color of textfield "{}" ...'.format(t0.name)) response = t0.Get_font_color_pco() @@ -120,6 +128,8 @@ time.sleep(1) +# ============================================================================ +# ============================ Position functions ============================ # request the x/y position of textfield "t0" again print('Requesting x/y position of textfield "{}" ...'.format(t0.name)) x_position = t0.Get_place_xcen() @@ -138,6 +148,8 @@ t0.Set_place_ycen(y_position) print() +# ============================================================================ +# ============================= End of example =============================== print('Returning to REPL in 5 seconds') # wait for 5 more seconds to safely finish the may still running threads diff --git a/nextion/__init__.py b/nextion/__init__.py index d540d35..0d9c522 100644 --- a/nextion/__init__.py +++ b/nextion/__init__.py @@ -15,4 +15,5 @@ from .nextion_radio import NexRadio from .nextion_slider import NexSlider from .nextion_text import NexText +from .nextion_variable import NexVariable from .nextion_waveform import NexWaveform diff --git a/nextion/nextion_variable.py b/nextion/nextion_variable.py new file mode 100644 index 0000000..638a6b5 --- /dev/null +++ b/nextion/nextion_variable.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +""" +NexVariable + +Functions to interact with a Nextion Variable element +""" + +# custom packages +from .common import Common, CommonTextMixin, CommonValueMixin + + +class NexVariableError(Exception): + """Base class for exceptions in this module.""" + pass + + +class NexVariable(Common, CommonTextMixin, CommonValueMixin): + """docstring for NexVariable""" + def __init__(self, nh, pid: int, cid: int, name: str) -> None: + """ + Init variable + + :param nh: The Nextion hardware interface object + :type nh: NexHardware + :param pid: The page ID + :type pid: int + :param cid: The component ID + :type cid: int + :param name: The component name + :type name: str + """ + super().__init__(nh, pid, cid, name)