mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-20 11:31:24 +01:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8957ed4f66 | ||
|
|
3bd6befa70 | ||
|
|
85f51dcdba | ||
|
|
26d95ecfb4 | ||
|
|
da7579a6e8 | ||
|
|
e9584301ab | ||
|
|
4b7b544fa4 | ||
|
|
810a0928cb | ||
|
|
13390ca758 | ||
|
|
df383d88f2 | ||
|
|
04ed26e2b8 | ||
|
|
23d05f13ee | ||
|
|
88116856d4 | ||
|
|
cc6a702712 | ||
|
|
c5cf9692ad | ||
|
|
63e3228d83 |
249
MicroView.cpp
249
MicroView.cpp
@@ -631,11 +631,11 @@ void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color
|
||||
bool intersected = false;
|
||||
|
||||
// Optimization: relative x squared only changes with the outer loop/the horizontal scan.
|
||||
int16_t rx2 = (x-x0) * (x-x0);
|
||||
uint16_t rx2 = (x-x0) * (x-x0);
|
||||
|
||||
// Scan vertically...
|
||||
for (uint16_t y = yStart; y <= yEnd; ++y) {
|
||||
int16_t ry2 = (y-y0) * (y-y0);
|
||||
uint16_t ry2 = (y-y0) * (y-y0);
|
||||
if (rx2 + ry2 <= radiusSq) {
|
||||
pixel(x, y, color, mode);
|
||||
intersected = true;
|
||||
@@ -1443,7 +1443,20 @@ void MicroViewWidget::reDraw() {
|
||||
this->drawFace();
|
||||
this->draw();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Draw a signed decimal numeric value at the current cursor location.
|
||||
|
||||
The value is right justified with leading spaces, within a field the length of the maximum posible for the widget's value range.
|
||||
*/
|
||||
void MicroViewWidget::drawNumValue(int16_t value) {
|
||||
char strBuffer[7];
|
||||
char formatStr[] = "%1d";
|
||||
|
||||
formatStr[1] = '0' + getMaxValLen(); // Set the field width for the value range
|
||||
sprintf(strBuffer, formatStr, value);
|
||||
uView.print(strBuffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// MicroViewWidget Class - end
|
||||
// -------------------------------------------------------------------------------------
|
||||
@@ -1459,6 +1472,7 @@ void MicroViewWidget::reDraw() {
|
||||
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
|
||||
style=0;
|
||||
totalTicks=30;
|
||||
noValDraw=false;
|
||||
prevValue=getMinValue();
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
@@ -1467,24 +1481,29 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_
|
||||
|
||||
/** \brief MicroViewSlider class initialisation with style.
|
||||
|
||||
Initialise the MicroViewSlider widget with style WIDGETSTYLE0 or WIDGETSTYLE1 or WIDGETSTYLE2 (like 0, but vertical) or WIDGETSTYLE3 (like 1, but vertical). If this list gets any longer, it might be better as a switch/case statement.
|
||||
Initialise the MicroViewSlider widget with style WIDGETSTYLE0 or WIDGETSTYLE1 or WIDGETSTYLE2 (like 0, but vertical) or WIDGETSTYLE3 (like 1, but vertical).
|
||||
Add WIDGETNOVALUE to the style to suppress displaying the numeric value. E.g. WIDGETSTYLE0 + WIDGETNOVALUE
|
||||
*/
|
||||
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):MicroViewWidget(newx, newy, min, max) {
|
||||
if (sty==WIDGETSTYLE1) {
|
||||
style=1;
|
||||
totalTicks=60;
|
||||
}
|
||||
else if (sty==WIDGETSTYLE2) {
|
||||
style=2;
|
||||
totalTicks=20;
|
||||
}
|
||||
else if (sty==WIDGETSTYLE3) {
|
||||
style=3;
|
||||
totalTicks=40;
|
||||
}
|
||||
else { // Use style 0 if specified or invalid
|
||||
style=0;
|
||||
totalTicks=30;
|
||||
noValDraw = sty & WIDGETNOVALUE; // set "no value draw" flag as specified
|
||||
|
||||
switch(sty & ~WIDGETNOVALUE) {
|
||||
case WIDGETSTYLE1:
|
||||
style=1;
|
||||
totalTicks=60;
|
||||
break;
|
||||
case WIDGETSTYLE2:
|
||||
style=2;
|
||||
totalTicks=20;
|
||||
break;
|
||||
case WIDGETSTYLE3:
|
||||
style=3;
|
||||
totalTicks=40;
|
||||
break;
|
||||
default:
|
||||
style=0;
|
||||
totalTicks=30;
|
||||
break;
|
||||
}
|
||||
|
||||
prevValue=getMinValue();
|
||||
@@ -1533,71 +1552,58 @@ void MicroViewSlider::drawFace() {
|
||||
Convert the current value of the widget and draw the ticker representing the value.
|
||||
*/
|
||||
void MicroViewSlider::draw() {
|
||||
uint8_t offsetX, offsetY;
|
||||
uint8_t tickPosition=0;
|
||||
char strBuffer[7];
|
||||
char formatStr[] = "%1d";
|
||||
|
||||
formatStr[1] = '0' + getMaxValLen(); // Set the field width for the value range
|
||||
|
||||
offsetX=getX();
|
||||
offsetY=getY();
|
||||
// Draw the initial pointer or erase the previous pointer
|
||||
drawPointer();
|
||||
|
||||
if (needFirstDraw) {
|
||||
if (style==0 || style==1){ //Horizontal
|
||||
tickPosition = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
}
|
||||
else { //Vertical
|
||||
tickPosition = ((float)(uint16_t)(getMaxValue()-prevValue)/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
|
||||
}
|
||||
|
||||
sprintf(strBuffer, formatStr, prevValue); // print with fixed width so that blank space will cover larger value
|
||||
needFirstDraw=false;
|
||||
}
|
||||
else {
|
||||
// Draw previous pointer in XOR mode to erase it
|
||||
if (style==0 || style==1){ //Horizontal
|
||||
tickPosition = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
}
|
||||
else { //Vertical
|
||||
tickPosition = ((float)(uint16_t)(getMaxValue()-prevValue)/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
|
||||
}
|
||||
|
||||
// Draw current pointer
|
||||
if (style==0 || style==1){ //Horizontal
|
||||
tickPosition = ((float)(uint16_t)(getValue()-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
}
|
||||
else { //Vertical
|
||||
tickPosition = ((float)(uint16_t)(getMaxValue()-getValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
|
||||
}
|
||||
|
||||
sprintf(strBuffer, formatStr, getValue()); // print with fixed width so that blank space will cover larger value
|
||||
prevValue=getValue();
|
||||
// Draw current pointer
|
||||
drawPointer();
|
||||
}
|
||||
|
||||
// Draw value
|
||||
if (style==0)
|
||||
uView.setCursor(offsetX+totalTicks+4, offsetY+1);
|
||||
else if (style==1)
|
||||
uView.setCursor(offsetX, offsetY+10);
|
||||
else if (style==2)
|
||||
uView.setCursor(offsetX+1, offsetY+totalTicks+4);
|
||||
else //style==3
|
||||
uView.setCursor(offsetX+9, offsetY);
|
||||
// Draw numeric value if required
|
||||
if (!noValDraw) {
|
||||
uint8_t offsetX = getX();
|
||||
uint8_t offsetY = getY();
|
||||
|
||||
uView.print(strBuffer);
|
||||
switch(style) {
|
||||
case 0:
|
||||
uView.setCursor(offsetX+totalTicks+4, offsetY+1);
|
||||
break;
|
||||
case 1:
|
||||
uView.setCursor(offsetX, offsetY+10);
|
||||
break;
|
||||
case 2:
|
||||
uView.setCursor(offsetX+1, offsetY+totalTicks+4);
|
||||
break;
|
||||
default:
|
||||
uView.setCursor(offsetX+9, offsetY);
|
||||
break;
|
||||
}
|
||||
|
||||
drawNumValue(prevValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Use XOR mode to erase or draw the pointer for prevValue
|
||||
void MicroViewSlider::drawPointer() {
|
||||
uint8_t tickPosition;
|
||||
uint8_t offsetX = getX();
|
||||
uint8_t offsetY = getY();
|
||||
|
||||
if (style==0 || style==1) { // Horizontal
|
||||
tickPosition = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
}
|
||||
else { // Vertical
|
||||
tickPosition = ((float)(uint16_t)(getMaxValue()-prevValue)/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
@@ -1615,6 +1621,7 @@ void MicroViewSlider::draw() {
|
||||
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
|
||||
style=0;
|
||||
radius=15;
|
||||
noValDraw=false;
|
||||
prevValue=getMinValue();
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
@@ -1624,9 +1631,12 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
|
||||
/** \brief MicroViewGauge class initialisation with style.
|
||||
|
||||
Initialise the MicroViewGauge widget with style WIDGETSTYLE0 or WIDGETSTYLE1.
|
||||
Add WIDGETNOVALUE to the style to suppress displaying the numeric value. E.g. WIDGETSTYLE0 + WIDGETNOVALUE
|
||||
*/
|
||||
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):MicroViewWidget(newx, newy, min, max) {
|
||||
if (sty==WIDGETSTYLE0) {
|
||||
noValDraw = sty & WIDGETNOVALUE; // set "no value draw" flag as specified
|
||||
|
||||
if ((sty & ~WIDGETNOVALUE) == WIDGETSTYLE0) {
|
||||
style=0;
|
||||
radius=15;
|
||||
}
|
||||
@@ -1651,23 +1661,23 @@ void MicroViewGauge::drawFace() {
|
||||
offsetY=getY();
|
||||
|
||||
uView.circle(offsetX,offsetY,radius);
|
||||
|
||||
|
||||
for (int i=150;i<=390;i+=30) { // Major tick from 150 degree to 390 degree
|
||||
degreeSec=i*(PI/180);
|
||||
fromSecX = cos(degreeSec) * (radius / 1.5);
|
||||
fromSecY = sin(degreeSec) * (radius / 1.5);
|
||||
toSecX = cos(degreeSec) * (radius / 1);
|
||||
toSecY = sin(degreeSec) * (radius / 1);
|
||||
toSecX = cos(degreeSec) * radius;
|
||||
toSecY = sin(degreeSec) * radius;
|
||||
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
|
||||
}
|
||||
|
||||
if(radius>15) {
|
||||
for (int i=150;i<=390;i+=15) { // Minor tick from 150 degree to 390 degree
|
||||
if (radius>15) {
|
||||
for (int i=165;i<=375;i+=30) { // Minor tick from 165 degree to 375 degree
|
||||
degreeSec=i*(PI/180);
|
||||
fromSecX = cos(degreeSec) * (radius / 1.3);
|
||||
fromSecY = sin(degreeSec) * (radius / 1.3);
|
||||
toSecX = cos(degreeSec) * (radius / 1);
|
||||
toSecY = sin(degreeSec) * (radius / 1);
|
||||
toSecX = cos(degreeSec) * radius;
|
||||
toSecY = sin(degreeSec) * radius;
|
||||
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
|
||||
}
|
||||
}
|
||||
@@ -1678,54 +1688,47 @@ void MicroViewGauge::drawFace() {
|
||||
Convert the current value of the widget and draw the ticker representing the value.
|
||||
*/
|
||||
void MicroViewGauge::draw() {
|
||||
uint8_t offsetX, offsetY;
|
||||
uint8_t maxValLen, valOffset;
|
||||
float degreeSec, toSecX, toSecY;
|
||||
char strBuffer[7];
|
||||
char formatStr[] = "%1d"; // The 1 will be replaced later by the proper length
|
||||
|
||||
maxValLen = getMaxValLen();
|
||||
formatStr[1] = '0' + maxValLen; // Set the field width for the value range
|
||||
valOffset = maxValLen * 3 - 1; // Offset left of centre to print the value
|
||||
|
||||
offsetX=getX();
|
||||
offsetY=getY();
|
||||
// Draw the initial pointer or erase the previous pointer
|
||||
drawPointer();
|
||||
|
||||
if (needFirstDraw) {
|
||||
degreeSec = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*240; // total 240 degree in the widget
|
||||
degreeSec = (degreeSec+150) * (PI/180); // 150 degree starting point
|
||||
toSecX = cos(degreeSec) * (radius / 1.2);
|
||||
toSecY = sin(degreeSec) * (radius / 1.2);
|
||||
uView.line(offsetX,offsetY,1+offsetX+toSecX,1+offsetY+toSecY, WHITE,XOR);
|
||||
sprintf(strBuffer, formatStr, prevValue); // print with fixed width so that blank space will cover larger value
|
||||
needFirstDraw=false;
|
||||
}
|
||||
else {
|
||||
// Draw previous pointer in XOR mode to erase it
|
||||
degreeSec = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*240; // total 240 degree in the widget
|
||||
degreeSec = (degreeSec+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);
|
||||
|
||||
// draw current pointer
|
||||
degreeSec = ((float)(uint16_t)(getValue()-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*240; // total 240 degree in the widget
|
||||
degreeSec = (degreeSec+150) * (PI/180); // 150 degree starting point
|
||||
toSecX = cos(degreeSec) * (radius / 1.2);
|
||||
toSecY = sin(degreeSec) * (radius / 1.2);
|
||||
uView.line(offsetX,offsetY,1+offsetX+toSecX,1+offsetY+toSecY, WHITE,XOR);
|
||||
|
||||
sprintf(strBuffer, formatStr, getValue()); // print with fixed width so that blank space will cover larger value
|
||||
prevValue=getValue();
|
||||
// Draw current pointer
|
||||
drawPointer();
|
||||
}
|
||||
|
||||
// Draw value
|
||||
if (style>0)
|
||||
uView.setCursor(offsetX-valOffset, offsetY+10);
|
||||
else
|
||||
uView.setCursor(offsetX-valOffset, offsetY+11);
|
||||
|
||||
uView.print(strBuffer);
|
||||
// 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
|
||||
|
||||
if (style > 0)
|
||||
uView.setCursor(offsetX, offsetY+10);
|
||||
else
|
||||
uView.setCursor(offsetX, offsetY+11);
|
||||
|
||||
drawNumValue(prevValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 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())
|
||||
* 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);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
14
MicroView.h
14
MicroView.h
@@ -77,10 +77,13 @@
|
||||
|
||||
#define WIDGETSTYLE0 0
|
||||
#define WIDGETSTYLE1 1
|
||||
// Added for Vertical slider styles
|
||||
#define WIDGETSTYLE2 2
|
||||
//Added for Vertical slider styles
|
||||
#define WIDGETSTYLE3 3
|
||||
|
||||
// Flag to be added to widget style to indicate no numeric value display
|
||||
#define WIDGETNOVALUE 0x80
|
||||
|
||||
#define SETCONTRAST 0x81
|
||||
#define DISPLAYALLONRESUME 0xA4
|
||||
#define DISPLAYALLON 0xA5
|
||||
@@ -237,8 +240,8 @@ public:
|
||||
int16_t getMinValue();
|
||||
int16_t getMaxValue();
|
||||
int16_t getValue();
|
||||
void setMinValue(int16_t min);
|
||||
void setMaxValue(int16_t max);
|
||||
void setMinValue(int16_t max);
|
||||
void setValue(int16_t val);
|
||||
uint8_t getMaxValLen();
|
||||
/** \brief Draw widget value overridden by child class. */
|
||||
@@ -246,7 +249,8 @@ public:
|
||||
/** \brief Draw widget face overridden by child class. */
|
||||
virtual void drawFace(){};
|
||||
void reDraw();
|
||||
|
||||
void drawNumValue(int16_t value);
|
||||
virtual ~MicroViewWidget(){};
|
||||
private:
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
@@ -262,7 +266,9 @@ public:
|
||||
void draw();
|
||||
void drawFace();
|
||||
private:
|
||||
void drawPointer();
|
||||
uint8_t totalTicks, style;
|
||||
bool noValDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
@@ -273,7 +279,9 @@ public:
|
||||
void draw();
|
||||
void drawFace();
|
||||
private:
|
||||
void drawPointer();
|
||||
uint8_t radius, style;
|
||||
bool noValDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
|
||||
@@ -92,6 +92,14 @@ void loop() {
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.21b: 22nd September 2014 by Esmit Pérez and Scott Allen**
|
||||
* re-factored code if/else with switch - Esmit Pérez
|
||||
* simplified draw() to remove redundant code - Esmit Pérez
|
||||
* added WIDGETNOVALUE to widgets - Scott
|
||||
* fixed compiler warning - Scott
|
||||
* improved gauge minor ticks - Scott
|
||||
* added destructor for MicroViewWidget base class - Scott
|
||||
|
||||
**v1.20b: 27th August 2014 by Scott Allen, Emil Ong**
|
||||
* added Flashing Heart Example - JP
|
||||
* added getScreenBuffer() for access to screen RAM - Scott
|
||||
|
||||
353
examples/MicroViewWidgetDemo/MicroViewWidgetDemo.ino
Normal file
353
examples/MicroViewWidgetDemo/MicroViewWidgetDemo.ino
Normal file
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
MicroView Arduino Library
|
||||
Copyright (C) 2014 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/>.
|
||||
*/
|
||||
|
||||
#include <MicroView.h>
|
||||
|
||||
// The Arduino build process doesn't create a prototype for the spin function,
|
||||
// (probably because it has a function pointer as a parameter)
|
||||
// so it's added here.
|
||||
void spin(int16_t lowVal, int16_t highVal, int16_t stepSize,
|
||||
unsigned long stepDelay, void (*drawFunction)(int16_t val));
|
||||
|
||||
MicroViewWidget *widget1, *widget2;
|
||||
|
||||
int16_t prevVal; // previous widget value
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/* ==================== Demo 1 ====================
|
||||
Horizontal slider style 0, with and without numeric value.
|
||||
Range 0 to 100.
|
||||
================================================ */
|
||||
demoNumber(1);
|
||||
|
||||
widget1 = new MicroViewSlider(4, 16, 0, 100);
|
||||
widget2 = new MicroViewSlider(4, 32, 0, 100, WIDGETSTYLE0 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 100, 5, 100, update2widgets);
|
||||
|
||||
delete widget1;
|
||||
delete widget2;
|
||||
|
||||
/* ==================== Demo 2 ====================
|
||||
Horizontal slider style 1, with and without numeric value.
|
||||
Range 100 to 200.
|
||||
================================================ */
|
||||
demoNumber(2);
|
||||
|
||||
widget1 = new MicroViewSlider(0, 10, 100, 200, WIDGETSTYLE1);
|
||||
widget2 = new MicroViewSlider(0, 32, 100, 200, WIDGETSTYLE1 + WIDGETNOVALUE);
|
||||
|
||||
spin(100, 200, 5, 100, update2widgets);
|
||||
|
||||
delete widget1;
|
||||
delete widget2;
|
||||
|
||||
/* ==================== Demo 3 ====================
|
||||
Vertical slider style 2, with and without numeric value.
|
||||
Range 0 to 5000.
|
||||
================================================ */
|
||||
demoNumber(3);
|
||||
|
||||
widget1 = new MicroViewSlider(10, 12, 0, 5000, WIDGETSTYLE2);
|
||||
widget2 = new MicroViewSlider(48, 12, 0, 5000, WIDGETSTYLE2 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 5000, 250, 100, update2widgets);
|
||||
|
||||
delete widget1;
|
||||
delete widget2;
|
||||
|
||||
/* ==================== Demo 4 ====================
|
||||
Vertical slider style 3, with and without numeric value.
|
||||
Range -20 to 20.
|
||||
================================================ */
|
||||
demoNumber(4);
|
||||
|
||||
widget1 = new MicroViewSlider(16, 4, -20, 20, WIDGETSTYLE3);
|
||||
widget2 = new MicroViewSlider(54, 4, -20, 20, WIDGETSTYLE3 + WIDGETNOVALUE);
|
||||
|
||||
spin(-20, 20, 2, 100, update2widgets);
|
||||
|
||||
delete widget1;
|
||||
delete widget2;
|
||||
|
||||
/* ==================== Demo 5 ====================
|
||||
Gauge style 0, with and without numeric value.
|
||||
Range 0 to 200.
|
||||
================================================ */
|
||||
demoNumber(5);
|
||||
|
||||
widget1 = new MicroViewGauge(15, 24, 0, 200, WIDGETSTYLE0);
|
||||
widget2 = new MicroViewGauge(48, 24, 0, 200, WIDGETSTYLE0 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 200, 10, 100, update2widgets);
|
||||
|
||||
delete widget1;
|
||||
delete widget2;
|
||||
|
||||
/* ==================== Demo 6 ====================
|
||||
Gauge style 1, with numeric value.
|
||||
Range -10 to 150.
|
||||
================================================ */
|
||||
demoNumber(6);
|
||||
|
||||
widget1 = new MicroViewGauge(32, 24, -10, 150, WIDGETSTYLE1);
|
||||
|
||||
spin(-10, 150, 8, 100, update1widget);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 7 ====================
|
||||
Gauge style 1, with no numeric value.
|
||||
Range 0 to 240.
|
||||
================================================ */
|
||||
demoNumber(7);
|
||||
|
||||
widget1 = new MicroViewGauge(32, 24, 0, 240, WIDGETSTYLE1 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 240, 4, 33, update1widget);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 8 ====================
|
||||
Slider style 0, with no numeric value.
|
||||
Value manually displayed in hexadecimal.
|
||||
Range 0 to 0xff.
|
||||
================================================ */
|
||||
demoNumber(8);
|
||||
|
||||
widget1 = new MicroViewSlider(4, 16, 0, 0xff, WIDGETSTYLE0 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 0xff, 5, 39, customSlider0);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 9 ====================
|
||||
Slider style 1, with no numeric value.
|
||||
Value manually displayed, centred above the slider.
|
||||
Range -30000 to 30000.
|
||||
================================================ */
|
||||
demoNumber(9);
|
||||
|
||||
widget1 = new MicroViewSlider(2, 24, -30000, 30000, WIDGETSTYLE1 + WIDGETNOVALUE);
|
||||
|
||||
spin(-30000, 30000, 1500, 50, customSlider1);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 10 ====================
|
||||
Slider style 2, with no numeric value.
|
||||
Value manually displayed.
|
||||
Pointer moves from low at the top to high at the bottom.
|
||||
Range 0 to 600.
|
||||
Note: The widget getValue() method will return a wrong
|
||||
value. It is changed to reverse the pointer direction.
|
||||
================================================ */
|
||||
demoNumber(10);
|
||||
|
||||
widget1 = new MicroViewSlider(20, 10, 0, 600, WIDGETSTYLE2 + WIDGETNOVALUE);
|
||||
|
||||
spin(0, 600, 30, 100, customSlider2);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 11 ====================
|
||||
Slider style 3, with no numeric value.
|
||||
Value manually displayed, beside the pointer.
|
||||
Range 0 to 11.
|
||||
"These go to eleven!" - Nigel Tufnel of Spinal Tap.
|
||||
================================================ */
|
||||
demoNumber(11);
|
||||
|
||||
widget1 = new MicroViewSlider(24, 2, 0, 11, WIDGETSTYLE3 + WIDGETNOVALUE);
|
||||
prevVal = widget1->getValue();
|
||||
|
||||
spin(0, 11, 1, 250, customSlider3);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 12 ====================
|
||||
Gauge style 0, with no numeric value.
|
||||
Value manually displayed beneath, with a decimal point,
|
||||
in a larger font.
|
||||
"km/h" added to the bottom of the gauge.
|
||||
For simplicity, the range and values are actually
|
||||
10 times what is to be displayed, so they can be set,
|
||||
stored and manipulated as integers.
|
||||
Range 0.0 to 20.0 (actually 0 to 200).
|
||||
================================================ */
|
||||
demoNumber(12);
|
||||
|
||||
widget1 = new MicroViewGauge(35, 17, 0, 200, WIDGETSTYLE0 + WIDGETNOVALUE);
|
||||
|
||||
// draw the fixed "km/h" text
|
||||
uView.setCursor(widget1->getX() - 11, widget1->getY() + 11);
|
||||
uView.print("km/h");
|
||||
|
||||
spin(0, 200, 1, 40, customGauge0);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ==================== Demo 13 ====================
|
||||
Gauge style 1, with no numeric value.
|
||||
Value manually displayed beneath, as a letter.
|
||||
Range 1 to 26 (A to Z).
|
||||
================================================ */
|
||||
demoNumber(13);
|
||||
|
||||
widget1 = new MicroViewGauge(36, 24, 1, 26, WIDGETSTYLE1 + WIDGETNOVALUE);
|
||||
|
||||
spin( 1, 26, 1, 200, customGauge1);
|
||||
|
||||
delete widget1;
|
||||
|
||||
/* ================== end of loop() ================== */
|
||||
}
|
||||
|
||||
// Function to update widget1
|
||||
void update1widget(int16_t val) {
|
||||
widget1->setValue(val);
|
||||
}
|
||||
|
||||
// Function to update widget1 and widget2
|
||||
void update2widgets(int16_t val) {
|
||||
widget1->setValue(val);
|
||||
widget2->setValue(val);
|
||||
}
|
||||
|
||||
// Update function for Demo 8
|
||||
void customSlider0(int16_t val) {
|
||||
widget1->setValue(val);
|
||||
uView.setCursor(widget1->getX() + 34, widget1->getY() + 1);
|
||||
uView.print("0x");
|
||||
if (val < 0x10) { // add leading 0 if necessary. Only 2 digits supported.
|
||||
uView.print('0');
|
||||
}
|
||||
uView.print(val, HEX);
|
||||
}
|
||||
|
||||
// Update function for Demo 9
|
||||
void customSlider1(int16_t val) {
|
||||
uint8_t offsetY = widget1->getY() - 10;
|
||||
uint8_t offsetX = widget1->getX() + 14;
|
||||
uView.setCursor(offsetX, offsetY);
|
||||
uView.print(" "); // erase the previous value in case it's longer
|
||||
// calculate the offset to centre the value
|
||||
offsetX += ((widget1->getMaxValLen() - getInt16PrintLen(val)) * 3);
|
||||
uView.setCursor(offsetX, offsetY);
|
||||
uView.print(val);
|
||||
widget1->setValue(val);
|
||||
}
|
||||
|
||||
// Update function for Demo 10
|
||||
void customSlider2(int16_t val) {
|
||||
uView.setCursor(widget1->getX() + 1, widget1->getY() + 24);
|
||||
widget1->drawNumValue(val);
|
||||
// calculate to reverse the pointer direction
|
||||
widget1->setValue((int16_t) ((int32_t) widget1->getMaxValue() +
|
||||
(int32_t) widget1->getMinValue() -
|
||||
(int32_t) val));
|
||||
}
|
||||
|
||||
// Update function for Demo 11
|
||||
void customSlider3(int16_t val) {
|
||||
int16_t maxVal = widget1->getMaxValue();
|
||||
uint16_t range = (uint16_t) (maxVal - widget1->getMinValue());
|
||||
uint8_t offsetX = widget1->getX() + 9;
|
||||
|
||||
// erase previous value.
|
||||
// pointer position is calculated the same way as the widget code.
|
||||
uint8_t offsetY = (float)(uint16_t)(maxVal - prevVal) / (float)range * 40;
|
||||
uView.setCursor(offsetX, offsetY);
|
||||
uView.print(" "); // This is being lazy. Should calculate width for value.
|
||||
|
||||
// draw new value
|
||||
offsetY = (float)(uint16_t)(maxVal - val) / (float)range * 40;
|
||||
uView.setCursor(offsetX, offsetY);
|
||||
widget1->drawNumValue(val);
|
||||
|
||||
widget1->setValue(val);
|
||||
}
|
||||
|
||||
// Update function for Demo 12
|
||||
void customGauge0(int16_t val) {
|
||||
widget1->setValue(val);
|
||||
|
||||
uView.setCursor(widget1->getX() - 17, widget1->getY() + 19);
|
||||
uView.setFontType(1);
|
||||
// add leading space if necessary, to right justify.
|
||||
// only 2 digit (plus decimal) numbers are supported.
|
||||
if (val < 100) {
|
||||
uView.print(' ');
|
||||
}
|
||||
uView.print((float)val / 10, 1);
|
||||
uView.setFontType(0);
|
||||
}
|
||||
|
||||
// Update function for Demo 13
|
||||
void customGauge1(int16_t val) {
|
||||
widget1->setValue(val);
|
||||
uView.setCursor(widget1->getX() - 2, widget1->getY() + 9);
|
||||
uView.print((char)(val + 'A' - 1));
|
||||
}
|
||||
|
||||
// Clear the screen buffer and draw the demo number in the corner
|
||||
void demoNumber(int num) {
|
||||
uView.clear(PAGE);
|
||||
uView.setCursor(0, 0);
|
||||
uView.print(num);
|
||||
uView.print(":");
|
||||
}
|
||||
|
||||
// Spin up, then down, through the values.
|
||||
//
|
||||
// For each value, call the update function and display the new screen.
|
||||
void spin(int16_t lowVal, int16_t highVal, int16_t stepSize,
|
||||
unsigned long stepDelay, void (*drawFunction)(int16_t val)) {
|
||||
drawFunction(lowVal);
|
||||
uView.display();
|
||||
delay(1500);
|
||||
|
||||
for (int16_t i = lowVal + stepSize; i <= highVal; i += stepSize) {
|
||||
drawFunction(i);
|
||||
uView.display();
|
||||
prevVal = i;
|
||||
delay(stepDelay);
|
||||
if ((i == 0) && (lowVal != 0)) { // pause briefly for a value of 0
|
||||
delay(750);
|
||||
}
|
||||
}
|
||||
|
||||
delay(1500);
|
||||
|
||||
for (int16_t i = highVal; i >= lowVal; i -= stepSize) {
|
||||
drawFunction(i);
|
||||
uView.display();
|
||||
prevVal = i;
|
||||
delay(stepDelay);
|
||||
if ((i == 0) && (lowVal != 0)) { // pause briefly for a value of 0
|
||||
delay(750);
|
||||
}
|
||||
}
|
||||
|
||||
delay(1500);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ setValue KEYWORD2
|
||||
draw KEYWORD2
|
||||
reDraw KEYWORD2
|
||||
drawFace KEYWORD2
|
||||
drawNumValue KEYWORD2
|
||||
checkComm KEYWORD2
|
||||
|
||||
#######################################
|
||||
@@ -82,5 +83,5 @@ WIDGETSTYLE0 LITERAL1
|
||||
WIDGETSTYLE1 LITERAL1
|
||||
WIDGETSTYLE2 LITERAL1
|
||||
WIDGETSTYLE3 LITERAL1
|
||||
|
||||
WIDGETNOVALUE LITERAL1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user