From 9d03f472335be2c696547c8484421dba8252f145 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Thu, 23 May 2024 23:11:34 +0200 Subject: [PATCH] [nextion] Add basic functions to Intelligent series (#6791) --- esphome/components/nextion/nextion.h | 67 +++++++++++++++++++ .../components/nextion/nextion_commands.cpp | 20 +++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/esphome/components/nextion/nextion.h b/esphome/components/nextion/nextion.h index dfa74f644d..4546baa4d8 100644 --- a/esphome/components/nextion/nextion.h +++ b/esphome/components/nextion/nextion.h @@ -952,6 +952,73 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe */ bool set_protocol_reparse_mode(bool active_mode); + // ======== Nextion Intelligent Series ======== + + /** + * Set the video id of a component. + * @param component The component name. + * @param vid_id The video ID. + * + * Example: + * ```cpp + * it.set_component_vid("textview", 1); + * ``` + * + * This will change the video id of the component `textview`. + * + * Note: Requires Nextion Intelligent series display. + */ + void set_component_vid(const char *component, uint8_t vid_id); + + /** + * Set the drag availability of a component. + * @param component The component name. + * @param drag False: Drag not available, True: Drag available. + * + * Example: + * ```cpp + * it.set_component_drag("textview", true); + * ``` + * + * This will enable drag to the component `textview`. + * + * Note: Requires Nextion Intelligent series display. + */ + void set_component_drag(const char *component, bool drag); + + /** + * Set the opaqueness (fading) of a component. + * @param component The component name. + * @param aph An integer between 0 and 127 related to the opaqueness/fading level. + * + * Example: + * ```cpp + * it.set_component_aph("textview", 64); + * ``` + * + * This will set the opaqueness level of the component `textview` to 64. + * + * Note: Requires Nextion Intelligent series display. + */ + void set_component_aph(const char *component, uint8_t aph); + + /** + * Set the position of a component. + * @param component The component name. + * @param x The new X (horizontal) coordinate for the component. + * @param y The new Y (vertical) coordinate for the component. + * + * Example: + * ```cpp + * it.set_component_aph("textview", 64, 35); + * ``` + * + * This will move the component `textview` to the column 64 of row 35 of the display. + * + * Note: Requires Nextion Intelligent series display. + */ + void set_component_position(const char *component, uint32_t x, uint32_t y); + // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) void register_touch_component(NextionComponentBase *obj) { this->touch_.push_back(obj); } diff --git a/esphome/components/nextion/nextion_commands.cpp b/esphome/components/nextion/nextion_commands.cpp index fdd6c74d99..398e9dd502 100644 --- a/esphome/components/nextion/nextion_commands.cpp +++ b/esphome/components/nextion/nextion_commands.cpp @@ -148,7 +148,25 @@ void Nextion::set_component_pic(const char *component, uint8_t pic_id) { } void Nextion::set_component_picc(const char *component, uint8_t pic_id) { - this->add_no_result_to_queue_with_printf_("set_component_pic", "%s.picc=%" PRIu8, component, pic_id); + this->add_no_result_to_queue_with_printf_("set_component_picc", "%s.picc=%" PRIu8, component, pic_id); +} + +// Set video +void Nextion::set_component_vid(const char *component, uint8_t vid_id) { + this->add_no_result_to_queue_with_printf_("set_component_vid", "%s.vid=%" PRIu8, component, vid_id); +} + +void Nextion::set_component_drag(const char *component, bool drag) { + this->add_no_result_to_queue_with_printf_("set_component_drag", "%s.drag=%i", component, drag ? 1 : 0); +} + +void Nextion::set_component_aph(const char *component, uint8_t aph) { + this->add_no_result_to_queue_with_printf_("set_component_aph", "%s.aph=%" PRIu8, component, aph); +} + +void Nextion::set_component_position(const char *component, uint32_t x, uint32_t y) { + this->add_no_result_to_queue_with_printf_("set_component_position_x", "%s.x=%" PRIu32, component, x); + this->add_no_result_to_queue_with_printf_("set_component_position_y", "%s.y=%" PRIu32, component, y); } void Nextion::set_component_text_printf(const char *component, const char *format, ...) {