diff --git a/MicroView.cpp b/MicroView.cpp index cffada8..aa52e68 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1362,8 +1362,8 @@ int MicroView::readSerial(void) The MicroViewWidget class is the parent class for child widget like MicroViewSlider and MicroViewGauge. */ MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max) { - x=newx; - y=newy; + posX=newx; + posY=newy; value=min; valLen=getInt16PrintLen(value); minValue=min; @@ -1372,16 +1372,16 @@ MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_ } /** \brief Get widget x position. */ -uint8_t MicroViewWidget::getX() { return x; } +uint8_t MicroViewWidget::getX() { return posX; } /** \brief Get widget y position. */ -uint8_t MicroViewWidget::getY() { return y; } +uint8_t MicroViewWidget::getY() { return posY; } /** \brief Set widget x position. */ -void MicroViewWidget::setX(uint8_t newx) { x = newx; } +void MicroViewWidget::setX(uint8_t newx) { posX = newx; } /** \brief Set widget y position. */ -void MicroViewWidget::setY(uint8_t newy) { y = newy; } +void MicroViewWidget::setY(uint8_t newy) { posY = newy; } /** \brief Get minimum value. @@ -1492,7 +1492,7 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_ style=0; totalTicks=30; noValDraw=false; - prevValue=getMinValue(); + prevValue=minValue; needFirstDraw=true; drawFace(); draw(); @@ -1525,7 +1525,7 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_ break; } - prevValue=getMinValue(); + prevValue=minValue; needFirstDraw=true; drawFace(); draw(); @@ -1536,32 +1536,30 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_ Draw image/diagram representing the widget's face. */ void MicroViewSlider::drawFace() { - uint8_t offsetX, offsetY, endOffset; - offsetX=getX(); - offsetY=getY(); + uint8_t endOffset; //Horizontal styles, style 0 or 1 if (style==0 || style==1) { - endOffset = offsetX + totalTicks + 2; + endOffset = posX + totalTicks + 2; // Draw minor ticks - for (uint8_t i=offsetX+1; i15) { @@ -1697,7 +1687,7 @@ void MicroViewGauge::drawFace() { fromSecY = sin(degreeSec) * (radius / 1.3); toSecX = cos(degreeSec) * radius; toSecY = sin(degreeSec) * radius; - uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY); + uView.line(1+posX+fromSecX, 1+posY+fromSecY, 1+posX+toSecX, 1+posY+toSecY); } } } @@ -1714,20 +1704,19 @@ void MicroViewGauge::draw() { needFirstDraw=false; } else { - prevValue=getValue(); + prevValue=value; // Draw current pointer drawPointer(); } // Draw numeric value if required if (!noValDraw) { - uint8_t offsetY = getY(); - uint8_t offsetX = getX() - (getMaxValLen() * 3 - 1); // Offset left of centre to print the value + uint8_t offsetX = posX - (maxValLen * 3 - 1); // Offset left of centre to print the value if (style > 0) - uView.setCursor(offsetX, offsetY+10); + uView.setCursor(offsetX, posY+10); else - uView.setCursor(offsetX, offsetY+11); + uView.setCursor(offsetX, posY+11); drawNumValue(prevValue); } @@ -1735,19 +1724,15 @@ void MicroViewGauge::draw() { // Use XOR mode to erase or draw the pointer for prevValue void MicroViewGauge::drawPointer() { - uint8_t offsetX, offsetY; float degreeSec, toSecX, toSecY; - offsetX = getX(); - offsetY = getY(); - // total 240 degree in the widget with 150 degree starting point - degreeSec = (((float)(uint16_t)(prevValue-getMinValue()) / (float)(uint16_t)(getMaxValue()-getMinValue()) + degreeSec = (((float)(uint16_t)(prevValue-minValue) / (float)(uint16_t)(maxValue-minValue) * 240) + 150) * (PI / 180); toSecX = cos(degreeSec) * (radius / 1.2); toSecY = sin(degreeSec) * (radius / 1.2); - uView.line(offsetX,offsetY,1+offsetX+toSecX,1+offsetY+toSecY, WHITE,XOR); + uView.line(posX, posY, 1+posX+toSecX, 1+posY+toSecY, WHITE, XOR); } // ------------------------------------------------------------------------------------- diff --git a/MicroView.h b/MicroView.h index 4d9b58d..471de12 100644 --- a/MicroView.h +++ b/MicroView.h @@ -236,7 +236,6 @@ public: uint8_t getY(); void setX(uint8_t newx); void setY(uint8_t newy); - int16_t getMinValue(); int16_t getMaxValue(); int16_t getValue(); @@ -252,15 +251,16 @@ public: void reDraw(); void drawNumValue(int16_t value); virtual ~MicroViewWidget(){}; -private: - void setMaxValLen(); - uint8_t x; - uint8_t y; +protected: + uint8_t posX; + uint8_t posY; int16_t maxValue; int16_t minValue; int16_t value; uint8_t valLen; uint8_t maxValLen; +private: + void setMaxValLen(); }; class MicroViewSlider: public MicroViewWidget{