Bladeren bron

cmDspFx.c, cmDspFx.c : If the second character in the 'scalarOp' object is '$' then any input triggers an output.

master
kevin 4 jaren geleden
bovenliggende
commit
c9dc494178
2 gewijzigde bestanden met toevoegingen van 41 en 11 verwijderingen
  1. 24
    8
      src/dsp/cmDspFx.c
  2. 17
    3
      src/dsp/cmDspPgm.c

+ 24
- 8
src/dsp/cmDspFx.c Bestand weergeven

@@ -2909,6 +2909,7 @@ typedef struct cmDspScalar_str
2909 2909
   cmDspInst_t          inst;
2910 2910
   _cmDspScalarOpFunc_t func;
2911 2911
   unsigned             inPortCnt;
2912
+  bool                 allActiveFl;                  
2912 2913
 } cmDspScalarOp_t;
2913 2914
 
2914 2915
 cmDspRC_t _cmDspScalarOpFuncMult(cmDspCtx_t* ctx, cmDspInst_t* inst )
@@ -2966,6 +2967,7 @@ cmDspInst_t*  _cmDspScalarOpAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
2966 2967
   double             dfltVal[ inPortCnt ];
2967 2968
   unsigned           i;
2968 2969
   _cmDspScalarOpFunc_t fp = NULL;
2970
+  bool allActiveFl = false;
2969 2971
 
2970 2972
   // validate the count of input ports
2971 2973
   if( inPortCnt == 0 )
@@ -2974,12 +2976,26 @@ cmDspInst_t*  _cmDspScalarOpAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
2974 2976
     goto errLabel;
2975 2977
   }
2976 2978
 
2977
-  // locate the operation function
2978
-  if( strcmp(opIdStr,"*") == 0 )
2979
-    fp = _cmDspScalarOpFuncMult;
2980
-  else
2981
-    if( strcmp(opIdStr,"+") == 0 )
2982
-      fp = _cmDspScalarOpFuncAdd;
2979
+  if( opIdStr != NULL )
2980
+  {
2981
+    switch( opIdStr[0] )
2982
+    {
2983
+      case '*':
2984
+        fp = _cmDspScalarOpFuncMult;
2985
+        break;
2986
+      case '+':
2987
+        fp = _cmDspScalarOpFuncAdd;
2988
+        break;      
2989
+    }
2990
+
2991
+    // if the second character of the operator string is '$' then all input ports trigger an output
2992
+    if( strlen( opIdStr ) > 0 && opIdStr[1]=='$' )
2993
+      allActiveFl = true;
2994
+    
2995
+    
2996
+  }
2997
+  
2998
+  
2983 2999
 
2984 3000
   // validate the operation function
2985 3001
   if( fp == NULL )
@@ -3012,7 +3028,7 @@ cmDspInst_t*  _cmDspScalarOpAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
3012 3028
 
3013 3029
   p->inPortCnt = inPortCnt;
3014 3030
   p->func      = fp;
3015
-  
3031
+  p->allActiveFl = allActiveFl;
3016 3032
   va_end(vl1);
3017 3033
 
3018 3034
   return &p->inst;
@@ -3039,7 +3055,7 @@ cmDspRC_t _cmDspScalarOpRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
3039 3055
 
3040 3056
   if((rc = cmDspSetEvent(ctx,inst,evt)) == kOkDspRC )
3041 3057
   {
3042
-    if( evt->dstVarId == kBaseOpdSoId )
3058
+    if( evt->dstVarId == kBaseOpdSoId || p->allActiveFl )
3043 3059
       p->func(ctx,inst);
3044 3060
   }
3045 3061
 

+ 17
- 3
src/dsp/cmDspPgm.c Bestand weergeven

@@ -898,7 +898,7 @@ cmDspRC_t _cmDspSysPgm_UiTest(cmDspSysH_t h, void** userPtrPtr )
898 898
   cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL,   1, ">" );
899 899
   cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter", "meter",  3, 0.0,  0.0, 4.0);
900 900
   cmDspInst_t* ctp = cmDspSysAllocInst(h,"Counter", NULL,   3, 0.0, 10.0, 1.0 );
901
-                     cmDspSysAllocInst(h,"Label",  "label1", 1, "label2");
901
+  cmDspInst_t* lbl = cmDspSysAllocInst(h,"Label",  "label1", 1, "label2");
902 902
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
903 903
     return rc;
904 904
 
@@ -924,6 +924,8 @@ cmDspRC_t _cmDspSysPgm_UiTest(cmDspSysH_t h, void** userPtrPtr )
924 924
   cmDspSysInstallCb(h, chb, "out", prp, "in", NULL );
925 925
   cmDspSysInstallCb(h, chb, "sym", prp, "in", NULL );
926 926
 
927
+  cmDspSysInstallCb(h, mdp, "val", lbl, "in", NULL );
928
+
927 929
   return rc;
928 930
 
929 931
 }
@@ -2055,8 +2057,8 @@ cmDspRC_t _cmDspSysPgm_ScalarOp( cmDspSysH_t h, void** userPtrPtr )
2055 2057
 {
2056 2058
   cmDspRC_t rc;
2057 2059
 
2058
-  cmDspInst_t* add   = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "+", "in-0", 0.0, "in-1", 0.0 );
2059
-  cmDspInst_t* mul0  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
2060
+  cmDspInst_t* add   = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "+",  "in-0", 0.0, "in-1", 0.0 );
2061
+  cmDspInst_t* mul0  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*$", "in-0", 0.0, "in-1", 0.0 );
2060 2062
   cmDspInst_t* mul1  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
2061 2063
   cmDspInst_t* in    = cmDspSysAllocScalar( h, "Input",      0.0, 10.0, 0.001, 0.0);
2062 2064
   cmDspInst_t* in_m  = cmDspSysAllocScalar( h, "Input_M",    0.0, 10.0, 0.001, 0.0);
@@ -2068,6 +2070,18 @@ cmDspRC_t _cmDspSysPgm_ScalarOp( cmDspSysH_t h, void** userPtrPtr )
2068 2070
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
2069 2071
     goto errLabel;
2070 2072
 
2073
+  // Notice that changing 'in' or 'in_m' causes 'out' to be recomputed, but other
2074
+  // changes are cached prior to 'add'.  This prevents the program from going into
2075
+  // an infinite loop.
2076
+  //
2077
+  //     in   -> mult0
2078
+  //     in_m -> mult0--+
2079
+  // +-->fb   -> mult1  +----> add
2080
+  // |   fb_m -> mult1-------> add --------+------> out
2081
+  // |                                     |
2082
+  // +-------------------------------------+
2083
+  //
2084
+  
2071 2085
   cmDspSysInstallCb( h, in,    "val", mul0, "in-0", NULL );
2072 2086
   cmDspSysInstallCb( h, in_m,  "val", mul0, "in-1", NULL );
2073 2087
   cmDspSysInstallCb( h, fb,    "val", mul1, "in-0", NULL );

Laden…
Annuleren
Opslaan