V20
authorjoan <joan@abyz.me.uk>
Sun, 17 Aug 2014 18:53:43 +0000 (19:53 +0100)
committerjoan <joan@abyz.me.uk>
Sun, 17 Aug 2014 18:53:43 +0000 (19:53 +0100)
pigpio.3
pigpio.c
pigpio.h
pigpio.py
pigpiod_if.3
pigpiod_if.h
setup.py
x_pigs
x_pipe

index a5efe769b5df8e12df2eec6d0abd058df1efb8cf..7089390fcc1fcdfa32329c95d663eafaa5929ea5 100644 (file)
--- a/pigpio.3
+++ b/pigpio.3
@@ -2719,7 +2719,7 @@ level for pulseLen microseconds and then reset to not level.
 .EX
 user_gpio: 0-31
 .br
- pulseLen: 1-50
+ pulseLen: 1-100
 .br
     level: 0,1
 .br
@@ -5184,7 +5184,7 @@ PI_PUD_UP 2
 .br
 
 .br
-1-50, the length of a trigger pulse in microseconds.
+1-100, the length of a trigger pulse in microseconds.
 
 .br
 
index 7c468c31818f62715043f557bd8e952f4530aa13..8ddab172f7402dd141d8b11b34924783950c368a 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* pigpio version 19 */
+/* pigpio version 20 */
 
 #include <stdio.h>
 #include <string.h>
@@ -4705,7 +4705,7 @@ static void *pthSocketThreadHandler(void *fdC)
 
          case PI_CMD_PROCP:
             p[3] = myDoCommand(p, sizeof(buf)-1, buf+sizeof(int));
-            if (p[3] >= 0)
+            if (((int)p[3]) >= 0)
             {
                memcpy(buf, &p[3], 4);
                p[3] = 4 + (4*PI_MAX_SCRIPT_PARAMS);
@@ -4732,7 +4732,7 @@ static void *pthSocketThreadHandler(void *fdC)
          case PI_CMD_SPIX:
          case PI_CMD_SPIR:
 
-            if (p[3] > 0)
+            if (((int)p[3]) > 0)
             {
                write(sock, buf, p[3]);
             }
index d125f4dfc9d6d04ad55d85e77df7ed17feba47a8..e15e85fd3b769e4cac8c40a07363ebe37bfb1eb4 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 19
+#define PIGPIO_VERSION 20
 
 /*TEXT
 
@@ -2102,7 +2102,7 @@ level for pulseLen microseconds and then reset to not level.
 
 . .
 user_gpio: 0-31
- pulseLen: 1-50
+ pulseLen: 1-100
     level: 0,1
 . .
 
@@ -3411,7 +3411,7 @@ PI_PUD_UP 2
 
 pulseLen::
 
-1-50, the length of a trigger pulse in microseconds.
+1-100, the length of a trigger pulse in microseconds.
 
 *pulses::
 
index 73dbd485815bdbe03573a0ba8ffb51e8bb46fc4e..ab176739794c0c017f4b24df249308bad56982e5 100644 (file)
--- a/pigpio.py
+++ b/pigpio.py
@@ -246,7 +246,7 @@ import os
 import atexit
 import codecs
 
-VERSION = "1.9"
+VERSION = "1.10"
 
 exceptions = True
 
@@ -651,22 +651,39 @@ else:
    def _b(x):
       return codecs.latin_1_encode(x)[0]
 
-def _u2i(number):
-   """Converts a 32 bit unsigned number to signed."""
+def u2i(number):
+   """
+   Converts a 32 bit unsigned number to signed.
+
+   number:= an unsigned 32 bit number
+
+   ...
+   print(u2i(4294967272))
+   -24
+   print(u2i(37))
+   37
+   ...
+   """
    mask = (2 ** 32) - 1
    if number & (1 << 31):
       v = number | ~mask
    else:
       v = number & mask
-   if v >= 0:
-      return v;
-   else:
+   return v
+
+def _u2i(number):
+   """
+   Converts a 32 bit unsigned number to signed.  If the number
+   is negative it indicates an error.  On error a pigpio
+   exception will be raised if exceptions is True.
+   """
+   v = u2i(number)
+   if v < 0:
       if exceptions:
          raise error(error_text(v))
-      else:
-         return v
+   return v
 
-def _pigpio_command(sl, cmd, p1, p2):
+def _pigpio_command(sl, cmd, p1, p2, rl=True):
    """
    Runs a pigpio socket command.
 
@@ -678,10 +695,10 @@ def _pigpio_command(sl, cmd, p1, p2):
    sl.l.acquire()
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
    dummy, res = struct.unpack('12sI', sl.s.recv(16))
-   sl.l.release()
+   if rl: sl.l.release()
    return res
 
-def _pigpio_command_ext(sl, cmd, p1, p2, p3, extents):
+def _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=True):
    """
    Runs an extended pigpio socket command.
 
@@ -701,7 +718,7 @@ def _pigpio_command_ext(sl, cmd, p1, p2, p3, extents):
    sl.l.acquire()
    sl.s.sendall(ext)
    dummy, res = struct.unpack('12sI', sl.s.recv(16))
-   sl.l.release()
+   if rl: sl.l.release()
    return res
 
 class _callback_ADT:
@@ -1772,10 +1789,15 @@ class pi():
       (count, data) = pi.i2c_read_device(h, 12)
       ...
       """
-      bytes = _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRD, handle, count))
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(
+         _pigpio_command(self.sl, _PI_CMD_I2CRD, handle, count, False))
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def i2c_write_device(self, handle, data):
       """
@@ -2030,10 +2052,14 @@ class pi():
          # process read failure
       ...
       """
-      bytes = _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRK, handle, reg))
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(_pigpio_command(self.sl, _PI_CMD_I2CRK, handle, reg, False))
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def i2c_block_process_call(self, handle, reg, data):
       """
@@ -2071,11 +2097,16 @@ class pi():
       # I p3 len
       ## extension ##
       # s len data bytes
-      bytes = _u2i(_pigpio_command_ext(
-         self.sl, _PI_CMD_I2CPK, handle, reg, len(data), [data]))
+
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(_pigpio_command_ext(
+         self.sl, _PI_CMD_I2CPK, handle, reg, len(data), [data]), False)
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def i2c_write_i2c_block_data(self, handle, reg, data):
       """
@@ -2135,11 +2166,16 @@ class pi():
       ## extension ##
       # I count
       extents = [struct.pack("I", count)]
-      bytes = _u2i(_pigpio_command_ext(
-         self.sl, _PI_CMD_I2CRI, handle, reg, 4, extents))
+
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(_pigpio_command_ext(
+         self.sl, _PI_CMD_I2CRI, handle, reg, 4, extents), False)
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def spi_open(self, spi_channel, spi_baud, spi_flags=0):
       """
@@ -2231,11 +2267,15 @@ class pi():
          # error path
       ...
       """
-      bytes = _u2i(_pigpio_command(
-         self.sl, _PI_CMD_SPIR, handle, count))
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(_pigpio_command(
+         self.sl, _PI_CMD_SPIR, handle, count, False))
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def spi_write(self, handle, data):
       """
@@ -2290,11 +2330,16 @@ class pi():
       # I p3 len
       ## extension ##
       # s len data bytes
-      bytes = _u2i(_pigpio_command_ext(
-         self.sl, _PI_CMD_SPIX, handle, 0, len(data), [data]))
+
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(_pigpio_command_ext(
+         self.sl, _PI_CMD_SPIX, handle, 0, len(data), [data]), False)
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def serial_open(self, tty, ser_baud, ser_flags=0):
       """
@@ -2382,11 +2427,15 @@ class pi():
          # process read data
       ...
       """
-      bytes = _u2i(_pigpio_command(self.sl, _PI_CMD_SERR, handle, count))
-
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(
+         _pigpio_command(self.sl, _PI_CMD_SERR, handle, count, False))
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    def serial_write(self, handle, data):
       """
@@ -2436,7 +2485,7 @@ class pi():
       level for pulse_len microseconds and then reset to not level.
 
       user_gpio:= 0-31
-      pulse_len:= 1-50
+      pulse_len:= 1-100
           level:= 0-1
 
       ...
@@ -2535,11 +2584,19 @@ class pi():
       (s, pars) = pi.script_status(sid)
       ...
       """
-      status = _u2i(_pigpio_command(self.sl, _PI_CMD_PROCP, script_id, 0))
-      if status > 0:
-         params = struct.unpack('I10i', self.sl.s.recv(44))
-         return params[0], params[1:]
-      return status, ()
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(
+         _pigpio_command(self.sl, _PI_CMD_PROCP, script_id, 0, False))
+      if bytes > 0:
+         data = self._rxbuf(bytes)
+         pars = struct.unpack('11i', data)
+         status = pars[0]
+         params = pars[1:]
+      else:
+         status = bytes
+         params = ()
+      self.sl.l.release()
+      return status, params
 
    def stop_script(self, script_id):
       """
@@ -2601,10 +2658,15 @@ class pi():
       (count, data) = pi.bb_serial_read(4)
       ...
       """
-      bytes = _u2i(_pigpio_command(self.sl, _PI_CMD_SLR, user_gpio, 10000))
+      # Don't raise exception.  Must release lock.
+      bytes = u2i(
+         _pigpio_command(self.sl, _PI_CMD_SLR, user_gpio, 10000, False))
       if bytes > 0:
-         return bytes, self._rxbuf(bytes)
-      return bytes, ""
+         data = self._rxbuf(bytes)
+      else:
+         data = ""
+      self.sl.l.release()
+      return bytes, data
 
    
    def bb_serial_read_close(self, user_gpio):
@@ -2956,8 +3018,8 @@ def xref():
    PUD_OFF = 0 
    PUD_UP = 2 
 
-   pulse_len: 1-50
-   A whole number.
+   pulse_len: 1-100
+   The length of the trigger pulse in microseconds.
 
    pulses:
    A list of class pulse objects defining the characteristics of a
index 9dc11174df18ab4b7b472ab7a5251284513a71db..10f86440bab5d16f93cf820e6b4074c22bf1b012 100644 (file)
@@ -1502,7 +1502,7 @@ level for pulseLen microseconds and then reset to not level.
 .EX
 user_gpio: 0-31.
 .br
- pulseLen: 1-50.
+ pulseLen: 1-100.
 .br
     level: 0,1.
 .br
@@ -3149,7 +3149,7 @@ PI_PUD_UP 2
 .br
 
 .IP "\fBpulseLen\fP" 0
-1-50, the length of a trigger pulse in microseconds.
+1-100, the length of a trigger pulse in microseconds.
 
 .br
 
index 2b36df9150d66c0a7de314e91cb1fe6fae7d5563..e62ff8367bb6d134a24b3b594cf2d97d5c1ce101 100644 (file)
@@ -1120,7 +1120,7 @@ level for pulseLen microseconds and then reset to not level.
 
 . .
 user_gpio: 0-31.
- pulseLen: 1-50.
+ pulseLen: 1-100.
     level: 0,1.
 . .
 
@@ -2044,7 +2044,7 @@ PI_PUD_UP 2
 . .
 
 pulseLen::
-1-50, the length of a trigger pulse in microseconds.
+1-100, the length of a trigger pulse in microseconds.
 
 *pulses::
 An array of pulsed to be added to a waveform.
index 5b28e4c50ff218d42c29ce3425ab7619fdbb719a..84dd5da0fc230eae87c0f9c39e6d8060e743229b 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from distutils.core import setup
 
 setup(name='pigpio',
-      version='1.9',
+      version='1.10',
       author='joan',
       author_email='joan@abyz.co.uk',
       maintainer='joan',
diff --git a/x_pigs b/x_pigs
index c2d7442b098e6c52b83de2e34984bb9cbbd45726..d2d9b9d3c8c38a756a7e330684da291e986ce2d1 100755 (executable)
--- a/x_pigs
+++ b/x_pigs
@@ -86,7 +86,7 @@ s=$(pigs pfs $GPIO 800)
 if [[ $s = 800 ]]; then echo "PFS-b ok"; else echo "PFS-b fail ($s)"; fi
 
 s=$(pigs pigpv)
-if [[ $s = 19 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
+if [[ $s = 20 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
 
 s=$(pigs prs $GPIO 255)
 if [[ $s = 250 ]]; then echo "PRG-a ok"; else echo "PRG-a fail ($s)"; fi
diff --git a/x_pipe b/x_pipe
index 9792fd9d47ae9ad8cfd35d065800872f76e6e0b2..0e9f87731dd32980ddfbfc3b8c550c23653e3680 100755 (executable)
--- a/x_pipe
+++ b/x_pipe
@@ -119,7 +119,7 @@ if [[ $s = 800 ]]; then echo "PFS-b ok"; else echo "PFS-b fail ($s)"; fi
 
 echo "pigpv" >/dev/pigpio
 read -t 1 s </dev/pigout
-if [[ $s = 19 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
+if [[ $s = 20 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
 
 echo "prs $GPIO 255" >/dev/pigpio
 read -t 1 s </dev/pigout