DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerialLCD.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
  3. *
  4. * This file is part of Giess-o-mat.
  5. *
  6. * Giess-o-mat is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Giess-o-mat is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. // see https://github.com/sparkfun/SparkFun_SerLCD_Arduino_Library
  20. #include <Arduino.h>
  21. #include "SerialLCD.h"
  22. #ifdef FUNCTION_UI
  23. #define LCD_DELAY 3 // 3
  24. SerialLCD::SerialLCD(int tx_pin) {
  25. #if defined(PLATFORM_AVR)
  26. lcd = new SendOnlySoftwareSerial(tx_pin);
  27. #elif defined(PLATFORM_ESP)
  28. lcd = new SoftwareSerial(tx_pin);
  29. #endif
  30. lcd->begin(9600);
  31. }
  32. SerialLCD::~SerialLCD(void) {
  33. delete lcd;
  34. }
  35. void SerialLCD::init(void) {
  36. clear();
  37. cursor(0);
  38. setBacklight(255);
  39. lcd->write(0x7C);
  40. lcd->write(0x03); // 0x03=20 chars. 0x04=16 chars
  41. delay(LCD_DELAY);
  42. lcd->write(0x7C);
  43. lcd->write(0x05); // 0x05=4 lines, 0x06=2 lines
  44. delay(LCD_DELAY);
  45. }
  46. void SerialLCD::clear(void) {
  47. lcd->write(0xFE);
  48. lcd->write(0x01);
  49. delay(LCD_DELAY);
  50. }
  51. // 0 no cursor, 1 underline, 2 blinking, 3 both
  52. void SerialLCD::cursor(int style) {
  53. lcd->write(0xFE);
  54. lcd->write(0x0C); // display on, no cursor
  55. delay(LCD_DELAY);
  56. if (style == 1) {
  57. lcd->write(0xFE);
  58. lcd->write(0x0E); // underline cursor on
  59. delay(LCD_DELAY);
  60. } else if (style == 2) {
  61. lcd->write(0xFE);
  62. lcd->write(0x0D); // blinking cursor on
  63. delay(LCD_DELAY);
  64. } else if (style == 3) {
  65. lcd->write(0xFE);
  66. lcd->write(0x0F); // both cursors on
  67. delay(LCD_DELAY);
  68. }
  69. }
  70. void SerialLCD::setBacklight(uint8_t val) {
  71. val = map(val, 0, 255, 0, 30);
  72. lcd->write(0x7C);
  73. lcd->write(0x80 + val);
  74. delay(LCD_DELAY);
  75. }
  76. void SerialLCD::position(int line, int col) {
  77. int cursor = 0;
  78. if (line == 1) {
  79. cursor = 64;
  80. } else if (line == 2) {
  81. cursor = 20;
  82. } else if (line == 3) {
  83. cursor = 84;
  84. }
  85. lcd->write(0xFE);
  86. lcd->write(0x80 + cursor + col);
  87. delay(LCD_DELAY);
  88. }
  89. void SerialLCD::saveSplash(void) {
  90. lcd->write(0x7C);
  91. lcd->write(0x0A);
  92. }
  93. void SerialLCD::enableSplash(void) {
  94. lcd->write(0x7C);
  95. lcd->write(0x30);
  96. }
  97. void SerialLCD::disableSplash(void) {
  98. lcd->write(0x7C);
  99. lcd->write(0x31);
  100. }
  101. void SerialLCD::write(const char *text) {
  102. lcd->print(text);
  103. delay(LCD_DELAY);
  104. }
  105. void SerialLCD::write(int line, const char *text) {
  106. position(line, 0);
  107. write(text);
  108. }
  109. void SerialLCD::write(int line, int col, const char *text) {
  110. position(line, col);
  111. write(text);
  112. }
  113. #endif // FUNCTION_UI