Skip to content

Commit

Permalink
Merge pull request #11 from brainelectronics/feature/add-missing-clas…
Browse files Browse the repository at this point in the history
…s-specific-functions

Add missing class specific functions
  • Loading branch information
brainelectronics authored Jul 30, 2022
2 parents d1beb1b + c91bcc2 commit af4f5e0
Show file tree
Hide file tree
Showing 17 changed files with 845 additions and 24 deletions.
15 changes: 15 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.8.0] - 2022-07-30
### Added
- Support all class specific functions of
- Button
- Dual state button
- Number
- Slider
- Waveform

### Changed
- Add full line comment between different section of examples

### Fixed
- Flake8 warnings in several classes due to many imports and inheritance

## [0.7.1] - 2022-07-29
### Fixed
- Add class `CommonPointerMixin` to [`common`](nextion/common.py)
Expand Down
76 changes: 76 additions & 0 deletions examples/button/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@
# create a button instance
b0 = NexButton(nh, 0, 1, "b0")

# ============================================================================
# ============================== Example values ==============================
# new values of button
button_text = "btn txt"
background_color_value = 63488 # red
font_color_value = 31 # blue
pressed_background_color_value = 64480 # orange
pressed_font_color_value = 2047 # cyan
x_offset = 20
y_offset = 20

# ============================================================================
# ============================== Text functions ==============================
# request the text of button "b0"
print('Requesting button "{}" text ...'.format(b0.name))
response = b0.getText()
Expand Down Expand Up @@ -62,6 +68,8 @@

time.sleep(1)

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

time.sleep(1)

# ============================================================================
# ============================== Font functions ==============================
# request the font color of button "b0"
print('Requesting font color of button "{}" ...'.format(b0.name))
response = b0.Get_font_color_pco()
Expand Down Expand Up @@ -120,6 +130,8 @@

time.sleep(1)

# ============================================================================
# ============================ Position functions ============================
# request the x/y position of button "b0" again
print('Requesting x/y position of button "{}" ...'.format(b0.name))
x_position = b0.Get_place_xcen()
Expand All @@ -138,6 +150,70 @@
b0.Set_place_ycen(y_position)
print()

time.sleep(1)

# ============================================================================
# ============================ Special functions =============================
# request the pressed font color of button "b0"
print('Requesting pressed font color of button "{}" ...'.format(b0.name))
response = b0.Get_press_font_color_pco2()
print('Pressed font color of button "{}" is: "{}"'.format(b0.name, response))
print()

time.sleep(1)

# modify the pressed font color of button "b0" to "cyan"
# search for RGB565 Colors. Cyan is "2047" at 65k colors
print('Set font color of button "{}" to "{}"'.
format(b0.name, pressed_font_color_value))
b0.Set_press_font_color_pco2(pressed_font_color_value)
print()

time.sleep(1)

# request the pressed font color of button "b0" again
print('Requesting pressed font color of button "{}" ...'.format(b0.name))
response = b0.Get_press_font_color_pco2()
print('Pressed font color of button "{}" is: "{}"'.format(b0.name, response))
print()

# sanity check
if response != pressed_font_color_value:
print('WARNING: GET value did not match SET value')

time.sleep(1)

# request the pressed background color of button "b0"
print('Requesting pressed background color of button "{}" ...'.format(b0.name))
response = b0.Get_press_background_color_bco2()
print('Pressed background color of button "{}" is: "{}"'.
format(b0.name, response))
print()

time.sleep(1)

# modify the pressed background color of button "b0" to "orange"
# search for RGB565 Colors. Red is "64480" at 65k colors
print('Set pressed background color of button "{}" to "{}"'.
format(b0.name, pressed_background_color_value))
b0.Set_press_background_color_bco2(pressed_background_color_value)
print()

time.sleep(1)

# request the pressed background color of button "b0" again
print('Requesting pressed background color of button "{}" ...'.format(b0.name))
response = b0.Get_press_background_color_bco2()
print('Pressed background color of button "{}" is: "{}"'.
format(b0.name, response))
print()

# sanity check
if response != pressed_background_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
85 changes: 84 additions & 1 deletion examples/dual_button/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@
# create a dual state button instance
bt0 = NexDSButton(nh, 0, 1, "bt0")

# ============================================================================
# ============================== Example values ==============================
# new values for dual state button
button_text = "btn txt"
button_value = 1 # 1 is active (green), 0 is inactive (grey)
background_color_value = 63488 # red
font_color_value = 31 # blue
pressed_background_color_value = 64480 # orange
x_offset = 20
y_offset = 20

# ============================================================================
# =========================== Text+Value functions ===========================
# request the text of dual state button "bt0"
print('Requesting dual state button "{}" text ...'.format(bt0.name))
response_text = bt0.getText()
Expand All @@ -55,7 +61,8 @@
print()

# modify dual state button "bt0" being released by default
print('Set dual state button "{}" state to "{}"'.format(bt0.name, button_value))
print('Set dual state button "{}" state to "{}"'.
format(bt0.name, button_value))
bt0.setValue(button_value)
print()

Expand All @@ -81,6 +88,43 @@

time.sleep(1)

# ============================================================================
# =========================== Background functions ===========================
# request the background color of dual state button "bt0"
print('Requesting background color of dual state button "{}" ...'.
format(bt0.name))
response = bt0.Get_state0_color_bco0()
print('Background color of dual state button "{}" is: "{}"'.
format(bt0.name, response))
print()

time.sleep(1)

# modify the background color of dual state button "bt0" to "red"
# search for RGB565 Colors. Red is "63488" at 65k colors
print('Set background color of dual state button "{}" to "{}"'.
format(bt0.name, background_color_value))
bt0.Set_state0_color_bco0(background_color_value)
print()

time.sleep(1)

# request the background color of dual state button "bt0" again
print('Requesting background color of dual state button "{}" ...'.
format(bt0.name))
response = bt0.Get_state0_color_bco0()
print('Background color of dual state button "{}" is: "{}"'.
format(bt0.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 dual state button "bt0"
print('Requesting font color of dual state button "{}" ...'.format(bt0.name))
response = bt0.Get_font_color_pco()
Expand Down Expand Up @@ -112,6 +156,8 @@

time.sleep(1)

# ============================================================================
# ============================ Position functions ============================
# request the x/y position of dual state button "bt0" again
print('Requesting x/y position of dual state button "{}" ...'.format(bt0.name))
x_position = bt0.Get_place_xcen()
Expand All @@ -130,6 +176,43 @@
bt0.Set_place_ycen(y_position)
print()

time.sleep(1)

# ============================================================================
# ============================ Special functions =============================
# request the pressed background color of dual state button "bt0"
print('Requesting pressed background color of dual state button "{}" ...'.
format(bt0.name))
response = bt0.Get_state1_color_bco1()
print('Pressed background color of dual state button "{}" is: "{}"'.
format(bt0.name, response))
print()

time.sleep(1)

# modify the pressed background color of dual state button "bt0" to "red"
# search for RGB565 Colors. Red is "63488" at 65k colors
print('Set pressed background color of dual state button "{}" to "{}"'.
format(bt0.name, pressed_background_color_value))
bt0.Set_state1_color_bco1(pressed_background_color_value)
print()

time.sleep(1)

# request the pressed background color of dual state button "bt0" again
print('Requesting pressed background color of dual state button "{}" ...'.
format(bt0.name))
response = bt0.Get_state0_color_bco0()
print('Pressed background color of dual state button "{}" is: "{}"'.
format(bt0.name, response))
print()

# sanity check
if response != pressed_background_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
50 changes: 49 additions & 1 deletion examples/number/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@
# create a number instance
n0 = NexNumber(nh, 0, 1, "n0")

# ============================================================================
# ============================== Example values ==============================
# new values of number field
number_value = randint(1, 100)
background_color_value = 63488 # red
font_color_value = 31 # blue
x_offset = 20
y_offset = 20

number_length = 2
# numer = 300, length = 0 -> "300"
# length = 1 -> "3"
# length = 2 -> "30"
# length = 3 -> "300"
# length = 4 -> "0300"

# ============================================================================
# ============================== Value functions =============================
# request the value of number "n0"
print('Requesting number "{}" value ...'.format(n0.name))
response = n0.getValue()
Expand Down Expand Up @@ -63,6 +73,8 @@

time.sleep(1)

# ============================================================================
# =========================== Background functions ===========================
# request the background color of number "n0"
print('Requesting background color of number "{}" ...'.format(n0.name))
response = n0.Get_background_color_bco()
Expand Down Expand Up @@ -92,6 +104,8 @@

time.sleep(1)

# ============================================================================
# ============================== Font functions ==============================
# request the font color of number "n0"
print('Requesting font color of number "{}" ...'.format(n0.name))
response = n0.Get_font_color_pco()
Expand Down Expand Up @@ -121,6 +135,8 @@

time.sleep(1)

# ============================================================================
# ============================ Position functions ============================
# request the x/y position of number "n0" again
print('Requesting x/y position of number "{}" ...'.format(n0.name))
x_position = n0.Get_place_xcen()
Expand All @@ -139,6 +155,38 @@
n0.Set_place_ycen(y_position)
print()

# ============================================================================
# ============================ Special functions =============================
# request the number length of number "n0"
print('Requesting number length of number "{}" ...'.format(n0.name))
response = n0.Get_number_length()
print('Number length of number "{}" is: "{}"'.format(n0.name, response))
print()

time.sleep(1)

# modify the number length of number "n0"
print('Set number length of number "{}" to "{}"'.
format(n0.name, number_length))
n0.Set_number_length(number_length)
print()

time.sleep(1)

# request the number length of number "n0" again
print('Requesting number length of number "{}" ...'.format(n0.name))
response = n0.Get_number_length()
print('Number length of number "{}" is: "{}"'.format(n0.name, response))
print()

# sanity check
if response != number_length:
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
Loading

0 comments on commit af4f5e0

Please sign in to comment.