Make motor uninterest work by using RemoveCallback3 and a custom function to check that the pCon is the correct one.

Remove any prior interest for this motor and pCon before installing the new one. Limits the interest callback message count to one.

r1987 | dcl | 2007-05-25 16:17:44 +1000 (Fri, 25 May 2007) | 3 lines
This commit is contained in:
Douglas Clowes
2007-05-25 16:17:44 +10:00
parent efe6f72b43
commit 6ed6e5e6cb

13
motor.c
View File

@ -1180,6 +1180,16 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
iRet = Tcl_Eval(pServ->pSics->pTcl,pCommand);
return iRet;
}
static int CheckMotiMatch(const void* context, const void* pUserData)
{
pMotInfo pMoti = (pMotInfo) pUserData;
SConnection *pCon = (SConnection*) context;
if (pMoti->pCon == pCon)
return 0;
return 1;
}
/*----------------------------------------------------------------------------
The wrapper function for a motor. Commands currently supported are:
@ -1280,6 +1290,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
}
pMoti->lastValue = fValue;
RemoveCallback3(self->pCall, InterestCallback, CheckMotiMatch, pCon); /* only this one */
lID = RegisterCallback(self->pCall, SCGetContext(pCon),MOTDRIVE, InterestCallback,
pMoti, KillInfo);
SCRegister(pCon,pSics, self->pCall,lID);
@ -1289,7 +1300,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
}
else if(strcmp(pCurrent->text,"uninterest") == 0)
{
RemoveCallback2(self->pCall,pCon);
RemoveCallback3(self->pCall, InterestCallback, CheckMotiMatch, pCon);
SCSendOK(pCon);
DeleteTokenList(pList);
return 1;