Start a new topic
Solved

Arduino library progress bar workaround

Hello everyone!


I just got my first nextion display 3.2`` and got the problem with progress bar.

As we all know that new command to set progress bar state is:

j0.val=jo.val+5

 So this function is not in library:

https://github.com/itead/ITEADLIB_Arduino_Nextion


The workaround


1. Edit file: NexProgressBar.cpp

remove: 

bool setValue(uint32_t number);

 add:

 bool setValuePlus(uint32_t number);
 bool setValueMinus(uint32_t number);


2. Edit file: NexProgressBar.h

remove:

bool NexProgressBar::setValue(uint32_t number)
{
    char buf[10] = {0};
    String cmd;
    
    utoa(number, buf, 10);
    cmd += getObjName();
    cmd += ".val=";
    cmd += buf;

    sendCommand(cmd.c_str());
    return recvRetCommandFinished();
}

 

add:

bool NexProgressBar::setValuePlus(uint32_t number)
{
    char buf[10] = {0};
    String cmd;
    
    utoa(number, buf, 10);
    cmd += getObjName();
    cmd += ".val=";
	cmd += getObjName();
	cmd += ".val+";
    cmd += buf;

    sendCommand(cmd.c_str());
    return recvRetCommandFinished();
}

  

This may be not the best solution, but his works with example from library.


Arduino progress bar test: 

#include "Nextion.h"

NexText t0 = NexText(0, 1, "t0");
NexProgressBar j0  = NexProgressBar(0, 2, "j0");

int msg[50];
uint32_t number = 0;

void setup() {
  Serial.begin(115200);
  //Display init
  nexInit();
  t0.setText("Boot...");
  uint32_t bootint = 0;
  delay(2000);
  t0.setText("Loading...");
}

void loop() {
    delay(100);
    j0.getValue(&number);
    
    if (number <= 99){
        number =+1;
        j0.setValuePlus(number); 
    } else {
      t0.setText("READY!");
    }
}

  

p.s. For ESP8266 change variable "j0" to something else, for example "bootBar1" in Arduino sketch and NextionEditor ObjectName/Component name.


Please repost in the Free Chat section.  As this is not a bug it will end up getting deleted.

It has good information, it will be a shame if it is lost.

This would only make sense as a addition, but not to remove the default, since that might be how you use progress bars, but with progress bars that should display non-linear processes that'll not allow for that.

e.g. with data transfer over async connections you might want to update the bar once per second but the data transmitted will upload with varying speed so one sec is not always plus a constant amount of data transmitted.


On the other hand doing the math on the controller side (where it has to be done usually anyway) and sending the result allows for your and my use case ;-)


I agree with Scruff.r that the math should be done "where the variables for the calculations are".

This would normally be on the connecting MCU.


A small caveat to this is the Enhanced series, where the data receiving MCU isn't the connecting MCU

But rather in that case, the Nextion is the controller.  Calculations should then be on the Nextion.

You know, I just decided to see what was in the Library

The .setValue is a function already there in NexProgressBar.cpp modified 28 days ago.

Line 32 Perhaps?


Is there really such a thing as Negative Progress for setValueMinus?

I might also question if to go from 0 to 100 if I really wanted to jam the RX/TX with so much traffic.

from 0 to 100 uses 2003+ bytes (1203 sent and 800 received) and is rather poor use of the RX/TX lines.

The delay of 100ms also means an unnecessary delay of 10sec to go from 0 to 100 percent.


Certainly another approach would be to have the animation performed by the Nextion and limit the amount of data sent to the Nextion over serial.  But then again, why put the Nextion into a state where it is busy for 10 seconds.





Login or Signup to post a comment