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.

main.cpp 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <Arduino.h>
  20. #include "Functionality.h"
  21. #include "WifiStuff.h"
  22. #include "DebugLog.h"
  23. #include "config.h"
  24. #include "config_pins.h"
  25. unsigned long last_led_blink_time = 0;
  26. void setup() {
  27. pinMode(BUILTIN_LED_PIN, OUTPUT);
  28. digitalWrite(BUILTIN_LED_PIN, HIGH);
  29. Serial.begin(115200);
  30. debug.println("Initializing Giess-o-mat");
  31. debug.println("Version: " FIRMWARE_VERSION);
  32. #ifdef FUNCTION_UI
  33. debug.println("Initializing UI");
  34. ui_setup();
  35. #endif // FUNCTION_UI
  36. #ifdef FUNCTION_CONTROL
  37. debug.println("Initializing Control");
  38. control_setup();
  39. #endif // FUNCTION_CONTROL
  40. #ifdef PLATFORM_ESP
  41. debug.println("Initializing WiFi");
  42. wifi_setup();
  43. #endif // PLATFORM_ESP
  44. debug.println("Ready, starting main loop");
  45. digitalWrite(BUILTIN_LED_PIN, LOW);
  46. #ifdef FUNCTION_CONTROL
  47. #ifndef FUNCTION_UI
  48. // give ui unit some time to initialize
  49. debug.println("Waiting for UI to boot");
  50. delay(3000);
  51. #endif // ! FUNCTION_UI
  52. debug.println("Starting state machine");
  53. control_begin();
  54. #endif // FUNCTION_CONTROL
  55. }
  56. void loop() {
  57. #ifdef PLATFORM_ESP
  58. wifi_run();
  59. #endif // PLATFORM_ESP
  60. #ifdef FUNCTION_UI
  61. ui_run();
  62. #endif // FUNCTION_UI
  63. #ifdef FUNCTION_CONTROL
  64. control_run();
  65. #endif // FUNCTION_CONTROL
  66. // blink heartbeat LED
  67. if ((millis() - last_led_blink_time) >= LED_BLINK_INTERVAL) {
  68. last_led_blink_time = millis();
  69. digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
  70. }
  71. }