Skip to content

Commit

Permalink
default button and io set
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Oct 16, 2023
1 parent 564100c commit ae6fb1d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Firmware/Bentuino/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"BUTTON_DEFAULT_PIN=32",
"USE_IO",
"IO_MAX_COUNT=4",
"IO_DEFAULT_PIN=17",
"IO_DEFAULT_MODE=IOComponent::PinMode::A_OUTPUT",
"USE_BATTERY",
"BATTERY_DEFAULT_PIN=35",
"BATTERY_DEFAUT_RAW_MIN=222",
Expand Down
2 changes: 2 additions & 0 deletions Firmware/Bentuino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ build_flags =

-D USE_IO
-D IO_MAX_COUNT=4
-D IO_DEFAULT_PIN=17
-D IO_DEFAULT_MODE=IOComponent::PinMode::A_OUTPUT

-D USE_BATTERY
-D BATTERY_DEFAULT_PIN=35
Expand Down
2 changes: 2 additions & 0 deletions Firmware/Bentuino/src/Common/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@
{ \
String n = #itemName + String(i + 1); \
AddStaticOrDynamicComponent(n, Type, i == 0); \
addItemInternal(i); \
} \
return true; \
} \
\
HandleSetParamInternalStart \
CheckAndSetParam(count); \
HandleSetParamInternalEnd; \
Expand Down
11 changes: 11 additions & 0 deletions Firmware/Bentuino/src/Common/script/Script.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "Script.h"
#define FATAL(func, msg) \
{ \
Serial.print("Fatal: " func " "); \
Expand Down Expand Up @@ -139,6 +140,10 @@ void Script::launchWasmTask()
if (stopFunc != NULL)
foundFunc += " / stop";

result = m3_FindFunction(&setScriptParamFunc, runtime, "setParam");
if (setScriptParamFunc != NULL)
foundFunc += " / setParam";

DBG("Found functions : " + foundFunc);

isRunning = true;
Expand Down Expand Up @@ -205,6 +210,12 @@ void Script::stop()
}
}

void Script::setScriptParam(int index, float value)
{
if (stopFunc != NULL)
m3_CallV(setScriptParamFunc, index, value);
}

void Script::shutdown()
{
stop();
Expand Down
3 changes: 3 additions & 0 deletions Firmware/Bentuino/src/Common/script/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Script
IM3Function initFunc;
IM3Function updateFunc;
IM3Function stopFunc;
IM3Function setScriptParamFunc;

static float timeAtLaunch;

Expand All @@ -40,6 +41,8 @@ class Script
void shutdown();
void stop();

void setScriptParam(int index, float value);

#if WASM_ASYNC
static void launchWasmTaskStatic(void *);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ FillOSCQueryBoolParam(alwaysTrigger);
FillOSCQueryBoolParamReadOnly(valid);
FillOSCQueryEnumParam(triggerAction, triggerActionOptions, ActionMax);
FillOSCQueryStringParam(triggerValue);
FillOSCQueryInternalEnd
}
;
FillOSCQueryInternalEnd;

};

DeclareComponentManager(Behaviour, BEHAVIOUR, behaviours, behaviour)

void addItemInternal(int index) { };
void onChildComponentEvent(const ComponentEvent &e) override;
DeclareComponentEventTypes(CommandLaunched);
DeclareComponentEventNames("CommandLaunched");
Expand Down
16 changes: 13 additions & 3 deletions Firmware/Bentuino/src/Component/components/io/IOComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CheckAndSetParam(inverted);
HandleSetParamInternalEnd;

CheckFeedbackParamInternalStart
CheckAndSendParamFeedback(value);
CheckAndSendParamFeedback(value);
CheckFeedbackParamInternalEnd;

FillSettingsInternalStart
Expand All @@ -69,5 +69,15 @@ FillOSCQueryInternalEnd

// Manager

DeclareComponentManager(IO, IO, gpio, gpio)
EndDeclareComponent
DeclareComponentManager(IO, IO, gpio, gpio)

void addItemInternal(int index)
{
if (index == 0)
{
items[index]->pin = IO_DEFAULT_PIN;
items[index]->mode = IO_DEFAULT_MODE;
}
};

EndDeclareComponent
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ class ButtonComponent : public IOComponent
};

DeclareComponentManager(Button, BUTTON, buttons, button)
void addItemInternal(int index) { if(index == 0) items[index]->pin = BUTTON_DEFAULT_PIN; };
EndDeclareComponent
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ DeclareScriptFunctionReturn1(LedStripManagerComponent, get, uint32_t, uint32_t)

DeclareScriptFunctionVoid3(LedStripManagerComponent, setBlendMode, uint32_t, uint32_t, uint32_t) { return items[0]->userLayers[(int)arg2]->setBlendMode((LedStripLayer::BlendMode)arg3); }

void addItemInternal(int index) { };

#endif

EndDeclareComponent
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bool ScriptComponent::handleCommandInternal(const String &command, var *data, in
{
script.stop();
return true;
}else if(CheckCommand("setScriptParam", 2)){
script.setScriptParam(data[0].intValue(), (float)data[1]);
return true;
}

return false;
Expand Down

0 comments on commit ae6fb1d

Please sign in to comment.