Skip to content

Commit

Permalink
Merge pull request #1193 from collmot/feat/param-notify-changed
Browse files Browse the repository at this point in the history
Added paramNotifyChanged() to let apps notify the core when they modify the value of a parameter programmatically
  • Loading branch information
krichardsson authored Jan 24, 2023
2 parents 695ac2f + 59df69f commit 9e7e697
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit 9e7e697

Please sign in to comment.