Esempio n. 1
0
void testdrawtriangle(void) {
  for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    display.display();
  }
}
Esempio n. 2
0
void testfillrect(void) {
  uint8_t color = 1;
  for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
  }
}
Esempio n. 3
0
void testfillroundrect(void) {
  uint8_t color = BLACK;
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
Esempio n. 4
0
void testfilltriangle(void) {
  uint8_t color = BLACK;
  for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
Esempio n. 5
0
void _drawMessages() {
  //Move the cursor to the bottom of the screen
  display.setCursor(0, display.height());
  display.setTextWrap(true);
  int8_t row = _bottom;

  display.clearDisplay();

  //If first message is blank quit
  ChatMessage first = getFromChatBuffer(_bottom);
  if (strlen(first.name) == 0) {
    display.setCursor(1, 1);
    display.print("Nothing's here");
    safeDisplay();
    return;
  }

  //Draw each message starting from the bottom of the screen
  while (display.getCursorY() >= 0 && row >= 0) {
    ChatMessage message = getFromChatBuffer(row);

    //Stop drawing messages if we hit an empty one
    if (strlen(message.message) == 0 && strlen(message.name) == 0) {
      break;
    }

    //Determine if the the mesage is two line or not
    bool twoLine = (strlen(message.name) + strlen(message.message) > _maxCharsPerRow);

    //Move cursor up to print the line(s)
    uint8_t y = display.getCursorY() - ANX_FONT_HEIGHT;
    if (twoLine) {
      y -= ANX_FONT_HEIGHT;
    }
    display.setCursor(0, y);

    //Ensure username is null terminated
    char name[USERNAME_MAX_LENGTH + 1];
    memcpy(name, message.name, USERNAME_MAX_LENGTH);
    name[USERNAME_MAX_LENGTH] = '\0';

    //Ensure message is null terminated
    char msg[ANX_CHAT_MAX_LENGTH + 1];
    memcpy(msg, message.message, ANX_CHAT_MAX_LENGTH);
    msg[ANX_CHAT_MAX_LENGTH] = '\0';

    display.print("@");
    display.print(name);
    display.print(":");
    display.println(msg);

    //Move cursor back up above the message we just printed
    display.setCursor(0, y);

    row--;
  }

  //Show
  safeDisplay();
}
Esempio n. 6
0
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];

  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = rand()%display.width();
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = rand()%(5) + 1;
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
    }
    display.display();
    delay(20);

    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
	icons[f][XPOS] = rand()%(display.width());
	icons[f][YPOS] = 0;
	icons[f][DELTAY] = rand()%(5) + 1;
      }
    }
   }
}
Esempio n. 7
0
void testdrawline() {
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int8_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
    display.display();
  }
  delay(25);
}
void Demo1()
{
	Serial.println("Display: circle");
	// Clear the buffer.
	display.clearDisplay();
	// draw a circle, 10 pixel radius
	display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
	display.display();
	DemoTimer.stop();
	DemoTimer.initializeMs(2000, Demo2).start();	
}
Esempio n. 9
0
/**
   Popup input window with text centered. Window height is based on maxChars
*/
void ANXInputWindow(char * message, char *title, uint8_t maxChars) {

  uint8_t w = (display.width() * .8) + 4;
  uint8_t maxCharsPerRow = w / ANX_FONT_WIDTH;
  uint8_t rows = (maxChars / maxCharsPerRow) + 1;
  uint8_t textHeight = rows * ANX_FONT_HEIGHT;
  uint8_t h = textHeight + ANX_FONT_HEIGHT + 3 + 2;
  uint8_t x = (display.width() - w) / 2;
  uint8_t y = (display.height() - h) / 2;
  uint8_t tx = (display.width() - (ANX_FONT_WIDTH * strlen(title))) / 2;
  uint8_t ty = y + 1;

  display.fillRoundRect(x, y, w, h, 2, BLACK);
  display.drawRoundRect(x, y, w, h, 2, WHITE);
  display.fillRoundRect(x, y, w, ANX_FONT_HEIGHT + 1, 2, WHITE);

  display.setCursor(tx, ty);
  display.setTextColor(INVERSE);
  display.print(title);

  ANXInput(message, x + 2, y + ANX_FONT_HEIGHT + 3, maxChars, maxCharsPerRow);
}
Esempio n. 10
0
void init()
{
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Allow debug output to serial

	Serial.println("Display start");
	display.begin(SSD1306_SWITCHCAPVCC);
	display.display();
	delay(2000);

	// Clear the buffer.
	display.clearDisplay();

	// draw a circle, 10 pixel radius
	display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
	display.display();
	delay(2000);
	display.clearDisplay();

	// text display tests
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0,0);
	display.println("Sming Framework");
	display.setTextColor(BLACK, WHITE); // 'inverted' text
	display.setCursor(104, 7);
	display.println("v1.0");
	//----
	display.setTextColor(WHITE);
	display.println("Let's do smart things");
	display.setTextSize(3);
	display.print("IoT");
	display.display();

	delay(2000);
}
Esempio n. 11
0
void testdrawcircle(void) {
  for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
    display.display();
  }
}
Esempio n. 12
0
void test_task(void*)   {
	while(1){
		display.begin();
		//display.setContrast(50);
		display.display();

		delay(2000);
		display.clearDisplay();   // clears the screen and buffer

		// draw a single pixel
		display.drawPixel(10, 10, WHITE);
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw many lines
		testdrawline();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw rectangles
		testdrawrect();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw multiple rectangles
		testfillrect();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw mulitple circles
		testdrawcircle();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw a circle, 10 pixel radius
		display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
		display.display();
		delay(2000);
		display.clearDisplay();

		testdrawroundrect();
		delay(2000);
		display.clearDisplay();

		testfillroundrect();
		delay(2000);
		display.clearDisplay();

		testdrawtriangle();
		delay(2000);
		display.clearDisplay();

		testfilltriangle();
		delay(2000);
		display.clearDisplay();

		// draw the first ~12 characters in the font
		testdrawchar();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw scrolling text
		testscrolltext();
		delay(2000);
		display.clearDisplay();

		// text display tests
		display.setTextSize(2);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.println((char*)"Hello, world!");
		display.setTextColor(WHITE, BLACK); // 'inverted' text
		display.println((char*)"3.141592");
		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.print((char*)"0x");
		display.println((char*)"DEADBEEF");
		display.display();
		delay(2000);

		// rotation example
		display.clearDisplay();
		display.setRotation(1);  // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further.
		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.println((char*)"Rotation");
		display.setTextSize(1);
		display.println((char*)"Example!");
		display.display();
		delay(2000);

		// revert back to no rotation
		display.setRotation(0);

		// miniature bitmap display
		display.clearDisplay();
		display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, WHITE);
		display.display();

		// invert the display
		display.invertDisplay(true);
		delay(1000);
		display.invertDisplay(false);
		delay(1000);

		// draw a bitmap icon and 'animate' movement
		testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
	}
}
Esempio n. 13
0
void testdrawrect(void) {
  for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
    display.display();
  }
}
Esempio n. 14
0
/**
   Interactively accepts input from the user
   Max input size is determined by remaining cells at given start row. No scrolling.
*/
void ANXInput(char *message, uint8_t startX, uint8_t startY, uint8_t maxChars, uint8_t maxCharsPerRow) {
  int messageLen = strlen(message);             //Size of the message
  int cursor = messageLen;       //Location of cursor in the text, put cursor at end of message to continue
  uint8_t row = 0;          //Row of the cursor
  uint8_t col = 0;          //Col of the cursor
  uint8_t cindex = 0;   //index within input char array
  int maxCols = (display.width() - startX) / ANX_FONT_WIDTH;    //Max number of cols available
  int maxRows = (display.height() - startY) / ANX_FONT_HEIGHT;  //Max number of rows available
  int maxLen = min(maxCols * maxRows, maxChars);           //Maximum possible size of the message (limited by input space and buffer)

  //Use the user specified chars per row if specified
  if (maxCharsPerRow > 0) {
    maxCols = min(maxCharsPerRow, maxCols);
  }

  //Print the message, if any
  ANXInputMoveCursor(row, col, startX, startY);
  display.print(message);

  //Iteractively get input from user
  while (1) {
    row = cursor / maxCols;
    col = cursor % maxCols;

    ANXInputClearChar(row, col, startX, startY);
    ANXInputDrawCursor(row, col, startX, startY);

    if (message[cursor] != NULL) {
      ANXInputMoveCursor(row, col, startX, startY);
      display.print(message[cursor]);
    }

    safeDisplay();

    uint8_t button = waitForButton();
    if ((button & BUTTON_DOWN) > 0) {

      //Move char index to the end pro-actively since unsigned won't wrap to -1
      if (cindex == 0) cindex = INPUT_CHARS_COUNT;
      cindex--;

      if (cursor >= messageLen) {
        messageLen++;
      }
      message[cursor] = INPUT_CHARS[cindex];

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      deepSleep(BUTTON_REPEAT_DELAY);
    }

    if ((button & BUTTON_UP) > 0) {
      cindex++;
      if (cindex >= INPUT_CHARS_COUNT) cindex = 0;
      if (cursor >= messageLen) {
        messageLen++;
      }
      message[cursor] = INPUT_CHARS[cindex];

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      deepSleep(BUTTON_REPEAT_DELAY);
    }

    if ((button & BUTTON_RIGHT) > 0) {
      ANXInputDrawCursor(row, col, startX, startY);

      //Prevent cursor from going off the deep end
      if (cursor < maxLen - 1) {
        cursor++;
      }

      if (cursor < messageLen) {
        cindex = ANXIndexOf(INPUT_CHARS, message[cursor]);
      } else {
        messageLen++;
        cindex = 0;
      }

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      //Don't allow repeats
      clearButtonState();
    }

    if ((button & BUTTON_LEFT) > 0) {
      //Prevent cursor underun
      if (cursor > 0) {
        ANXInputDrawCursor(row, col, startX, startY);
        cursor--;
      }

      if (cursor < messageLen) {
        cindex = ANXIndexOf(INPUT_CHARS, message[cursor]);
      } else {
        messageLen++;
        cindex = 0;
      }

      //Don't allow repeats
      clearButtonState();
    }

    if ((button & BUTTON_ENTER) > 0) {
      //Don't allow repeats
      clearButtonState();
      return;
    }
  }
}