test

Dependencies:   ad5422_arduino mbed LT1446 ADS1248-1 LM35-1 Flash FT813 PGA280_ADS1259

TFT/display.PidScreen.cpp

Committer:
nikmaos
Date:
2020-08-14
Revision:
6:cfe7cb0bdb1a
Parent:
5:21240fa1ee4c
Child:
7:c364201bc3ed

File content as of revision 6:cfe7cb0bdb1a:

#include "display.h"
void Display::PidScreen(/*костыль костылей*/float (*btf)(unsigned char*),float temp, float ras,uint16_t power1,uint16_t power2,PID_t* PID1,PID_t* PID2)
{
    char key=pressedButton;
    char str_v[48];
    char sel=0;
    
    StartDL();
    (*_TFT).DL(CLEAR_COLOR_RGB(31, 63, 127));
    // clear buffers for preset values
    (*_TFT).DL(CLEAR(1, 1, 1));
    (*_TFT).DL(COLOR_RGB(255, 255, 255));    
    (*_TFT).Text(300, 10 , 29, 0, "PID Controller Menu");
    myWdget_NumPad(500,80);   
    
    //поля для отображения настроек
    sprintf(str_v,"PID temp: %0.2f oC       | Power: %04d",temp,power1);    
    myWdget_Edit(34,78,420,40,0,str_v);
        
    sprintf(str_v,"PID Rashod: %0.4f cm3/kg | Power: %04d",ras,power2);
    myWdget_Edit(34,78+44,420,40,0,str_v);
    
    (*_TFT).DL(TAG_MASK(1));
    
    (*_TFT).DL(TAG(SEL_P1));
    sprintf(str_v,"P1: %04.2f",PID1->kP);
    if(selectedEditor==EDIT_P1)
    {sel=1;
        myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }    
    myWdget_Edit(34,78+44+44,420/2-2,40,sel,str_v);    
    sel=0;
    
    (*_TFT).DL(TAG(SEL_P2));
    sprintf(str_v,"P2: %04.2f",PID2->kP);
    if(selectedEditor==EDIT_P2)
    {
    sel=1;
    myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }
    myWdget_Edit(34+420/2+2,78+44+44,420/2-2,40,sel,str_v);
    sel=0;
    
    (*_TFT).DL(TAG(SEL_I1));
    sprintf(str_v,"I1: %06.1f",PID1->kI);
    if(selectedEditor==EDIT_I1)
    {
    sel=1;
    myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }
    myWdget_Edit(34,78+44*3,420/2-2,40,sel,str_v);
    sel=0;
    
    (*_TFT).DL(TAG(SEL_I2));
    sprintf(str_v,"I2: %06.1f",PID2->kI);
    if(selectedEditor==EDIT_I2)
    {
    sel=1;
    myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }
    myWdget_Edit(34+420/2+2,78+44*3,420/2-2,40,sel,str_v);
    sel=0;
    
    (*_TFT).DL(TAG(SEL_D1));
    sprintf(str_v,"D1: %05.2f",PID1->kD);
    if(selectedEditor==EDIT_D1)
    {
    sel=1;
    myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }
    myWdget_Edit(34,78+44*4,420/2-2,40,sel,str_v);
    sel=0;
    
    (*_TFT).DL(TAG(SEL_D2));
    sprintf(str_v,"D2: %05.2f",PID2->kD);
    if(selectedEditor==EDIT_D2)
    {
    sel=1;
    
    myWdget_Edit_change(str_v);        
        sprintf(str_v,"%s",str_edit);
    }
    myWdget_Edit(34+420/2+2,78+44*4,420/2-2,40,sel,str_v);
    sel=0;
    
    (*_TFT).DL(TAG(BACK_PRESS));
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    if(key==BACK_PRESS)        
    (*_TFT).Button(34, 325, 120, 36, 27, OPT_FLAT, "Back");    
    else
    (*_TFT).Button(34, 325, 120, 36, 27, 0, "Back");
    
    
    (*_TFT).DL(TAG(CANCEL_PRESS));
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    if(key==CANCEL_PRESS)
    {
    (*_TFT).Button(325, 325, 120, 36, 27, OPT_FLAT, "Cancel");
    selectedEditor=EDIT_NONE;
    for(int i=0;i<10;i++)
    str_edit[i]=0;
    cursor=0;
    str_edit[0]='_';
    }
    else
    (*_TFT).Button(325, 325, 120, 36, 27, 0, "Cancel");
    
    (*_TFT).DL(TAG(APPLY_PRESS));
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    if(key==APPLY_PRESS)
    {
    (*_TFT).Button(200, 325, 120, 36, 27, OPT_FLAT, "Apply");
    //Применение значений
    if(selectedEditor==EDIT_P1)
    PID1->kP=btf(str_edit);
    
    if(selectedEditor==EDIT_P2)
    PID2->kP=btf(str_edit);
    
    if(selectedEditor==EDIT_I1)
    PID1->kI=btf(str_edit);
    
    if(selectedEditor==EDIT_I2)
    PID2->kI=btf(str_edit);
    
    if(selectedEditor==EDIT_D1)
    PID1->kD=btf(str_edit);
    
    if(selectedEditor==EDIT_D2)
    PID2->kD=btf(str_edit);
    
    selectedEditor=EDIT_NONE;
    for(int i=0;i<10;i++)
    str_edit[i]=0;
    cursor=0;
    str_edit[0]='_';    
    }
    else
    (*_TFT).Button(200, 325, 120, 36, 27, 0, "Apply");
    
    (*_TFT).DL(TAG(SAVE_PRESS));
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    if(key==SAVE_PRESS)        
    (*_TFT).Button(200, 365, 120, 36, 27, OPT_FLAT, "Save");    
    else
    (*_TFT).Button(200, 365, 120, 36, 27, 0, "Save");
    
    //переключатели ПИДов
    (*_TFT).DL(TAG(PID1SW_PRESS));    
    (*_TFT).Toggle(260, 420,50,27,0,0,"OFF""\xff""ON");
    if(key==PID1SW_PRESS)
    {PID1->enabled=~PID1->enabled;}
    if(PID1->enabled)
    (*_TFT).Toggle(260, 420,50,27,0,0xFFFF,"OFF""\xff""ON");//ПИД1 вкл
    
    (*_TFT).DL(TAG(PID2SW_PRESS));    
    (*_TFT).Toggle(385, 420,50,27,0,0,"OFF""\xff""ON");
    if(key==PID2SW_PRESS)    
    {PID2->enabled=~PID2->enabled;}
    if(PID2->enabled)
    (*_TFT).Toggle(385, 420,50,27,0,0xFFFF,"OFF""\xff""ON");//ПИД2 вкл
    (*_TFT).DL(TAG_MASK(0));
    
    
    
    FinishDL();
}