_oLED.ino 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.flipScreenVertically();
  40. display.setFont(ArialMT_Plain_24);
  41. display.setTextAlignment(TEXT_ALIGN_LEFT);
  42. display.drawString(0, 24, "STARTING");
  43. display.display();
  44. }
  45. // --------------------------------------------------------------------
  46. // Activate the OLED. Always print the same info.
  47. // These are 4 fields:
  48. // SSID, IP, ID,
  49. //
  50. // --------------------------------------------------------------------
  51. void acti_oLED()
  52. {
  53. # if OLED>=1
  54. // Initialising the UI will init the display too.
  55. display.clear();
  56. #if OLED==1
  57. display.setFont(ArialMT_Plain_16);
  58. display.drawString(0, 0, "READY, SSID=");
  59. display.drawString(0, 16, WiFi.SSID());
  60. display.drawString(0, 32, "IP=");
  61. display.drawString(0, 48, WiFi.localIP().toString().c_str() );
  62. #elif OLED==2
  63. display.setFont(ArialMT_Plain_16);
  64. display.drawString(0, 0, "READY, SSID=");
  65. display.drawString(0, 16, WiFi.SSID());
  66. display.drawString(0, 32, "IP=");
  67. display.drawString(0, 48, WiFi.localIP().toString().c_str() );
  68. #endif
  69. display.display();
  70. #endif // OLED
  71. delay(4000);
  72. }
  73. // --------------------------------------------------------------------
  74. // Print a message on the OLED.
  75. // Note: The whole message must fit in the buffer
  76. //
  77. // --------------------------------------------------------------------
  78. void msg_oLED(String mesg)
  79. {
  80. #if OLED>=1
  81. display.clear();
  82. display.flipScreenVertically();
  83. display.setFont(ArialMT_Plain_24);
  84. display.setTextAlignment(TEXT_ALIGN_LEFT);
  85. display.drawString(0, 24, String(mesg));
  86. display.display();
  87. yield();
  88. #endif //OLED
  89. }
  90. // Print a smaller OLED message consisting of two strings
  91. void msg_lLED(String mesg, String mesg2)
  92. {
  93. #if OLED>=1
  94. display.clear();
  95. display.flipScreenVertically();
  96. display.setFont(ArialMT_Plain_16);
  97. display.setTextAlignment(TEXT_ALIGN_LEFT);
  98. display.drawString(0, 8, String(mesg));
  99. display.drawString(0, 36, String(mesg2));
  100. display.display();
  101. yield();
  102. #endif //OLED
  103. }
  104. // --------------------------------------------------------------------
  105. // Print the OLED address in use
  106. //
  107. // --------------------------------------------------------------------
  108. void addr_oLED()
  109. {
  110. #if _DUSB>=1
  111. Serial.print(F("OLED_ADDR=0x"));
  112. Serial.println(OLED_ADDR, HEX);
  113. #endif //_DUSB
  114. }
  115. #endif