Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added paramNotifyChanged() to let apps notify the core when they modify the value of a parameter programmatically #1193

Merged
merged 2 commits into from
Jan 24, 2023
Merged
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
15 changes: 11 additions & 4 deletions src/modules/src/param_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static const uint8_t typeLength[] = {

//Private functions
static int variableGetIndex(int id);
static void paramNotifyChanged(int index);
static char paramWriteByNameProcess(char* group, char* name, int type, void *valptr);


Expand Down Expand Up @@ -368,6 +369,10 @@ void paramWriteProcess(CRTPPacket *p)

crtpSendPacketBlock(p);

paramNotifyChanged(index);
}

static void paramNotifyChanged(int index) {
if (params[index].callback) {
params[index].callback();
}
Expand Down Expand Up @@ -407,9 +412,7 @@ static char paramWriteByNameProcess(char* group, char* name, int type, void *val

paramSet(index, valptr);

if (params[index].callback) {
params[index].callback();
}
paramNotifyChanged(index);

return 0;
}
Expand Down Expand Up @@ -575,6 +578,8 @@ void paramSetInt(paramVarId_t varid, int valuei)
pk.size = 3 + paramSize;
crtpSendPacketBlock(&pk);
#endif

paramNotifyChanged(varid.index);
}

void paramSetFloat(paramVarId_t varid, float valuef)
Expand All @@ -595,6 +600,8 @@ void paramSetFloat(paramVarId_t varid, float valuef)
pk.size += 4;
crtpSendPacketBlock(&pk);
#endif

paramNotifyChanged(varid.index);
}

void paramSetByName(CRTPPacket *p)
Expand All @@ -619,7 +626,7 @@ void paramSetByName(CRTPPacket *p)
type = p->data[1 + strlen(group) + 1 + strlen(name) + 1];
valPtr = &p->data[1 + strlen(group) + 1 + strlen(name) + 2];

error = paramWriteByNameProcess(group, name, type, valPtr);
error = paramWriteByNameProcess(group, name, type, valPtr); /* calls callback */

p->data[1 + strlen(group) + 1 + strlen(name) + 1] = error;
p->size = 1 + strlen(group) + 1 + strlen(name) + 1 + 1;
Expand Down