68 Commits

Author SHA1 Message Date
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
JP
301bd6acf5 added history to newly commited code 2014-10-04 14:00:42 +10:00
jpliew
80a0c70c34 Merge pull request #22 from MLXXXp/widget_protected_variables
Changed private variables in the MicroViewWidget base class to protected, for direct use by child classes
2014-10-04 13:52:36 +10:00
jpliew
c75d14abff Merge pull request #21 from ben-zen/circle_drawing
Improved circleFill() drawing
2014-10-04 13:52:12 +10:00
jpliew
1aa32fb0c2 Merge pull request #20 from MLXXXp/replace_sprintf
Replaced sprintf calls with dedicated code
2014-10-04 13:51:22 +10:00
Scott Allen
5e24583c31 Refactored widget code to eliminate needFirstDraw variable 2014-09-25 16:43:43 -04:00
Scott Allen
b05451f4c6 Use constructor initialisation lists for widget variables 2014-09-25 16:02:47 -04:00
Scott Allen
0d8545d6f8 Changed widget base class variables from private to protected
Base variables are now accessed directly by child widgets instead of
using methods
2014-09-25 12:48:21 -04:00
ben-zen
8ae691c4c2 Fixed whitespace before pull request. 2014-09-23 21:39:06 -07:00
ben-zen
12a9c5c2ac Merged up-to-date geekammo repo with my circleFill() changes. 2014-09-23 21:22:34 -07:00
ben-zen
68f0c20fd5 Replaced body of previous circleFill() method in the MicroView class, in preparation for a pull request. 2014-09-23 21:14:20 -07:00
Scott Allen
38be4163c0 Replaced sprintf calls with dedicated code
Using sprintf generates a large amount of code. By replacing the
sprintf calls with dedicated code, program size is reduced when
widgets are used.

Also:
- Added a getValLen method for widgets which returns the print
length for the current value, similar to the existing getMaxValLen.
- The value for widgets is now initialised to the minimum value,
instead of 0, because 0 could be outside the specified range.
- Added getValLen and getMaxValLen keywords.
- The MicroViewWidgetDemo example sketch was modified to use
the new getValLen method, plus a few other small changes.
2014-09-22 19:16:34 -04:00
JP
8957ed4f66 added version info for README.md 2014-09-22 20:07:05 +10:00
jpliew
3bd6befa70 Merge pull request #19 from MLXXXp/MicroViewWidgetDemo
MicroView widget demo, mainly for new WIDGETNOVALUE flag
2014-09-22 19:55:54 +10:00
jpliew
85f51dcdba Merge pull request #18 from MLXXXp/widget_no_value
Add an option to supress the display of the numeric value for widgets
2014-09-22 19:55:14 +10:00
Scott Allen
26d95ecfb4 Initial commit of the widget demo sketch 2014-09-17 20:38:59 -04:00
Scott Allen
da7579a6e8 Code refactoring for widget pointers
Added private methods to replace duplicated code
2014-09-17 19:50:09 -04:00
Scott Allen
e9584301ab Widget numeric value supression option
The user can add a flag to the style, for all widgets, to supress
the display of the numeric value.

Added new widget method drawNumValue() to simplify the code,
which can also be called by the user, e.g. for a custom numeric
value location.
2014-09-17 16:01:35 -04:00
Scott Allen
4b7b544fa4 Improved drawing of gauge minor ticks
Don't bother drawing gauge minor ticks over major ticks
2014-09-17 11:17:10 -04:00
Scott Allen
810a0928cb Add destructor for MicroViewWidget base class
Destructor added to prevent compiler warning for object delete.
2014-09-15 19:32:33 -04:00
Scott Allen
13390ca758 Fix compiler warning: signed/unsigned comparison 2014-09-15 19:19:15 -04:00
Esmit Pérez C
df383d88f2 Indentation fixes 2014-09-14 15:09:32 -05:00
Esmit Pérez C
04ed26e2b8 Corrected indentation 2014-09-14 14:56:43 -05:00
Esmit Pérez C
23d05f13ee Indentation fixes 2014-09-14 13:48:53 -05:00
Esmit Pérez C
88116856d4 Code cleanups for previous refactoring 2014-09-14 10:18:00 -05:00
Esmit Pérez C
cc6a702712 removed unneeded comments 2014-09-14 10:07:53 -05:00
Esmit Pérez C
c5cf9692ad Documentation changes
Removed comments regarding design decisions. MicroViewSlider:draw()
retested to ensure refactoring did not introduce regressions.
2014-09-12 23:16:08 -05:00
Esmit Pérez C
63e3228d83 Code refactorings 2014-09-12 20:43:38 -05:00
jpliew
c86b454924 Merge pull request #15 from MLXXXp/add_keywords
Add keywords for existing functions
2014-08-27 10:15:11 +10:00
JP
ad46711f11 added version history 2014-08-27 10:14:36 +10:00
JP
34de240739 Merge branch 'emilong-circle-fill' 2014-08-27 10:09:04 +10:00
Scott Allen
6333d7c561 Removed duplicate "invert" keyword 2014-08-26 12:42:07 -04:00
Scott Allen
a5ed62704a Added keywords for existing functions
Added missing setColumnAddress, setPageAddress and data keywords.
Moved getScreenBuffer keyword to a more appropriate location.
2014-08-26 10:49:09 -04:00
Emil Ong
9573e7d6cc Fix clipping issue for circleFill when top is offscreen.
Replaced circleFill algorithm with a scanning algorithm. Also fixes
problem with XOR draw mode for filled circles.
2014-08-24 14:28:33 -07:00
Scott Allen
86784fe2a4 Merge branch 'master' of https://github.com/geekammo/MicroView-Arduino-Library 2014-08-21 10:55:24 -04:00
JP
cf97ba6c23 added Flashing Heart Example 2014-08-21 13:47:36 +10:00
Scott Allen
dfe47be3c8 Merge branch 'user_screen_access'
Change name from uView.screenBuffer() to uView.getScreenBuffer()
2014-08-20 17:26:56 -04:00
jpliew
db155041ff Merge pull request #13 from MLXXXp/user_screen_access
Add uView.screenBuffer() for access to screen RAM.
2014-08-20 20:46:43 +10:00
Scott Allen
ba0b779740 Changed name from screenBuffer to getScreenBuffer 2014-08-20 06:24:57 -04:00
Scott Allen
8eab806dec Merge branch 'master' of https://github.com/MLXXXp/MicroView-Arduino-Library 2014-08-19 11:07:37 -04:00
Scott Allen
9873dc728a Merge branch 'user_screen_access'
Added screenBuffer keyword
2014-08-19 11:02:34 -04:00
Scott Allen
72fdeeb77b Added screenBuffer keyword 2014-08-19 10:57:31 -04:00
Scott Allen
4a8583e2a6 Merge branch 'user_screen_access'
Add function to get a pointer to the start of the RAM screen buffer
for direct write and read access.
2014-08-19 10:16:51 -04:00
Scott Allen
b0e4a9600f Add uView.screenBuffer() for access to screen RAM.
Returns a pointer to the start of the RAM screen buffer
for direct write and read access.
2014-08-19 10:01:51 -04:00
JP
9dba039aa5 v1.19b 2014-08-19 13:14:20 +10:00
jpliew
e5e5ecb037 Merge pull request #12 from MLXXXp/left_scroll
Left scroll
2014-08-19 12:37:20 +10:00
Scott Allen
e203d3b7cd Merge branch 'user_screen_access'
Allow users to gain direct write and read access to the RAM screen buffer.
2014-08-17 08:41:00 -04:00
Scott Allen
c07b86476a Add uView.scrollLeft() function.
Same as existing uView.scrollRight() but in the opposite direction.
2014-08-16 22:58:28 -04:00
Scott Allen
db2904c64e Merge branch 'master' of https://github.com/geekammo/MicroView-Arduino-Library 2014-08-16 22:43:42 -04:00
Scott Allen
b91baf75f8 Add uView.screenBuffer() for access to screen RAM.
Returns a pointer the the start of the RAM screen buffer
for direct write and read access.
2014-08-16 21:56:47 -04:00
jpliew
6208dcd106 Merge pull request #11 from MLXXXp/slider_ticks
Simplify slider widget drawFace() function.
2014-08-12 12:17:02 +10:00
jpliew
1349942310 Merge pull request #10 from MLXXXp/widget_val_range
Handle full signed 16 bit ranges for widgets.
2014-08-12 12:16:46 +10:00
Scott Allen
95626610e1 Merge branch 'slider_ticks'.
Simplified slider widget drawFace() function.
2014-08-10 20:33:05 -04:00
Scott Allen
0b56edc962 Handle full signed 16 bit ranges for widgets.
Widgets will now work properly with minimum and maximum values
from −32,768 to 32,767.
Also, place the numeric value field close to sliders
and horizontally centred in gauges.
2014-08-10 20:23:16 -04:00
Scott Allen
4bbfea3cf2 Simplify slider widget drawFace() function.
Use just one loop to draw all minor ticks.
Use a second loop to extend lines for major ticks.
Use totalTicks variable to determine number of ticks to draw.
2014-08-10 15:37:48 -04:00
Scott Allen
0eeb47d20a Fix reDraw keyword - changed spaces to tab. 2014-08-05 17:59:30 -04:00
Scott Allen
fa93b3e21e Added reDraw keyword. 2014-08-04 19:47:38 -04:00
JP
78e7abeafa merged vSlider_reverse_2 2014-08-05 09:41:47 +10:00
jpliew
0d06e90e3d Merge pull request #9 from MLXXXp/vSlider_reverse_2
Reverse direction of virtical sliders
2014-08-05 09:39:19 +10:00
Scott Allen
cc1d78384a Changed vertical slider direction.
Low values at the bottom. High values at the top.
2014-08-04 19:20:18 -04:00
Scott Allen
77928f1b74 Fixed compiler warning in MicroViewSlider.
In drawFace, majorLine could be left uninitialised if style was invalid
(although this couldn't happen with the current code).
Also cleaned up the WIDGETSTYLE tests.
2014-08-04 17:54:10 -04:00
JP
00a80911de fixed typo 2014-08-04 21:27:06 +10:00
JP
b64d5e4417 fixed child widget double declare of reDraw() 2014-08-04 21:23:06 +10:00
7 changed files with 941 additions and 270 deletions

View File

@@ -591,7 +591,6 @@ void MicroView::circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, ui
pixel(x0 - y, y0 + x, color, mode);
pixel(x0 + y, y0 - x, color, mode);
pixel(x0 - y, y0 - x, color, mode);
}
}
@@ -605,41 +604,62 @@ void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius) {
/** \brief Draw filled circle with color and mode.
Draw filled circle with radius using color and mode at x,y of the screen buffer.
Draw filled circle with radius using color and mode at x,y of the screen
buffer. Uses the Bresenham circle algorithm with a few modifications to
paint the circle without overlapping draw operations.
*/
void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode) {
// TODO - - find a way to check for no overlapping of pixels so that XOR draw mode will work perfectly
int8_t f = 1 - radius;
int8_t ddF_x = 1;
int8_t ddF_y = -2 * radius;
int8_t x = 0;
int8_t y = radius;
// Temporary disable fill circle for XOR mode.
if (mode==XOR) return;
for (uint8_t i=y0-radius; i<=y0+radius; i++) {
pixel(x0, i, color, mode);
}
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t
color, uint8_t mode) {
int8_t x = radius;
int8_t y = 0;
int8_t radiusError = 1 - x;
int8_t y_last = y0 + x;
int8_t y_low;
int8_t x_alt;
int8_t x_alt_max;
while (x >= y) {
pixel(x + x0, y + y0, color, mode);
x_alt = (x0 - x);
x_alt_max = x0 + x;
while (x_alt < x_alt_max) {
pixel(x_alt, y + y0, color, mode);
x_alt++;
}
if (y != x) {
pixel(y + x0, x + y0, color, mode);
pixel(y + x0, y0 - x, color, mode);
}
if (y != 0) {
pixel(x + x0, y0 - y, color, mode);
x_alt = (x0 - x);
x_alt_max = x0 + x;
while (x_alt < x_alt_max) {
pixel(x_alt, y0 - y, color, mode);
x_alt++;
}
if (y != x) {
pixel(x0 - y, x + y0, color, mode);
pixel(x0 - y, y0 - x, color, mode);
if (y_last > y0 + x) {
x_alt = x0 - y + 1;
x_alt_max = x0 + y;
y_last = y0 + x;
y_low = y0 - x;
while (x_alt < x_alt_max) {
pixel(x_alt, y_last, color, mode);
pixel(x_alt, y_low, color, mode);
x_alt++;
}
}
}
}
y++;
if (radiusError<0) {
radiusError += 2 * y + 1;
} else {
x--;
radiusError += 2 * (y - x + 1);
}
x++;
ddF_x += 2;
f += ddF_x;
for (uint8_t i=y0-y; i<=y0+y; i++) {
pixel(x0+x, i, color, mode);
pixel(x0-x, i, color, mode);
}
for (uint8_t i=y0-x; i<=y0+x; i++) {
pixel(x0+y, i, color, mode);
pixel(x0-y, i, color, mode);
}
}
}
@@ -858,13 +878,26 @@ void MicroView::scrollStop(void){
*/
void MicroView::scrollRight(uint8_t start, uint8_t stop){
if (stop<start) // stop must be larger or equal to start
return;
return;
scrollStop(); // need to disable scrolling before starting to avoid memory corrupt
command(RIGHTHORIZONTALSCROLL, 0);
command(start, 0x7, stop); // scroll speed frames , TODO
command(0x00, 0xFF, ACTIVATESCROLL);
}
/** \brief Left scrolling.
Set row start to row stop on the OLED to scroll left. Refer to http://learn.microview.io/intro/general-overview-of-microview.html for explanation of the rows.
*/
void MicroView::scrollLeft(uint8_t start, uint8_t stop){
if (stop<start) // stop must be larger or equal to start
return;
scrollStop(); // need to disable scrolling before starting to avoid memory corrupt
command(LEFTHORIZONTALSCROLL, 0);
command(start, 0x7, stop); // scroll speed frames , TODO
command(0x00, 0xFF, ACTIVATESCROLL);
}
/** \brief Vertical flip.
Flip the graphics on the OLED vertically.
@@ -891,6 +924,14 @@ void MicroView::flipHorizontal(boolean flip) {
}
}
/** \brief Get pointer to screen buffer
Return a pointer to the start of the RAM screen buffer for direct access.
*/
uint8_t *MicroView::getScreenBuffer(void) {
return screenmemory;
}
/** \brief Parse command.
Command stored in serCmd array will be parsed to performed draw functions.
@@ -1335,25 +1376,28 @@ 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) {
setX(newx);
setY(newy);
value=0;
setMinValue(min);
setMaxValue(max);
MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max):
posX(newx),
posY(newy),
minValue(min),
maxValue(max),
value(min)
{
valLen=getInt16PrintLen(value);
setMaxValLen();
}
/** \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.
@@ -1377,35 +1421,87 @@ int16_t MicroViewWidget::getValue() { return value; }
The minimum value of the widget is set to the variable passed in.
*/
void MicroViewWidget::setMinValue(int16_t min) { minValue=min; }
void MicroViewWidget::setMinValue(int16_t min) {
minValue = min;
setMaxValLen();
}
/** \brief Set maximum value.
The maximum value of the widget is set to the variable passed in.
*/
void MicroViewWidget::setMaxValue(int16_t max) { maxValue=max; }
void MicroViewWidget::setMaxValue(int16_t max) {
maxValue = max;
setMaxValLen();
}
/** \brief Set current value.
/** \brief Get the maximum possible print length of the value
The current value of the widget is set to the variable passed in.
Return the maximum number of characters that would be printed using uView.print(value) for the current value range.
*/
void MicroViewWidget::setValue(int16_t val) {
if ((val<=maxValue) && (val>=minValue)){
value=val;
this->draw();
uint8_t MicroViewWidget::getMaxValLen() { return maxValLen; }
/** \brief Set current value and update widget.
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);
if (doDraw) {
this->draw();
}
}
}
/** \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.
*/
uint8_t MicroViewWidget::getValLen() { return valLen; }
/** \brief MicroView Widget reDraw routine.
Redraws the widget.
*/
void MicroViewWidget::reDraw() {
needFirstDraw=true;
this->drawFace();
this->drawPointer(); // initial pointer (will be erased)
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) {
for (uint8_t i = maxValLen - getInt16PrintLen(value); i > 0; i--) {
uView.print(" ");
}
uView.print(value);
}
/* Set the maximum number of characters that would be printed
using uView.print(value) for the current value range.
*/
void MicroViewWidget::setMaxValLen() {
uint8_t minLen, maxLen;
maxLen = getInt16PrintLen(maxValue);
minLen = getInt16PrintLen(minValue);
maxValLen = maxLen >= minLen ? maxLen : minLen;
}
// -------------------------------------------------------------------------------------
// MicroViewWidget Class - end
// -------------------------------------------------------------------------------------
@@ -1418,44 +1514,50 @@ void MicroViewWidget::reDraw() {
Initialise the MicroViewSlider widget with default style.
*/
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
style=0;
totalTicks=30;
prevValue=getMinValue();
needFirstDraw=true;
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(value)
{
drawFace();
drawPointer(); // Initial pointer (will be erased)
draw();
}
/** \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==WIDGETSTYLE0) {
style=0;
totalTicks=30;
}
else if (sty==WIDGETSTYLE1) {
style=1;
totalTicks=60;
}
else if (sty==WIDGETSTYLE2) {
style=2;
totalTicks=20;
}
else if (sty==WIDGETSTYLE3) {
style=3;
totalTicks=40;
}
else { //unrecognized style, so use default
style=0;
totalTicks=30;
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):
MicroViewWidget(newx, newy, min, max),
prevValue(value)
{
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();
needFirstDraw=true;
drawFace();
drawPointer(); // Initial pointer (will be erased)
draw();
}
@@ -1464,71 +1566,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, majorLine;
offsetX=getX();
offsetY=getY();
if(style==0)
majorLine=4;
else if (style==1)
majorLine=7;
else if (style==2)
majorLine=3;
else if (style==3)
majorLine=5;
uint8_t endOffset;
//Horizontal styles, style 0 or 1
if (style==0 || style==1) {
// Draw major tickers
for (uint8_t i=0; i<majorLine;i++) {
uView.lineV(offsetX+1+(i*10), offsetY+3, 5);
endOffset = posX + totalTicks + 2;
// Draw minor ticks
for (uint8_t i=posX+1; i<endOffset; i+=2) {
uView.lineV(i, posY+5, 3);
}
// 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) { //Longer line, more minor ticks
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);
}
for (uint8_t i=0; i<4;i++) {
uView.lineV(offsetX+53+(i*2), offsetY+5, 3);
}
// Draw extensions for major ticks
for (uint8_t i=posX+1; i<endOffset; i+=10) {
uView.lineV(i, posY+3, 2);
}
}
//Vertical styles, style 2 or 3
else {
// Draw major tickers
for (uint8_t i=0; i<majorLine;i++) {
uView.lineH(offsetX, offsetY+1+(i*10), 5);
endOffset = posY + totalTicks + 2;
// Draw minor ticks
for (uint8_t i=posY+1; i<=endOffset; i+=2) {
uView.lineH(posX, i, 3);
}
// Draw minor tickers
for (uint8_t i=0; i<4;i++) {
uView.lineH(offsetX, offsetY+3+(i*2), 3);
}
for (uint8_t i=0; i<4;i++) {
uView.lineH(offsetX, offsetY+13+(i*2), 3);
}
if(style==3) { //Explicit test for style
for (uint8_t i=0; i<4;i++) {
uView.lineH(offsetX, offsetY+23+(i*2), 3);
}
for (uint8_t i=0; i<4;i++) {
uView.lineH(offsetX, offsetY+33+(i*2), 3);
}
// Draw extensions for major ticks
for (uint8_t i=posY+1; i<=endOffset; i+=10) {
uView.lineH(posX+3, i, 2);
}
}
}
@@ -1538,64 +1599,45 @@ 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[5];
offsetX=getX();
offsetY=getY();
drawPointer(); // Erase the previous pointer
prevValue=value;
drawPointer(); // Draw the current pointer
if (needFirstDraw) {
tickPosition= (((float)(prevValue-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
if (style==0 || style==1){ //Horizontal
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
}
else { //Vertical
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
// Draw numeric value if required
if (!noValDraw) {
switch(style) {
case 0:
uView.setCursor(posX+totalTicks+4, posY+1);
break;
case 1:
uView.setCursor(posX, posY+10);
break;
case 2:
uView.setCursor(posX+1, posY+totalTicks+4);
break;
default:
uView.setCursor(posX+9, posY);
break;
}
sprintf(strBuffer,"%4d", prevValue); // we need to force 4 digit so that blank space will cover larger value
needFirstDraw=false;
drawNumValue(prevValue);
}
else {
// Draw previous pointer in XOR mode to erase it
tickPosition= (((float)(prevValue-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
if (style==0 || style==1){ //Horizontal
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
}
else { //Vertical
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
}
}
// Draw current pointer
tickPosition= (((float)(getValue()-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
if (style==0 || style==1){ //Horizontal
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
}
else { //Vertical
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
}
// Use XOR mode to erase or draw the pointer for prevValue
void MicroViewSlider::drawPointer() {
uint8_t tickPosition;
sprintf(strBuffer,"%4d", getValue()); // we need to force 4 digit so that blank space will cover larger value
prevValue=getValue();
if (style==0 || style==1) { // Horizontal
tickPosition = ((float)(uint16_t)(prevValue-minValue)/(float)(uint16_t)(maxValue-minValue))*totalTicks;
uView.lineH(posX+tickPosition, posY, 3, WHITE, XOR);
uView.pixel(posX+1+tickPosition, posY+1, WHITE, XOR);
}
else { // Vertical
tickPosition = ((float)(uint16_t)(maxValue-prevValue)/(float)(uint16_t)(maxValue-minValue))*totalTicks;
uView.lineV(posX+7, posY+tickPosition, 3, WHITE, XOR);
uView.pixel(posX+6, posY+1+tickPosition, WHITE, XOR);
}
// Draw value
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);
}
// -------------------------------------------------------------------------------------
@@ -1610,21 +1652,30 @@ void MicroViewSlider::draw() {
Initialise the MicroViewGauge widget with default style.
*/
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
style=0;
radius=15;
prevValue=getMinValue();
needFirstDraw=true;
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(value)
{
drawFace();
drawPointer(); // Initial pointer (will be erased)
draw();
}
/** \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) {
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):
MicroViewWidget(newx, newy, min, max),
prevValue(value)
{
noValDraw = sty & WIDGETNOVALUE; // set "no value draw" flag as specified
if ((sty & ~WIDGETNOVALUE) == WIDGETSTYLE0) {
style=0;
radius=15;
}
@@ -1632,9 +1683,9 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
style=1;
radius=23;
}
prevValue=getMinValue();
needFirstDraw=true;
drawFace();
drawPointer(); // Initial pointer (will be erased)
draw();
}
@@ -1643,30 +1694,27 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
Draw image/diagram representing the widget's face.
*/
void MicroViewGauge::drawFace() {
uint8_t offsetX, offsetY;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
offsetX=getX();
offsetY=getY();
uView.circle(offsetX,offsetY,radius);
uView.circle(posX, posY, 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);
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
toSecX = cos(degreeSec) * radius;
toSecY = sin(degreeSec) * radius;
uView.line(1+posX+fromSecX, 1+posY+fromSecY, 1+posX+toSecX, 1+posY+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);
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
toSecX = cos(degreeSec) * radius;
toSecY = sin(degreeSec) * radius;
uView.line(1+posX+fromSecX, 1+posY+fromSecY, 1+posX+toSecX, 1+posY+toSecY);
}
}
}
@@ -1676,48 +1724,34 @@ void MicroViewGauge::drawFace() {
Convert the current value of the widget and draw the ticker representing the value.
*/
void MicroViewGauge::draw() {
uint8_t offsetX, offsetY;
drawPointer(); // Erase the previous pointer
prevValue=value;
drawPointer(); // Draw the current pointer
// Draw numeric value if required
if (!noValDraw) {
uint8_t offsetX = posX - (maxValLen * 3 - 1); // Offset left of centre to print the value
if (style > 0)
uView.setCursor(offsetX, posY+10);
else
uView.setCursor(offsetX, posY+11);
drawNumValue(prevValue);
}
}
// Use XOR mode to erase or draw the pointer for prevValue
void MicroViewGauge::drawPointer() {
float degreeSec, toSecX, toSecY;
char strBuffer[5];
offsetX=getX();
offsetY=getY();
// total 240 degree in the widget with 150 degree starting point
degreeSec = (((float)(uint16_t)(prevValue-minValue) / (float)(uint16_t)(maxValue-minValue)
* 240) + 150) * (PI / 180);
if (needFirstDraw) {
degreeSec = (((float)(prevValue-getMinValue())/(float)(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,"%4d", prevValue); // we need to force 4 digit so that blank space will cover larger value
needFirstDraw=false;
}
else {
// Draw previous pointer in XOR mode to erase it
degreeSec = (((float)(prevValue-getMinValue())/(float)(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)(getValue()-getMinValue())/(float)(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,"%4d", getValue()); // we need to force 4 digit so that blank space will cover larger value
prevValue=getValue();
}
// Draw value
if(style>0)
uView.setCursor(offsetX-10,offsetY+10);
else
uView.setCursor(offsetX-11,offsetY+11);
uView.print(strBuffer);
toSecX = cos(degreeSec) * (radius / 1.2);
toSecY = sin(degreeSec) * (radius / 1.2);
uView.line(posX, posY, 1+posX+toSecX, 1+posY+toSecY, WHITE, XOR);
}
// -------------------------------------------------------------------------------------
@@ -1831,4 +1865,36 @@ void MVSPIClass::setClockDivider(uint8_t rate)
MVSPIClass MVSPI;
MicroView uView;
/** \brief Get the number of characters for a 16 bit signed value.
Return the number of characters that would be printed using uView.print(x) for x being a signed 16 bit integer.
*/
uint8_t getInt16PrintLen(int16_t val) {
int16_t i;
uint8_t count;
if (val >= 10000) {
return 5;
}
if (val <= -10000) {
return 6;
}
if (val >= 0) {
count = 1;
}
else {
count = 2;
val = abs(val);
}
i = 10;
while (val >= i) {
count++;
i *= 10;
}
return count;
}

View File

@@ -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
@@ -114,7 +117,7 @@
#define DEACTIVATESCROLL 0x2E
#define SETVERTICALSCROLLAREA 0xA3
#define RIGHTHORIZONTALSCROLL 0x26
#define LEFT_HORIZONTALSCROLL 0x27
#define LEFTHORIZONTALSCROLL 0x27
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
@@ -192,6 +195,7 @@ public:
uint8_t getLCDHeight(void);
void setColor(uint8_t color);
void setDrawMode(uint8_t mode);
uint8_t *getScreenBuffer(void);
// Font functions
uint8_t getFontWidth(void);
@@ -226,31 +230,39 @@ private:
class MicroViewWidget {
public:
bool needFirstDraw;
MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max);
uint8_t getX();
uint8_t getY();
void setX(uint8_t newx);
void setY(uint8_t newy);
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);
void setValue(int16_t val, boolean doDraw);
uint8_t getValLen();
uint8_t getMaxValLen();
/** \brief Draw widget value overridden by child class. */
virtual void draw(){};
/** \brief Draw widget face overridden by child class. */
virtual void draw(){};
/** \brief Draw widget face overridden by child class. */
virtual void drawFace(){};
void reDraw();
private:
uint8_t x;
uint8_t y;
int16_t maxValue;
void drawNumValue(int16_t value);
virtual ~MicroViewWidget(){};
protected:
uint8_t posX;
uint8_t posY;
int16_t minValue;
int16_t maxValue;
int16_t value;
uint8_t valLen;
uint8_t maxValLen;
private:
/** \brief Draw or erase the widget pointer. Overridden by child class. */
virtual void drawPointer(){};
void setMaxValLen();
};
class MicroViewSlider: public MicroViewWidget{
@@ -259,9 +271,10 @@ public:
MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty);
void draw();
void drawFace();
void reDraw();
private:
uint8_t totalTicks, style;
void drawPointer();
uint8_t style, totalTicks;
boolean noValDraw;
int16_t prevValue;
};
@@ -271,9 +284,10 @@ public:
MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty);
void draw();
void drawFace();
void reDraw();
private:
uint8_t radius, style;
void drawPointer();
uint8_t style, radius;
boolean noValDraw;
int16_t prevValue;
};
@@ -342,4 +356,8 @@ void MVSPIClass::detachInterrupt() {
}
extern MicroView uView;
/** \brief Get the number of print characters for a 16 bit signed value. */
uint8_t getInt16PrintLen(int16_t val);
#endif

View File

@@ -92,6 +92,41 @@ 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
* added getValLen method for widgets to return length of current value - Scott Allen
* initialised widget with minimum value instead of 0 - Scott Allen
* added getValLen and getMaxValLen keywords
* modified MicroViewDemo example to use getValLen method - Scott Allen
**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
* added keywords for existing functions - Scott
* fixed circleFill() - Emil
**v1.19b: 19th August 2014 by Scott Allen**
* added uView.scrollLeft() function
* simplified Silder Widget drawFace() function
* added full signed 16 bit ranges for widgets
* improved drawing for minor and major ticks
**v1.18b: 5th August 2014 by Scott Allen**
* fixed compiler warning in MicroViewSlider
* changed vertical slider direction.
**v1.17b: 4th August 2014 by JP Liew**
* added reDraw() for MicroViewWidget class
* removed Serial.begin() from uView.begin() so that user can have control
@@ -104,7 +139,7 @@ void loop() {
* improved lots of low level routines, Fast SPI
* fixed some compilation warnings
* reduced overdriving display inputs
* added uVuew.end() to power off the display
* added uView.end() to power off the display
* improved speed of display() and clear() functions
* fixed positionning of "3" on clock face

View File

@@ -0,0 +1,101 @@
/*
MicroView Arduino Flashing Heart Demo
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>
const unsigned char logo [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x00, 0x00,
0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFE, 0xFE,
0xFE, 0xFE, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char logo2 [] = {
0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,
0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
uView.begin();
uView.clear(PAGE);
}
void loop() {
unsigned char i,j;
for (i=0; i<6; i++) {
uView.setPageAddress(i);
uView.setColumnAddress(0);
for (j=0;j<0x40;j++) {
uView.data(logo[i*0x40+j]);
}
}
delay(800);
for (i=0; i<6; i++) {
uView.setPageAddress(i);
uView.setColumnAddress(0);
for (j=0;j<0x40;j++) {
uView.data(logo2[i*0x40+j]);
}
}
delay(150);
}

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();
}
}

View File

@@ -0,0 +1,354 @@
/*
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 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) {
widget1->setValue(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() - widget1->getValLen()) * 3);
uView.setCursor(offsetX, offsetY);
uView.print(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();
prevVal = lowVal;
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);
}

View File

@@ -17,7 +17,6 @@ MicroViewGauge KEYWORD1
#######################################
begin KEYWORD2
invert KEYWORD2
clear KEYWORD2
invert KEYWORD2
contrast KEYWORD2
@@ -50,6 +49,10 @@ scrollVertLeft KEYWORD2
scrollStop KEYWORD2
flipVertical KEYWORD2
flipHorizontal KEYWORD2
setColumnAddress KEYWORD2
setPageAddress KEYWORD2
data KEYWORD2
getScreenBuffer KEYWORD2
getX KEYWORD2
getY KEYWORD2
@@ -60,8 +63,12 @@ getMaxValue KEYWORD2
setMaxValue KEYWORD2
setMinValue KEYWORD2
setValue KEYWORD2
getValLen KEYWORD2
getMaxValLen KEYWORD2
draw KEYWORD2
reDraw KEYWORD2
drawFace KEYWORD2
drawNumValue KEYWORD2
checkComm KEYWORD2
#######################################
@@ -78,5 +85,5 @@ WIDGETSTYLE0 LITERAL1
WIDGETSTYLE1 LITERAL1
WIDGETSTYLE2 LITERAL1
WIDGETSTYLE3 LITERAL1
WIDGETNOVALUE LITERAL1