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.
 
 
 
 
 
 

128 rivejä
3.3 KiB

  1. #ifndef APP_H
  2. #define APP_H
  3. #include <Arduino.h>
  4. #include <Spirulerie.h>
  5. #include "DataTypes.h"
  6. #include "SPIFFS.h"
  7. #include "TimeSystem.h"
  8. #include "TextContent.h"
  9. #include "DataSaveLoad.h"
  10. #include "WiFiSystem.h"
  11. #include "Tasks/TaskActuators.h"
  12. #include "Tasks/TaskThermometer.h"
  13. #include "Tasks/TaskAudioEngine.h"
  14. #include "Tasks/TaskInput.h"
  15. #include "Tasks/TaskApplication.h"
  16. #include "GraphicsEngine/GraphicsEngine.h"
  17. #include "GraphicsEngine/SimplexNoise.h"
  18. #include "GraphicsEngine/SpriteArrays.h"
  19. #include "GraphicsEngine/Elements.h"
  20. #include "Scenes/Scene.h"
  21. #include "Scenes/SceneMainMenu.h"
  22. #include "Scenes/SceneLoadingScreen.h"
  23. #include "Scenes/SceneTopMenu.h"
  24. #include "Scenes/ScenePumpUse.h"
  25. #include "Scenes/SceneModeSelection.h"
  26. #include "Scenes/SceneCustomModeSettings.h"
  27. #include "Scenes/SceneSettingsMenu.h"
  28. #include "Scenes/SceneTime.h"
  29. #include "Scenes/SceneThermometerCalibration.h"
  30. #include "Scenes/SceneHeatingSettings.h"
  31. #include "Scenes/SceneScreenSaverSettings.h"
  32. #include "Scenes/TestScene.h"
  33. // Commenting options
  34. #define SERIAL_DEBUG // TODO faudrait l'implémenter car les serial debug sont par default partout...
  35. //#define RESET_EEPROM_AT_BOOT // utile pour reset une carte quand on a modifié la partition d'EEPROM
  36. // Defines
  37. #define MAX_PERCENTAGE_LIGHT 35 // do not go above this value or the LED will fail (burn, melt plastic etc...)
  38. #define MAX_PERCENTAGE_HEATER 75 // So it doesn't draw too much current
  39. #define SECONDS_TO_SCREENSAVER 45 // only if screensaver is enabled in settings
  40. // Main container class for program
  41. class Application
  42. {
  43. // *** PUBLIC MEMBERS ***
  44. public:
  45. // Singleton
  46. static Application *singleton;
  47. // Member classes
  48. GraphicsEngine Graphics;
  49. WiFiSystem WifiSystem;
  50. // RTOS Queues
  51. QueueHandle_t temperatureQueue;
  52. QueueHandle_t TSensorActiveQueue;
  53. QueueHandle_t PWMActionsQueue;
  54. QueueHandle_t inputQueue;
  55. QueueHandle_t audioQueue;
  56. // RTOS Tasks
  57. TaskHandle_t audioTask;
  58. TaskHandle_t thermometerTask;
  59. TaskHandle_t actuatorTask;
  60. TaskHandle_t applicationTask;
  61. TaskHandle_t inputManagementTask;
  62. // App will control the actuators if true
  63. bool lightNominal = true;
  64. bool heatNominal = true;
  65. bool pumpNominal = true;
  66. bool isOnMainMenu = true;
  67. bool modeNeedsRefresh = true;
  68. ModeParameters parameters;
  69. // *** PUBLIC METHODS ***
  70. public:
  71. // Constructor
  72. Application();
  73. void Init();
  74. void Update();
  75. // Retrieve obfuscated data
  76. float GetCurrentTemperature();
  77. float GetCurrentLightLevel();
  78. bool GetPumpState();
  79. void LoadScene(Scene *scene);
  80. // Intertask communication
  81. void SendAction(uint8_t PWMChannel, float percentage, uint32_t fadetime);
  82. void PlayMelody(Melodies melody);
  83. void ChangeLight(uint8_t percentage_A, uint8_t percentage_B, uint32_t fade_time);
  84. void ChangePump(uint8_t percentage, uint32_t fadetime);
  85. // *** PRIVATE METHODS ***
  86. private:
  87. // Actuator management
  88. void Lighting();
  89. void Heating();
  90. void Pump();
  91. void StopHeating();
  92. // Booleans test
  93. bool IsDay();
  94. bool IsDebouncedInput(BTN btn);
  95. // *** PRIVATE MEMBERS ***
  96. private:
  97. Scene *m_current_scene;
  98. uint8_t m_current_pump_level = 0;
  99. uint8_t m_current_light_level = 0;
  100. float m_current_temperature = -1;
  101. uint64_t m_last_btn_press_time = 0;
  102. bool m_is_in_screensaver = false;
  103. ModeParameters m_mode_hibernation;
  104. ModeParameters m_mode_normal;
  105. };
  106. #endif