2021-07-12 06:57 PM
Hi, I would like that use a callback of timer (programmed with 10ms) to override the "ScreenView::handleTickEvent()" function, because this function has interrupt in ~14ms.
I managed to create the function and link the cpp and C files, but I couldn't use C++ functions (about graph..) in the timer callback that I created, there is an error like "was not declared in this scope" in which when I use it in the "handleTickEvent" function there is no error. Why is this happening?
Here is the .c file:
#include <gui/main_screen/MainView.hpp>
#include <math.h>
#include <stdlib.h>
extern "C" void CallbackTim5();
int slide_value = 0;
int xlabel_0 = 10;
int xlabel_1 = 11;
int xlabel_2 = 12;
int xlabel_3 = 13;
int xlabel_4 = 14;
int xlabel_5 = 15;
int xlabel_6 = 16;
int xlabel_7 = 17;
int xlabel_8 = 18;
int xlabel_9 = 19;
int xlabel_10 = 20;
int contDataPoint=0;
int msCounter=0;
//here dont works
void CallbackTim5(){
msCounter++;
// Insert each second tick
if (msCounter % 2 == 0)
{
// Insert "random" points along a sine wave
graph_control.addDataPoint(10);
graph_response.addDataPoint(20);
graph_setpoint.addDataPoint(slide_value);
contDataPoint++;
if(contDataPoint >= 300){
contDataPoint = 0;
if((xlabel_0 >= 300) && (xlabel_0 < 1000)){
Unicode::snprintf(xLabelGraph1Buffer, 147,
"%d %d %d %d %d %d %d %d %d %d %d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
xLabelGraph1.invalidate();
Unicode::snprintf(xLabelGraph2Buffer, 147,
"%d %d %d %d %d %d %d %d %d %d %d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
}
else if(xlabel_0 >= 1000){
Unicode::snprintf(xLabelGraph1Buffer, 147,
"%d%d%d%d%d%d%d%d%d%d%d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
xLabelGraph1.invalidate();
Unicode::snprintf(xLabelGraph2Buffer, 147,
"%d%d%d%d%d%d%d%d%d%d%d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
}
else{
Unicode::snprintf(xLabelGraph1Buffer, 147,
"%d %d %d %d %d %d %d %d %d %d %d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
xLabelGraph1.invalidate();
Unicode::snprintf(xLabelGraph2Buffer, 147,
"%d %d %d %d %d %d %d %d %d %d %d",
xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
}
xLabelGraph2.invalidate();
xlabel_0 += 10;
xlabel_1 += 10;
xlabel_2 += 10;
xlabel_3 += 10;
xlabel_4 += 10;
xlabel_5 += 10;
xlabel_6 += 10;
xlabel_7 += 10;
xlabel_8 += 10;
xlabel_9 += 10;
xlabel_10 += 10;
}
}
}
MainView::MainView()
{
tickCounter = 0;
}
void MainView::setupScreen()
{
MainViewBase::setupScreen();
// Initialize graph range with default slider value at start up
sliderValueChanged(sliderSetpoint.getValue());
}
void MainView::tearDownScreen()
{
MainViewBase::tearDownScreen();
}
//here works
void MainView::handleTickEvent()
{
// tickCounter++;
//
// // Insert each second tick
// if (tickCounter % 2 == 0)
// {
// // Insert "random" points along a sine wave
// graph_control.addDataPoint(10);
// graph_response.addDataPoint(20);
// graph_setpoint.addDataPoint(slide_value);
//
// contDataPoint++;
// if(contDataPoint >= 300){
//
// contDataPoint = 0;
// if((xlabel_0 >= 300) && (xlabel_0 < 1000)){
// Unicode::snprintf(xLabelGraph1Buffer, 147,
// "%d %d %d %d %d %d %d %d %d %d %d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
//
// xLabelGraph1.invalidate();
//
// Unicode::snprintf(xLabelGraph2Buffer, 147,
// "%d %d %d %d %d %d %d %d %d %d %d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
// }
// else if(xlabel_0 >= 1000){
// Unicode::snprintf(xLabelGraph1Buffer, 147,
// "%d%d%d%d%d%d%d%d%d%d%d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
//
// xLabelGraph1.invalidate();
//
// Unicode::snprintf(xLabelGraph2Buffer, 147,
// "%d%d%d%d%d%d%d%d%d%d%d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
// }
// else{
// Unicode::snprintf(xLabelGraph1Buffer, 147,
// "%d %d %d %d %d %d %d %d %d %d %d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
//
// xLabelGraph1.invalidate();
//
// Unicode::snprintf(xLabelGraph2Buffer, 147,
// "%d %d %d %d %d %d %d %d %d %d %d",
// xlabel_0, xlabel_1, xlabel_2, xlabel_3, xlabel_4, xlabel_5,
// xlabel_6, xlabel_7, xlabel_8, xlabel_9, xlabel_10);
// }
//
//
// xLabelGraph2.invalidate();
//
// xlabel_0 += 10;
// xlabel_1 += 10;
// xlabel_2 += 10;
// xlabel_3 += 10;
// xlabel_4 += 10;
// xlabel_5 += 10;
// xlabel_6 += 10;
// xlabel_7 += 10;
// xlabel_8 += 10;
// xlabel_9 += 10;
// xlabel_10 += 10;
// }
// }
}
void MainView::sliderValueChanged(int value)
{
slide_value = value;
}
void MainView::resetButtonEvent(){
}
void MainView::setButtonEvent(){
}
void MainView::autoButtonEvent(){
}
Error:
Without Error:
2021-07-13 11:29 AM
How display config you use _? LTDC ? TickEvent is based on refresh rate on LCD for example 60Hz ... around 16ms , then when your display support and you need 10ms setup it to 100Hz frame refresh...
2023-03-08 05:39 AM
you cannot access a member of MainView like graph_control from a c function.
your callback must be a member of your view if you want to use this concept