From 5d4fa4223c4a257969ee2a9bd4e34e32045f9ef9 Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Mon, 7 Feb 2022 21:49:55 +0100 Subject: [PATCH] Allow for the resetting of a graph. --- src/elem/XGraph.c | 30 +++++++++++++++++------------- src/elem/XGraph.h | 8 ++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/elem/XGraph.c b/src/elem/XGraph.c index 530c7781d..45dbbc7a9 100644 --- a/src/elem/XGraph.c +++ b/src/elem/XGraph.c @@ -92,8 +92,6 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n pXData->nMargin = 5; pXData->nBufMax = nBufMax; - pXData->nBufCnt = 0; - pXData->nPlotIndStart = 0; pXData->colGraph = colGraph; pXData->eStyle = GSLCX_GRAPH_STYLE_DOT; @@ -103,17 +101,6 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n pXData->nWndHeight = rElem.h - (2*pXData->nMargin); pXData->nWndWidth = rElem.w - (2*pXData->nMargin); - // Default scale is - // - Each data point (buffer row) gets 1 pixel in X direction - // - Data value is directly mapped to height in Y direction - pXData->nPlotValMin = 0; - pXData->nPlotValMax = pXData->nWndHeight; - pXData->nPlotIndMax = pXData->nWndWidth; - - - // Clear the buffer - memset(pBuf,0,nBufMax*sizeof(int16_t)); - // Determine if scrollbar should be enabled if (pXData->nPlotIndMax >= pXData->nBufMax) { @@ -138,6 +125,7 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n sElem.colElemFrameGlow = GSLC_COL_WHITE; if (nPage != GSLC_PAGE_NONE) { pElemRef = gslc_ElemAdd(pGui,nPage,&sElem,GSLC_ELEMREF_DEFAULT); + gslc_ElemXGraphReset(pGui, pElemRef); return pElemRef; #if (GSLC_FEATURE_COMPOUND) } else { @@ -145,6 +133,7 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n pGui->sElemTmp = sElem; pGui->sElemRefTmp.pElem = &(pGui->sElemTmp); pGui->sElemRefTmp.eElemFlags = GSLC_ELEMREF_DEFAULT | GSLC_ELEMREF_REDRAW_FULL; + gslc_ElemXGraphReset(pGui, &(pGui->sElemRefTmp); return &(pGui->sElemRefTmp); #endif } @@ -239,6 +228,21 @@ void gslc_ElemXGraphAdd(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal) gslc_ElemSetRedraw(pGui,pElemRef,GSLC_REDRAW_INC); } +void gslc_ElemXGraphReset(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef) { + + pXData->nBufCnt = 0; + pXData->nPlotIndStart = 0; + + // Default scale is + // - Each data point (buffer row) gets 1 pixel in X direction + // - Data value is directly mapped to height in Y direction + pXData->nPlotValMin = 0; + pXData->nPlotValMax = pXData->nWndHeight; + pXData->nPlotIndMax = pXData->nWndWidth; + + memset(pBuf,0,nBufMax*sizeof(int16_t)); +} + bool gslc_ElemXGraphDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw) { diff --git a/src/elem/XGraph.h b/src/elem/XGraph.h index 472c5b264..fd69f4784 100644 --- a/src/elem/XGraph.h +++ b/src/elem/XGraph.h @@ -155,6 +155,14 @@ bool gslc_ElemXGraphDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw); /// void gslc_ElemXGraphAdd(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal); +/// Reset the graphs values. +/// +/// \param[in] pGui: Pointer to GUI +/// \param[in] pElemRef: Pointer to Element reference +/// +/// \return none +/// +void gslc_ElemXGraphReset(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef); /// /// Set the graph scroll position (nScrollPos) as a fraction of