Skip to content

Commit

Permalink
noParam functional
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Oct 11, 2023
1 parent 20ec686 commit c9b78f1
Show file tree
Hide file tree
Showing 41 changed files with 1,080 additions and 737 deletions.
18 changes: 13 additions & 5 deletions Firmware/Bentuino/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@
"USE_SERVER",
"USE_WIFI",
"USE_OSC",
"USE_STREAMING",
"USE_SCRIPT",
"USE_POWER",
"POWER_KEEP_PIN=12",
"POWER_WAKEUP_BUTTON=32",
"POWER_WAKEUP_BUTTON_STATE=true",
"LEDSTRIP_MAX_COUNT=2",
"USE_LEDSTRIP",
"LEDSTRIP_MAX_COUNT=1",
"LED_DEFAULT_EN_PIN=27",
"LED_DEFAULT_DATA_PIN=25",
"LED_DEFAULT_CLK_PIN=26",
Expand All @@ -259,9 +262,12 @@
"LED_DEFAULT_BRIGHTNESS=0.5f",
"LED_MAX_BRIGHTNESS=0.5f",
"LED_MAX_COUNT=100",
"BUTTON_MAX_COUNT=1",
"USE_BUTTON",
"BUTTON_MAX_COUNT=16",
"BUTTON_DEFAULT_PIN=32",
"IO_MAX_COUNT=1",
"USE_IO",
"IO_MAX_COUNT=16",
"USE_BATTERY",
"BATTERY_DEFAULT_PIN=35",
"BATTERY_DEFAUT_RAW_MIN=222",
"BATTERY_DEFAULT_RAW_MAX=335",
Expand All @@ -274,10 +280,12 @@
"FILES_DEFAULT_SD_MOSI=13",
"FILES_DEFAULT_SD_SCK=14",
"FILES_DEFAULT_SD_CS=15",
"USE_SEQUENCE",
"USE_IMU",
"IMU_DEFAULT_SDA=23",
"IMU_DEFAULT_SCL=22",
"BEHAVIOUR_MAX_COUNT=2",
"USE_DUMMY",
"USE_BEHAVIOUR",
"BEHAVIOUR_MAX_COUNT=16",
"DUMMY_MAX_COUNT=1",
"ESP32",
"ESP_PLATFORM",
Expand Down
28 changes: 14 additions & 14 deletions Firmware/Bentuino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ build_flags =
-D USE_SERVER
-D USE_WIFI
-D USE_OSC
; -D USE_STREAMING
; -D USE_SCRIPT
-D USE_STREAMING
-D USE_SCRIPT


-D USE_POWER
-D POWER_KEEP_PIN=12
-D POWER_WAKEUP_BUTTON=32
-D POWER_WAKEUP_BUTTON_STATE=true

; -D USE_LEDSTRIP
-D LEDSTRIP_MAX_COUNT=2
-D USE_LEDSTRIP
-D LEDSTRIP_MAX_COUNT=1
-D LED_DEFAULT_EN_PIN=27
-D LED_DEFAULT_DATA_PIN=25
-D LED_DEFAULT_CLK_PIN=26
Expand All @@ -76,14 +76,14 @@ build_flags =
-D LED_MAX_BRIGHTNESS=0.5f
-D LED_MAX_COUNT=100

; -D USE_BUTTON
-D BUTTON_MAX_COUNT=1
-D USE_BUTTON
-D BUTTON_MAX_COUNT=16
-D BUTTON_DEFAULT_PIN=32

; -D USE_IO
-D IO_MAX_COUNT=1
-D USE_IO
-D IO_MAX_COUNT=16

; -D USE_BATTERY
-D USE_BATTERY
-D BATTERY_DEFAULT_PIN=35
-D BATTERY_DEFAUT_RAW_MIN=222
-D BATTERY_DEFAULT_RAW_MAX=335
Expand All @@ -98,16 +98,16 @@ build_flags =
-D FILES_DEFAULT_SD_SCK=14
-D FILES_DEFAULT_SD_CS=15

; -D USE_SEQUENCE
-D USE_SEQUENCE

; -D USE_IMU
-D USE_IMU
-D IMU_DEFAULT_SDA=23
-D IMU_DEFAULT_SCL=22

; -D USE_BEHAVIOUR
-D BEHAVIOUR_MAX_COUNT=2
-D USE_BEHAVIOUR
-D BEHAVIOUR_MAX_COUNT=16

-D USE_DUMMY
; -D USE_DUMMY
-D DUMMY_MAX_COUNT=1

; -D USE_SERVO
Expand Down
18 changes: 13 additions & 5 deletions Firmware/Bentuino/server/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="http://192.168.1.162/server/osc-browser.min.js"></script>
<script type="text/javascript" src="http://192.168.1.162/server/jquery.min.js"></script>
<script type="text/javascript" src="/server/osc-browser.min.js"></script>
<script type="text/javascript" src="/server/jquery.min.js"></script>
<title>Bentuino Settings</title>
<style>
body {
Expand Down Expand Up @@ -190,14 +192,20 @@ <h1>Bentuino Settings</h1>

var oscWS;

async function connectToServer() {
function connectToServer() {
const editorContainer = document.getElementById('editor');
editorContainer.innerHTML = 'Connecting to server...';

const response = await fetch("http://" + ip);
data = await response.json();
buildStructure();
initWebSocket();
$.get("http://" + ip, function (_data) {
data = _data;
console.log(data);
buildStructure();
initWebSocket();
});
// const response = await fetch("http://" + ip);
// data = await response.json();
// buildStructure();
// initWebSocket();
}

function initWebSocket() {
Expand Down
2 changes: 2 additions & 0 deletions Firmware/Bentuino/server/jquery.min.js

Large diffs are not rendered by default.

125 changes: 101 additions & 24 deletions Firmware/Bentuino/src/Common/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Class Helpers
#define DeclareSingleton(Class) static Class *instance;
#define ImplementSingleton(Class) Class *Class::instance = NULL;
#define ImplementManagerSingleton(Class) Class##ManagerComponent *Class##ManagerComponent::instance = NULL;
#define InitSingleton() instance = this;
#define DeleteSingleton() instance = NULL;

Expand All @@ -23,7 +24,7 @@
};

// Component Helpers
#define AddComponent(name, comp, Type, enabled) comp = addComponent<Type##Component>(name, enabled, o["components"][name]);
#define AddComponent(name, Type, enabled) addComponent<Type##Component>(name, enabled, o["components"][name]);
#define AddOwnedComponent(comp) addComponent(comp, o["components"][(comp)->name]);
#define AddDefaultComponentListener(comp) comp->addListener(std::bind(&Component::onChildComponentEvent, this, std::placeholders::_1));

Expand Down Expand Up @@ -54,6 +55,32 @@
} \
;

// Manager

#define DeclareComponentManager(Type, MType, mName, itemName) \
DeclareComponentSingleton(Type##Manager, #mName, ) \
DeclareIntParam(count, 1); \
\
bool initInternal(JsonObject o) override \
{ \
AddIntParam(count); \
for (int i = 0; i < count; i++) \
{ \
String n = #itemName + String(i + 1); \
AddComponent(n, Type, i == 0); \
} \
return true; \
} \
HandleSetParamInternalStart \
CheckAndSetParam(count); \
HandleSetParamInternalEnd; \
FillSettingsInternalStart \
FillSettingsParam(count); \
FillSettingsInternalEnd; \
FillOSCQueryInternalStart \
FillOSCQueryIntParam(count); \
FillOSCQueryInternalEnd

// > Events
#define DeclareComponentEventTypes(...) enum ComponentEventTypes \
{ \
Expand Down Expand Up @@ -94,49 +121,99 @@
#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 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 DeclareP2DParam(name, val1, val2) float name[2]{val1, val2};
#define DeclareP3DParam(name, val1, val2, val3) float name[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 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 HandleSetParamMotherClass(Class) \
if (Class::handleSetParamInternal(paramName, data, numData)) \
return true;

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

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

#define FillSettingsInternalMotherClass(Class) Class::fillSettingsParamsInternal(o, configOnly);

#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 FillOSCQueryInternalStart \
virtual void fillOSCQueryParamsInternal(JsonObject o, const String &fullPath) \
{
#define FillOSCQueryInternalEnd }

#define FillOSCQueryInternalMotherClass(Class) Class::fillOSCQueryParamsInternal(o, fullPath);

// Script

#define LinkScriptFunctionsStart \
Expand Down
Loading

0 comments on commit c9b78f1

Please sign in to comment.