FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: Interfacing with sensors, under the hood of EVE Screen designer (ESD)  (Read 330 times)

techtoys

  • Newbie
  • *
  • Posts: 18
    • View Profile

Hi

Studying how to update a ESD label with value returned from a temperature sensor. My version of ESD is 4.5 beta 2.
Project modified from a basic example : WidgetOpacity as the starting point. I have changed the font size of the ESD Label "Widget Opacity" with an Input Logic Interface. Screen shot of ESD UI attached for reference.

My target is to update the font size with a temperature sensor reading, from 16 to 34.
From ESD simulation the Font size is fixed, because I have not supplied the function to update the reading yet. However, project compiled OK and running good.

Now an Eclipse project is generated with MainPage__Generated.c created with full listing at the end of this post.
I can see that ESD_Label_Font__Property() is changed as follows:

Code: [Select]
ft_int16_t MainPage_ESD_Label_Font__Property(void *c)
{
MainPage *context = (MainPage *)c;
void *owner = context->Owner;
return context->temp_sensor(owner);
}

I think the key is to get context->temp_sensor(owner) updated for whatever period I need via an API.
Under #ifdef ESD_SIMULATION...#endif there are two function prototypes:

Code: [Select]
int MainPage__Get_temp_sensor__ESD(void *context) { return ((MainPage__ESD *)context)->temp_sensor; }
void MainPage__Set_temp_sensor__ESD(void *context, int value) { ((MainPage__ESD *)context)->temp_sensor = value; }

These two functions are not present beyond ESD_SIMULATION.

My question:

Is MainPage__Set_temp_sensor__ESD() the API I need to supply in order to update the font size? Where is the right place to put API to update the temperature reading?

From ESD user guide there are not many examples.


Code: [Select]
//File name: MainPage__Generated.c

#include "MainPage.h"

extern void Ft_Esd_Noop(void *context);
int MainPage_temp_sensor__Default(void *context) { return 16L; }

static ft_int16_t MainPage_ESD_Label_Font__Property(void *context);
static const char * MainPage_ESD_Label_Text__Property(void *context) { return "Widget Opacity"; }
static ft_int16_t MainPage_ESD_Slider_Min__Property(void *context) { return 16; }
static ft_int16_t MainPage_ESD_Slider_Max__Property(void *context) { return 34; }
static ft_uint8_t MainPage_ESD_Gauge_Alpha__Property(void *context);
static ft_uint8_t MainPage_ESD_Clock_Alpha__Property(void *context);
static ft_int16_t MainPage_ESD_Slider_1_Max__Property(void *context) { return 255; }

static Ft_Esd_WidgetSlots s_MainPage__Slots = {
(void(*)(void *))Ft_Esd_Widget_Initialize,
(void(*)(void *))Ft_Esd_Widget_Start,
(void(*)(void *))Ft_Esd_Widget_Enable,
(void(*)(void *))Ft_Esd_Widget_Update,
(void(*)(void *))Ft_Esd_Widget_Render,
(void(*)(void *))Ft_Esd_Widget_Idle,
(void(*)(void *))Ft_Esd_Widget_Disable,
(void(*)(void *))MainPage_End,
};


void MainPage__Fixed_Position__Initializer(MainPage *context)
{
Ft_Esd_Layout_Fixed *object = &context->Fixed_Position;
Ft_Esd_Layout_Fixed__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 0;
object->Widget.LocalY = 0;
object->Widget.LocalWidth = 50;
object->Widget.LocalHeight = 50;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)context);
}

void MainPage__ESD_Label__Initializer(MainPage *context)
{
Ft_Esd_Label *object = &context->ESD_Label;
Ft_Esd_Label__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 10;
object->Widget.LocalY = 12;
object->Widget.LocalWidth = 330;
object->Widget.LocalHeight = 44;
object->Font = MainPage_ESD_Label_Font__Property;
object->Text = MainPage_ESD_Label_Text__Property;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)&context->Fixed_Position);
}

void MainPage__ESD_Slider__Initializer(MainPage *context)
{
Ft_Esd_Slider *object = &context->ESD_Slider;
Ft_Esd_Slider__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 40;
object->Widget.LocalY = 164;
object->Widget.LocalWidth = 300;
object->Widget.LocalHeight = 40;
object->Value = 16;
object->Min = MainPage_ESD_Slider_Min__Property;
object->Max = MainPage_ESD_Slider_Max__Property;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)&context->Fixed_Position);
}

void MainPage__ESD_Gauge__Initializer(MainPage *context)
{
Ft_Esd_Gauge *object = &context->ESD_Gauge;
Ft_Esd_Gauge__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 75;
object->Widget.LocalY = 217;
object->Widget.LocalWidth = 186;
object->Widget.LocalHeight = 155;
object->Alpha = MainPage_ESD_Gauge_Alpha__Property;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)&context->Fixed_Position);
}

void MainPage__ESD_Clock__Initializer(MainPage *context)
{
Ft_Esd_Clock *object = &context->ESD_Clock;
Ft_Esd_Clock__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 211;
object->Widget.LocalY = 73;
object->Widget.LocalWidth = 90;
object->Widget.LocalHeight = 82;
object->Alpha = MainPage_ESD_Clock_Alpha__Property;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)&context->Fixed_Position);
}

void MainPage__ESD_Slider_1__Initializer(MainPage *context)
{
Ft_Esd_Slider *object = &context->ESD_Slider_1;
Ft_Esd_Slider__Initializer(object);
object->Owner = context;
object->Widget.Active = 1;
object->Widget.LocalX = 20;
object->Widget.LocalY = 404;
object->Widget.LocalWidth = 418;
object->Widget.LocalHeight = 42;
object->Value = 255;
object->Max = MainPage_ESD_Slider_1_Max__Property;
Ft_Esd_Widget_InsertBottom((Ft_Esd_Widget *)object, (Ft_Esd_Widget *)&context->Fixed_Position);
}

void MainPage__Initializer(MainPage *context)
{
Ft_Esd_Widget__Initializer((Ft_Esd_Widget *)context);
context->Widget.ClassId = MainPage_CLASSID;
context->Widget.Slots = &s_MainPage__Slots;
context->Widget.LocalX = 0;
context->Widget.LocalY = 0;
context->Widget.LocalWidth = 400;
context->Widget.LocalHeight = 300;
context->temp_sensor = MainPage_temp_sensor__Default;
MainPage__Fixed_Position__Initializer(context);
MainPage__ESD_Label__Initializer(context);
MainPage__ESD_Slider__Initializer(context);
MainPage__ESD_Gauge__Initializer(context);
MainPage__ESD_Clock__Initializer(context);
MainPage__ESD_Slider_1__Initializer(context);
}

void MainPage_End(MainPage *context)
{
void *owner = context->Owner;
Ft_Esd_Widget_End((Ft_Esd_Widget *)context);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->Fixed_Position);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->ESD_Label);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->ESD_Slider);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->ESD_Gauge);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->ESD_Clock);
Ft_Esd_Widget_Detach((Ft_Esd_Widget *)&context->ESD_Slider_1);
}

ft_int16_t MainPage_ESD_Label_Font__Property(void *c)
{
MainPage *context = (MainPage *)c;
void *owner = context->Owner;
return context->temp_sensor(owner);
}

ft_uint8_t MainPage_ESD_Gauge_Alpha__Property(void *c)
{
MainPage *context = (MainPage *)c;
void *owner = context->Owner;
return context->ESD_Slider_1.Value;
}

ft_uint8_t MainPage_ESD_Clock_Alpha__Property(void *c)
{
MainPage *context = (MainPage *)c;
void *owner = context->Owner;
return context->ESD_Slider.Value;
}

#ifdef ESD_SIMULATION
#include <stdlib.h>

typedef struct
{
MainPage Instance;
int temp_sensor;
} MainPage__ESD;

int MainPage__Get_temp_sensor__ESD(void *context) { return ((MainPage__ESD *)context)->temp_sensor; }
void MainPage__Set_temp_sensor__ESD(void *context, int value) { ((MainPage__ESD *)context)->temp_sensor = value; }

void *MainPage__Create__ESD()
{
MainPage__ESD *context = (MainPage__ESD *)malloc(sizeof(MainPage__ESD));
MainPage__Initializer(&context->Instance);
context->Instance.Owner = context;
context->temp_sensor = 16L;
context->Instance.temp_sensor = MainPage__Get_temp_sensor__ESD;
return context;
}

void MainPage__Destroy__ESD(void *context)
{
free(context);
}


#endif /* ESD_SIMULATION */

//end of file


Thank you.



« Last Edit: July 27, 2019, 05:23:55 PM by techtoys »
Logged

scorpioprise

  • Newbie
  • *
  • Posts: 18
    • View Profile

Seems to me you had the same problem I had...
I wish that reading http://www.ftdicommunity.com/index.php?topic=146.msg541#msg541 shall help you.
That's the "hack" I used  ;)
Cheers
Logged

techtoys

  • Newbie
  • *
  • Posts: 18
    • View Profile

Thank you for the link. I am following suggestion by pauljiao. It is working. I like it more because ESD_FUNCTION() macro is available and I can simulate the result under the UI of Screen Designer. My user function looks like this:

Code: [Select]
#ifndef api_font_resizer__H
#define api_font_resizer__H

#include "Ft_Esd.h"

ESD_FUNCTION(api_font_resizer, Type=uint16_t)
uint16_t api_font_resizer();

#endif

In MainPage__Generated.c :

Code: [Select]
ft_int16_t MainPage_ESD_Label_Font__Property(void *c)
{
MainPage *context = (MainPage *)c;
void *owner = context->Owner;
return api_font_resizer();
}

I am trying to structure the project with FreeRTOS, with all GUI related functions run in a task and all modelling tasks allocated to another. So it is like running in 2 threads.

The main thread listing:

Code: [Select]
#include "FT_Platform.h"
#include "freertos/FreeRTOS.h"
#include "Ft_Esd_App.h"
#include "api_font_resizer.h"

uint16_t api_font_resizer(){
static uint16_t msec=0, size= 16;
if(msec++ ==300){ //this is not 300msec. Timing should be adjusted.
if (size++ ==34){
size = 16;
}
msec=0;
}
return size;
}

void setup() {
xTaskCreatePinnedToCore(guiTask,"GuiTask",10000,NULL,1,NULL,1);
}

static uint32_t test_loop_counter=0;

void loop() {
vTaskDelay( 5000 / portTICK_PERIOD_MS ); //delay for 5 sec.
printf("Test loop counter: %d/n", test_loop_counter++);
}


Listing of Ft_Esd_App.h:

Code: [Select]
#ifndef COMPONENTS_FTDI_FT_ESD_FRAMEWORK_FT_ESD_APP_H_
#define COMPONENTS_FTDI_FT_ESD_FRAMEWORK_FT_ESD_APP_H_

#include "Ft_Esd.h"
ft_int32_t Ft_main(ft_int32_t argc, ft_char8_t *argv[]);

#include "freertos/FreeRTOS.h"

void guiTask(void *pvParameters)
{
Ft_main(0, 0);
}

#endif
It is working demonstrated by a looping "Widget Opacity" font size from 16 <-> 34, and a serial printout Test loop counter %d in parallel.

But it seems to me that ESD as a graphical framework shall have an interface for this out-of-the-box instead of a user function. I mean, if a user wants to migrate an old LED-based design to a modern GUI with EVE, he may want to keep existing code for the critical part unchanged (e.g. motor control, sensor sampling intact). Migration task is to change only a value displayed on 7 segments LED board to a 5" LCD controlled by EVE. Rewriting the major part of software to place it under MainPage__Generated.c or user_functions.c should be avoided.

I can see from Logic Interface that there are several tools available such as Signal, Slot, Input, & Variable. With Variable it can be Public, Read-only, and Private. So, did I miss anything from the user guide to update Variable or Slot with standard API subscription?
Logged