4 Commits

6 changed files with 710 additions and 320 deletions

View File

@@ -17,6 +17,9 @@
// Change the total fonts included
#define TOTALFONTS 7
#define recvLEN 100
char serInStr[recvLEN]; // TODO - need to fix a value so that this will not take up too much memory.
uint8_t serCmd[recvLEN];
// 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[]={
@@ -140,7 +143,6 @@ void MicroView::begin() {
command(DISPLAYALLONRESUME); // 0xA4
command(SEGREMAP | 0x1);
command(COMSCANDEC);
command(SETCOMPINS); // 0xDA
@@ -157,6 +159,7 @@ void MicroView::begin() {
command(DISPLAYON); //--turn on oled panel
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
Serial.begin(115200);
}
void MicroView::command(uint8_t c) {
@@ -233,6 +236,18 @@ void MicroView::clear(uint8_t mode, uint8_t c) {
}
}
void MicroView::invert(boolean inv) {
if (inv)
command(INVERTDISPLAY);
else
command(NORMALDISPLAY);
}
void MicroView::contrast(uint8_t contrast) {
command(SETCONTRAST); // 0x81
command(contrast);
}
// This routine is to transfer the page buffer to the LCD controller's memory.
void MicroView::display(void) {
uint8_t i, j;
@@ -633,14 +648,14 @@ size_t MicroView::write(uint8_t c) {
}
void MicroView::stopScroll(void){
void MicroView::scrollStop(void){
command(DEACTIVATESCROLL);
}
void MicroView::scrollRight(uint8_t start, uint8_t stop){
if (stop<start) // stop must be larger or equal to start
return;
stopScroll(); // need to disable scrolling before starting to avoid memory corrupt
scrollStop(); // need to disable scrolling before starting to avoid memory corrupt
command(RIGHTHORIZONTALSCROLL);
command(0x00);
command(start);
@@ -650,310 +665,584 @@ size_t MicroView::write(uint8_t c) {
command(0xFF);
command(ACTIVATESCROLL);
}
MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max) {
setX(newx);
setY(newy);
value=0;
// if (min>max) {
// setMinValue(max);
// setMaxValue(min);
// }
// else {
setMinValue(min);
setMaxValue(max);
// }
//drawFace();
//setValue(min);
void MicroView::flipVertical(boolean flip) {
if (flip) {
command(COMSCANINC);
}
else {
command(COMSCANDEC);
}
}
uint8_t MicroViewWidget::getX() { return x; }
uint8_t MicroViewWidget::getY() { return y; }
void MicroViewWidget::setX(uint8_t newx) { x = newx; }
void MicroViewWidget::setY(uint8_t newy) { y = newy; }
int16_t MicroViewWidget::getMinValue() { return minValue; }
int16_t MicroViewWidget::getMaxValue() { return maxValue; }
int16_t MicroViewWidget::getValue() { return value; }
void MicroViewWidget::setMinValue(int16_t min) { minValue=min; }
void MicroViewWidget::setMaxValue(int16_t max) { maxValue=max; }
void MicroViewWidget::setValue(int16_t val) {
if (val<=maxValue) {
value=val;
this->draw();
void MicroView::flipHorizontal(boolean flip) {
if (flip) {
command(SEGREMAP | 0x0);
}
else {
command(SEGREMAP | 0x1);
}
}
// -------------------------------------------------------------------------------------
// Slider Widget - start
// -------------------------------------------------------------------------------------
void MicroView::doCmd(uint8_t cmdCount) {
// decode command
switch (serCmd[0]) {
case CMD_CLEAR: {
Serial.println("clear");
if (cmdCount==1) {
clear(serCmd[1]);
} else if (cmdCount==2) {
clear(serCmd[1], serCmd[2]);
}
break;
}
case CMD_INVERT: {
Serial.println("invert");
if (cmdCount==1) {
invert(serCmd[1]);
}
break;
}
case CMD_CONTRAST: {
Serial.println("contrast");
if (cmdCount==1) {
contrast(serCmd[1]);
}
break;
}
case CMD_DISPLAY: {
Serial.println("display");
if (cmdCount==0) {
display();
}
break;
}
case CMD_SETCURSOR: {
Serial.println("setCursor");
if (cmdCount==2) {
setCursor(serCmd[1], serCmd[2]);
}
break;
}
case CMD_PIXEL: {
Serial.println("pixel");
if (cmdCount==2) {
pixel(serCmd[1],serCmd[2]);
display();
} else if (cmdCount=4) {
pixel(serCmd[1],serCmd[2],serCmd[3],serCmd[4]);
display();
}
break;
}
case CMD_LINE: {
Serial.println("line");
if (cmdCount==4) {
line(serCmd[1],serCmd[2],serCmd[3],serCmd[4]);
display();
} else if (cmdCount==6) {
line(serCmd[1],serCmd[2],serCmd[3],serCmd[4],serCmd[5],serCmd[6]);
display();
}
break;
}
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
case CMD_LINEH: {
Serial.println("lineH");
if (cmdCount==3) {
lineH(serCmd[1], serCmd[2], serCmd[3]);
display();
} else if (cmdCount==5) {
lineH(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
display();
}
break;
}
case CMD_LINEV: {
Serial.println("lineV");
if (cmdCount==3) {
lineV(serCmd[1], serCmd[2], serCmd[3]);
display();
} else if (cmdCount==5) {
lineV(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
display();
}
break;
}
case CMD_RECT: {
Serial.println("rect");
if (cmdCount==4) {
rect(serCmd[1], serCmd[2], serCmd[3], serCmd[4]);
display();
} else if (cmdCount==6) {
rect(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5], serCmd[6]);
display();
}
break;
}
case CMD_RECTFILL: {
Serial.println("rectFill");
if (cmdCount==4) {
rectFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4]);
display();
} else if (cmdCount==6) {
rectFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5], serCmd[6]);
display();
}
break;
}
case CMD_CIRCLE: {
Serial.println("circle");
if (cmdCount==3) {
circle(serCmd[1], serCmd[2], serCmd[3]);
display();
} else if (cmdCount==5) {
circle(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
display();
}
break;
}
case CMD_CIRCLEFILL: {
Serial.println("circleFill");
if (cmdCount==3) {
circleFill(serCmd[1], serCmd[2], serCmd[3]);
display();
} else if (cmdCount==5) {
circleFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
display();
}
break;
}
case CMD_DRAWCHAR: {
Serial.println("drawChar");
if (cmdCount==3) {
drawChar(serCmd[1], serCmd[2], serCmd[3]);
display();
} else if (cmdCount==5) {
drawChar(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
display();
}
break;
}
case CMD_DRAWBITMAP: {
// TODO
break;
}
case CMD_GETLCDWIDTH: {
Serial.println("getLCDWidth");
if (cmdCount==0) {
Serial.println(getLCDWidth());
}
break;
}
case CMD_GETLCDHEIGHT: {
Serial.println("getLCDHeight");
if (cmdCount==0) {
Serial.println(getLCDHeight());
}
break;
}
case CMD_SETCOLOR: {
Serial.println("setColor");
if (cmdCount==1) {
setColor(serCmd[1]);
}
break;
}
case CMD_SETDRAWMODE: {
Serial.println("drawMode");
if (cmdCount==1) {
setDrawMode(serCmd[1]);
}
break;
}
default:
break;
}
}
void MicroView::checkComm(void) {
int count = readSerial();
char *result;
uint8_t index=0;
int temp;
if (count>0) {
// process Serial data
result=strtok(serInStr,",");
if (result !=NULL) {
temp=atoi(result);
serCmd[index]=(uint8_t)temp & 0xff; // we only need 8 bit number
index++;
for (uint8_t i;i<recvLEN;i++) {
result=strtok(NULL,",");
if (result != NULL) {
temp=atoi(result);
serCmd[index]=(uint8_t)temp & 0xff; // we only need 8 bit number
index++;
}
else {
break;
}
}
/*
// debug output
Serial.print("command received=");
Serial.println(index);
for (uint8_t i=0;i<index;i++) {
Serial.println(serCmd[i]);
}
*/
}
doCmd(index-1); // index-1 is the total parameters count of a command
}
}
int MicroView::readSerial(void)
{
int i=0;
if(!Serial.available())
return -1;
while (Serial.available()>0)
{
if( i < recvLEN)
{
serInStr[i++] = Serial.read();
delay(2);
}
else
break;
}
serInStr[i]='\0';
return i;
}
// -------------------------------------------------------------------------------------
// MicroViewWidget Class - start
// -------------------------------------------------------------------------------------
MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max) {
setX(newx);
setY(newy);
value=0;
setMinValue(min);
setMaxValue(max);
}
uint8_t MicroViewWidget::getX() { return x; }
uint8_t MicroViewWidget::getY() { return y; }
void MicroViewWidget::setX(uint8_t newx) { x = newx; }
void MicroViewWidget::setY(uint8_t newy) { y = newy; }
int16_t MicroViewWidget::getMinValue() { return minValue; }
int16_t MicroViewWidget::getMaxValue() { return maxValue; }
int16_t MicroViewWidget::getValue() { return value; }
void MicroViewWidget::setMinValue(int16_t min) { minValue=min; }
void MicroViewWidget::setMaxValue(int16_t max) { maxValue=max; }
void MicroViewWidget::setValue(int16_t val) {
if ((val<=maxValue) && (val>=minValue)){
value=val;
this->draw();
}
}
// -------------------------------------------------------------------------------------
// MicroViewWidget Class - end
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// Slider Widget - start
// -------------------------------------------------------------------------------------
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
style=0;
totalTicks=30;
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
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;
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
else {
style=1;
totalTicks=60;
}
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 {
style=1;
totalTicks=60;
}
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
void MicroViewSlider::drawFace() {
uint8_t offsetX, offsetY, majorLine;
offsetX=getX();
offsetY=getY();
if(style>0)
majorLine=7;
else
majorLine=4;
// Draw major tickers
for (uint8_t i=0; i<majorLine;i++) {
uView.lineV(offsetX+1+(i*10), offsetY+3, 5);
}
void MicroViewSlider::drawFace() {
uint8_t offsetX, offsetY, majorLine;
offsetX=getX();
offsetY=getY();
if(style>0)
majorLine=7;
else
majorLine=4;
// Draw major tickers
for (uint8_t i=0; i<majorLine;i++) {
uView.lineV(offsetX+1+(i*10), offsetY+3, 5);
}
// Draw minor tickers
// 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>0) {
for (uint8_t i=0; i<4;i++) {
uView.lineV(offsetX+3+(i*2), offsetY+5, 3);
uView.lineV(offsetX+33+(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>0) {
if (style>0) {
for (uint8_t i=0; i<4;i++) {
uView.lineV(offsetX+33+(i*2), offsetY+5, 3);
uView.lineV(offsetX+43+(i*2), offsetY+5, 3);
}
if (style>0) {
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);
}
for (uint8_t i=0; i<4;i++) {
uView.lineV(offsetX+53+(i*2), offsetY+5, 3);
}
}
}
}
void MicroViewSlider::draw() {
uint8_t offsetX, offsetY;
uint8_t tickPosition=0;
char strBuffer[5];
offsetX=getX();
offsetY=getY();
if (needFirstDraw) {
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, 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
tickPosition= (((float)(prevValue-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
// Draw current pointer
tickPosition= (((float)(getValue()-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
sprintf(strBuffer,"%4d", getValue()); // we need to force 4 digit so that blank space will cover larger value
prevValue=getValue();
}
void MicroViewSlider::draw() {
uint8_t offsetX, offsetY;
uint8_t tickPosition=0;
char strBuffer[5];
offsetX=getX();
offsetY=getY();
// Draw value
if(style>0)
uView.setCursor(offsetX,offsetY+10);
else
uView.setCursor(offsetX+34,offsetY+1);
uView.print(strBuffer);
}
if (needFirstDraw) {
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, 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
tickPosition= (((float)(prevValue-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
// Draw current pointer
tickPosition= (((float)(getValue()-getMinValue())/(float)(getMaxValue()-getMinValue()))*totalTicks);
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
sprintf(strBuffer,"%4d", getValue()); // we need to force 4 digit so that blank space will cover larger value
prevValue=getValue();
}
// -------------------------------------------------------------------------------------
// Slider Widget - end
// -------------------------------------------------------------------------------------
// Draw value
if(style>0)
uView.setCursor(offsetX,offsetY+10);
else
uView.setCursor(offsetX+34,offsetY+1);
uView.print(strBuffer);
}
// -------------------------------------------------------------------------------------
// Gauge Widget - start
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// Slider Widget - end
// -------------------------------------------------------------------------------------
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
style=0;
radius=15;
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
// -------------------------------------------------------------------------------------
// Gauge Widget - start
// -------------------------------------------------------------------------------------
MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
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) {
style=0;
radius=15;
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
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) {
style=0;
radius=15;
}
else {
style=1;
radius=23;
}
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
else {
style=1;
radius=23;
}
needFirstDraw=true;
prevValue=getMinValue();
drawFace();
draw();
}
void MicroViewGauge::drawFace() {
uint8_t offsetX, offsetY, majorLine;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
offsetX=getX();
offsetY=getY();
void MicroViewGauge::drawFace() {
uint8_t offsetX, offsetY, majorLine;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
offsetX=getX();
offsetY=getY();
uView.circle(offsetX,offsetY,radius);
for (int i=150;i<=390;i+=30) { // Major tick from 150 degree to 390 degree
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);
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
degreeSec=i*(PI/180);
fromSecX = cos(degreeSec) * (radius / 1.5);
fromSecY = sin(degreeSec) * (radius / 1.5);
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);
}
if(radius>15) {
for (int i=150;i<=390;i+=15) { // Minor tick from 150 degree to 390 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);
}
}
}
}
void MicroViewGauge::draw() {
uint8_t offsetX, offsetY;
uint8_t tickPosition=0;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
char strBuffer[5];
offsetX=getX();
offsetY=getY();
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);
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();
}
void MicroViewGauge::draw() {
uint8_t offsetX, offsetY;
uint8_t tickPosition=0;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
// Draw value
if(style>0)
uView.setCursor(offsetX-10,offsetY+10);
else
uView.setCursor(offsetX-11,offsetY+11);
uView.print(strBuffer);
}
char strBuffer[5];
offsetX=getX();
offsetY=getY();
// -------------------------------------------------------------------------------------
// Slider Widget - end
// -------------------------------------------------------------------------------------
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);
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);
void MVSPIClass::begin() {
// Set SS to high so a connected chip will be "deselected" by default
digitalWrite(SS, HIGH);
sprintf(strBuffer,"%4d", getValue()); // we need to force 4 digit so that blank space will cover larger value
prevValue=getValue();
}
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
pinMode(SS, OUTPUT);
// Draw value
if(style>0)
uView.setCursor(offsetX-10,offsetY+10);
else
uView.setCursor(offsetX-11,offsetY+11);
uView.print(strBuffer);
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of
// the SS pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
// Set direction register for SCK and MOSI pin.
// MISO pin automatically overrides to INPUT.
// By doing this AFTER enabling SPI, we avoid accidentally
// clocking in a single bit since the lines go directly
// from "input" to SPI control.
// http://code.google.com/p/arduino/issues/detail?id=888
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
}
void MVSPIClass::end() {
SPCR &= ~_BV(SPE);
}
void MVSPIClass::setBitOrder(uint8_t bitOrder)
{
if(bitOrder == LSBFIRST) {
SPCR |= _BV(DORD);
} else {
SPCR &= ~(_BV(DORD));
}
}
// -------------------------------------------------------------------------------------
// Slider Widget - end
// -------------------------------------------------------------------------------------
void MVSPIClass::begin() {
// Set SS to high so a connected chip will be "deselected" by default
digitalWrite(SS, HIGH);
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
pinMode(SS, OUTPUT);
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of
// the SS pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
// Set direction register for SCK and MOSI pin.
// MISO pin automatically overrides to INPUT.
// By doing this AFTER enabling SPI, we avoid accidentally
// clocking in a single bit since the lines go directly
// from "input" to SPI control.
// http://code.google.com/p/arduino/issues/detail?id=888
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
}
void MVSPIClass::end() {
SPCR &= ~_BV(SPE);
}
void MVSPIClass::setBitOrder(uint8_t bitOrder)
{
if(bitOrder == LSBFIRST) {
SPCR |= _BV(DORD);
} else {
SPCR &= ~(_BV(DORD));
}
}
void MVSPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}
void MVSPIClass::setClockDivider(uint8_t rate)
{
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
}
MVSPIClass MVSPI;
MicroView uView;
void MVSPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}
void MVSPIClass::setClockDivider(uint8_t rate)
{
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
}
MVSPIClass MVSPI;
MicroView uView;

View File

@@ -64,6 +64,28 @@
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
typedef enum CMD {
CMD_CLEAR, //0
CMD_INVERT, //1
CMD_CONTRAST, //2
CMD_DISPLAY, //3
CMD_SETCURSOR, //4
CMD_PIXEL, //5
CMD_LINE, //6
CMD_LINEH, //7
CMD_LINEV, //8
CMD_RECT, //9
CMD_RECTFILL, //10
CMD_CIRCLE, //11
CMD_CIRCLEFILL, //12
CMD_DRAWCHAR, //13
CMD_DRAWBITMAP, //14
CMD_GETLCDWIDTH, //15
CMD_GETLCDHEIGHT, //16
CMD_SETCOLOR, //17
CMD_SETDRAWMODE //18
} commCommand_t;
class MicroView : public Print{
public:
MicroView(void) {};
@@ -81,10 +103,11 @@ public:
void setColumnAddress(uint8_t add);
void setPageAddress(uint8_t add);
// LCD Draw functions
// LCD Draw functions
void clear(uint8_t mode);
void clear(uint8_t mode, uint8_t c);
void invert(uint8_t i);
void invert(boolean inv);
void contrast(uint8_t contrast);
void display(void);
void setCursor(uint8_t x, uint8_t y);
void pixel(uint8_t x, uint8_t y);
@@ -125,7 +148,13 @@ public:
void scrollLeft(uint8_t start, uint8_t stop);
void scrollVertRight(uint8_t start, uint8_t stop);
void scrollVertLeft(uint8_t start, uint8_t stop);
void stopScroll(void);
void scrollStop(void);
void flipVertical(boolean flip);
void flipHorizontal(boolean flip);
// Communication
void checkComm(void);
void doCmd(uint8_t index);
private:
//uint8_t cs;
@@ -135,6 +164,8 @@ private:
uint16_t fontMapWidth;
//unsigned char *fontsPointer[TOTALFONTS];
static const unsigned char *fontsPointer[];
int readSerial(void);
};
class MicroViewWidget {

View File

@@ -16,7 +16,7 @@ Arduino library for MicroView.
2. Start Arduino IDE.
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
### Example 1
### Example 1 - Hello World!
<pre><code>
#include &lt;MicroView.h&gt;
@@ -30,7 +30,7 @@ void loop() {
}
</code></pre>
### Example 2
### Example 2 - Basic Drawing
<pre><code>
#include &lt;MicroView.h&gt;
@@ -50,7 +50,7 @@ void loop() {
}
</code></pre>
### Example 3
### Example 3 - Widgets
<pre><code>
#include &lt;MicroView.h&gt;
@@ -72,13 +72,38 @@ void loop() {
}
</code></pre>
### Example 4 - Communication
<pre><code>
#include &lt;MicroView.h&gt;
void setup() {
uView.begin();
uView.clear(PAGE);
}
void loop() {
uView.checkComm();
}
</code></pre>
## History
**v1.06b: by JP Liew**
**v1.08b: 18th February 2014 by JP Liew**
* added verticalFlip(), horizontalFlip()
**v1.07b: 15th February 2014 by JP Liew**
* changed function name stopScroll to scrollStop for consistency
* added contrast function
* added invert function
* added KEYWORD to keywords.txt
* added checkComm() function to communicate with host PC
**v1.06b: 9th February 2014 by JP Liew**
* fixed Slider negative value not working
* added round Gauge widget
* changed Example 3 to show round Gauge
**v1.05b: 6th February by JP Liew**
**v1.05b: 6th February 2014 by JP Liew**
* changed MICROVIEW class name to MicroView
* created MICROVIEWWIDGET class
* added routines to draw widget

View File

@@ -1,18 +1,17 @@
#include <MicroView.h>
#include <Time.h>
//#define PI 3.141592654
#define clocksize 24
uint8_t onDelay=5; // This is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
uint8_t onDelay=5; // this is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
void setup() {
uView.begin(); // Begin of MicroView
uView.clear(ALL); // Erase hardware memory inside the OLED controller
uView.display(); // Display the content in the buffer memory, by default it is the MicroView logo
uView.begin(); // begin of MicroView
uView.clear(ALL); // erase hardware memory inside the OLED controller
uView.display(); // display the content in the buffer memory, by default it is the MicroView logo
setTime(10,10,01,17,1,2014);
delay(500);
uView.clear(PAGE); // Erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
}
void loop() {
@@ -261,8 +260,6 @@ void loop() {
}
}
uView.clear(PAGE);
}

View File

@@ -1,39 +1,30 @@
#include <SPI.h>
#include <MicroView.h>
MicroViewWidget *widget[4];
void setup() {
widget[0] = new MicroViewSlider(0,0,0,100);
widget[1] = new MicroViewSlider(0,10,0,150);
widget[2] = new MicroViewSlider(0,20,0,50);
widget[3] = new MicroViewSlider(0,30,0,200);
Serial.begin(115200);
Serial.println("start");
uView.begin();
uView.clear(PAGE);
widget[0]->draw();
widget[1]->draw();
widget[2]->draw();
widget[3]->draw();
}
void loop() {
for (int i=0;i<101;i++) {
widget[0]->setValue(i);
widget[1]->setValue(100-i);
widget[2]->setValue(i);
widget[3]->setValue(100-i);
uView.display();
}
for(int i=100; i>-1;i--) {
widget[0]->setValue(i);
widget[1]->setValue(100-i);
widget[2]->setValue(i);
widget[3]->setValue(100-i);
uView.display();
}
#include <MicroView.h>
MicroViewWidget *widget[4]; // declaring an array of 4 MicroViewWidget
void setup() {
uView.begin(); // init and start MicroView
uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
widget[0] = new MicroViewSlider(0,0,0,100); // declare widget0 as a Slider at x=0, y=0, min=0, max=100
widget[1] = new MicroViewSlider(0,10,0,150); // declare widget0 as a Slider at x=0, y=10, min=0, max=150
widget[2] = new MicroViewSlider(0,20,0,50); // declare widget0 as a Slider at x=0, y=20, min=0, max=50
widget[3] = new MicroViewSlider(0,30,0,200); // declare widget0 as a Slider at x=0, y=30, min=0, max=200
}
void loop() {
for (int i=0;i<=100;i++) {
widget[0]->setValue(i); // set value i to widget0
widget[1]->setValue(100-i);
widget[2]->setValue(i);
widget[3]->setValue(100-i);
uView.display();
}
for(int i=100; i>=0;i--) {
widget[0]->setValue(i);
widget[1]->setValue(100-i);
widget[2]->setValue(i);
widget[3]->setValue(100-i);
uView.display();
}
}

View File

@@ -7,18 +7,75 @@
#######################################
MICROVIEW KEYWORD1
uView KEYWORD1
MicroViewWidget KEYWORD1
MicroViewSlider KEYWORD1
MicroViewGauge KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
invert KEYWORD2
clear KEYWORD2
home KEYWORD2
invert KEYWORD2
contrast KEYWORD2
display KEYWORD2
setCursor KEYWORD2
pixel KEYWORD2
line KEYWORD2
lineH KEYWORD2
lineV KEYWORD2
rect KEYWORD2
rectFill KEYWORD2
circle KEYWORD2
circleFill KEYWORD2
drawChar KEYWORD2
getLCDWidth KEYWORD2
getLCDHeight KEYWORD2
setColor KEYWORD2
setDrawMode KEYWORD2
getFontWidth KEYWORD2
getFontHeight KEYWORD2
getTotalFonts KEYWORD2
getFontType KEYWORD2
setFontType KEYWORD2
getFontStartChar KEYWORD2
getFontTotalChar KEYWORD2
scrollRight KEYWORD2
scrollLeft KEYWORD2
scrollVertRight KEYWORD2
scrollVertLeft KEYWORD2
scrollStop KEYWORD2
flipVertical KEYWORD2
flipHorizontal KEYWORD2
getX KEYWORD2
getY KEYWORD2
setX KEYWORD2
setY KEYWORD2
getMinValue KEYWORD2
getMaxValue KEYWORD2
setMaxValue KEYWORD2
setMinValue KEYWORD2
setValue KEYWORD2
draw KEYWORD2
drawFace KEYWORD2
checkComm KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
BLACK LITERAL1
WHITE LITERAL1
NORM LITERAL1
XOR LITERAL1
PAGE LITERAL1
ALL LITERAL1
WIDGETSTYLE0 LITERAL1
WIDGETSTYLE1 LITERAL1
WIDGETSTYLE2 LITERAL1