mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-03-03 08:44:05 +01:00
declared permanent uView variable
This commit is contained in:
102
MicroView.cpp
102
MicroView.cpp
@@ -2,7 +2,7 @@
|
||||
#include <MicroView.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// Add header of the fonts here
|
||||
// Add header of the fonts here. Remove as many as possible to get conserve FLASH memory.
|
||||
#include <font5x7.h>
|
||||
#include <font8x16.h>
|
||||
#include <fontlargenumber.h>
|
||||
@@ -14,13 +14,12 @@
|
||||
// Change the total fonts included
|
||||
#define TOTALFONTS 7
|
||||
|
||||
// Add the font name as declared in the header file.
|
||||
// Add the font name as declared in the header file. Remove as many as possible to get conserve FLASH memory.
|
||||
const unsigned char *MICROVIEW::fontsPointer[]={font5x7,font8x16,sevensegment,fontlargenumber, space01,space02,space03};
|
||||
|
||||
|
||||
/*
|
||||
Screen memory buffer 64 x 48 divided by 8 = 384 bytes
|
||||
Screen memory buffer is required because in SPI mode, the host cannot read the SSD1306's GDRAM of the controller. This buffer serves as a scratch RAM for graphical functions.
|
||||
Page buffer 64 x 48 divided by 8 = 384 bytes
|
||||
Page buffer is required because in SPI mode, the host cannot read the SSD1306's GDRAM of the controller. This page buffer serves as a scratch RAM for graphical functions. All drawing function will first be drawn on this page buffer, only upon calling display() function will transfer the page buffer to the actual LCD controller's memory.
|
||||
*/
|
||||
static uint8_t screenmemory [] = {
|
||||
// LCD Memory organised in 64 horizontal pixel and 6 rows of byte
|
||||
@@ -65,16 +64,13 @@ static uint8_t screenmemory [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
void MICROVIEW::begin() {
|
||||
|
||||
// default 5x7 font
|
||||
setFontType(0);
|
||||
setFontColor(WHITE);
|
||||
setFontDrawMode(NORM);
|
||||
setColor(WHITE);
|
||||
setDrawMode(NORM);
|
||||
setCursor(0,0);
|
||||
|
||||
|
||||
// Setting up SPI pins
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(SCK, OUTPUT);
|
||||
@@ -144,6 +140,7 @@ void MICROVIEW::begin() {
|
||||
command(0x40);
|
||||
|
||||
command(DISPLAYON); //--turn on oled panel
|
||||
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
|
||||
}
|
||||
|
||||
void MICROVIEW::command(uint8_t c) {
|
||||
@@ -176,7 +173,6 @@ void MICROVIEW::setColumnAddress(uint8_t add) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Clear GDRAM inside the LCD controller - mode = ALL
|
||||
Clear screen page buffer - mode = PAGE
|
||||
@@ -221,8 +217,7 @@ void MICROVIEW::clear(uint8_t mode, uint8_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// This routine is to transfer the page buffer to the LCD controller's memory.
|
||||
void MICROVIEW::display(void) {
|
||||
uint8_t i, j;
|
||||
|
||||
@@ -244,9 +239,9 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
cursorY += fontHeight;
|
||||
cursorX = 0;
|
||||
} else if (c == '\r') {
|
||||
// skip em
|
||||
// skip
|
||||
} else {
|
||||
drawChar(cursorX, cursorY, c, fontColor, fontMode);
|
||||
drawChar(cursorX, cursorY, c, foreColor, drawMode);
|
||||
cursorX += fontWidth+1;
|
||||
if ((cursorX > (LCDWIDTH - fontWidth))) {
|
||||
cursorY += fontHeight;
|
||||
@@ -263,6 +258,10 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
cursorY=y;
|
||||
}
|
||||
|
||||
void MICROVIEW::pixel(uint8_t x, uint8_t y) {
|
||||
pixel(x,y,foreColor,drawMode);
|
||||
}
|
||||
|
||||
void MICROVIEW::pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) {
|
||||
if ((x<0) || (x>=LCDWIDTH) || (y<0) || (y>=LCDHEIGHT))
|
||||
return;
|
||||
@@ -281,6 +280,12 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
//display();
|
||||
}
|
||||
|
||||
// Draw line using current fore color and current draw mode
|
||||
void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||
line(x0,y0,x1,y1,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw line using color and mode
|
||||
// bresenham's algorithm
|
||||
void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) {
|
||||
uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
|
||||
@@ -320,14 +325,32 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw horizontal line using current fore color and current draw mode
|
||||
void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width) {
|
||||
line(x,y,x+width,y,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw horizontal line using color and draw mode
|
||||
void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) {
|
||||
line(x,y,x+width,y,color,mode);
|
||||
}
|
||||
|
||||
// Draw vertical line using current fore color and current draw mode
|
||||
void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height) {
|
||||
line(x,y,x,y+height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw vertical line using color and draw mode
|
||||
void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode) {
|
||||
line(x,y,x,y+height,color,mode);
|
||||
}
|
||||
|
||||
// Draw rectangle using current fore color and current draw mode
|
||||
void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
rect(x,y,width,height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw rectangle using color and draw mode
|
||||
void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
uint8_t tempHeight;
|
||||
|
||||
@@ -343,7 +366,14 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
lineV(x,y+1, tempHeight, color, mode);
|
||||
lineV(x+width-1, y+1, tempHeight, color, mode);
|
||||
}
|
||||
|
||||
|
||||
// Draw filled rectangle using current fore color and current draw mode
|
||||
void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
rectFill(x,y,width,height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw filled rectangle using color and mode
|
||||
void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
// TODO - need to optimise the memory map draw so that this function will not call pixel one by one
|
||||
for (int i=x; i<x+width;i++) {
|
||||
@@ -351,8 +381,13 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw circle using current fore color and current draw mode
|
||||
void MICROVIEW::circle(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
circle(x0,y0,radius,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw circle using color and mode
|
||||
void MICROVIEW::circle(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;
|
||||
@@ -389,18 +424,24 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
|
||||
|
||||
void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uint8_t mode) {
|
||||
// Draw filled circle using current fore color and current draw mode
|
||||
void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
circleFill(x0,y0,radius,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw filled circle using color and mode
|
||||
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 - r;
|
||||
int8_t f = 1 - radius;
|
||||
int8_t ddF_x = 1;
|
||||
int8_t ddF_y = -2 * r;
|
||||
int8_t ddF_y = -2 * radius;
|
||||
int8_t x = 0;
|
||||
int8_t y = r;
|
||||
int8_t y = radius;
|
||||
|
||||
// Temporary disable fill circle for XOR mode.
|
||||
if (mode==XOR) return;
|
||||
|
||||
for (uint8_t i=y0-r; i<=y0+r; i++) {
|
||||
for (uint8_t i=y0-radius; i<=y0+radius; i++) {
|
||||
pixel(x0, i, color, mode);
|
||||
}
|
||||
|
||||
@@ -470,23 +511,27 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
|
||||
}
|
||||
|
||||
void MICROVIEW::setFontColor(uint8_t color) {
|
||||
fontColor=color;
|
||||
void MICROVIEW::setColor(uint8_t color) {
|
||||
foreColor=color;
|
||||
}
|
||||
|
||||
void MICROVIEW::setFontDrawMode(uint8_t mode) {
|
||||
fontMode=mode;
|
||||
void MICROVIEW::setDrawMode(uint8_t mode) {
|
||||
drawMode=mode;
|
||||
}
|
||||
|
||||
// Draw character using current fore color and current draw mode
|
||||
void MICROVIEW::drawChar(uint8_t x, uint8_t y, uint8_t c) {
|
||||
drawChar(x,y,c,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw character using color and mode
|
||||
void MICROVIEW::drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode) {
|
||||
//void MICROVIEW::drawChar(uint8_t x, uint8_t line, uint8_t c, uint8_t mode) {
|
||||
|
||||
// TODO - New routine to take font of any height, at the moment limited to font height in multiple of 8 pixels
|
||||
|
||||
uint8_t rowsToDraw,row, tempC;
|
||||
uint8_t i,j,temp;
|
||||
uint16_t charPerBitmapRow,charColPositionOnBitmap,charRowPositionOnBitmap,charBitmapStartPosition;
|
||||
|
||||
|
||||
if ((c<fontStartChar) || (c>(fontStartChar+fontTotalChar-1))) // no bitmap for the required c
|
||||
return;
|
||||
|
||||
@@ -590,5 +635,6 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
command(ACTIVATESCROLL);
|
||||
}
|
||||
|
||||
MICROVIEW uView;
|
||||
|
||||
|
||||
|
||||
24
MicroView.h
24
MicroView.h
@@ -85,18 +85,29 @@ public:
|
||||
void invert(uint8_t i);
|
||||
void display(void);
|
||||
void setCursor(uint8_t x, uint8_t y);
|
||||
void pixel(uint8_t x, uint8_t y);
|
||||
void pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode);
|
||||
void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
|
||||
void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode);
|
||||
void lineH(uint8_t x, uint8_t y, uint8_t width);
|
||||
void lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode);
|
||||
void lineV(uint8_t x, uint8_t y, uint8_t height);
|
||||
void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode);
|
||||
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
|
||||
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
|
||||
void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
|
||||
void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
|
||||
void circle(uint8_t x, uint8_t y, uint8_t radius);
|
||||
void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t color, uint8_t mode);
|
||||
void circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uint8_t mode);
|
||||
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius);
|
||||
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode);
|
||||
void drawChar(uint8_t x, uint8_t y, uint8_t c);
|
||||
void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode);
|
||||
void drawBitmap(void);
|
||||
uint8_t getLCDWidth(void);
|
||||
uint8_t getLCDHeight(void);
|
||||
void setColor(uint8_t color);
|
||||
void setDrawMode(uint8_t mode);
|
||||
|
||||
// Font functions
|
||||
uint8_t getFontWidth(void);
|
||||
@@ -106,12 +117,7 @@ public:
|
||||
uint8_t setFontType(uint8_t type);
|
||||
uint8_t getFontStartChar(void);
|
||||
uint8_t getFontTotalChar(void);
|
||||
|
||||
// applicable for PRINT function
|
||||
void setFontColor(uint8_t color);
|
||||
void setFontDrawMode(uint8_t mode);
|
||||
|
||||
|
||||
|
||||
// LCD Rotate Scroll functions
|
||||
void scrollRight(uint8_t start, uint8_t stop);
|
||||
void scrollLeft(uint8_t start, uint8_t stop);
|
||||
@@ -123,9 +129,11 @@ private:
|
||||
//uint8_t cs;
|
||||
volatile uint8_t *mosiport, *sckport, *csport, *dcport; // use volatile because these are fixed location port address
|
||||
uint8_t mosipinmask, sckpinmask, cspinmask, dcpinmask;
|
||||
uint8_t fontColor,fontMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
|
||||
uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
|
||||
uint16_t fontMapWidth;
|
||||
//unsigned char *fontsPointer[TOTALFONTS];
|
||||
static const unsigned char *fontsPointer[];
|
||||
};
|
||||
|
||||
extern MICROVIEW uView;
|
||||
#endif
|
||||
65
README.md
65
README.md
@@ -1,33 +1,62 @@
|
||||
MicroView Arduino Library
|
||||
================================
|
||||
# MicroView Arduino Library
|
||||
|
||||
Developed by [Geek Ammo Pty Ltd](http://www.geekammo.com) based on Arduino and other Open Source libraries.
|
||||
|
||||
Description
|
||||
-----------
|
||||
## Description
|
||||
|
||||
Arduino library for MicroView.
|
||||
|
||||
History
|
||||
-------
|
||||
## Required Libraries
|
||||
|
||||
1. SPI.h
|
||||
2. [Time.h](http://www.pjrc.com/teensy/td_libs_Time.html) NOTE: Only required when using clock/time functions.
|
||||
|
||||
## Installation Instructions
|
||||
|
||||
1. Extract / Check out to Arduino's libraries folder.
|
||||
2. Start Arduino IDE.
|
||||
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
|
||||
### Example
|
||||
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE); // clear the page buffer
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uView.line(0,0,64,48);
|
||||
uView.circle(32,24,10);
|
||||
uView.rect(10,10,20,20);
|
||||
uView.pixel(50,5);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" MicroView");
|
||||
uView.display(); // display current page buffer
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
|
||||
**v1.04b: 3rd February 2014 by JP Liew
|
||||
* declared permanent uView variable.
|
||||
* cleaned code and added some remarks.
|
||||
* added drawing functions that make use of default color and draw mode.
|
||||
* added example in README.md
|
||||
|
||||
**v1.03b: 1st February 2014 by JP Liew**
|
||||
* added 7 segment number only font.
|
||||
|
||||
**v1.02b: 31th January 2014 by JP Liew**
|
||||
* added sprite animation demo.
|
||||
|
||||
|
||||
**v1.01b: 30th January 2014 by JP Liew**
|
||||
* fixed font draw XOR mode bug.
|
||||
* added analog clock demo.
|
||||
|
||||
|
||||
**v1.00b: 30th January 2014 by JP Liew**
|
||||
* Initial commit. Beta with minor bugs.
|
||||
|
||||
Required Libraries
|
||||
------------------
|
||||
1. SPI.h
|
||||
2. [Time.h](http://www.pjrc.com/teensy/td_libs_Time.html) NOTE: Only required when using clock/time functions.
|
||||
|
||||
Installation Instructions
|
||||
-------------------------
|
||||
1. Extract / Check out to Arduino's libraries folder.
|
||||
2. Start Arduino IDE.
|
||||
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
|
||||
Reference in New Issue
Block a user