Skip to content

Commit

Permalink
Working POC, need to test with everything back
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Oct 10, 2023
1 parent 4800e19 commit 20ec686
Show file tree
Hide file tree
Showing 22 changed files with 634 additions and 268 deletions.
4 changes: 4 additions & 0 deletions Firmware/Bentuino/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
"ARDUINO_ESP32_DEV",
"ARDUINO_BENTUINO",
"USE_SERIAL",
"USE_SERVER",
"USE_WIFI",
"USE_OSC",
"USE_POWER",
"POWER_KEEP_PIN=12",
"POWER_WAKEUP_BUTTON=32",
Expand All @@ -263,6 +266,7 @@
"BATTERY_DEFAUT_RAW_MIN=222",
"BATTERY_DEFAULT_RAW_MAX=335",
"BATTERY_DEFAULT_LOW_VOLTAGE=3.3f",
"USE_FILES",
"FILES_DEFAULT_SDSPEED=27000000",
"FILES_DEFAULT_SD_EN=16",
"FILES_DEFAULT_SD_POWER_VALUE=false",
Expand Down
8 changes: 4 additions & 4 deletions Firmware/Bentuino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ build_flags =

-D USE_SERIAL

; -D USE_SERVER
; -D USE_WIFI
; -D USE OSC
-D USE_SERVER
-D USE_WIFI
-D USE_OSC
; -D USE_STREAMING
; -D USE_SCRIPT

Expand Down Expand Up @@ -89,7 +89,7 @@ build_flags =
-D BATTERY_DEFAULT_RAW_MAX=335
-D BATTERY_DEFAULT_LOW_VOLTAGE=3.3f

; -D USE_FILES
-D USE_FILES
-D FILES_DEFAULT_SDSPEED=27000000
-D FILES_DEFAULT_SD_EN=16
-D FILES_DEFAULT_SD_POWER_VALUE=false
Expand Down
1 change: 0 additions & 1 deletion Firmware/Bentuino/server/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ <h1>Bentuino Settings</h1>
for (const key in node.CONTENTS) {
var item = node.CONTENTS[key];


if (item.TYPE) {
// Handle parameters
var paramsContainer = containerDiv.querySelector(".parameters");
Expand Down
74 changes: 56 additions & 18 deletions Firmware/Bentuino/src/Common/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
{ \
public:

#define DeclareSubComponent(ParentClass, ClassPrefix, Type, Derives) \
DeclareComponentClass(ParentClass, ClassPrefix, Derives) \
#define DeclareSubComponent(ParentClass, ClassPrefix, Type, Derives) \
DeclareComponentClass(ParentClass, ClassPrefix, Derives) \
ClassPrefix##Component(const String &name = Type, bool enabled = true) : ParentClass(name, enabled) {} \
~ClassPrefix##Component() {} \
~ClassPrefix##Component() {} \
virtual String getTypeString() const override { return Type; }

#define DeclareComponentSingleton(ClassPrefix, Type, Derives) \
DeclareComponentClass(Component, ClassPrefix, Derives) \
DeclareSingleton(ClassPrefix##Component) \
#define DeclareComponentSingleton(ClassPrefix, Type, Derives) \
DeclareComponentClass(Component, ClassPrefix, Derives) \
DeclareSingleton(ClassPrefix##Component) \
ClassPrefix##Component(const String &name = Type, bool enabled = true) : Component(name, enabled) { InitSingleton() } \
~ClassPrefix##Component() { DeleteSingleton() } \
~ClassPrefix##Component() { DeleteSingleton() } \
virtual String getTypeString() const override { return Type; }

#define DeclareComponent(ClassPrefix, Type, Derives) DeclareSubComponent(Component, ClassPrefix, Type, Derives)
Expand Down Expand Up @@ -83,21 +83,59 @@

// Parameter Helpers
#define AddDefaultParameterListener(Class, param) param->addListener(std::bind(&Class::onParameterEvent, this, std::placeholders::_1));
#define SendParameterFeedback(param) CommunicationComponent::instance->sendParameterFeedback(this, param);
#define SendParameterFeedback(param) CommunicationComponent::instance->sendParameterFeedback(this, param);

#define DeclareParameter(param, val, isConfig) Parameter param {#param, val, var(), var(),isConfig}
#define DeclareRangeParameter(param, val, min, max, isConfig) Parameter param {#param, val, min, max,isConfig}
// Parameter class system
#define DeclareParameter(param, val, isConfig) \
Parameter param { #param, val, var(), var(), isConfig }
#define DeclareRangeParameter(param, val, min, max, isConfig) \
Parameter param { #param, val, min, max, isConfig }
#define DeclareConfigParameter(param, val) DeclareParameter(param, val, true)
#define DeclareRangeConfigParameter(param, val, min, max) DeclareRangeParameter(param, val, min, max, true)

#define AddParameter(param) addParameter(&param)
#define AddAndSetParameter(param) { addParameter(&param); param.set(Settings::getVal(o, #param , param.val)); }

// #define AddParameter(name, val) addParameter(name, val)
// #define AddRangeParameter(name, val, minVal, maxVal, isConfig) addParameter(name, val, minVal, maxVal, false)
// Only config parameters check the settings
// #define AddConfigParameter(name, val) addParameter(name, Settings::getVal(o, name, val), var(), var(), true)
// #define AddRangeConfigParameter(name, val, minVal, maxVal) addParameter(name, Settings::getVal(o, name, val), minVal, maxVal, true)
// #define AddParameter(param) addParameter(&param)
// #define AddAndSetParameter(param)
// {
// addParameter(&param);
// param.set(Settings::getVal(o, #param, param.val));
// }

// Class-less parameter system
#define DeclareBoolParam(name, val) bool name = val;
#define DeclareIntParam(name, val) int name = val;
#define DeclareFloatParam(name, val) float name = val;
#define DeclareStringParam(name, val) String name = val;
#define DeclareP2DParam(name, val1, val2) float val[2]{val1, val2};
#define DeclareP3DParam(name, val1, val2, val3) float val[3]{val1, val2, val3};

#define AddBoolParam(param) addParam(&param, ParamType::Bool); param = Settings::getVal<bool>(o, #param, param);
#define AddIntParam(param) addParam(&param, ParamType::Int); param = Settings::getVal<int>(o, #param, param);
#define AddFloatParam(param) addParam(&param, ParamType::Float); param = Settings::getVal<float>(o, #param, param);
#define AddStringParam(param) addParam(&param, ParamType::Str); param = Settings::getVal<String>(o, #param, param);
#define AddP2DParam(param) addParam(&param, ParamType::P2D);
#define AddP3DParam(param) addParam(&param, ParamType::P3D);

#define SetParam(param, val) { var pData[1]; pData[0] = val; setParam(&param,pData,1); };
#define SetParam2(param, val1, val2) { var pData[2]; pData[0] = val1; pData[1] = val2; setParam(&param,pData,2); };
#define SetParam3(param, val, val2, val3) { var pData[3]; pData[0] = val1; pData[1] = val2; pData[2] = val3; setParam(&param,pData,3); };

#define HandleSetParamInternalStart virtual bool handleSetParamInternal(const String &paramName, var *data, int numData) override {
#define HandleSetParamInternalEnd return false; }

#define CheckAndSetParam(param) { if(paramName == #param) { setParam(&param, data, numData); return true; } }



#define FillSettingsParam(param) { o[#param] = param; }
#define FillSettingsInternalStart virtual void fillSettingsParamsInternal(JsonObject o, bool configOnly = false) override {
#define FillSettingsInternalEnd }

#define FillOSCQueryBoolParam(param) fillOSCQueryParam(o, fullPath, #param, ParamType::Bool, &param);
#define FillOSCQueryIntParam(param) fillOSCQueryParam(o, fullPath, #param, ParamType::Int, &param);
#define FillOSCQueryFloatParam(param) fillOSCQueryParam(o, fullPath, #param, ParamType::Float, &param);
#define FillOSCQueryStringParam(param) fillOSCQueryParam(o, fullPath, #param, ParamType::Str, &param);
#define FillOSCQueryInternalStart virtual void fillOSCQueryParamsInternal(JsonObject o, const String& fullPath) {
#define FillOSCQueryInternalEnd }

// Script

Expand Down
48 changes: 24 additions & 24 deletions Firmware/Bentuino/src/Common/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ bool Settings::clearSettings()
return true;
}

var Settings::getVal(JsonObject o, const String &name, var defaultVal)
{
// DBG("Get val " + name + "/" + String((int)o.containsKey(name)));

if (!o.containsKey(name))
return defaultVal;

JsonVariant val = o[name].containsKey("value") ? o[name]["value"].as<JsonVariant>() : o[name].as<JsonVariant>();

switch (defaultVal.type)
{
case 'b':
return val.as<bool>();
case 'i':
return val.as<int>();
case 'f':
return val.as<float>();
case 's':
return val.as<String>();
}

NDBG("Type not found " + defaultVal.type);
return var();
}
// var Settings::getVal(JsonObject o, const String &name, var defaultVal)
// {
// // DBG("Get val " + name + "/" + String((int)o.containsKey(name)));

// if (!o.containsKey(name))
// return defaultVal;

// JsonVariant val = o[name].containsKey("value") ? o[name]["value"].as<JsonVariant>() : o[name].as<JsonVariant>();

// switch (defaultVal.type)
// {
// case 'b':
// return val.as<bool>();
// case 'i':
// return val.as<int>();
// case 'f':
// return val.as<float>();
// case 's':
// return val.as<String>();
// }

// NDBG("Type not found " + defaultVal.type);
// return var();
// }
15 changes: 14 additions & 1 deletion Firmware/Bentuino/src/Common/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@ class Settings
static bool saveSettings();
static bool clearSettings();

static var getVal(JsonObject o, const String& name, var defaultVal);
template<class T>
static T getVal(JsonObject o, const String &name, T defaultVal)
{
if (o.containsKey(name))
{
return o[name].as<T>();
}
else
{
return defaultVal;
}
}

// static var getVal(JsonObject o, const String& name, var defaultVal);
};
Loading

0 comments on commit 20ec686

Please sign in to comment.