20190816
Dependencies: LCD_DISCO_F429ZI TS_DISCO_F429ZI BSP_DISCO_F429ZI
Revision 0:81007dc65bac, committed 2019-08-16
- Comitter:
- VASKO
- Date:
- Fri Aug 16 22:22:05 2019 +0000
- Commit message:
- 20190816
Changed in this revision
diff -r 000000000000 -r 81007dc65bac BSP_DISCO_F429ZI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP_DISCO_F429ZI.lib Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/BSP_DISCO_F429ZI/#53d9067a4feb
diff -r 000000000000 -r 81007dc65bac LCD_DISCO_F429ZI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_DISCO_F429ZI.lib Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/LCD_DISCO_F429ZI/#dc55a068bc1a
diff -r 000000000000 -r 81007dc65bac PrjDefs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrjDefs.h Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,146 @@ +#ifndef PrjDefs_h_active +#define PrjDefs_h_active + +#include "mbed.h" +#include "LCD_DISCO_F429ZI.h" +#include "TS_DISCO_F429ZI.h" +#include "rtos.h" + +//#define ParsLength (insert needed ParsLength here) // по умолчанию 4 +#define BaudRate 115200 // по умолчанию 9600 +//#define WorkTx (insert TxPin name here) // по умолчанию PA_9, PD_8 или USBTX (зависит от платы) +//#define WorkRx (insert RxPin name here) // по умолчанию PA_10, PD_9 или USBRX (зависит от платы) +//#define UsedSerialClass Serial // по умолчанию RawSerial +#include "TxRxService.h" + +enum PrjEventCodes { + PrjEventNone, + Cmd_cT = 0x16, + CmdPWM, +// CmdTempS, +// Cmd_dTdt, + CmdExtra, + CmdStart, + CmdStop, + CmdPlus, + CmdMinus, + CmdExtraPars, + CmdSelExtraPars, + cT_Selected, + dT_Selected, + TempS_Selected, + TempS_Changing, + dTdt_Selected, + dTdt_Changing, + ChangingParamNone, + KP_Changing, + KI_Changing, + KD_Changing, + PWM_Changing, + KP_Selected, + KI_Selected, + KD_Selected, + PWM_Selected, + PrjEventCodesUndef}; + +enum ChangingParamNums { + ChangingParamNumsUndef}; + +typedef struct { + uint16_t xr; + uint16_t yr; + uint16_t wr; + uint16_t hr; + uint32_t cr; + uint16_t xt; + uint16_t yt; + uint32_t ct; + uint8_t s[10] = "---"; + uint8_t gap = 2; + uint32_t cx = LCD_COLOR_LIGHTGRAY; + } RT_Pars; + +extern bool Start; +extern uint8_t ChangingParam; +extern uint8_t ExtraSelected; +extern uint8_t TempR_Selected; +extern float TempS; +extern float dTdt; +extern float cT; +extern float dT; +extern float KProp; +extern float KInt; +extern float KDif; +extern float PWM; + + +extern RT_Pars TempR_Rect; +extern RT_Pars TempS_Rect; +extern RT_Pars dTdt_Rect; +extern RT_Pars Extra_Rect; +extern RT_Pars Start_Rect; +extern RT_Pars Plus_Rect; +extern RT_Pars Minus_Rect; +extern RT_Pars SelExtra_Rect; + +extern void InitLCDandTS(); +extern void R_T(RT_Pars *rp); +extern bool HitTest(RT_Pars *rp,uint16_t x,uint16_t y); +extern void RxMsgThrdFunc(); +extern void TouchScreenThrdFunc(); +extern void InitRects(); +extern void ReStartH(); +extern void Start_H(); +extern void StopH(); + + + +#define MailLength 30 + +extern Mail<MsgType, MailLength> MsgMail; +extern Thread RxMsgThrd; +extern Thread TouchScreenThrd; +extern Thread TouchScreenThrd; +extern LCD_DISCO_F429ZI lcd; +extern TS_DISCO_F429ZI ts; + +#define LowerLimit(Value,Min) if(Value < Min) Value = Min; +#define UpperLimit(Value,Max) if(Value > Max) Value = Max; +#define LoUpLimit(Value,Min,Max) LowerLimit(Value,Min) UpperLimit(Value,Max) + +#define MaxPower 1 +#define MinPower 0 +#define MaxKProp 1 +#define KPropStep 0.001 +#define MaxKInt 1 +#define KIntStep 0.001 +#define MaxKDif 1 +#define KDifStep 0.001 +#define MaxPWM 1 +#define PWM_Step 0.01 +#define dTdtStep 0.01 +#define Max_dTdt 2 +#define MaxTempS 150 +#define DefaultRectColor LCD_COLOR_LIGHTGRAY +#define ChangingRectColor LCD_COLOR_YELLOW +#define DefaultTextColor LCD_COLOR_WHITE +#define ChangingTextColor LCD_COLOR_BLACK + +#define ScreenWidth 240 +#define ScreenHeight 320 +#define DefaultRectHeight 75 +#define DefaultSpace 4 +#define DefaultRightRectWidth DefaultRectHeight +#define DefaultLeftRectXpos DefaultSpace +#define DefaultRightRectXpos (ScreenWidth - DefaultRightRectWidth - DefaultSpace) +#define DefaultLeftRectWidth (ScreenWidth - DefaultRightRectWidth - 3*DefaultSpace) + +#define Default1stRowRectYpos DefaultSpace +#define Default2ndRowRectYpos (DefaultSpace*2 + DefaultRectHeight) +#define Default3rdRowRectYpos (DefaultSpace*3 + 2*DefaultRectHeight) +#define Default4thRowRectYpos (DefaultSpace*4 + 3*DefaultRectHeight) + +#define TextXpos 8 +#define TextYpos 28 + +#endif //#ifndef PrjDefs_h_active \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac PrjVars.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrjVars.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,30 @@ +#include "PrjDefs.h" + +Thread RxMsgThrd; +Thread TouchScreenThrd; + +LCD_DISCO_F429ZI lcd; +TS_DISCO_F429ZI ts; + +Mail<MsgType, MailLength> MsgMail; +bool Start = 0; +uint8_t ChangingParam = ChangingParamNone; +uint8_t ExtraSelected = PWM_Selected; +uint8_t TempR_Selected = cT_Selected; +float TempS = 100; +float dTdt = 0.1; +float cT; +float dT; +float KProp = 0.100; +float KInt = 0.002; +float KDif = 0.100; +float PWM = 0; + +RT_Pars TempR_Rect = {DefaultLeftRectXpos,Default1stRowRectYpos,DefaultLeftRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor}; +RT_Pars TempS_Rect = {DefaultLeftRectXpos,Default2ndRowRectYpos,DefaultLeftRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor}; +RT_Pars dTdt_Rect = {DefaultLeftRectXpos,Default3rdRowRectYpos,DefaultLeftRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor}; +RT_Pars Extra_Rect = {DefaultLeftRectXpos,Default4thRowRectYpos,DefaultLeftRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor}; +RT_Pars Start_Rect = {DefaultRightRectXpos,Default1stRowRectYpos,DefaultRightRectWidth,DefaultRectHeight,LCD_COLOR_GREEN,TextXpos,TextYpos,LCD_COLOR_BLACK,"P/S"}; +RT_Pars Plus_Rect = {DefaultRightRectXpos,Default2ndRowRectYpos,DefaultRightRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor," +"}; +RT_Pars Minus_Rect = {DefaultRightRectXpos,Default3rdRowRectYpos,DefaultRightRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor," -"}; +RT_Pars SelExtra_Rect = {DefaultRightRectXpos,Default4thRowRectYpos,DefaultRightRectWidth,DefaultRectHeight,DefaultRectColor,TextXpos,TextYpos,DefaultTextColor," S"};
diff -r 000000000000 -r 81007dc65bac RxMsgThread.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RxMsgThread.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,118 @@ +#include "PrjDefs.h" + +DigitalOut xx(PG_13); +//Ticker Tick; + +float dTprev = 0; +float IntPart = 0; +float PL = 0; +float Power = 0; +float RefT = 0; +bool Expired; +bool Down; + +void ResetPID(){ + dTprev = 0; + IntPart = 0; + PL = 0; + Power = 0; + }//ResetPID + +float GetRefT(float r){ + if (Expired) return TempS; + float _f = r; + if(Start){ + if(Down) _f -= dTdt * 0.1; + else _f += dTdt * 0.1; + } + else _f = 0; + if(Down && (_f<=TempS)) { Expired = 1; return TempS; } + else if((!Down) && (_f>=TempS)){ Expired = 1; return TempS; } + else return _f; + }//GetRefT + +void ReStartH(){ + RefT = cT; + Expired = 0; + if(cT<=TempS) Down =0; + else Down = 1; + }//StartH + +void Start_H(){ + ReStartH(); + Start = 1; + }//StartH + +void StopH(){ + RefT = 0; + Expired = 0; + Down = 0; + Start = 0; + ResetPID(); + PWM = 0; + }//StopH + +void PID(){ + float _f = dT * KProp / 10.0; + Power = _f; + LoUpLimit(Power, 0, MaxPower); + IntPart += (dT * KInt / 100.0); + LoUpLimit(IntPart, 0, MaxPower); + Power += IntPart; + _f = -(KDif * (dT - dTprev) / 10.0); + LoUpLimit(_f, 0, MaxPower); + Power += _f; + LoUpLimit(Power, 0, MaxPower); + PWM = Power; + dTprev = dT; + }//PID + +void RxMsgThrdFunc(){ +MsgType _msg; +MsgType *_mail; +TxRxServiceInit(); +while (1) { + TxRxStates _trs = GetMsg(&_msg.cmd); + if(_trs == RxRcvd){ + cT = _msg.pars.f[0]; + if(Start){ + RefT = GetRefT(RefT); + dT = RefT - cT; + xx=1; + PID(); + xx=0; + _mail = MsgMail.alloc(); + if(ExtraSelected == PWM_Selected) _mail->cmd = PWM_Selected; + else if(ExtraSelected == PWM_Changing) _mail->cmd = PWM_Changing; + else _mail->cmd = PrjEventNone; + _mail->pars.f[0] = PWM; + MsgMail.put(_mail); + + _mail = MsgMail.alloc(); + if(TempR_Selected == cT_Selected){ + _mail->cmd = cT_Selected; + _mail->pars.f[0] = cT; + }else{ + _mail->cmd = dT_Selected; + _mail->pars.f[0] = dT; + } + MsgMail.put(_mail); + }else{//if(Start) + PWM = 0; + ResetPID(); + _mail = MsgMail.alloc(); + _mail->cmd = cT_Selected; + _mail->pars.f[0] = cT; + MsgMail.put(_mail); + }//else{//if(Start) + + + + _msg.cmd = CmdPWM; + _msg.pars.f[0] = PWM; + SendMsg(&_msg.cmd); + + }//if(_trs == RxRcvd) + ThisThread::sleep_for(1); + }//while(1) +}//RxMsgThrdFunc \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac TS_DISCO_F429ZI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TS_DISCO_F429ZI.lib Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/TS_DISCO_F429ZI/#4f8b6df8e235
diff -r 000000000000 -r 81007dc65bac TS_Thread.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TS_Thread.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,283 @@ +#include "PrjDefs.h" + +#define mSperTick 10 +#define DelayBetweenTouch 5 +#define DelayAfter1stTouch 50 +#define PauseDelay 10 +#define DelayBefore1stTouch 1 + +int32_t TickCtr = 0; +int32_t TouchNum = 0; +uint32_t TouchDelay = DelayBefore1stTouch; +float pwm = 0; +uint16_t x; +uint16_t y; + +void Incrementer(float *f,float step,float max){ + (*f) += step; + if((*f) > max) (*f) = max; + } + +void Decrementer(float *f,float step,float min){ + (*f) -= step; + if((*f) < min) (*f) = min; + } + +bool HitTest(RT_Pars *rp){ + if(x < ((rp->xr) + (rp->gap))) return false; + if(x > ((rp->xr) + (rp->wr) - (rp->gap))) return false; + if(y < ((rp->yr) + (rp->gap))) return false; + if(y > ((rp->yr) + (rp->hr) - (rp->gap))) return false; + return true; + }//HitTest + +void SetChangingParam(uint8_t v){ + if(ChangingParam == v)ChangingParam = ChangingParamNone; + else ChangingParam = v; + MsgType *_mail; + _mail = MsgMail.alloc(); + _mail->cmd = dTdt_Selected; + _mail->pars.f[0] = dTdt; + MsgMail.put(_mail); + _mail = MsgMail.alloc(); + _mail->cmd = TempS_Selected; + _mail->pars.f[0] = TempS; + MsgMail.put(_mail); + _mail = MsgMail.alloc(); + switch (ExtraSelected){ + case KP_Selected: { _mail->cmd = KP_Selected; _mail->pars.f[0] = KProp; break; } + case KI_Selected: { _mail->cmd = KI_Selected; _mail->pars.f[0] = KInt; break; } + case KD_Selected: { _mail->cmd = KD_Selected; _mail->pars.f[0] = KDif; break; } + case PWM_Selected: { _mail->cmd = PWM_Selected; _mail->pars.f[0] = PWM; break; } + default: { _mail->cmd = PrjEventNone; break; } + }//switch (ExtraSelected) + MsgMail.put(_mail); + }//SetChangingParam + +void SelExtraPar(uint8_t v){ + if(++ExtraSelected > PWM_Selected) ExtraSelected = KP_Selected; + SetChangingParam(ChangingParamNone); + }//SelExtraPar + +bool TouchDispatcher(){ + + MsgType _msg; + + + if(HitTest(&Start_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + _mail->cmd = CmdStart; + if(Start) { PWM = 0; StopH(); } + else { Start_H();} + _mail->pars.ui8[0] = Start; + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&Start_Rect)) + else if(HitTest(&TempR_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + if(TempR_Selected == cT_Selected){ + TempR_Selected = dT_Selected; + _mail->cmd = cT_Selected; + _mail->pars.f[0] = cT; + }else{ + TempR_Selected = cT_Selected; + _mail->cmd = dT_Selected; + _mail->pars.f[0] = dT; + } + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&TempR_Rect)) + else if(HitTest(&TempS_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + if(ChangingParam != TempS_Changing) SetChangingParam(TempS_Changing); + else SetChangingParam(TempS_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = TempS; + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&TempS_Rect)) + else if(HitTest(&dTdt_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + if(ChangingParam != dTdt_Changing) SetChangingParam(dTdt_Changing); + else SetChangingParam(dTdt_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = dTdt; + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&dTdt_Rect)) + else if(HitTest(&SelExtra_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + SelExtraPar(0); + switch (ExtraSelected){ + case KP_Selected: { _mail->cmd = KP_Selected; _mail->pars.f[0] = KProp; break; } + case KI_Selected: { _mail->cmd = KI_Selected; _mail->pars.f[0] = KInt; break; } + case KD_Selected: { _mail->cmd = KD_Selected; _mail->pars.f[0] = KDif; break; } + case PWM_Selected: { _mail->cmd = PWM_Selected; _mail->pars.f[0] = PWM; break; } + default: { _mail->cmd = PrjEventNone; break; } + }//switch (ExtraSelected) + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&ChooseExOpt_Rect)) + else if(HitTest(&Extra_Rect)){ + if(TouchNum == 1){ + MsgType *_mail = MsgMail.alloc(); + switch (ExtraSelected){ + case KP_Selected: { + if(ChangingParam != KP_Changing) SetChangingParam(KP_Changing); + else SetChangingParam(KP_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = KProp; + break; }//KP_Selected + case KI_Selected: { + if(ChangingParam != KI_Changing) SetChangingParam(KI_Changing); + else SetChangingParam(KI_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = KInt; + break; } + case KD_Selected: { + if(ChangingParam != KD_Changing) SetChangingParam(KD_Changing); + else SetChangingParam(KD_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = KDif; + break; } + case PWM_Selected: { + if(ChangingParam != PWM_Changing) SetChangingParam(PWM_Changing); + else SetChangingParam(PWM_Selected); + _mail->cmd = ChangingParam; + _mail->pars.f[0] = PWM; + break; } + default: { _mail->cmd = PrjEventNone; break; } + }//switch (ExtraSelected) + MsgMail.put(_mail); + }//if(TouchNum == 1) + }//if(HitTest(&Extra_Rect)) + else if(HitTest(&Plus_Rect)){ + MsgType *_mail = MsgMail.alloc(); + switch(ChangingParam){ + case TempS_Changing:{ + Incrementer(&TempS,1,MaxTempS); + _mail->cmd = TempS_Changing; + _mail->pars.f[0] = TempS; + ReStartH(); + break;} + case dTdt_Changing:{ + Incrementer(&dTdt,dTdtStep,Max_dTdt); + _mail->cmd = dTdt_Changing; + _mail->pars.f[0] = dTdt; + break;} + case KP_Changing:{ + Incrementer(&KProp,KPropStep,MaxKProp); + _mail->cmd = KP_Changing; + _mail->pars.f[0] = KProp; + break;} + case KI_Changing:{ + Incrementer(&KInt,KIntStep,MaxKInt); + _mail->cmd = KI_Changing; + _mail->pars.f[0] = KInt; + break;} + case KD_Changing:{ + Incrementer(&KDif,KDifStep,MaxKDif); + _mail->cmd = KD_Changing; + _mail->pars.f[0] = KDif; + break;} + case PWM_Changing:{ + Incrementer(&PWM,PWM_Step,MaxPWM); + _mail->cmd = PWM_Changing; + _mail->pars.f[0] = PWM; + break;} + default: { _mail->cmd = PrjEventNone; break; } + }//switch(ChangingParam) + MsgMail.put(_mail); + }//if(HitTest(&Plus_Rect)) + else if(HitTest(&Minus_Rect)){ + MsgType *_mail = MsgMail.alloc(); + switch(ChangingParam){ + case TempS_Changing:{ + Decrementer(&TempS,1,0); + _mail->cmd = TempS_Changing; + _mail->pars.f[0] = TempS; + ReStartH(); + break;} + case dTdt_Changing:{ + Decrementer(&dTdt,dTdtStep,0); + _mail->cmd = dTdt_Changing; + _mail->pars.f[0] = dTdt; + break;} + case KP_Changing:{ + Decrementer(&KProp,KPropStep,0); //_f=(*(float *))ui32; + _mail->cmd = KP_Changing; + _mail->pars.f[0] = KProp; + break;} + case KI_Changing:{ + Decrementer(&KInt,KIntStep,0); + _mail->cmd = KI_Changing; + _mail->pars.f[0] = KInt; + break;} + case KD_Changing:{ + Decrementer(&KDif,KDifStep,0); + _mail->cmd = KD_Changing; + _mail->pars.f[0] = KDif; + break;} + case PWM_Changing:{ + Decrementer(&PWM,PWM_Step,0); + _mail->cmd = PWM_Changing; + _mail->pars.f[0] = PWM; + break;} + default: { _mail->cmd = PrjEventNone; break; } + }//switch(ChangingParam) + MsgMail.put(_mail); + }//if(HitTest(&Minus_Rect)) + else return 0; + return 1; +/* + if(HitTest(&ExOptions_Rect,TS_State.X,TS_State.Y)){ + MsgType *_mail = MsgMail.alloc(); + _mail->cmd = ExOptSetting; + MsgMail.put(_mail); + } + if(HitTest(&ChooseExOpt_Rect,TS_State.X,TS_State.Y)){ + MsgType *_mail = MsgMail.alloc(); + _mail->cmd = ExOptChoosing; + MsgMail.put(_mail); + } +*/ +}//TouchDispatcher + +void TouchScreenThrdFunc(){ +TS_StateTypeDef TS_State; +while(1){ + ts.GetState(&TS_State); + if(TS_State.TouchDetected){ + x = TS_State.X; + y = TS_State.Y; + if(++TickCtr > TouchDelay){ + TickCtr=0; + TouchNum++; + if(!TouchDispatcher()){ + TickCtr=0; + TouchNum=0; + TouchDelay = DelayBefore1stTouch; + } + if(TouchNum == 1) TouchDelay = DelayAfter1stTouch; + else TouchDelay = DelayBetweenTouch; + }//if(++TickCtr>TouchDelay) + + }else{//if(TS_State.TouchDetected) + TickCtr=0; + TouchNum=0; + TouchDelay = DelayBefore1stTouch; + } + ThisThread::sleep_for(mSperTick); +}//while(1) +}//TouchScreenThrdFunc +/* + pwm += 0.001; if (pwm > 1) pwm = 0; + _msg.cmd = 0x17; + _msg.pars.f[0] = pwm; + SendMsg(&_msg.cmd); +*/ \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac TxRxService.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TxRxService.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,101 @@ +#include "PrjDefs.h" + +UsedSerialClass Wcom(WorkTx,WorkRx); + +uint8_t ArrTx[ArrTxSize] = ArrTxInitializer; +MsgType ArrRx; +MsgType RxBuff; +MsgType TxBuff; +uint8_t *pArrTx = &ArrTx[0]; +uint8_t *pArrRx = &ArrRx.cmd; +bool RxBuffFull = 0; +bool ArrTxBusy = 0; +bool TxBuffFull = 0; +bool HdrRcvd = 0; +bool MsgEnabled = 0; +uint8_t HBctr = 0; + +uint8_t GetCheckSum(uint8_t *p){ + uint8_t cs = 0; + for(int i = 0; i < (sizeof(MsgType)-1); i++){ + cs = cs + *(p++); + cs = cs + 1; + } + return cs; + } + +void IntrTx(); + +void CopyArr_InitTx(uint8_t *parr){ + memcpy(&ArrTx[HeaderLength], parr, sizeof(TxBuff)); + pArrTx = &ArrTx[0]; + Wcom.putc(*pArrTx); + if(!ArrTxBusy) { + ArrTxBusy = 1; + Wcom.attach(IntrTx, Serial::TxIrq); + } + TxBuffFull = 0; + } + +void IntrTx() { + if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) Wcom.putc(*pArrTx); + else { + if(TxBuffFull) CopyArr_InitTx(&TxBuff.cmd); + else { + Wcom.attach(NULL, Serial::TxIrq); + ArrTxBusy = 0; + } + } + }//IntrTx + +TxRxStates SendMsg(uint8_t *parr){ + if(TxBuffFull){ return TxBuffBusy; } + *(parr + (sizeof(MsgType)-1)) = GetCheckSum(parr); + if(ArrTxBusy) { //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!! + memcpy(&TxBuff.cmd, parr, sizeof(TxBuff)); //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!! + TxBuffFull=1; //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!! + if(!ArrTxBusy) CopyArr_InitTx(&TxBuff.cmd);//ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!! + } else CopyArr_InitTx(parr); + return TxOK; + }//StartTx + +void IntrRx() { + uint8_t _ch = Wcom.getc(); + if(_ch == HeaderByte){ + if((++HBctr) >= HeaderLength){ + HdrRcvd = 1; + pArrRx = &ArrRx.cmd; + MsgEnabled = 0; + } + }else{ + HBctr = 0; + if(HdrRcvd) { HdrRcvd = 0; MsgEnabled = 1; } + } + if(MsgEnabled){ + *pArrRx = _ch; + if ( pArrRx++ >= &ArrRx.cs ){ + pArrRx = &ArrRx.cmd; + memcpy(&RxBuff.cmd, &ArrRx.cmd, sizeof(RxBuff)); + RxBuffFull = 1; + MsgEnabled = 0; + } + }//if(MsgEnabled) + }//IntrRx + +void TxRxServiceInit(){ +#ifdef BaudRate + Wcom.baud(BaudRate); +#endif + Wcom.attach(IntrRx, Serial::RxIrq); + Wcom.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил + } + +TxRxStates GetMsg(uint8_t *parr){ + if(!RxBuffFull) return RxBuffEmpty; + else{ + memcpy(parr, &RxBuff.cmd, sizeof(RxBuff)); + RxBuffFull = 0; + if(GetCheckSum(&RxBuff.cmd) == RxBuff.cs) return RxRcvd; + else return RxCS_Err; + } + }//GetMsg \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac TxRxService.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TxRxService.h Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,88 @@ + +#ifndef ParsLength + #define ParsLength 4 +#endif +#if ParsLength>16 + #error The length of the parameters seems to be too long. Maybe You should use a different Protocol. +#elif ParsLength<2 + #error The length of the parameters seems to be meaningless. Maybe You should use a different Protocol. +#endif + +#ifndef UsedSerialClass + #define UsedSerialClass RawSerial +#endif + +#define HeaderByte 0x00 +#define HeaderLength (ParsLength+1) + +// ++++++++ Назначение параметров используемого U(S)ART по умолчанию +// У F031K6 U(S)ART один, поэтому +// для F031K6 и для всех неопробованных плат назначается +// U(S)ART по умолчанию (USBTX,USBRX). +#ifndef WorkTx + #ifdef TARGET_NUCLEO_L432KC + #define WorkTx PA_9 // USART1 + #elif defined TARGET_NUCLEO_F072RB + #define WorkTx PA_9 // USART1 + #elif defined TARGET_DISCO_F429ZI + #define WorkTx PG_14 // USART6; USART1(PA_9,PA_10) используется для терминала + #elif defined TARGET_NUCLEO_F031K6 + #define WorkTx USBTX + #else + #define WorkTx USBTX + #endif +#endif +#ifndef WorkRx + #ifdef TARGET_NUCLEO_L432KC + #define WorkRx PA_10 // USART1 + #elif defined TARGET_NUCLEO_F072RB + #define WorkRx PA_10 // USART1 + #elif defined TARGET_DISCO_F429ZI + #define WorkRx PG_9 // USART6; USART1(PA_9,PA_10) используется для терминала + #elif defined TARGET_NUCLEO_F031K6 + #define WorkRx USBRX + #else + #define WorkRx USBRX + #endif +#endif +// Назначение выводов используемого U(S)ART по умолчанию -------- + + +#pragma pack(push, 1)//https://os.mbed.com/forum/bugs-suggestions/topic/4264/ проблема выравнивания данных +typedef union { + uint8_t ui8[ParsLength]; + int8_t i8[ParsLength]; + uint16_t ui16[ParsLength/2]; + int16_t i16[ParsLength/2]; +#if ParsLength>=4 + uint32_t ui32[ParsLength/4]; + int32_t i32[ParsLength/4]; + float f[ParsLength/4]; +#endif + } ParsType; + +typedef struct { + uint8_t cmd; + ParsType pars; + uint8_t cs; + } MsgType; +#pragma pack(pop) + +#define ArrTxSize (HeaderLength + sizeof(MsgType)) +#define ArrRxSize (HeaderLength + sizeof(MsgType)) + +enum TxRxStates { + TxOK, + TxBuffBusy, + RxBuffEmpty, + RxRcvd, + RxCS_Err, + Undefined + }; + +#define ArrTxInitializer {HeaderByte,HeaderByte,HeaderByte,HeaderByte,HeaderByte} + +extern void TxRxServiceInit(); +extern TxRxStates SendMsg(uint8_t *parr); +extern TxRxStates GetMsg(uint8_t *parr); + \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac Utils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utils.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,48 @@ +#include "PrjDefs.h" + +void InitRects(){ + R_T(&TempR_Rect); + sprintf((char*)TempS_Rect.s, "Ttg=%3.0fC", TempS); + R_T(&TempS_Rect); + sprintf((char*)dTdt_Rect.s, "dTdt%1.2f", dTdt); + R_T(&dTdt_Rect); + sprintf((char*)Extra_Rect.s, "KP=%1.3f", KProp); + sprintf((char*)Extra_Rect.s, "PL=%1.3f", PWM); + R_T(&Extra_Rect); + R_T(&Start_Rect); + R_T(&Plus_Rect); + R_T(&Minus_Rect); + R_T(&SelExtra_Rect); + }//InitRects + +void InitLCDandTS() { + BSP_LCD_SetFont(&Font24); + lcd.SetTextColor(LCD_COLOR_WHITE); + uint8_t status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); + if (status != TS_OK){ + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); + lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); + wait(1); + }else{ + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); + wait(0.5); + } + lcd.Clear(LCD_COLOR_BLACK); + lcd.SetBackColor(LCD_COLOR_BLACK); +}//InitLCDandTS + +void R_T(RT_Pars *rp){ + uint32_t _c = lcd.GetTextColor(); + uint32_t _b = lcd.GetBackColor(); + lcd.SetTextColor(rp->cr); + lcd.FillRect(rp->xr, rp->yr, rp->wr, rp->hr); + lcd.SetBackColor(rp->cr); + lcd.SetTextColor(rp->ct); + lcd.DisplayStringAt(((rp->xr)+(rp->xt)), ((rp->yr)+(rp->yt)), &(rp->s[0]), LEFT_MODE); +// lcd.SetBackColor(_b); +// lcd.SetTextColor(_c); + }//R_T \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,143 @@ +#include "PrjDefs.h" + +int main() +{ + + MsgType _msg; + + RxMsgThrd.start(RxMsgThrdFunc); + RxMsgThrd.set_priority(osPriorityHigh); + + TouchScreenThrd.start(TouchScreenThrdFunc); + TouchScreenThrd.set_priority(osPriorityAboveNormal); + + InitLCDandTS(); + + InitRects(); + + while(1){ + osEvent evt = MsgMail.get(0); + if (evt.status == osEventMail) { + MsgType *mail = (MsgType*)evt.value.p; + switch ( mail->cmd ){ + case Cmd_cT:{ + float _f = mail->pars.f[0]; +// sprintf((char*)TempR_Rect.s, "T= 3.1fC"); + sprintf((char*)TempR_Rect.s, "Tcr=%3.0fC", mail->pars.f[0]); +// if( _f >= 100) sprintf((char*)TempR_Rect.s, "T=%3.1fC", cT); +// else sprintf((char*)TempR_Rect.s, "T= %2.1fC", cT); + R_T(&TempR_Rect); + break;} + case cT_Selected:{ + float _f = mail->pars.f[0]; + sprintf((char*)TempR_Rect.s, "Tcr=%3.0fC", mail->pars.f[0]); +// if( _f >= 100) sprintf((char*)TempR_Rect.s, "T=%3.1fC", _f); +// else sprintf((char*)TempR_Rect.s, "T= %2.1fC", _f); + TempR_Rect.cr = DefaultRectColor; + TempR_Rect.ct = DefaultTextColor; + R_T(&TempR_Rect); + break;}//cT_Selected + case dT_Selected:{ + float _f = mail->pars.f[0]; + if(_f < 0) _f = -_f; + if(_f>=100) sprintf((char*)TempR_Rect.s, "dT=%+3.f", mail->pars.f[0]); + else if(_f>=10) sprintf((char*)TempR_Rect.s, "dT=%+2.1f", mail->pars.f[0]); + else sprintf((char*)TempR_Rect.s, "dT=%+1.2f", mail->pars.f[0]); + TempR_Rect.cr = LCD_COLOR_LIGHTBLUE; + TempR_Rect.ct = ChangingTextColor; + R_T(&TempR_Rect); + break;}//dT_Selected + case CmdStart:{ + if(mail->pars.ui8[0])Start_Rect.cr = LCD_COLOR_RED; + else Start_Rect.cr = LCD_COLOR_GREEN; + R_T(&Start_Rect); + break;} + case CmdPWM:{ + sprintf((char*)dTdt_Rect.s, "P=%1.3f", mail->pars.f[0]); + R_T(&dTdt_Rect); + break;} + case KP_Changing:{ + sprintf((char*)Extra_Rect.s, "KP=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = ChangingRectColor; + Extra_Rect.ct = ChangingTextColor; + R_T(&Extra_Rect); + break;}//case KP_Changing + case KI_Changing:{ + sprintf((char*)Extra_Rect.s, "KI=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = ChangingRectColor; + Extra_Rect.ct = ChangingTextColor; + R_T(&Extra_Rect); + break;}//case KI_Changing + case KD_Changing:{ + sprintf((char*)Extra_Rect.s, "KD=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = ChangingRectColor; + Extra_Rect.ct = ChangingTextColor; + R_T(&Extra_Rect); + break;}//case KD_Changing + case PWM_Changing:{ + sprintf((char*)Extra_Rect.s, "PL=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = ChangingRectColor; + Extra_Rect.ct = ChangingTextColor; + R_T(&Extra_Rect); + break;}//case PWM_Changing + case KP_Selected:{ + sprintf((char*)Extra_Rect.s, "KP=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = DefaultRectColor; + Extra_Rect.ct = DefaultTextColor; + R_T(&Extra_Rect); + break;}//case KP_Selected + case KI_Selected:{ + sprintf((char*)Extra_Rect.s, "KI=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = DefaultRectColor; + Extra_Rect.ct = DefaultTextColor; + R_T(&Extra_Rect); + break;}//case KI_Selected + case KD_Selected:{ + sprintf((char*)Extra_Rect.s, "KD=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = DefaultRectColor; + Extra_Rect.ct = DefaultTextColor; + R_T(&Extra_Rect); + break;}//case KD_Selected + case PWM_Selected:{ + sprintf((char*)Extra_Rect.s, "PL=%1.3f", mail->pars.f[0]); + Extra_Rect.cr = DefaultRectColor; + Extra_Rect.ct = DefaultTextColor; + R_T(&Extra_Rect); + break;}//case PWM_Selected + case TempS_Changing:{ + TempS_Rect.cr = ChangingRectColor; + TempS_Rect.ct = ChangingTextColor; + sprintf((char*)TempS_Rect.s, "Ttg=%3.0fC", mail->pars.f[0]); + R_T(&TempS_Rect); + break;}//case TempS_Changing + case TempS_Selected:{ + TempS_Rect.cr = DefaultRectColor; + TempS_Rect.ct = DefaultTextColor; + sprintf((char*)TempS_Rect.s, "Ttg=%3.0fC", mail->pars.f[0]); + R_T(&TempS_Rect); + break;}//case TempS_Selected + case dTdt_Changing:{ + dTdt_Rect.cr = ChangingRectColor; + dTdt_Rect.ct = ChangingTextColor; + sprintf((char*)dTdt_Rect.s, "dTdt%1.2f", dTdt); + R_T(&dTdt_Rect); + break;}//dTdt_Changing + case dTdt_Selected:{ + dTdt_Rect.cr = DefaultRectColor; + dTdt_Rect.ct = DefaultTextColor; + sprintf((char*)dTdt_Rect.s, "dTdt%1.2f", dTdt); + R_T(&dTdt_Rect); + break;}//dTdt_Selected + default: break; + }//switch + MsgMail.free(mail); + }//if (evt.status == osEventMail) + +// ThisThread::sleep_for(1); + }//while(1) +}//main + +/* +DigitalOut xx(PG_13);//зеленый светодиод LD3 DISCO + lcd.FillTriangle(45,45,80,142,177,157); +*/ \ No newline at end of file
diff -r 000000000000 -r 81007dc65bac mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Aug 16 22:22:05 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#b81aeff1a3e171c6421984faa2cc18d0e35746c0