Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/puara_basic_template/puara_basic_template.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ Puara puara;
// Dummy sensor data
float sensor;

void onPuaraSettingsChanged()
{
// Process here any change of settings by the user, OSC port, etc.
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

puara.set_settings_changed_handler(onPuaraSettingsChanged);
/*
* the Puara start function initializes the filesystem, reads json configuration and
* settings, start the wi-fi AP or connects to SSID, starts the webserver, inits serial
Expand Down
5 changes: 5 additions & 0 deletions src/puara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ void Puara::write_settings_json()
return g_puara.settings.write_settings_json();
}

void Puara::set_settings_changed_handler(std::function<void()> func)
{
return g_puara.settings.set_settings_changed_handler(std::move(func));
}

double Puara::getVarNumber(std::string varName)
{
return g_puara.settings.getVarNumber(varName);
Expand Down
3 changes: 3 additions & 0 deletions src/puara.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <string>
#include <string_view>
#include <functional>

typedef void* httpd_handle_t;
class Puara
Expand Down Expand Up @@ -50,6 +51,8 @@ class Puara
void read_settings_json();
void write_settings_json();

void set_settings_changed_handler(std::function<void()>);

bool start_serial_listening();
void send_serial_data(std::string data);

Expand Down
8 changes: 7 additions & 1 deletion src/puara_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ void JSONSettings::write_config_json()

void JSONSettings::write_settings_json()
{

cJSON* root = cJSON_CreateObject();
cJSON* settings = cJSON_CreateArray();
cJSON* setting = NULL;
Expand Down Expand Up @@ -254,6 +253,13 @@ void JSONSettings::write_settings_json()
LOG("write_settings_json: Delete json entity");
cJSON_Delete(root);

if(this->on_settings_changed)
this->on_settings_changed();
}

void JSONSettings::set_settings_changed_handler(std::function<void()> func)
{
this->on_settings_changed = std::move(func);
}

}
5 changes: 5 additions & 0 deletions src/puara_filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <esp_err.h>

#include <functional>
#include <unordered_map>
#include <vector>
#include <string>
Expand Down Expand Up @@ -38,14 +39,18 @@ struct JSONSettings // TODO: remove from puara_filesystem
void read_settings_json();
void write_settings_json();

void set_settings_changed_handler(std::function<void()>);

double getVarNumber(std::string varName);
std::string getVarText(std::string varName);

friend class Webserver;
friend class Serial;

// Private API used by puara_web
std::vector<settingsVariables> variables;
std::unordered_map<std::string, int> variables_fields;
std::function<void()> on_settings_changed;

// Private API used by puara_serial
void read_settings_json_internal(std::string& contents, bool merge = false);
Expand Down
1 change: 1 addition & 0 deletions src/puara_web.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <string>
#include <unordered_map>
#include <functional>

typedef void* httpd_handle_t;
struct httpd_req;
Expand Down