From 5981d495cc10107333c988c38c98f6129f3a054f Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 13 Feb 2018 09:14:28 +0000 Subject: [PATCH] V66: #178 update script parameters command PROCU --- command.c | 6 +++-- pigpio.3 | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ pigpio.c | 36 ++++++++++++++++++++++++++++ pigpio.h | 45 ++++++++++++++++++++++++++++++++++- pigpio.py | 37 ++++++++++++++++++++++++++++- pigpiod_if2.3 | 34 ++++++++++++++++++++++++++ pigpiod_if2.c | 21 +++++++++++++++- pigpiod_if2.h | 24 ++++++++++++++++++- pigs.1 | 39 ++++++++++++++++++++++++++++++ setup.py | 2 +- x_pigs | 2 +- 11 files changed, 304 insertions(+), 8 deletions(-) diff --git a/command.c b/command.c index 4e97bbe..81ce6a6 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 65+ +This version is for pigpio version 66+ */ #include @@ -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. diff --git a/pigpio.3 b/pigpio.3 index f913f14..5e7277b 100644 --- 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 diff --git a/pigpio.c b/pigpio.c index 8b121f9..f8f32e0 100644 --- 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) diff --git a/pigpio.h b/pigpio.h index f2aff01..cdbe03b 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#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*/ /* diff --git a/pigpio.py b/pigpio.py index 5186b8b..c091937 100644 --- 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 diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index a4541f5..6357f88 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -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 diff --git a/pigpiod_if2.c b/pigpiod_if2.c index d56fd61..85bc27c 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 11 */ +/* PIGPIOD_IF2_VERSION 13 */ #include #include @@ -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; diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 8efd130..76d6ab0 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #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 2d5c631..51a9e08 100644 --- 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 diff --git a/setup.py b/setup.py index 3609ae9..6e1bcce 100644 --- 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 3e33a2a..125718e 100755 --- 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