Ejemplo n.º 1
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();
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
  float soil = 65.5;
  float temp = 5.5;

	// I2C change parameters to fit to your LCD
	if ( !display.init(OLED_I2C_RESET,OLED_ADAFRUIT_I2C_128x64) )
		exit(EXIT_FAILURE);

	display.begin();
	
	// init done
	display.clearDisplay();   // clears the screen and buffer

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("     XBee Messung\n");
  display.drawLine(0, 10, display.width()-1, 10, WHITE);
  display.setCursor(0,15);
  display.printf("Bodenfeuchte: %4.1f %%\n", soil);
  display.printf("Temperatur:   %4.1f C\n\n\n", temp);
  if(soil > 50) {
    display.print("--> Feucht genug\n");
  } else {
    display.print("--> Zu Trocken! \n");
  }
  
  display.display();

  // Free PI GPIO ports
  display.close();
}
Ejemplo n.º 3
0
void aurora_cpt_oled::init()
{
	oled1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
	oled1.clearDisplay();   // clears the screen and buffer
	oled1.display();
	oled1.setTextSize(1);
	oled1.setTextColor(WHITE);
}
Ejemplo n.º 4
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();	
}
Ejemplo n.º 6
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);
}
void init()
{
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Debug output to serial

	display.begin(SSD1306_SWITCHCAPVCC);
	display.clearDisplay();

	dht.begin();

	WifiStation.config(WIFI_SSID, WIFI_PWD);
	WifiStation.enable(true);
	WifiAccessPoint.enable(false);

	// Run our method when station was connected to AP (or not connected)
	WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for connection timeout at start
}
Ejemplo n.º 8
0
int main()
{
	int i, j;
	int black = 1;
	display.init(PIN_DC, PIN_RESET, PIN_CS, OLED_ADAFRUIT_SPI_128x32);
	display.begin();

	/* 左上 */
	display.drawPixel(0, 0, WHITE);
	display.display();
	sleep(2);

	/* 左下 */
	display.drawPixel(0, 31, WHITE);
	display.display();
	sleep(2);

	/* 右上 */	
	display.drawPixel(127, 0, WHITE);
	display.display();
	sleep(2);

	/* 右下 */
        display.drawPixel(127, 31, WHITE);
        display.display();
        sleep(2);

	for (i = 0; i < 32; i++) {
		for (j = 0; j < 128; j++) {
			//display.drawPixel(j, i, (black % 2) ? BLACK : WHITE);
			display.drawPixel(j, i, WHITE);
			display.display();
			black++;
		}
		//black = i;
		//display.display();
	}

	display.clearDisplay();
	display.close();
	return 0;
}
void Demo2()
{
	Serial.println("Display: some text");
	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();
	DemoTimer.stop();      // Finish demo
}
Ejemplo n.º 10
0
void testscrolltext(void) {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(10,0);
  display.clearDisplay();
  display.println((char*)"scroll");
  display.display();

  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrolldiagright(0x00, 0x07);
  delay(2000);
  display.startscrolldiagleft(0x00, 0x07);
  delay(2000);
  display.stopscroll();
}
Ejemplo n.º 11
0
void MyDisplay::update()
{
    Wire.lock();

#if DISPLAY_TYPE == DISPLAY_TYPE_SSD1306
    display.clearDisplay();
    // text display tests
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("MySensors gateway");
    display.setTextSize(1);
    display.setCursor(0,9);
    if (AppSettings.wired)
    {
        if (!Network.getClientIP().isNull())
        {
            display.print("IP  :");
            display.println(Network.getClientIP().toString());
        } 
        else
        {
            display.setTextColor(BLACK, WHITE); // 'inverted' text
            display.println("connecting ...");
            display.setTextColor(WHITE);
        }
    }
    else
    {
        if (WifiStation.isConnected())
        {
            display.print("AP  :");
            display.println(Network.getClientIP().toString());
        } 
        else
        {
            display.setTextColor(BLACK, WHITE); // 'inverted' text
            display.println("connecting ...");
            display.setTextColor(WHITE);
        }
    }
    display.setCursor(0,18);
    if (isMqttConfigured())
    {
        display.print("MQTT:");
        display.println(MqttServer());
    }
    else
    {
        display.setTextColor(BLACK, WHITE); // 'inverted' text
        display.println("configure MQTT !");
        display.setTextColor(WHITE);
    }

    display.setCursor(0,27);
    display.println(SystemClock.getSystemTimeString().c_str());
    display.setCursor(0,36);
    display.print("HEAP :");
    display.setTextColor(BLACK, WHITE); // 'inverted' text
    display.println(system_get_free_heap_size());

    display.setTextColor(WHITE);

    //display.setTextColor(BLACK, WHITE); // 'inverted' text
    //display.setTextSize(3);
    display.display();
#elif DISPLAY_TYPE == DISPLAY_TYPE_20X4
    lcd.setCursor(0, 0);
    lcd.print((char *)"MySensors gateway   ");
    lcd.setCursor(0, 1);
    lcd.print((char *)build_git_sha);
    for (int i=0; i<(20-strlen((char *)build_git_sha)); i++)
        lcd.print(" ");
    lcd.setCursor(0, 2);
    lcd.print("HEAP :");
    String heap(system_get_free_heap_size());
    lcd.print(heap.c_str());
    for (int i=0; i<20-6-heap.length(); i++)
        lcd.print(" ");
    lcd.setCursor(0, 3);
    lcd.print("IP   :");
    String ip = Network.getClientIP().toString();
    lcd.print(ip.c_str());
    for (int i=0; i<20-6-ip.length(); i++)
        lcd.print(" ");
#endif

    Wire.unlock();
}
Ejemplo 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);
	}
}