7 Commits

Author SHA1 Message Date
JP Liew
cfc8b5cb68 added History 2015-03-29 09:34:32 +11:00
JP Liew
a4a45b7e6d Merge branch 'master' of https://github.com/geekammo/MicroView-Arduino-Library 2015-03-29 09:31:39 +11:00
JP Liew
601881997d Merge pull request #28 from MLXXXp/widget_background_demo
Example sketch to demonstrate use of widget setValue() optional second argument
2015-03-29 09:29:10 +11:00
JP Liew
2a7b01cfbc updated History 2015-03-29 09:28:33 +11:00
JP Liew
b35e3f2e01 Merge pull request #27 from MLXXXp/widget_setvalue_nodraw
Add optional second argument to widget setValue which can supress display buffer update
2015-03-29 09:26:15 +11:00
Scott Allen
66405a0972 Added example sketch to demonstrate use of widget setValue() function's
optional second argument.
2015-03-27 17:54:16 -04:00
Scott Allen
82f3863036 Overloaded the widget setValue() function to add a boolean variable which
controls whether the display buffer is updated.

Also changed bool declarations to boolean, for consistency.
2015-03-25 17:51:42 -04:00
4 changed files with 110 additions and 6 deletions

View File

@@ -1441,19 +1441,29 @@ void MicroViewWidget::setMaxValue(int16_t max) {
*/
uint8_t MicroViewWidget::getMaxValLen() { return maxValLen; }
/** \brief Set current value.
/** \brief Set current value and update widget.
The current value of the widget is set to the variable passed in.
The current value of the widget is set to the variable passed in and the widget is drawn with the new value.
*/
void MicroViewWidget::setValue(int16_t val) {
setValue(val, true);
}
/** \brief Set current value with optional update.
The current value of the widget is set to the variable passed in. The widget is drawn with the new value if the doDraw argument is true.
*/
void MicroViewWidget::setValue(int16_t val, boolean doDraw) {
if ((val<=maxValue) && (val>=minValue)) {
value = val;
valLen = getInt16PrintLen(val);
this->draw();
if (doDraw) {
this->draw();
}
}
}
/** \brief Get the print length of the value
/** \brief Get the print length of the value.
Return the number of characters that would be printed using uView.print(value) for the current value.
*/

View File

@@ -241,6 +241,7 @@ public:
void setMinValue(int16_t min);
void setMaxValue(int16_t max);
void setValue(int16_t val);
void setValue(int16_t val, boolean doDraw);
uint8_t getValLen();
uint8_t getMaxValLen();
/** \brief Draw widget value overridden by child class. */
@@ -273,7 +274,7 @@ public:
private:
void drawPointer();
uint8_t style, totalTicks;
bool noValDraw;
boolean noValDraw;
int16_t prevValue;
};
@@ -286,7 +287,7 @@ public:
private:
void drawPointer();
uint8_t style, radius;
bool noValDraw;
boolean noValDraw;
int16_t prevValue;
};

View File

@@ -92,6 +92,9 @@ void loop() {
</code></pre>
## History
**v1.23b: 29th March 2015 by Scott Allen**
* added overloaded setValue() function to add a boolean argument doDraw which controls whether the display buffer is updated.
**v1.22b: 4th October 2014 by Scott Allen and Ben Lewis**
* replaced circleFill() with a faster algorithm, better looking circle - Ben Lewis
* replaced sprintf with dedicated code, reduced program size - Scott Allen

View File

@@ -0,0 +1,90 @@
/*
MicroView Arduino Library
Copyright (C) 2015 GeekAmmo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
An example of using the optional second argument of the widget
setVal() function to update a widget without drawing the changes
to the screen buffer.
This, along with the widget reDraw() function, allows widgets to be
maintained in the "background" while other things are being displayed.
In this example,
a guage and a slider are both continually updated with the same
incrementing value. The widgets are alternately switched between the
"background" and being displayed, at random intervals.
*/
#include <MicroView.h>
const int highVal = 100; // high value for widget range
int wValue = 0; // value for widgets
MicroViewWidget *guage1, *slider1;
boolean guage1On, slider1On; // true if widget is being displayed
void setup() {
uView.begin();
guage1 = new MicroViewGauge(32, 20, 0, highVal);
guage1On = false; // begin with guage1 off screen
uView.clear(PAGE);
slider1 = new MicroViewSlider(8, 16, 0, highVal);
slider1On = true; // begin with slider1 on screen
// Init the random number generator using an
// unconnected analog pin.
randomSeed(analogRead(A0));
}
void loop() {
// Display a widget for a random number of value increments
for (int c = random(5, 16); c > 0; c--) {
uView.display();
delay(500);
wValue++;
if (wValue > highVal) {
wValue = 0;
}
// If the second setValue() argument is false, then
// the display buffer is not updated.
//
// In a practical application, the widgets would be set with
// the values that are being monitored.
guage1->setValue(wValue, guage1On);
slider1->setValue(wValue, slider1On);
}
// Switch which widget is being displayed
uView.clear(PAGE);
guage1On = !guage1On;
slider1On = !slider1On;
if (guage1On) {
guage1->reDraw();
}
if (slider1On) {
slider1->reDraw();
}
}