2024-06-07 12:26 AM
Hello.
I would use a static graph to display data. In the handletickevent function, I update the addDataPoint(x data, y data) function for the given page, but nothing appears on the graph, the scale is fine, but no line or change in the x direction can be seen on the display. I am currently using the tickcounter++ variable value for X data, which also increases in debug. For X data, I entered 0min, 200max data in the touchgfx program. I also tried the dynamic graph.
Thanks if anyone can help.
Solved! Go to Solution.
2024-06-08 04:19 AM - edited 2024-06-08 04:20 AM
Good, Please note that just clearing the static graph doesnt reset the horizontal plotting. You must also reset X coordinate value and start increasing it again from 0 to 200 (if your X range is 0-200).
If you need constantly scrolling curve, then dynamic graph is right choice. Select scroll as dynamic behavior:
then just simply add points like
dynamicGraph1.addDataPoint(some_value);
and graph-widget will place it to first free position (and also scrolls the curve if it is full).
So with dynamic graph you dont have to worry about X values. Naturally using dynamicGraph requires that the x interval of the data points is constant, otherwise the graph will be distorted in the direction of the X-axis.
Br JTP
2024-06-07 02:56 AM
Hello @Thomas8607 and welcome to the TouchGFX community !
Can you post your code ?
Regards,
2024-06-07 03:02 AM
Hello LouisB,
Here is my screen cpp(tickCounter declared in hpp protect) :
LiveDataScreenView::LiveDataScreenView()
{
}
void LiveDataScreenView::setupScreen()
{
LiveDataScreenViewBase::setupScreen();
DisplayValues.ActiveScreenNumber = 3;
tickCounter = 0;
graph1.clear();
if(SettingsValues.RadioButtonSelectedItem == 1)
{
graph1.setGraphRangeY(0, 300);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(10);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(20);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
else if(SettingsValues.RadioButtonSelectedItem == 2)
{
graph1.setGraphRangeY(0, 6000);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(200);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(1000);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
else if(SettingsValues.RadioButtonSelectedItem == 3)
{
graph1.setGraphRangeY(-4, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(2);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
else if(SettingsValues.RadioButtonSelectedItem == 4)
{
graph1.setGraphRangeY(0, 9000);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(100);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(1000);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
else if(SettingsValues.RadioButtonSelectedItem == 5)
{
graph1.setGraphRangeY(0, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(1);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
else if(SettingsValues.RadioButtonSelectedItem == 6)
{
graph1.setGraphRangeY(0, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(1);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
else if(SettingsValues.RadioButtonSelectedItem == 7)
{
graph1.setGraphRangeY(0, 250);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(5);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(25);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
else if(SettingsValues.RadioButtonSelectedItem == 8)
{
graph1.setGraphRangeY(0, 250);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(5);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(25);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
}
void LiveDataScreenView::tearDownScreen()
{
LiveDataScreenViewBase::tearDownScreen();
}
void LiveDataScreenView::handleTickEvent()
{
tickCounter++;
HardwareValues.TickCounter = tickCounter; // for debugging
if (tickCounter % 2 == 0) // Insert each second tick
{
if(SettingsValues.RadioButtonSelectedItem == 1)
{
graph1.addDataPoint(tickCounter, 20/*DisplayValues.Speed*/);
}
else if(SettingsValues.RadioButtonSelectedItem == 2)
{
graph1.addDataPoint(tickCounter, DisplayValues.Rpm);
}
else if(SettingsValues.RadioButtonSelectedItem == 3)
{
graph1.addDataPoint((float)tickCounter, DisplayValues.Acceleration);
}
else if(SettingsValues.RadioButtonSelectedItem == 4)
{
graph1.addDataPoint(tickCounter, (uint16_t)DisplayValues.TravelledMeter);
}
else if(SettingsValues.RadioButtonSelectedItem == 5)
{
graph1.addDataPoint((float)tickCounter, DisplayValues.ImapPressure);
}
else if(SettingsValues.RadioButtonSelectedItem == 6)
{
graph1.addDataPoint((float)tickCounter, DisplayValues.EmapPressure);
}
else if(SettingsValues.RadioButtonSelectedItem == 7)
{
graph1.addDataPoint(tickCounter, DisplayValues.IntakeTemp);
}
else if(SettingsValues.RadioButtonSelectedItem == 8)
{
graph1.addDataPoint(tickCounter, DisplayValues.CoolantTemp);
}
graph1.invalidate();
}
if(DisplayValues.BootScreenActivate == 1 && DisplayValues.ActiveScreenNumber != 0) {
static_cast<FrontendApplication*>(Application::getInstance())->gotoBootScreenScreenSlideTransitionEast();
}
}
void LiveDataScreenView::RadioButtonSet(uint16_t itemSel)
{
switch(itemSel)
{
case 1: radioButtonGroup1.setSelected(radioButton1);
break;
case 2: radioButtonGroup1.setSelected(radioButton2);
break;
case 3: radioButtonGroup1.setSelected(radioButton3);
break;
case 4: radioButtonGroup1.setSelected(radioButton4);
break;
case 5: radioButtonGroup1.setSelected(radioButton5);
break;
case 6: radioButtonGroup1.setSelected(radioButton6);
break;
case 7: radioButtonGroup1.setSelected(radioButton7);
break;
case 8: radioButtonGroup1.setSelected(radioButton8);
break;
}
}
void LiveDataScreenView::radioButton1Selected()
{
SettingsValues.RadioButtonSelectedItem = 1;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 300);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(10);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(20);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
void LiveDataScreenView::radioButton2Selected()
{
SettingsValues.RadioButtonSelectedItem = 2;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 6000);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(200);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(1000);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
void LiveDataScreenView::radioButton3Selected()
{
SettingsValues.RadioButtonSelectedItem = 3;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(-4, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(2);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
void LiveDataScreenView::radioButton4Selected()
{
SettingsValues.RadioButtonSelectedItem = 4;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 9000);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(100);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(1000);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
void LiveDataScreenView::radioButton5Selected()
{
SettingsValues.RadioButtonSelectedItem = 5;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(1);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
void LiveDataScreenView::radioButton6Selected()
{
SettingsValues.RadioButtonSelectedItem = 6;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 4);
graph1.setScaleY(10);
graph1MajorYAxisGrid.setInterval(1);
graph1MajorYAxisGrid.setScale(10);
graph1MajorYAxisLabel.setInterval(1);
graph1MajorYAxisLabel.setLabelDecimals(1);
graph1MajorYAxisLabel.setScale(10);
}
void LiveDataScreenView::radioButton7Selected()
{
SettingsValues.RadioButtonSelectedItem = 7;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 250);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(5);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(25);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
void LiveDataScreenView::radioButton8Selected()
{
SettingsValues.RadioButtonSelectedItem = 8;
ExtEEPROM.writeToEEPROM(RadioButtonSelectedItem_EEPROMADDRESS, SettingsValues.RadioButtonSelectedItem);
graph1.clear();
graph1.setGraphRangeY(0, 250);
graph1.setScaleY(1);
graph1MajorYAxisGrid.setInterval(5);
graph1MajorYAxisGrid.setScale(1);
graph1MajorYAxisLabel.setInterval(25);
graph1MajorYAxisLabel.setLabelDecimals(0);
graph1MajorYAxisLabel.setScale(1);
}
Thank you!
2024-06-08 12:15 AM - edited 2024-06-08 12:16 AM
2024-06-08 12:28 AM
Check in debuger if your handletick func is called ...
2024-06-08 12:37 AM
I tried it. The tickcounter increments
2024-06-08 12:41 AM
Try break on next ifs or change
if ((tickCounter % 2) == 0)
2024-06-08 12:52 AM
2024-06-08 03:54 AM
Hello Thomas
Maybe slow down process bit, now its adding points maybe 30 times / sec. Also divide counter when using as x coordinate, in your version x- value is running out of screen in few seconds, I guess.
tickCounter++;
HardwareValues.TickCounter = tickCounter; // for debugging
if (tickCounter % 60 == 0) // Insert each second tick
{
if(SettingsValues.RadioButtonSelectedItem == 1)
{
graph1.addDataPoint(tickCounter/60, 20/*DisplayValues.Speed*/);
}
And also clear tickCounter when radiobutton is pressed.
Basically your simplified tickHandler- code seems to work in 4.23.2 simulator and also STM32U5DK2 target.
Br JTP
2024-06-08 04:00 AM - edited 2024-06-08 04:01 AM
I will try it with == 60, if i change radiobutton then i clrear the graph (is is good)
Thank you!