V66: #178 update script parameters command PROCU

This commit is contained in:
joan 2018-02-13 09:14:28 +00:00
parent 1737d47747
commit 5981d495cc
11 changed files with 304 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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*/
/*

View File

@ -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

View 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

View 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;

View 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

39
pigs.1
View File

@ -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

View File

@ -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',

2
x_pigs
View File

@ -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