V66: #178 update script parameters command PROCU
authorjoan <joan@abyz.co.uk>
Tue, 13 Feb 2018 09:14:28 +0000 (09:14 +0000)
committerjoan <joan@abyz.co.uk>
Tue, 13 Feb 2018 09:14:28 +0000 (09:14 +0000)
command.c
pigpio.3
pigpio.c
pigpio.h
pigpio.py
pigpiod_if2.3
pigpiod_if2.c
pigpiod_if2.h
pigs.1
setup.py
x_pigs

index 4e97bbe54ce8793067ad95d0c179ed5417a38a6a..81ce6a6d84462841c6610e3292cce265b1944d17 100644 (file)
--- a/command.c
+++ b/command.c
@@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
 */
 
 /*
-This version is for pigpio version 65+
+This version is for pigpio version 66+
 */
 
 #include <stdio.h>
@@ -148,6 +148,7 @@ cmdInfo_t cmdInfo[]=
    {PI_CMD_PROCP, "PROCP", 112, 7}, // gpioScriptStatus
    {PI_CMD_PROCR, "PROCR", 191, 0}, // gpioRunScript
    {PI_CMD_PROCS, "PROCS", 112, 0}, // gpioStopScript
+   {PI_CMD_PROCU, "PROCU", 191, 0}, // gpioUpdateScript
 
    {PI_CMD_PRRG,  "PRRG",  112, 2}, // gpioGetPWMrealRange
    {PI_CMD_PRS,   "PRS",   121, 2}, // gpioSetPWMrange
@@ -347,6 +348,7 @@ PROCD sid        Delete script\n\
 PROCP sid        Get script status and parameters\n\
 PROCR sid ...    Run script\n\
 PROCS sid        Stop script\n\
+PROCU sid ...    Set script parameters\n\
 PRRG g           Get GPIO PWM real range\n\
 PRS g v          Set GPIO PWM range\n\
 PUD g pud        Set GPIO pull up/down\n\
@@ -975,7 +977,7 @@ int cmdParse(
 
          break;
 
-      case 191: /* PROCR
+      case 191: /* PROCR PROCU
 
                    One to 11 parameters, first positive,
                    optional remainder, any value.
index f913f143f6815358eab99c6f09bdee424f993826..5e7277b2deda5b6a53f5f70d55e0a7ec463b8325 100644 (file)
--- a/pigpio.3
+++ b/pigpio.3
@@ -5185,6 +5185,68 @@ PI_TOO_MANY_PARAM.
 param is an array of up to 10 parameters which may be referenced in
 the script as p0 to p9.
 
+.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP"
+.IP "" 4
+This function runs a stored script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+   numPar: 0-10, the number of parameters
+.br
+    param: an array of parameters
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+.br
+
+.br
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+
+.IP "\fBint gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP"
+.IP "" 4
+This function sets the parameters of a script.  The script may or
+may not be running.  The first numPar parameters of the script are
+overwritten with the new values.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+   numPar: 0-10, the number of parameters
+.br
+    param: an array of parameters
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+.br
+
+.br
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+
 .IP "\fBint gpioScriptStatus(unsigned script_id, uint32_t *param)\fP"
 .IP "" 4
 This function returns the run status of a stored script as well as
@@ -9937,6 +9999,10 @@ A 16-bit word value.
 #define PI_CMD_EVT   116
 .br
 
+.br
+#define PI_CMD_PROCU 117
+.br
+
 .br
 
 .EE
index 8b121f9fae5b2d983368c474ad1530db75796b59..f8f32e06a94a0777652aa7ad778d009c28959d65 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -2207,6 +2207,10 @@ static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf)
 
       case PI_CMD_PROCS: res = gpioStopScript(p[1]); break;
 
+      case PI_CMD_PROCU:
+         res = gpioUpdateScript(p[1], p[3]/4, (uint32_t *)buf);
+         break;
+
       case PI_CMD_PRRG: res = gpioGetPWMrealRange(p[1]); break;
 
       case PI_CMD_PRS:
@@ -12279,6 +12283,38 @@ int gpioRunScript(unsigned script_id, unsigned numParam, uint32_t *param)
 }
 
 
+/* ----------------------------------------------------------------------- */
+
+int gpioUpdateScript(unsigned script_id, unsigned numParam, uint32_t *param)
+{
+   DBG(DBG_USER, "script_id=%d numParam=%d param=%08X",
+      script_id, numParam, (uint32_t)param);
+
+   CHECK_INITED;
+
+   if (script_id >= PI_MAX_SCRIPTS)
+      SOFT_ERROR(PI_BAD_SCRIPT_ID, "bad script id(%d)", script_id);
+
+   if (numParam > PI_MAX_SCRIPT_PARAMS)
+      SOFT_ERROR(PI_TOO_MANY_PARAM, "bad number of parameters(%d)", numParam);
+
+   if (gpioScript[script_id].state == PI_SCRIPT_IN_USE)
+   {
+      if ((numParam > 0) && (param != 0))
+      {
+         memcpy(gpioScript[script_id].script.par, param,
+            sizeof(uint32_t) * numParam);
+      }
+   }
+   else
+   {
+      return PI_BAD_SCRIPT_ID;
+   }
+
+   return 0;
+}
+
+
 /* ----------------------------------------------------------------------- */
 
 int gpioScriptStatus(unsigned script_id, uint32_t *param)
index f2aff015f978b9fb1bc8c28e79d52013684b773c..cdbe03b37263999c72abf7b2d897d497b6725d81 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
 #include <stdint.h>
 #include <pthread.h>
 
-#define PIGPIO_VERSION 65
+#define PIGPIO_VERSION 6601
 
 /*TEXT
 
@@ -207,6 +207,7 @@ SCRIPTS
 
 gpioStoreScript            Store a script
 gpioRunScript              Run a stored script
+gpioUpdateScript           Set a scripts parameters
 gpioScriptStatus           Get script status and parameters
 gpioStopScript             Stop a running script
 gpioDeleteScript           Delete a stored script
@@ -3741,6 +3742,46 @@ param is an array of up to 10 parameters which may be referenced in
 the script as p0 to p9.
 D*/
 
+/*F*/
+int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param);
+/*D
+This function runs a stored script.
+
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+   numPar: 0-10, the number of parameters
+    param: an array of parameters
+. .
+
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+D*/
+
+
+
+/*F*/
+int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param);
+/*D
+This function sets the parameters of a script.  The script may or
+may not be running.  The first numPar parameters of the script are
+overwritten with the new values.
+
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+   numPar: 0-10, the number of parameters
+    param: an array of parameters
+. .
+
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+D*/
+
 
 /*F*/
 int gpioScriptStatus(unsigned script_id, uint32_t *param);
@@ -6155,6 +6196,8 @@ PARAMS*/
 #define PI_CMD_EVM   115
 #define PI_CMD_EVT   116
 
+#define PI_CMD_PROCU 117
+
 /*DEF_E*/
 
 /*
index 5186b8bc7e51ac2748d996076c84bbf321783169..c09193787b8832e6d60d5a2c1c0aaaa9c25660de 100644 (file)
--- a/pigpio.py
+++ b/pigpio.py
@@ -168,6 +168,7 @@ Scripts
 
 store_script              Store a script
 run_script                Run a stored script
+update_script             Set a scripts parameters
 script_status             Get script status and parameters
 stop_script               Stop a running script
 delete_script             Delete a stored script
@@ -299,7 +300,7 @@ import threading
 import os
 import atexit
 
-VERSION = "1.39"
+VERSION = "1.40"
 
 exceptions = True
 
@@ -539,6 +540,8 @@ _PI_CMD_BSCX =114
 _PI_CMD_EVM  =115
 _PI_CMD_EVT  =116
 
+_PI_CMD_PROCU=117
+
 # pigpio error numbers
 
 _PI_INIT_FAILED     =-1
@@ -4265,6 +4268,38 @@ class pi():
       return _u2i(_pigpio_command_ext(
          self.sl, _PI_CMD_PROCR, script_id, 0, nump*4, extents))
 
+   def update_script(self, script_id, params=None):
+      """
+      Sets the parameters of a script.  The script may or
+      may not be running.  The first parameters of the script are
+      overwritten with the new values.
+
+      script_id:= id of stored script.
+         params:= up to 10 parameters required by the script.
+
+      ...
+      s = pi.update_script(sid, [par1, par2])
+
+      s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
+      ...
+      """
+      # I p1 script id
+      # I p2 0
+      # I p3 params * 4 (0-10 params)
+      ## (optional) extension ##
+      # I[] params
+      if params is not None:
+         ext = bytearray()
+         for p in params:
+            ext.extend(struct.pack("I", p))
+         nump = len(params)
+         extents = [ext]
+      else:
+         nump = 0
+         extents = []
+      return _u2i(_pigpio_command_ext(
+         self.sl, _PI_CMD_PROCU, script_id, 0, nump*4, extents))
+
    def script_status(self, script_id):
       """
       Returns the run status of a stored script as well as the
index a4541f508a3f8bdf38f708cbba9e02d3cab53c5f..6357f885eb4194dcb1958a29276f55dd40b8c046 100644 (file)
@@ -2584,6 +2584,40 @@ PI_TOO_MANY_PARAM
 param is an array of up to 10 parameters which may be referenced in
 the script as p0 to p9.
 
+.IP "\fBint update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP"
+.IP "" 4
+This function sets the parameters of a script.  The script may or
+may not be running.  The first numPar parameters of the script are
+overwritten with the new values.
+
+.br
+
+.br
+
+.EX
+       pi: >=0 (as returned by \fBpigpio_start\fP).
+.br
+script_id: >=0, as returned by \fBstore_script\fP.
+.br
+   numPar: 0-10, the number of parameters.
+.br
+    param: an array of parameters.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+.br
+
+.br
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+
 .IP "\fBint script_status(int pi, unsigned script_id, uint32_t *param)\fP"
 .IP "" 4
 This function returns the run status of a stored script as well
index d56fd61cb50a95934c1112b73fe1b6a1b23b7977..85bc27cc5c31fb55740e5427d3bb627a88a69f5b 100644 (file)
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* PIGPIOD_IF2_VERSION 11 */
+/* PIGPIOD_IF2_VERSION 13 */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1117,6 +1117,25 @@ int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)
       (pi, PI_CMD_PROCR, script_id, 0, numPar*4, 1, ext, 1);
 }
 
+int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)
+{
+   gpioExtent_t ext[1];
+
+   /*
+   p1=script id
+   p2=0
+   p3=numPar * 4
+   ## extension ##
+   uint32_t[numPar] pars
+   */
+
+   ext[0].size = 4 * numPar;
+   ext[0].ptr = param;
+
+   return pigpio_command_ext
+      (pi, PI_CMD_PROCU, script_id, 0, numPar*4, 1, ext, 1);
+}
+
 int script_status(int pi, unsigned script_id, uint32_t *param)
 {
    int status;
index 8efd1306f0a17f73b3110399dcdd7f6ab5660eac..76d6ab073e34a5e73ebb8dddd91ebca9f8269694 100644 (file)
@@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
 
 #include "pigpio.h"
 
-#define PIGPIOD_IF2_VERSION 12
+#define PIGPIOD_IF2_VERSION 13
 
 /*TEXT
 
@@ -178,6 +178,7 @@ SCRIPTS
 
 store_script               Store a script
 run_script                 Run a stored script
+update_script              Set a scripts parameters
 script_status              Get script status and parameters
 stop_script                Stop a running script
 delete_script              Delete a stored script
@@ -1721,6 +1722,27 @@ param is an array of up to 10 parameters which may be referenced in
 the script as p0 to p9.
 D*/
 
+/*F*/
+int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param);
+/*D
+This function sets the parameters of a script.  The script may or
+may not be running.  The first numPar parameters of the script are
+overwritten with the new values.
+
+. .
+       pi: >=0 (as returned by [*pigpio_start*]).
+script_id: >=0, as returned by [*store_script*].
+   numPar: 0-10, the number of parameters.
+    param: an array of parameters.
+. .
+
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+D*/
+
 /*F*/
 int script_status(int pi, unsigned script_id, uint32_t *param);
 /*D
diff --git a/pigs.1 b/pigs.1
index 2d5c631c50467baf43b4d09b6cb5d5990e8f1747..51a9e08add741b86cfddbdfb457fa8393ab697d8 100644 (file)
--- a/pigs.1
+++ b/pigs.1
@@ -3182,6 +3182,45 @@ ERROR: unknown script id
 
 .br
 
+.IP "\fBPROCU sid pars\fP - Set script parameters"
+.IP "" 4
+
+.br
+This command sets the parameters of a stored script \fBsid\fP passing
+it up to 10 parameters.
+
+.br
+Upon success nothing is returned.  On error a negative status code
+will be returned.
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0
+.br
+0
+.br
+$ pigs procu 0 50 500000
+.br
+$ pigs procr 0
+.br
+$ pigs procu 0 100
+.br
+$ pigs procu 0 200
+.br
+$ pigs procu 0 200 100000
+.br
+
+.EE
+
+.br
+
 .IP "\fBPRRG u\fP - Get GPIO PWM real range"
 .IP "" 4
 
index 3609ae9b39ee5263945362bd41a8b52b03b63825..6e1bcce3d76cc07f369bf6b3719224ece50f2626 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from distutils.core import setup
 
 setup(name='pigpio',
-      version='1.39',
+      version='1.40',
       author='joan',
       author_email='joan@abyz.me.uk',
       maintainer='joan',
diff --git a/x_pigs b/x_pigs
index 3e33a2a2d54948e066c298a614850686df7cc788..125718e12973be459d3630e41834c1bde70f6836 100755 (executable)
--- a/x_pigs
+++ b/x_pigs
@@ -50,7 +50,7 @@ s=$(pigs bs2 0)
 if [[ $s = "" ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi
 
 s=$(pigs h)
-if [[ ${#s} = 5384 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi
+if [[ ${#s} = 5423 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi
 
 s=$(pigs hwver)
 if [[ $s -ne 0 ]]; then echo "HWVER ok"; else echo "HWVER fail ($s)"; fi