_oLED.ino 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // 1-channel LoRa Gateway for ESP8266
  2. // Copyright (c) 2016, 2017, 2018, 2019 Maarten Westenberg version for ESP8266
  3. //
  4. // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
  5. // and many others.
  6. //
  7. // All rights reserved. This program and the accompanying materials
  8. // are made available under the terms of the MIT License
  9. // which accompanies this distribution, and is available at
  10. // https://opensource.org/licenses/mit-license.php
  11. //
  12. // NO WARRANTY OF ANY KIND IS PROVIDED
  13. //
  14. // Author: Maarten Westenberg (mw12554@hotmail.com)
  15. //
  16. // This file contains the state machine code enabling to receive
  17. // and transmit packages/messages.
  18. // ========================================================================================
  19. //
  20. #if OLED>=1
  21. // --------------------------------------------------------------------
  22. // Initilize the OLED functions.
  23. // This function will init the OLED screenb. Depending on the
  24. // availability of the reset button it will reset the display first.
  25. // --------------------------------------------------------------------
  26. void init_oLED()
  27. {
  28. #if defined OLED_RST
  29. pinMode(OLED_RST,OUTPUT);
  30. digitalWrite(OLED_RST, LOW); // low to reset OLED
  31. delay(100);
  32. digitalWrite(OLED_RST, HIGH); // must be high to turn on OLED
  33. delay(50);
  34. #else
  35. #endif
  36. // Initialising the UI will init the display too.
  37. display.init();
  38. delay(100);
  39. //display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR, FALSE)
  40. display.flipScreenVertically();
  41. display.setFont(ArialMT_Plain_24);
  42. display.setTextAlignment(TEXT_ALIGN_LEFT);
  43. display.drawString(0, 24, "STARTING");
  44. display.display();
  45. }
  46. // --------------------------------------------------------------------
  47. // Activate the OLED
  48. //
  49. // --------------------------------------------------------------------
  50. void acti_oLED()
  51. {
  52. // Initialising the UI will init the display too.
  53. display.clear();
  54. #if OLED==1
  55. display.setFont(ArialMT_Plain_16);
  56. display.drawString(0, 0, "READY, SSID=");
  57. display.drawString(0, 16, WiFi.SSID());
  58. display.drawString(0, 32, "IP=");
  59. display.drawString(0, 48, WiFi.localIP().toString().c_str() );
  60. #elif OLED==2
  61. display.setFont(ArialMT_Plain_16);
  62. display.drawString(0, 0, "READY, SSID=");
  63. display.drawString(0, 16, WiFi.SSID());
  64. display.drawString(0, 32, "IP=");
  65. display.drawString(0, 48, WiFi.localIP().toString().c_str() );
  66. #endif
  67. display.display();
  68. delay(4000);
  69. }
  70. // --------------------------------------------------------------------
  71. // Print a message on the OLED.
  72. // Note: The whole message must fit in the buffer
  73. //
  74. // --------------------------------------------------------------------
  75. void msg_oLED(String tim, String sf) {
  76. display.clear();
  77. display.setFont(ArialMT_Plain_16);
  78. display.setTextAlignment(TEXT_ALIGN_LEFT);
  79. display.drawString(0, 48, "LEN: " );
  80. // display.drawString(40, 48, String((int)messageLength) );
  81. display.display();
  82. yield();
  83. }
  84. // --------------------------------------------------------------------
  85. // Print the OLED address in use
  86. //
  87. // --------------------------------------------------------------------
  88. void addr_oLED()
  89. {
  90. #if _DUSB>=1
  91. Serial.print(F("OLED_ADDR=0x"));
  92. Serial.println(OLED_ADDR, HEX);
  93. #endif //_DUSB
  94. }
  95. #endif