ESP-LiveControl  1.99.1
HTTP server, AJAX API backend and Vue.js web application implementing self-contained, zero-install WiFi remote control of hardware modules attached to the Espressif ESP32 SoC
app_controller.hpp
Go to the documentation of this file.
1 
15 #ifndef APP_CONTROLLER_HPP__
16 #define APP_CONTROLLER_HPP__
17 
18 #include <Ticker.h>
19 //#include "freertos/FreeRTOS.h"
20 //#include "freertos/timers.h"
21 
22 #include "aux_hw_drv.hpp"
23 #include "api_server.hpp"
24 #include "multi_timer.hpp"
25 
26 #include "app_state_model.hpp"
27 
28 
46 {
47 public:
50  static constexpr auto constants = AppConstants{};
51 
52  // Runtime state plus JSON serialisation import/export
53  AppState &state;
54 
55  // Instance of auxiliary HW control module
56  AuxHwDrv aux_hw_drv;
57 
58  // Instance of HTTP API server. There must only be one.
59  APIServer* api_server;
60 
61  AppController(AppState &state, APIServer* api_server);
62  virtual ~AppController();
63 
68  void begin();
69 
71  // (except for network configuration which is separate) //
72  void set_setpoint_throttling_enabled(bool new_val);
73 
74  void set_frequency_min_khz(float n);
75  void set_frequency_max_khz(float n);
76  void set_frequency_khz(float n);
80  void _set_frequency_raw(float n);
81 
82  void set_duty_min_percent(float n);
83  void set_duty_max_percent(float n);
84  void set_duty_percent(float n);
87  void set_duty_changerate_percent_sec(float n);
88  void _set_duty_raw(float n);
89 
90  void set_lag_dt_ns(float n);
91  void set_lead_dt_ns(float n);
92 
95  void set_power_pwm_active(bool new_val);
96 
99  void set_oneshot_len(float n);
100 
103  void trigger_oneshot();
104 
105  void clear_shutdown();
106 
107  void set_current_limit(float n);
108 
111  void set_temp_1_limit(float n);
112  void set_temp_2_limit(float n);
113 
114  void set_relay_ref_active(bool new_val);
115 
116  void set_relay_dut_active(bool new_val);
117 
120  void set_fan_override(bool new_val);
121 
127  void save_settings();
128 
134  void restore_settings();
135 
136 
137 private:
138  // FreeRTOS task handle for application event task
139  static TaskHandle_t _app_event_task_handle;
140  // FreeRTOS event group handle for triggering event task actions
141  static EventGroupHandle_t _app_event_group;
142  // Timer for periodic events
143  Ticker event_timer_fast;
144  Ticker event_timer_slow;
145  // Timer for generating overcurrent reset pulse
146  MultiTimer oc_reset_timer;
147  // Timer for power output timing
148  MultiTimer power_output_timer;
149 
151 
152  void _initialize_ps_pwm_drv();
156  void _create_app_event_task();
157 
160  void _register_http_api(APIServer* api_server);
161 
164  void _connect_timer_callbacks();
165 
167 
170  static void _app_event_task(void *pVParameters);
171 
175  void _on_fast_timer_event_update_state();
176 
179  void _evaluate_temperature_sensors();
180 
184  static void _send_state_changed_event();
185 
189  void _push_state_update();
190 };
191 
192 #endif
Auxiliary hardware driver for ESP-AJAX-Lab.
AJAX HTTP API server for ESP-AJAX-Lab.
Definition: api_server.hpp:45
Application main controller for PS-PWM generator hardware.
Definition: app_controller.hpp:46
void set_temp_1_limit(float n)
Set overtemperature shutdown limits.
Definition: app_controller.cpp:224
void set_oneshot_len(float n)
Set power output oneshot pulse timer pulse length in seconds.
Definition: app_controller.cpp:192
void set_fan_override(bool new_val)
When set to true, override automatic and set fan permanently on.
Definition: app_controller.cpp:242
static constexpr auto constants
Configuration and initial values for the application state.
Definition: app_controller.hpp:50
void set_duty_changerate_percent_sec(float n)
Set rate of change of duty cycle in percent per second.
Definition: app_controller.cpp:141
void save_settings()
Save all runtime configurable settings to SPI flash. The settings are a subset of all values in struc...
Definition: app_controller.cpp:253
void trigger_oneshot()
Trigger the power output oneshot pulse.
Definition: app_controller.cpp:199
void set_frequency_changerate_khz_sec(float n)
Set rate of change of frequency in kHz per second.
Definition: app_controller.cpp:117
void set_power_pwm_active(bool new_val)
Activate PWM power output if arg is true.
Definition: app_controller.cpp:168
void restore_settings()
Read state back from SPI flash file and initialize the hardware with these settings.
Definition: app_controller.cpp:263
void begin()
Begin operation. This also starts the timer callbacks etc. This will fail if networking etc....
Definition: app_controller.cpp:88
Auxiliary hardware driver for ESP-AJAX-Lab This implements GPIO control for relays,...
Definition: aux_hw_drv.hpp:32
Ticker timer derivative allowing for a fixed number of repeated calls.
Definition: multi_timer.hpp:35
Ticker timer derivative allowing for a fixed number of repeated calls.
Constant / compile-time config values go here!
Definition: app_config.hpp:131
Application state containing data and settings model.
Definition: app_state_model.hpp:50