From c1e8756c4effa412575272081ab51ad4dc57d6fa Mon Sep 17 00:00:00 2001 From: Carl Zetie Date: Sun, 13 Jul 2014 14:42:34 -0400 Subject: [PATCH 1/3] Added Vertical Slider styles to Slider widget Added WIDGETSTYLE2 (like 0, but vertical) and WIDGETSTYLE3 (like 1, but vertical). NOTE: I don't have a build environment, so I can't even promise this will compile! So if it's crap, just treat it as a concept for an enhancement request! --- MicroView.cpp | 137 +++++++++++++++++++++++++++++++++++++------------- MicroView.h | 2 + keywords.txt | 1 + 3 files changed, 104 insertions(+), 36 deletions(-) diff --git a/MicroView.cpp b/MicroView.cpp index 6a12b4c..d884d9f 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1411,17 +1411,29 @@ size_t MicroView::write(uint8_t c) { /** \brief MicroViewSlider class initialisation with style. - Initialise the MicroViewSlider widget with style WIDGETSTYLE0 or WIDGETSTYLE1. + 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. */ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):MicroViewWidget(newx, newy, min, max) { if (sty==WIDGETSTYLE0) { style=0; totalTicks=30; } - else { + else if (sty==WIDGETSTYLE1) { style=1; totalTicks=60; } + else if (sty==WIDGETSTYLE2) { + style=2; + totalTicks=30; + } + else if (sty==WIDGETSTYLE3) { + style=3; + totalTicks=60; + } + else { //unrecognized style, so use default + style=0; + totalTicks=30; + } needFirstDraw=true; prevValue=getMinValue(); @@ -1438,31 +1450,33 @@ size_t MicroView::write(uint8_t c) { offsetX=getX(); offsetY=getY(); - if(style>0) - majorLine=7; - else - majorLine=4; + if(style%2==1) //style 1 or 3 + majorLine=7; + else //style 0 or 2 + majorLine=4; - // Draw major tickers - for (uint8_t i=0; i0) { - for (uint8_t i=0; i<4;i++) { - uView.lineV(offsetX+33+(i*2), offsetY+5, 3); +//Horizontal styles, style 0 or 1 + + if (style1==0 || style==1) { + // Draw major tickers + for (uint8_t i=0; i0) { + // Draw minor tickers + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+3+(i*2), offsetY+5, 3); + } + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+13+(i*2), offsetY+5, 3); + } + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+23+(i*2), offsetY+5, 3); + } + + if(style==1) { //Explicit test for style + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+33+(i*2), offsetY+5, 3); + } for (uint8_t i=0; i<4;i++) { uView.lineV(offsetX+43+(i*2), offsetY+5, 3); } @@ -1471,6 +1485,36 @@ size_t MicroView::write(uint8_t c) { } } } +//Vertical styles, style 2 or 3 + else { + // Draw major tickers + for (uint8_t i=0; i0) - uView.setCursor(offsetX,offsetY+10); - else - uView.setCursor(offsetX+34,offsetY+1); + if(style%2 > 0) //Style 1 or Style 3 + uView.setCursor(offsetX,offsetY+10); + else //Style 0 or Style 2 + uView.setCursor(offsetX+34,offsetY+1); uView.print(strBuffer); } @@ -1635,7 +1700,7 @@ size_t MicroView::write(uint8_t c) { } // ------------------------------------------------------------------------------------- - // Slider Widget - end + // Gauge Widget - end // ------------------------------------------------------------------------------------- /** \brief SPI Initialisation. diff --git a/MicroView.h b/MicroView.h index 4b35a31..7bd46c9 100644 --- a/MicroView.h +++ b/MicroView.h @@ -49,6 +49,8 @@ #define WIDGETSTYLE0 0 #define WIDGETSTYLE1 1 #define WIDGETSTYLE2 2 +//Added for Vertical slider styles +#define WIDGETSTYLE3 3 #define SETCONTRAST 0x81 #define DISPLAYALLONRESUME 0xA4 diff --git a/keywords.txt b/keywords.txt index a10e127..da714d1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -77,5 +77,6 @@ ALL LITERAL1 WIDGETSTYLE0 LITERAL1 WIDGETSTYLE1 LITERAL1 WIDGETSTYLE2 LITERAL1 +WIDGETSTYLE3 LITERAL1 From 7b66741f793ccb7912d2a80b9441d1f14f57ede6 Mon Sep 17 00:00:00 2001 From: Carl Zetie Date: Mon, 14 Jul 2014 07:48:20 -0400 Subject: [PATCH 2/3] Fixed my typo in MicroView.cpp Fixed my typo in MicroView.cpp --- MicroView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MicroView.cpp b/MicroView.cpp index d884d9f..882d5cb 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1457,7 +1457,7 @@ size_t MicroView::write(uint8_t c) { //Horizontal styles, style 0 or 1 - if (style1==0 || style==1) { + if (style==0 || style==1) { // Draw major tickers for (uint8_t i=0; i Date: Mon, 14 Jul 2014 18:39:13 -0400 Subject: [PATCH 3/3] Many bugs fixed OK, this version is actually worth looking at. Previous had more bugs than you could shake a stick at. vert_slider_test.ino illustrates the two slider styles, vertical versions of the two existing styles --- MicroView.cpp | 60 ++++++++++++++++++++++++-------------------- vert_slider_test.ino | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 vert_slider_test.ino diff --git a/MicroView.cpp b/MicroView.cpp index 882d5cb..433c812 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1424,11 +1424,11 @@ size_t MicroView::write(uint8_t c) { } else if (sty==WIDGETSTYLE2) { style=2; - totalTicks=30; + totalTicks=20; } else if (sty==WIDGETSTYLE3) { style=3; - totalTicks=60; + totalTicks=40; } else { //unrecognized style, so use default style=0; @@ -1450,11 +1450,17 @@ size_t MicroView::write(uint8_t c) { offsetX=getX(); offsetY=getY(); - if(style%2==1) //style 1 or 3 - majorLine=7; - else //style 0 or 2 + if(style==0) majorLine=4; - + else if (style==1) + majorLine=7; + else if (style==2) + majorLine=3; + else if (style==3) + majorLine=5; + + + //Horizontal styles, style 0 or 1 if (style==0 || style==1) { @@ -1473,7 +1479,7 @@ size_t MicroView::write(uint8_t c) { uView.lineV(offsetX+23+(i*2), offsetY+5, 3); } - if(style==1) { //Explicit test for style + if(style==1) { //Longer line, more minor ticks for (uint8_t i=0; i<4;i++) { uView.lineV(offsetX+33+(i*2), offsetY+5, 3); } @@ -1489,29 +1495,24 @@ size_t MicroView::write(uint8_t c) { else { // Draw major tickers for (uint8_t i=0; i 0) //Style 1 or Style 3 - uView.setCursor(offsetX,offsetY+10); - else //Style 0 or Style 2 + if(style==0) uView.setCursor(offsetX+34,offsetY+1); + else if (style==1) + uView.setCursor(offsetX,offsetY+10); + else if (style==2) + uView.setCursor(offsetX+1,offsetY+24); + else //style==3 + uView.setCursor(offsetX+9,offsetY); + uView.print(strBuffer); } diff --git a/vert_slider_test.ino b/vert_slider_test.ino new file mode 100644 index 0000000..e491de2 --- /dev/null +++ b/vert_slider_test.ino @@ -0,0 +1,47 @@ +#include + +int buttonPin = A0; // push button pin +int buttonState = 0; // variable for reading the pushbutton status +int onCount = 0; +MicroViewWidget *hWidget, *vWidget1, *vWidget2; + +void setup() { + uView.begin(); + uView.clear(PAGE); + + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); + digitalWrite(buttonPin,HIGH); + + //Create a slider to count how long the switch is on +// hWidget = new MicroViewSlider(0, 0, 0, 99, WIDGETSTYLE0); + vWidget1 = new MicroViewSlider(0, 0, 0, 255, WIDGETSTYLE2); + vWidget2 = new MicroViewSlider(31, 0, 0, 255, WIDGETSTYLE3); +} + +void loop() { + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. + // if it is not pressed, the buttonState is HIGH: + if (buttonState == HIGH) { + onCount = min(onCount+1, 255); +// hWidget->setValue(onCount); + vWidget1->setValue(onCount); + vWidget2->setValue(onCount); +// uView.setCursor(0,0); +// uView.print("OFF"); + uView.display(); + } + else { + onCount = max(onCount-1, 0); +// hWidget->setValue(onCount); + vWidget1->setValue(onCount); + vWidget2->setValue(onCount); +// uView.setCursor(0,0); +// uView.print("ON "); + uView.display(); + } +} +