Merge pull request #2 from joan2937/master

Pull from upstream
This commit is contained in:
Björn Schrader 2016-11-04 14:39:01 +01:00 committed by GitHub
commit 11f99f9b18
32 changed files with 14055 additions and 2819 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
*.o
*.so
pig2vcd
pigpiod
pigs
x_pigpio
x_pigpiod_if
x_pigpiod_if2

View File

@ -54,7 +54,7 @@ class sensor:
self.power = power
if power is not None:
pi.write(power, 1) # Switch sensor on.
pi.write(power, 1) # Switch sensor on.
time.sleep(2)
self.powered = True
@ -63,10 +63,10 @@ class sensor:
atexit.register(self.cancel)
self.bad_CS = 0 # Bad checksum count.
self.bad_SM = 0 # Short message count.
self.bad_MM = 0 # Missing message count.
self.bad_SR = 0 # Sensor reset count.
self.bad_CS = 0 # Bad checksum count.
self.bad_SM = 0 # Short message count.
self.bad_MM = 0 # Missing message count.
self.bad_SR = 0 # Sensor reset count.
# Power cycle if timeout > MAX_TIMEOUTS.
self.no_response = 0
@ -82,7 +82,7 @@ class sensor:
pi.set_pull_up_down(gpio, pigpio.PUD_OFF)
pi.set_watchdog(gpio, 0) # Kill any watchdogs.
pi.set_watchdog(gpio, 0) # Kill any watchdogs.
self.cb = pi.callback(gpio, pigpio.EITHER_EDGE, self._cb)
@ -99,16 +99,16 @@ class sensor:
if diff >= 50:
val = 1
if diff >= 200: # Bad bit?
self.CS = 256 # Force bad checksum.
if diff >= 200: # Bad bit?
self.CS = 256 # Force bad checksum.
else:
val = 0
if self.bit >= 40: # Message complete.
if self.bit >= 40: # Message complete.
self.bit = 40
elif self.bit >= 32: # In checksum byte.
self.CS = (self.CS<<1) + val
elif self.bit >= 32: # In checksum byte.
self.CS = (self.CS << 1) + val
if self.bit == 39:
@ -120,17 +120,17 @@ class sensor:
total = self.hH + self.hL + self.tH + self.tL
if (total & 255) == self.CS: # Is checksum ok?
if (total & 255) == self.CS: # Is checksum ok?
self.rhum = ((self.hH<<8) + self.hL) * 0.1
self.rhum = ((self.hH << 8) + self.hL) * 0.1
if self.tH & 128: # Negative temperature.
if self.tH & 128: # Negative temperature.
mult = -0.1
self.tH = self.tH & 127
else:
mult = 0.1
self.temp = ((self.tH<<8) + self.tL) * mult
self.temp = ((self.tH << 8) + self.tL) * mult
self.tov = time.time()
@ -141,17 +141,17 @@ class sensor:
self.bad_CS += 1
elif self.bit >=24: # in temp low byte
self.tL = (self.tL<<1) + val
elif self.bit >= 24: # in temp low byte
self.tL = (self.tL << 1) + val
elif self.bit >=16: # in temp high byte
self.tH = (self.tH<<1) + val
elif self.bit >= 16: # in temp high byte
self.tH = (self.tH << 1) + val
elif self.bit >= 8: # in humidity low byte
self.hL = (self.hL<<1) + val
elif self.bit >= 8: # in humidity low byte
self.hL = (self.hL << 1) + val
elif self.bit >= 0: # in humidity high byte
self.hH = (self.hH<<1) + val
elif self.bit >= 0: # in humidity high byte
self.hH = (self.hH << 1) + val
else: # header bits
pass
@ -168,14 +168,14 @@ class sensor:
self.tL = 0
self.CS = 0
else: # level == pigpio.TIMEOUT:
else: # level == pigpio.TIMEOUT:
self.pi.set_watchdog(self.gpio, 0)
if self.bit < 8: # Too few data bits received.
self.bad_MM += 1 # Bump missing message count.
self.no_response += 1
if self.no_response > self.MAX_NO_RESPONSE:
self.no_response = 0
self.bad_SR += 1 # Bump sensor reset count.
self.bad_SR += 1 # Bump sensor reset count.
if self.power is not None:
self.powered = False
self.pi.write(self.power, 0)
@ -228,7 +228,7 @@ class sensor:
self.pi.write(self.LED, 1)
self.pi.write(self.gpio, pigpio.LOW)
time.sleep(0.017) # 17 ms
time.sleep(0.017) # 17 ms
self.pi.set_mode(self.gpio, pigpio.INPUT)
self.pi.set_watchdog(self.gpio, 200)
@ -237,7 +237,7 @@ class sensor:
self.pi.set_watchdog(self.gpio, 0)
if self.cb != None:
if self.cb is not None:
self.cb.cancel()
self.cb = None
@ -250,7 +250,7 @@ if __name__ == "__main__":
import DHT22
# Intervals of about 2 seconds or less will eventually hang the DHT22.
INTERVAL=3
INTERVAL = 3
pi = pigpio.pi()
@ -275,7 +275,7 @@ if __name__ == "__main__":
next_reading += INTERVAL
time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.
time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.
s.cancel()

View File

@ -3,6 +3,7 @@
import time
import curses
import atexit
import sys
import pigpio
@ -17,6 +18,8 @@ def cleanup():
pi.stop()
pi = pigpio.pi()
if not pi.connected:
sys.exit(1)
stdscr = curses.initscr()
curses.noecho()
@ -43,7 +46,7 @@ while True:
tally = cb[g].tally()
mode = pi.get_mode(g)
col = (g / 11) * 25
col = (g // 11) * 25
row = (g % 11) + 2
stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD)

View File

@ -1,10 +1,14 @@
#
CC = gcc
AR = ar
RANLIB = ranlib
SIZE = size
SHLIB = gcc -shared
STRIPLIB = strip --strip-unneeded
# Set CROSS_PREFIX to prepend to all compiler tools at once for easier
# cross-compilation.
CROSS_PREFIX =
CC = $(CROSS_PREFIX)gcc
AR = $(CROSS_PREFIX)ar
RANLIB = $(CROSS_PREFIX)ranlib
SIZE = $(CROSS_PREFIX)size
STRIP = $(CROSS_PREFIX)strip
SHLIB = $(CC) -shared
STRIPLIB = $(STRIP) --strip-unneeded
CFLAGS += -O3 -Wall -pthread
@ -59,12 +63,15 @@ x_pigpiod_if2: x_pigpiod_if2.o $(LIB3)
pigpiod: pigpiod.o $(LIB1)
$(CC) -o pigpiod pigpiod.o $(LL1)
$(STRIP) pigpiod
pigs: pigs.o command.o
$(CC) -o pigs pigs.o command.o
$(STRIP) pigs
pig2vcd: pig2vcd.o
$(CC) -o pig2vcd pig2vcd.o
$(STRIP) pig2vcd
clean:
rm -f *.o *.i *.s *~ $(ALL)
@ -80,9 +87,9 @@ install: $(ALL)
install -m 0755 libpigpiod_if.so $(DESTDIR)$(libdir)
install -m 0755 libpigpiod_if2.so $(DESTDIR)$(libdir)
install -m 0755 -d $(DESTDIR)$(bindir)
install -m 0755 -s pig2vcd $(DESTDIR)$(bindir)
install -m 0755 -s pigpiod $(DESTDIR)$(bindir)
install -m 0755 -s pigs $(DESTDIR)$(bindir)
install -m 0755 pig2vcd $(DESTDIR)$(bindir)
install -m 0755 pigpiod $(DESTDIR)$(bindir)
install -m 0755 pigs $(DESTDIR)$(bindir)
if which python2; then python2 setup.py install; fi
if which python3; then python3 setup.py install; fi
install -m 0755 -d $(DESTDIR)$(mandir)/man1

193
README.md
View File

@ -1,96 +1,97 @@
# pigpio
pigpio is a C library for the Raspberry which allows control of the
general purpose input outputs (gpios).
Features
sampling and time-stamping of gpios 0-31 between 100,000 and 1,000,000 times per second.
provision of PWM on any number of the user gpios simultaneously.
provision of servo pulses on any number of the user gpios simultaneously.
callbacks when any of gpios 0-31 change state (callbacks receive the time of the event
accurate to a few microseconds).
notifications via pipe when any of gpios 0-31 change state.
callbacks at timed intervals.
reading/writing all of the gpios in a bank (0-31, 32-53) as a single operation.
individually setting gpio modes, reading and writing.
socket and pipe interfaces for the bulk of the functionality in addition to the
underlying C library calls.
the construction of arbitrary waveforms to give precise timing of output gpio
level changes (accurate to a few microseconds).
software serial links using any user gpio.
rudimentary permission control through the socket and pipe interfaces so users
can be prevented from "updating" inappropriate gpios.
creating and running scripts on the pigpio daemon.
Interfaces
The library provides a number of control interfaces
the C function interface
the /dev/pigpio pipe interface
the socket interface (used by the pigs utility and the Python module)
Utilities
A number of utility programs are provided
the pigpiod daemon.
the Python module.
the pigs command line utility.
the pig2vcd utility which converts notifications into the value change dump (VCD)
format (useful for viewing digital waveforms with GTKWave).
gpios
ALL gpios are identified by their Broadcom number. See elinux.org
There are 54 gpios in total, arranged in two banks.
Bank 1 contains gpios 0-31. Bank 2 contains gpios 32-54.
A user should only manipulate gpios in bank 1.
There are at least three types of board.
Type 1
26 pin header (P1).
Hardware revision numbers of 2 and 3.
User gpios 0-1, 4, 7-11, 14-15, 17-18, 21-25.
Type 2
26 pin header (P1) and an additional 8 pin header (P5).
Hardware revision numbers of 4, 5, 6, and 15.
User gpios 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
Type 3
40 pin expansion header (J8).
Hardware revision numbers of 16 or greater.
User gpios 2-27 (0 and 1 are reserved).
It is safe to read all the gpios. If you try to write a system gpio or change
its mode you can crash the Pi or corrupt the data on the SD card.
# pigpio
pigpio is a C library for the Raspberry which allows control of the
general purpose input outputs (gpios).
Features
sampling and time-stamping of gpios 0-31 between 100,000 and 1,000,000 times per second.
provision of PWM on any number of the user gpios simultaneously.
provision of servo pulses on any number of the user gpios simultaneously.
callbacks when any of gpios 0-31 change state (callbacks receive the time of the event
accurate to a few microseconds).
notifications via pipe when any of gpios 0-31 change state.
callbacks at timed intervals.
reading/writing all of the gpios in a bank (0-31, 32-53) as a single operation.
individually setting gpio modes, reading and writing.
socket and pipe interfaces for the bulk of the functionality in addition to the
underlying C library calls.
the construction of arbitrary waveforms to give precise timing of output gpio
level changes (accurate to a few microseconds).
software serial links using any user gpio.
rudimentary permission control through the socket and pipe interfaces so users
can be prevented from "updating" inappropriate gpios.
creating and running scripts on the pigpio daemon.
Interfaces
The library provides a number of control interfaces
the C function interface
the /dev/pigpio pipe interface
the socket interface (used by the pigs utility and the Python module)
Utilities
A number of utility programs are provided
the pigpiod daemon.
the Python module.
the pigs command line utility.
the pig2vcd utility which converts notifications into the value change dump (VCD)
format (useful for viewing digital waveforms with GTKWave).
gpios
ALL gpios are identified by their Broadcom number. See elinux.org
There are 54 gpios in total, arranged in two banks.
Bank 1 contains gpios 0-31. Bank 2 contains gpios 32-54.
A user should only manipulate gpios in bank 1.
There are at least three types of board.
Type 1
26 pin header (P1).
Hardware revision numbers of 2 and 3.
User gpios 0-1, 4, 7-11, 14-15, 17-18, 21-25.
Type 2
26 pin header (P1) and an additional 8 pin header (P5).
Hardware revision numbers of 4, 5, 6, and 15.
User gpios 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
Type 3
40 pin expansion header (J8).
Hardware revision numbers of 16 or greater.
User gpios 2-27 (0 and 1 are reserved).
It is safe to read all the gpios. If you try to write a system gpio or change
its mode you can crash the Pi or corrupt the data on the SD card.

320
command.c
View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
This version is for pigpio version 46+
This version is for pigpio version 57+
*/
#include <stdio.h>
@ -55,15 +55,34 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_BS1, "BS1", 111, 1}, // gpioWrite_Bits_0_31_Set
{PI_CMD_BS2, "BS2", 111, 1}, // gpioWrite_Bits_32_53_Set
{PI_CMD_BSCX, "BSCX", 193, 8}, // bscXfer
{PI_CMD_BSPIC, "BSPIC", 112, 0}, // bbSPIClose
{PI_CMD_BSPIO, "BSPIO", 134, 0}, // bbSPIOpen
{PI_CMD_BSPIX, "BSPIX", 193, 6}, // bbSPIXfer
{PI_CMD_CF1, "CF1", 195, 2}, // gpioCustom1
{PI_CMD_CF2, "CF2", 195, 6}, // gpioCustom2
{PI_CMD_CGI, "CGI", 101, 4}, // gpioCfgGetInternals
{PI_CMD_CSI, "CSI", 111, 1}, // gpioCfgSetInternals
{PI_CMD_EVM, "EVM", 122, 1}, // eventMonitor
{PI_CMD_EVT, "EVT", 112, 0}, // eventTrigger
{PI_CMD_FC, "FC", 112, 0}, // fileClose
{PI_CMD_FG, "FG", 121, 0}, // gpioGlitchFilter
{PI_CMD_FL, "FL", 127, 6}, // fileList
{PI_CMD_FN, "FN", 131, 0}, // gpioNoiseFilter
{PI_CMD_FO, "FO", 127, 2}, // fileOpen
{PI_CMD_FR, "FR", 121, 6}, // fileRead
{PI_CMD_FS, "FS", 133, 2}, // fileSeek
{PI_CMD_FW, "FW", 193, 0}, // fileWrite
{PI_CMD_GDC, "GDC", 112, 2}, // gpioGetPWMdutycycle
{PI_CMD_GPW, "GPW", 112, 2}, // gpioGetServoPulsewidth
@ -112,6 +131,9 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_NO, "NO", 101, 2}, // gpioNotifyOpen
{PI_CMD_NP, "NP", 112, 0}, // gpioNotifyPause
{PI_CMD_PADG, "PADG", 112, 2}, // gpioGetPad
{PI_CMD_PADS, "PADS", 121, 0}, // gpioSetPad
{PI_CMD_PARSE, "PARSE", 115, 0}, // cmdParseScript
{PI_CMD_PFG, "PFG", 112, 2}, // gpioGetPWMfrequency
@ -149,6 +171,8 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_SERVO, "S", 121, 0}, // gpioServo
{PI_CMD_SERVO, "SERVO", 121, 0}, // gpioServo
{PI_CMD_SHELL, "SHELL", 128, 2}, // shell
{PI_CMD_SLR, "SLR", 121, 6}, // gpioSerialRead
{PI_CMD_SLRC, "SLRC", 112, 0}, // gpioSerialReadClose
{PI_CMD_SLRO, "SLRO", 131, 0}, // gpioSerialReadOpen
@ -172,6 +196,7 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_WVAG, "WVAG", 192, 2}, // gpioWaveAddGeneric
{PI_CMD_WVAS, "WVAS", 196, 2}, // gpioWaveAddSerial
{PI_CMD_WVTAT, "WVTAT", 101, 2}, // gpioWaveTxAt
{PI_CMD_WVBSY, "WVBSY", 101, 2}, // gpioWaveTxBusy
{PI_CMD_WVCHA, "WVCHA", 197, 0}, // gpioWaveChain
{PI_CMD_WVCLR, "WVCLR", 101, 0}, // gpioWaveClear
@ -197,6 +222,7 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_DCR , "DCR" , 113, 0},
{PI_CMD_DCRA , "DCRA" , 101, 0},
{PI_CMD_DIV , "DIV" , 111, 0},
{PI_CMD_EVTWT, "EVTWT", 111, 0},
{PI_CMD_HALT , "HALT" , 101, 0},
{PI_CMD_INR , "INR" , 113, 0},
{PI_CMD_INRA , "INRA" , 101, 0},
@ -235,15 +261,23 @@ cmdInfo_t cmdInfo[]=
char * cmdUsage = "\n\
BC1 bits Clear gpios in bank 1\n\
BC2 bits Clear gpios in bank 2\n\
BC1 bits Clear GPIO in bank 1\n\
BC2 bits Clear GPIO in bank 2\n\
BI2CC sda Close bit bang I2C\n\
BI2CO sda scl baud | Open bit bang I2C\n\
BI2CZ sda ... I2C bit bang multiple transactions\n\
BR1 Read bank 1 gpios\n\
BR2 Read bank 2 gpios\n\
BS1 bits Set gpios in bank 2\n\
BS2 bits Set gpios in bank 2\n\
\n\
BSPIC cs Close bit bang SPI\n\
BSPIO cs miso mosi sclk baud flag | Open bit bang SPI\n\
BSPIX cs ... SPI bit bang transfer\n\
\n\
BR1 Read bank 1 GPIO\n\
BR2 Read bank 2 GPIO\n\
\n\
BS1 bits Set GPIO in bank 1\n\
BS2 bits Set GPIO in bank 2\n\
\n\
BSCX bctl bvs BSC I2C/SPI transfer\n\
\n\
CF1 ... Custom function 1\n\
CF2 ... Custom function 2\n\
@ -251,11 +285,20 @@ CF2 ... Custom function 2\n\
CGI Configuration get internals\n\
CSI v Configuration set internals\n\
\n\
FG g steady Set glitch filter on gpio\n\
FN g steady active | Set noise filter on gpio\n\
EVM h bits Set events to monitor\n\
EVT n Trigger event\n\
\n\
GDC g Get PWM dutycycle for gpio\n\
GPW g Get servo pulsewidth for gpio\n\
FC h Close file handle\n\
FG g steady Set glitch filter on GPIO\n\
FL pat n List files which match pattern\n\
FN g steady active | Set noise filter on GPIO\n\
FO file mode Open a file in mode\n\
FR h n Read bytes from file handle\n\
FS h n from Seek to file handle position\n\
FW h ... Write bytes to file handle\n\
\n\
GDC g Get PWM dutycycle for GPIO\n\
GPW g Get servo pulsewidth for GPIO\n\
\n\
H/HELP Display command help\n\
HC g f Set hardware clock frequency\n\
@ -281,8 +324,8 @@ I2CWS h b SMBus Write Byte: write byte\n\
I2CWW h r word SMBus Write Word Data: write word to register\n\
I2CZ h ... I2C multiple transactions\n\
\n\
M/MODES g mode Set gpio mode\n\
MG/MODEG g Get gpio mode\n\
M/MODES g mode Set GPIO mode\n\
MG/MODEG g Get GPIO mode\n\
MICS n Delay for microseconds\n\
MILS n Delay for milliseconds\n\
\n\
@ -291,34 +334,37 @@ NC h Close notification\n\
NO Request a notification\n\
NP h Pause notification\n\
\n\
P/PWM g v Set gpio PWM value\n\
P/PWM g v Set GPIO PWM value\n\
PADG pad Get pad drive strength\n\
PADS pad v Set pad drive strength\n\
PARSE text Validate script\n\
PFG g Get gpio PWM frequency\n\
PFS g v Set gpio PWM frequency\n\
PFG g Get GPIO PWM frequency\n\
PFS g v Set GPIO PWM frequency\n\
PIGPV Get pigpio library version\n\
PRG g Get gpio PWM range\n\
PRG g Get GPIO PWM range\n\
PROC text Store script\n\
PROCD sid Delete script\n\
PROCP sid Get script status and parameters\n\
PROCR sid ... Run script\n\
PROCS sid Stop script\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\
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\
\n\
R/READ g Read gpio level\n\
R/READ g Read GPIO level\n\
\n\
S/SERVO g v Set gpio servo pulsewidth\n\
S/SERVO g v Set GPIO servo pulsewidth\n\
SERC h Close serial handle\n\
SERDA h Check for serial data ready to read\n\
SERO text baud flags | Open serial device at baud with flags\n\
SERR h n Read bytes from serial handle\n\
SERRB h Read byte from serial handle\n\
SERW h ... Write bytes to serial handle\n\
SERWB h byte Write byte to serial handle\n\
SLR g v Read bit bang serial data from gpio\n\
SLRC g Close gpio for bit bang serial data\n\
SLRO g baud bitlen | Open gpio for bit bang serial data\n\
SERWB h byte Write byte to serial handle\n\
SHELL name str Execute a shell command\n\
SLR g v Read bit bang serial data from GPIO\n\
SLRC g Close GPIO for bit bang serial data\n\
SLRO g baud bitlen | Open GPIO for bit bang serial data\n\
SLRI g invert Invert serial logic (1 invert, 0 normal)\n\
SPIC h SPI close handle\n\
SPIO channel baud flags | SPI open channel at baud with flags\n\
@ -327,10 +373,10 @@ SPIW h ... SPI write bytes to handle\n\
SPIX h ... SPI transfer bytes to handle\n\
\n\
T/TICK Get current tick\n\
TRIG g micros l Trigger level for micros on gpio\n\
TRIG g micros l Trigger level for micros on GPIO\n\
\n\
W/WRITE g l Write level to gpio\n\
WDOG g millis Set millisecond watchdog on gpio\n\
W/WRITE g l Write level to GPIO\n\
WDOG g millis Set millisecond watchdog on GPIO\n\
WVAG triplets Wave add generic pulses\n\
WVAS g baud bitlen stopbits offset ... | Wave add serial data\n\
WVBSY Check if wave busy\n\
@ -345,15 +391,23 @@ WVNEW Start a new empty wave\n\
WVSC 0,1,2 Wave get DMA control block stats\n\
WVSM 0,1,2 Wave get micros stats\n\
WVSP 0,1,2 Wave get pulses stats\n\
WVTAT Returns the current transmitting wave\n\
WVTX wid Transmit wave as one-shot\n\
WVTXM wid wmde Transmit wave using mode\n\
WVTXR wid Transmit wave repeatedly\n\
\n\
\n\
Numbers may be entered as hex (prefix 0x), octal (prefix 0),\n\
otherwise they are assumed to be decimal.\n\
\n\
man pigs for full details.\n\n";
Examples\n\
\n\
pigs w 4 1 # set GPIO 4 high\n\
pigs r 5 # read GPIO 5\n\
pigs t # get current tick\n\
pigs i2co 1 0x20 0 # get handle to device 0x20 on I2C bus 1\n\
\n\
man pigs for full details.\n\
\n";
typedef struct
{
@ -364,8 +418,8 @@ typedef struct
static errInfo_t errInfo[]=
{
{PI_INIT_FAILED , "pigpio initialisation failed"},
{PI_BAD_USER_GPIO , "gpio not 0-31"},
{PI_BAD_GPIO , "gpio not 0-53"},
{PI_BAD_USER_GPIO , "GPIO not 0-31"},
{PI_BAD_GPIO , "GPIO not 0-53"},
{PI_BAD_MODE , "mode not 0-7"},
{PI_BAD_LEVEL , "level not 0-1"},
{PI_BAD_PUD , "pud not 0-2"},
@ -392,7 +446,7 @@ static errInfo_t errInfo[]=
{PI_BAD_CHANNEL , "DMA channel not 0-14"},
{PI_BAD_SOCKET_PORT , "socket port not 1024-30000"},
{PI_BAD_FIFO_COMMAND , "unknown fifo command"},
{PI_BAD_SECO_CHANNEL , "DMA secondary channel not 0-6"},
{PI_BAD_SECO_CHANNEL , "DMA secondary channel not 0-14"},
{PI_NOT_INITIALISED , "function called before gpioInitialise"},
{PI_INITIALISED , "function called after gpioInitialise"},
{PI_BAD_WAVE_MODE , "waveform mode not 0-1"},
@ -400,11 +454,11 @@ static errInfo_t errInfo[]=
{PI_BAD_WAVE_BAUD , "baud rate not 50-250K(RX)/50-1M(TX)"},
{PI_TOO_MANY_PULSES , "waveform has too many pulses"},
{PI_TOO_MANY_CHARS , "waveform has too many chars"},
{PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on gpio"},
{PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on GPIO"},
{PI_BAD_SERIAL_STRUC , "bad (null) serial structure parameter"},
{PI_BAD_SERIAL_BUF , "bad (null) serial buf parameter"},
{PI_NOT_PERMITTED , "no permission to update gpio"},
{PI_SOME_PERMITTED , "no permission to update one or more gpios"},
{PI_NOT_PERMITTED , "no permission to update GPIO"},
{PI_SOME_PERMITTED , "no permission to update one or more GPIO"},
{PI_BAD_WVSC_COMMND , "bad WVSC subcommand"},
{PI_BAD_WVSM_COMMND , "bad WVSM subcommand"},
{PI_BAD_WVSP_COMMND , "bad WVSP subcommand"},
@ -412,7 +466,7 @@ static errInfo_t errInfo[]=
{PI_BAD_SCRIPT , "invalid script"},
{PI_BAD_SCRIPT_ID , "unknown script id"},
{PI_BAD_SER_OFFSET , "add serial data offset > 30 minute"},
{PI_GPIO_IN_USE , "gpio already in use"},
{PI_GPIO_IN_USE , "GPIO already in use"},
{PI_BAD_SERIAL_COUNT , "must read at least a byte at a time"},
{PI_BAD_PARAM_NUM , "script parameter id not 0-9"},
{PI_DUP_TAG , "script has duplicate tag"},
@ -424,7 +478,7 @@ static errInfo_t errInfo[]=
{PI_SOCK_READ_FAILED , "socket read failed"},
{PI_SOCK_WRIT_FAILED , "socket write failed"},
{PI_TOO_MANY_PARAM , "too many script parameters (> 10)"},
{PI_NOT_HALTED , "script already running or failed"},
{PI_SCRIPT_NOT_READY , "script initialising"},
{PI_BAD_TAG , "script has unresolved tag"},
{PI_BAD_MICS_DELAY , "bad MICS delay (too large)"},
{PI_BAD_MILS_DELAY , "bad MILS delay (too large)"},
@ -453,11 +507,11 @@ static errInfo_t errInfo[]=
{PI_UNKNOWN_COMMAND , "unknown command"},
{PI_SPI_XFER_FAILED , "spi xfer/read/write failed"},
{PI_BAD_POINTER , "bad (NULL) pointer"},
{PI_NO_AUX_SPI , "need a B+ for auxiliary SPI"},
{PI_NOT_PWM_GPIO , "gpio is not in use for PWM"},
{PI_NOT_SERVO_GPIO , "gpio is not in use for servo pulses"},
{PI_NOT_HCLK_GPIO , "gpio has no hardware clock"},
{PI_NOT_HPWM_GPIO , "gpio has no hardware PWM"},
{PI_NO_AUX_SPI , "no auxiliary SPI on Pi A or B"},
{PI_NOT_PWM_GPIO , "GPIO is not in use for PWM"},
{PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"},
{PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"},
{PI_NOT_HPWM_GPIO , "GPIO has no hardware PWM"},
{PI_BAD_HPWM_FREQ , "hardware PWM frequency not 1-125M"},
{PI_BAD_HPWM_DUTY , "hardware PWM dutycycle not 0-1M"},
{PI_BAD_HCLK_FREQ , "hardware clock frequency not 4689-250M"},
@ -470,7 +524,7 @@ static errInfo_t errInfo[]=
{PI_TOO_MANY_SEGS , "too many I2C transaction segments"},
{PI_BAD_I2C_SEG , "an I2C transaction segment failed"},
{PI_BAD_SMBUS_CMD , "SMBus command not supported by driver"},
{PI_NOT_I2C_GPIO , "no bit bang I2C in progress on gpio"},
{PI_NOT_I2C_GPIO , "no bit bang I2C in progress on GPIO"},
{PI_BAD_I2C_WLEN , "bad I2C write length"},
{PI_BAD_I2C_RLEN , "bad I2C read length"},
{PI_BAD_I2C_CMD , "bad I2C command"},
@ -488,6 +542,24 @@ static errInfo_t errInfo[]=
{PI_BAD_ISR_INIT , "bad ISR initialisation"},
{PI_BAD_FOREVER , "loop forever must be last chain command"},
{PI_BAD_FILTER , "bad filter parameter"},
{PI_BAD_PAD , "bad pad number"},
{PI_BAD_STRENGTH , "bad pad drive strength"},
{PI_FIL_OPEN_FAILED , "file open failed"},
{PI_BAD_FILE_MODE , "bad file mode"},
{PI_BAD_FILE_FLAG , "bad file flag"},
{PI_BAD_FILE_READ , "bad file read"},
{PI_BAD_FILE_WRITE , "bad file write"},
{PI_FILE_NOT_ROPEN , "file not open for read"},
{PI_FILE_NOT_WOPEN , "file not open for write"},
{PI_BAD_FILE_SEEK , "bad file seek"},
{PI_NO_FILE_MATCH , "no files match pattern"},
{PI_NO_FILE_ACCESS , "no permission to access file"},
{PI_FILE_IS_A_DIR , "file is a directory"},
{PI_BAD_SHELL_STATUS , "bad shell return status"},
{PI_BAD_SCRIPT_NAME , "bad script name"},
{PI_BAD_SPI_BAUD , "bad SPI baud rate, not 50-500k"},
{PI_NOT_SPI_GPIO , "no bit bang SPI in progress on GPIO"},
{PI_BAD_EVENT_ID , "bad event id"},
};
@ -505,14 +577,14 @@ static int cmdMatch(char *str)
return CMD_UNKNOWN_CMD;
}
static int getNum(char *str, unsigned *val, int8_t *opt)
static int getNum(char *str, uint32_t *val, int8_t *opt)
{
int f, n;
unsigned v;
intmax_t v;
*opt = 0;
f = sscanf(str, " %i %n", &v, &n);
f = sscanf(str, " %ji %n", &v, &n);
if (f == 1)
{
@ -521,7 +593,7 @@ static int getNum(char *str, unsigned *val, int8_t *opt)
return n;
}
f = sscanf(str, " v%i %n", &v, &n);
f = sscanf(str, " v%ji %n", &v, &n);
if (f == 1)
{
@ -531,7 +603,7 @@ static int getNum(char *str, unsigned *val, int8_t *opt)
return n;
}
f = sscanf(str, " p%i %n", &v, &n);
f = sscanf(str, " p%ji %n", &v, &n);
if (f == 1)
{
@ -554,12 +626,12 @@ char *cmdStr(void)
int cmdParse(
char *buf, uint32_t *p, unsigned ext_len, char *ext, cmdCtlParse_t *ctl)
{
int f, valid, idx, val, pp, pars, n, n2, i;
int f, valid, idx, val, pp, pars, n, n2;
char *p8;
int32_t *p32;
char c;
uint32_t tp1=0, tp2=0, tp3=0;
int8_t to1, to2, to3;
uint32_t tp1=0, tp2=0, tp3=0, tp4=0, tp5=0;
int8_t to1, to2, to3, to4, to5;
int eaten;
/* Check that ext is big enough for the largest message. */
@ -609,10 +681,10 @@ int cmdParse(
break;
case 112: /* BI2CC GDC GPW I2CC
I2CRB MG MICS MILS MODEG NC NP PFG PRG
case 112: /* BI2CC FC GDC GPW I2CC I2CRB
MG MICS MILS MODEG NC NP PADG PFG PRG
PROCD PROCP PROCS PRRG R READ SLRC SPIC
WVDEL WVSC WVSM WVSP WVTX WVTXR
WVDEL WVSC WVSM WVSP WVTX WVTXR BSPIC
One positive parameter.
*/
@ -654,37 +726,23 @@ int cmdParse(
case 116: /* SYS
One parameter, a string of letters, digits, '-' and '_'.
One parameter, a string.
*/
f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2);
if ((f >= 0) && n)
{
p[3] = n;
ctl->opt[3] = CMD_NUMERIC;
memcpy(ext, buf+ctl->eaten, n);
ctl->eaten += n2;
valid = 1;
for (i=0; i<n; i++)
{
c = buf[ctl->eaten+i];
if ((!isalnum(c)) && (c != '_') && (c != '-'))
{
valid = 0;
break;
}
}
if (valid)
{
p[3] = n;
ctl->opt[3] = CMD_NUMERIC;
memcpy(ext, buf+ctl->eaten, n);
ctl->eaten += n2;
}
}
break;
case 121: /* HC I2CRD I2CRR I2CRW I2CWB I2CWQ P PFS PRS
PWM S SERVO SLR SLRI W WDOG WRITE WVTXM
case 121: /* HC FR I2CRD I2CRR I2CRW I2CWB I2CWQ P
PADS PFS PRS PWM S SERVO SLR SLRI W
WDOG WRITE WVTXM
Two positive parameters.
*/
@ -780,8 +838,53 @@ int cmdParse(
break;
case 131: /* BI2CO HP I2CO I2CPC I2CRI I2CWB I2CWW SLRO
SPIO TRIG
case 127: /* FL FO
Two parameters, first a string, other positive.
*/
f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2);
if ((f >= 0) && n)
{
p[3] = n;
ctl->opt[2] = CMD_NUMERIC;
memcpy(ext, buf+ctl->eaten, n);
ctl->eaten += n2;
ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]);
if ((ctl->opt[1] > 0) && ((int)p[1] >= 0))
valid = 1;
}
break;
case 128: /* SHELL
Two string parameters, the first space teminated.
The second arbitrary.
*/
f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2);
if ((f >= 0) && n)
{
valid = 1;
p[1] = n;
memcpy(ext, buf+ctl->eaten, n);
ctl->eaten += n;
ext[n] = 0; /* terminate first string */
n2 = strlen(buf+ctl->eaten+1);
memcpy(ext+n+1, buf+ctl->eaten+1, n2);
ctl->eaten += n2;
ctl->eaten ++;
p[3] = p[1] + n2 + 1;
}
break;
case 131: /* BI2CO HP I2CO I2CPC I2CRI I2CWB I2CWW
SLRO SPIO TRIG
Three positive parameters.
*/
@ -822,6 +925,56 @@ int cmdParse(
break;
case 133: /* FS
Three parameters. First and third positive.
Second may be negative when interpreted as an int.
*/
ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]);
ctl->eaten += getNum(buf+ctl->eaten, &p[2], &ctl->opt[2]);
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
if ((ctl->opt[1] > 0) && ((int)p[1] >= 0) &&
(ctl->opt[2] > 0) &&
(to1 == CMD_NUMERIC) && ((int)tp1 >= 0))
{
p[3] = 4;
memcpy(ext, &tp1, 4);
valid = 1;
}
break;
case 134: /* BSPIO
Six parameters. First to Fifth positive.
Sixth may be negative when interpreted as an int.
*/
ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]);
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
ctl->eaten += getNum(buf+ctl->eaten, &tp2, &to2);
ctl->eaten += getNum(buf+ctl->eaten, &tp3, &to3);
ctl->eaten += getNum(buf+ctl->eaten, &tp4, &to4);
ctl->eaten += getNum(buf+ctl->eaten, &tp5, &to5);
if ((ctl->opt[1] > 0) && ((int)p[1] >= 0) &&
(to1 == CMD_NUMERIC) && ((int)tp1 >= 0) &&
(to2 == CMD_NUMERIC) && ((int)tp2 >= 0) &&
(to3 == CMD_NUMERIC) && ((int)tp3 >= 0) &&
(to4 == CMD_NUMERIC) && ((int)tp4 >= 0) &&
(to5 == CMD_NUMERIC))
{
p[3] = 5 * 4;
memcpy(ext+ 0, &tp1, 4);
memcpy(ext+ 4, &tp2, 4);
memcpy(ext+ 8, &tp3, 4);
memcpy(ext+12, &tp4, 4);
memcpy(ext+16, &tp5, 4);
valid = 1;
}
break;
case 191: /* PROCR
One to 11 parameters, first positive,
@ -878,9 +1031,12 @@ int cmdParse(
break;
case 193: /* BI2CZ I2CWD I2CZ SERW SPIW SPIX
case 193: /* BI2CZ BSCX BSPIX FW I2CWD I2CZ SERW
SPIW SPIX
Two or more parameters, first >=0, rest 0-255.
BSCX is special case one or more.
*/
ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]);
@ -907,7 +1063,7 @@ int cmdParse(
p[3] = pars;
if (pars) valid = 1;
if (pars || (p[0]==PI_CMD_BSCX)) valid = 1;
}
break;

View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
This version is for pigpio version 23+
This version is for pigpio version 57+
*/
#ifndef COMMAND_H

View File

@ -11,6 +11,10 @@ pig2vd - A utility to convert pigpio notifications to VCD.
pig2vcd </dev/pigpioXX >file.VCD
.SH DESCRIPTION
.ad l
.nh
pig2vcd is a utility which reads notifications on stdin and writes the
output as a Value Change Dump (VCD) file on stdout.

2631
pigpio.3

File diff suppressed because it is too large Load Diff

2089
pigpio.c

File diff suppressed because it is too large Load Diff

1841
pigpio.h

File diff suppressed because it is too large Load Diff

1839
pigpio.py

File diff suppressed because it is too large Load Diff

203
pigpiod.1
View File

@ -11,6 +11,10 @@ pigpiod - A utility to start the pigpio library as a daemon.
sudo pigpiod [OPTION]...
.SH DESCRIPTION
.ad l
.nh
pigpiod is a utility which launches the pigpio library as a daemon.
.br
@ -30,70 +34,80 @@ pigpiod accepts the following configuration options
.SH OPTIONS
.IP "\fB-a value\fP"
DMA memory allocation mode
0=AUTO, 1=PMAP, 2=MBOX
default AUTO
DMA memory allocation mode.
0=AUTO, 1=PMAP, 2=MBOX.
Default AUTO
.
.IP "\fB-b value\fP"
gpio sample buffer in milliseconds
100-10000
default 120
GPIO sample buffer size in milliseconds.
100-10000.
Default 120
.
.IP "\fB-c value\fP"
library internal settings
default 0
Library internal settings.
.
Default 0
.
.IP "\fB-d value\fP"
primary DMA channel
0-14
default 14
Primary DMA channel.
0-14.
Default 14
.
.IP "\fB-e value\fP"
secondary DMA channel
0-6
default 5
Secondary DMA channel.
0-14.
Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel
.
.IP "\fB-f\fP"
disable fifo interface
default enabled
Disable fifo interface.
.
Default enabled
.
.IP "\fB-g\fP"
Run in foreground (do not fork).
.
Default disabled
.
.IP "\fB-k\fP"
disable local and remote socket interface
default enabled
Disable local and remote socket interface.
.
Default enabled
.
.IP "\fB-l\fP"
disable remote socket interface
default enabled
Disable remote socket interface.
.
Default enabled
.
.IP "\fB-n IP address\fP"
Allow IP address to use the socket interface.
Name (e.g. paul) or dotted quad (e.g. 192.168.1.66).
If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect
.
.IP "\fB-p value\fP"
socket port
1024-32000
default 8888
Socket port.
1024-32000.
Default 8888
.
.IP "\fB-s value\fP"
sample rate
1, 2, 4, 5, 8, 10
default 5
Sample rate.
1, 2, 4, 5, 8, or 10 microseconds.
Default 5
.
.IP "\fB-t value\fP"
clock peripheral
0=PWM 1=PCM
default PCM
Clock peripheral.
0=PWM 1=PCM.
Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio.
.
.IP "\fB-v -V\fP"
display pigpio version and exit
Display pigpio version and exit.
.
.
.IP "\fB-x mask\fP"
gpios which may be updated
A 54 bit mask with (1<<n) set if the user may update gpio #n.
default is the set of user gpios for the board revision
GPIO which may be updated.
A 54 bit mask with (1<<n) set if the user may update GPIO #n.
Default is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO
.
.br
.br
@ -125,23 +139,23 @@ pigpio provides a rudimentary permissions system for commands issued via the soc
.br
.br
All gpios may be read.
All GPIO may be read.
.br
.br
Only the user gpios for the board type or those specified by the -x option may be updated.
Only the user GPIO for the board type or those specified by the -x option may be updated.
.br
.br
.EX
Type 1 boards 0x03E6CF93
Type 1 boards 0x03E6CF93 (26 pin header)
.br
Type 2 boards 0xFBC6CF9C
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
.br
Type 3 boards 0x0FFFFFFC
Type 3 boards 0x0FFFFFFC (40 pin header)
.br
.EE
@ -154,42 +168,97 @@ In this context an update includes the following:
.br
.br
gpio mode set
GPIO mode set
.br
gpio pull/up down
GPIO pull/up down
.br
gpio write
GPIO write
.br
gpio set PWM (including range and frequency)
GPIO set PWM (including range and frequency)
.br
gpio set servo
GPIO set servo
.br
.br
In addition the bank clear and set commands, and the wave commands will only
affect updateable gpios.
affect updateable GPIO.
.br
.br
There are several special cases.
.SS Exceptions
.br
.br
The following exceptions are made for particular models.
.br
.br
The activity LED (green) may be written (gpio 16 for type 1 and 2
boards, gpio 47 for type 3 boards)
.SS Models A and B
.br
.br
The green activity LED (GPIO 16) may be written.
.br
.SS Models A+ and B+
.br
.br
The green activity LED (GPIO 47) may be written.
.br
The red power LED (GPIO 35) may be written.
.br
The high USB power mode (GPIO 38) may be written.
.br
.SS Pi Zero
.br
.br
The green activity LED (GPIO 47) may be written.
.br
.SS Pi2B
.br
.br
The green activity LED (GPIO 47) may be written.
.br
The red power LED (GPIO 35) may be written.
.br
The high USB power mode (GPIO 38) may be written.
.br
.SS Pi3B
.br
.br
The green activity LED and the red power LED are not writable.
.br
The USB power mode is fixed at 1.2 amps (high power).
.br
.br
.br
The power LED (red) may be written on type 3 boards (gpio 35).
.SS DMA Channels
.br
.br
The secondary channel is only used for the transmission of waves.
.br
.br
If possible use one of channels 0 to 6 for the secondary channel (a full channel).
.br
.br
A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel.
.br
.br
The high USB power mode gpio may be written (gpio 38 for type 3 boards).
.SH SEE ALSO

149
pigpiod.c
View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
This version is for pigpio version 43+
This version is for pigpio version 58+
*/
#include <sys/types.h>
@ -42,6 +42,8 @@ This version is for pigpio version 43+
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <sys/socket.h>
#include <netdb.h>
#include "pigpio.h"
@ -53,6 +55,7 @@ static unsigned bufferSizeMilliseconds = PI_DEFAULT_BUFFER_MILLIS;
static unsigned clockMicros = PI_DEFAULT_CLK_MICROS;
static unsigned clockPeripheral = PI_DEFAULT_CLK_PERIPHERAL;
static unsigned ifFlags = PI_DEFAULT_IF_FLAGS;
static int foreground = PI_DEFAULT_FOREGROUND;
static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_PRIMARY_CHANNEL;
static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_SECONDARY_CHANNEL;
static unsigned socketPort = PI_DEFAULT_SOCKET_PORT;
@ -65,6 +68,10 @@ static int updateMaskSet = 0;
static FILE * errFifo;
static uint32_t sockNetAddr[MAX_CONNECT_ADDRESSES];
static int numSockNetAddr = 0;
void fatal(char *fmt, ...)
{
char buf[128];
@ -86,19 +93,21 @@ void usage()
fprintf(stderr, "\n" \
"pigpio V%d\n" \
"Usage: sudo pigpiod [OPTION] ...\n" \
" -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n" \
" -b value, gpio sample buffer in milliseconds, default 120\n" \
" -c value, library internal settings, default 0\n" \
" -d value, primary DMA channel, 0-14, default 14\n" \
" -e value, secondary DMA channel, 0-6, default 5\n" \
" -f, disable fifo interface, default enabled\n" \
" -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default all interfaces\n" \
" -p value, socket port, 1024-32000, default 8888\n" \
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
" -v, -V, display pigpio version and exit\n" \
" -x mask, gpios which may be updated, default board user gpios\n" \
" -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n" \
" -b value, sample buffer size in ms, default 120\n" \
" -c value, library internal settings, default 0\n" \
" -d value, primary DMA channel, 0-14, default 14\n" \
" -e value, secondary DMA channel, 0-14, default 6\n" \
" -f, disable fifo interface, default enabled\n" \
" -g, run in foreground (do not fork), default disabled\n" \
" -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default local+remote\n" \
" -n IP addr, allow address, name or dotted, default allow all\n" \
" -p value, socket port, 1024-32000, default 8888\n" \
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
" -v, -V, display pigpio version and exit\n" \
" -x mask, GPIO which may be updated, default board GPIO\n" \
"EXAMPLE\n" \
"sudo pigpiod -s 2 -b 200 -f\n" \
" Set a sample rate of 2 microseconds with a 200 millisecond\n" \
@ -117,12 +126,43 @@ static uint64_t getNum(char *str, int *err)
return val;
}
static uint32_t checkAddr(char *addrStr)
{
int err;
struct addrinfo hints, *res;
struct sockaddr_in *sin;
const char *portStr;
uint32_t addr;
portStr = getenv(PI_ENVPORT);
if (!portStr) portStr = PI_DEFAULT_SOCKET_PORT_STR;
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags |= AI_CANONNAME;
err = getaddrinfo(addrStr, portStr, &hints, &res);
if (err) return 0;
sin = (struct sockaddr_in *)res->ai_addr;
addr = sin->sin_addr.s_addr;
freeaddrinfo(res);
return addr;
}
static void initOpts(int argc, char *argv[])
{
int opt, err, i;
uint32_t addr;
int64_t mask;
while ((opt = getopt(argc, argv, "a:b:c:d:e:fklp:s:t:x:vV")) != -1)
while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:p:s:t:x:vV")) != -1)
{
switch (opt)
{
@ -149,14 +189,14 @@ static void initOpts(int argc, char *argv[])
case 'd':
i = getNum(optarg, &err);
if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_PRIMARY_CHANNEL))
if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_DMA_CHANNEL))
DMAprimaryChannel = i;
else fatal("invalid -d option (%d)", i);
break;
case 'e':
i = getNum(optarg, &err);
if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_SECONDARY_CHANNEL))
if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_DMA_CHANNEL))
DMAsecondaryChannel = i;
else fatal("invalid -e option (%d)", i);
break;
@ -165,6 +205,10 @@ static void initOpts(int argc, char *argv[])
ifFlags |= PI_DISABLE_FIFO_IF;
break;
case 'g':
foreground = 1;
break;
case 'k':
ifFlags |= PI_DISABLE_SOCK_IF;
break;
@ -173,6 +217,13 @@ static void initOpts(int argc, char *argv[])
ifFlags |= PI_LOCALHOST_SOCK_IF;
break;
case 'n':
addr = checkAddr(optarg);
if (addr && (numSockNetAddr<MAX_CONNECT_ADDRESSES))
sockNetAddr[numSockNetAddr++] = addr;
else fatal("invalid -n option (%s)", optarg);
break;
case 'p':
i = getNum(optarg, &err);
if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT))
@ -253,40 +304,42 @@ int main(int argc, char **argv)
pid_t pid;
int flags;
/* Fork off the parent process */
pid = fork();
if (pid < 0) { exit(EXIT_FAILURE); }
/* If we got a good PID, then we can exit the parent process. */
if (pid > 0) { exit(EXIT_SUCCESS); }
/* Change the file mode mask */
umask(0);
/* Open any logs here */
/* NONE */
/* Create a new SID for the child process */
if (setsid() < 0) fatal("setsid failed (%m)");
/* Change the current working directory */
if ((chdir("/")) < 0) fatal("chdir failed (%m)");
/* check command line parameters */
initOpts(argc, argv);
/* Close out the standard file descriptors */
fclose(stdin);
fclose(stdout);
if (!foreground) {
/* Fork off the parent process */
pid = fork();
if (pid < 0) { exit(EXIT_FAILURE); }
/* If we got a good PID, then we can exit the parent process. */
if (pid > 0) { exit(EXIT_SUCCESS); }
/* Change the file mode mask */
umask(0);
/* Open any logs here */
/* NONE */
/* Create a new SID for the child process */
if (setsid() < 0) fatal("setsid failed (%m)");
/* Change the current working directory */
if ((chdir("/")) < 0) fatal("chdir failed (%m)");
/* Close out the standard file descriptors */
fclose(stdin);
fclose(stdout);
}
/* configure library */
@ -304,6 +357,8 @@ int main(int argc, char **argv)
if (updateMaskSet) gpioCfgPermissions(updateMask);
gpioCfgNetAddr(numSockNetAddr, sockNetAddr);
gpioCfgSetInternals(cfgInternals);
/* start library */

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
/* PIGPIOD_IF_VERSION 21 */
/* PIGPIOD_IF_VERSION 25 */
#include <stdio.h>
#include <stdlib.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
/* PIGPIOD_IF2_VERSION 3 */
/* PIGPIOD_IF2_VERSION 9 */
#include <stdio.h>
#include <stdlib.h>
@ -74,6 +74,19 @@ struct callback_s
callback_t *next;
};
struct evtCallback_s
{
int id;
int pi;
int event;
CBF_t f;
void * user;
int ex;
evtCallback_t *prev;
evtCallback_t *next;
};
/* GLOBALS ---------------------------------------------------------------- */
static int gPiInUse [MAX_PI];
@ -82,6 +95,7 @@ static int gPigCommand [MAX_PI];
static int gPigHandle [MAX_PI];
static int gPigNotify [MAX_PI];
static uint32_t gEventBits [MAX_PI];
static uint32_t gNotifyBits [MAX_PI];
static uint32_t gLastLevel [MAX_PI];
@ -93,6 +107,9 @@ static int gCancelState [MAX_PI];
static callback_t *gCallBackFirst = 0;
static callback_t *gCallBackLast = 0;
static evtCallback_t *geCallBackFirst = 0;
static evtCallback_t *geCallBackLast = 0;
/* PRIVATE ---------------------------------------------------------------- */
static void _pml(int pi)
@ -278,6 +295,7 @@ static int pigpioOpenSocket(char *addr, char *port)
static void dispatch_notification(int pi, gpioReport_t *r)
{
callback_t *p;
evtCallback_t *ep;
uint32_t changed;
int l, g;
@ -310,18 +328,37 @@ static void dispatch_notification(int pi, gpioReport_t *r)
}
else
{
g = (r->flags) & 31;
p = gCallBackFirst;
while (p)
if ((r->flags) & PI_NTFY_FLAGS_WDOG)
{
if (((p->pi) == pi) && ((p->gpio) == g))
g = (r->flags) & 31;
p = gCallBackFirst;
while (p)
{
if (p->ex) (p->f)(pi, g, PI_TIMEOUT, r->tick, p->user);
else (p->f)(pi, g, PI_TIMEOUT, r->tick);
if (((p->pi) == pi) && ((p->gpio) == g))
{
if (p->ex) (p->f)(pi, g, PI_TIMEOUT, r->tick, p->user);
else (p->f)(pi, g, PI_TIMEOUT, r->tick);
}
p = p->next;
}
}
else if ((r->flags) & PI_NTFY_FLAGS_EVENT)
{
g = (r->flags) & 31;
ep = geCallBackFirst;
while (ep)
{
if (((ep->pi) == pi) && ((ep->event) == g))
{
if (ep->ex) (ep->f)(pi, g, r->tick, ep->user);
else (ep->f)(pi, g, r->tick);
}
ep = ep->next;
}
p = p->next;
}
}
}
@ -447,8 +484,90 @@ static int intCallback(
return pigif_bad_callback;
}
static void findEventBits(int pi)
{
evtCallback_t *ep;
uint32_t bits = 0;
ep = geCallBackFirst;
while (ep)
{
if (ep->pi == pi) bits |= (1<<(ep->event));
ep = ep->next;
}
if (bits != gEventBits[pi])
{
gEventBits[pi] = bits;
pigpio_command(pi, PI_CMD_EVM, gPigHandle[pi], gEventBits[pi], 1);
}
}
static void _ewfe(
int pi, unsigned event, uint32_t tick, void *user)
{
*(int *)user = 1;
}
static int intEventCallback(
int pi, unsigned event, void *f, void *user, int ex)
{
static int id = 0;
evtCallback_t *ep;
if ((event >=0) && (event < 32) && f)
{
/* prevent duplicates */
ep = geCallBackFirst;
while (ep)
{
if ((ep->pi == pi) &&
(ep->event == event) &&
(ep->f == f))
{
return pigif_duplicate_callback;
}
ep = ep->next;
}
ep = malloc(sizeof(evtCallback_t));
if (ep)
{
if (!geCallBackFirst) geCallBackFirst = ep;
ep->id = id++;
ep->pi = pi;
ep->event = event;
ep->f = f;
ep->user = user;
ep->ex = ex;
ep->next = 0;
ep->prev = geCallBackLast;
if (ep->prev) (ep->prev)->next = ep;
geCallBackLast = ep;
findEventBits(pi);
return ep->id;
}
return pigif_bad_malloc;
}
return pigif_bad_callback;
}
static int recvMax(int pi, void *buf, int bufsize, int sent)
{
/*
Copy at most bufSize bytes from the receieved message to
buf. Discard the rest of the message.
*/
uint8_t scratch[4096];
int remaining, fetch, count;
@ -874,6 +993,9 @@ int wave_chain(int pi, char *buf, unsigned bufSize)
(pi, PI_CMD_WVCHA, 0, 0, bufSize, 1, ext, 1);
}
int wave_tx_at(int pi)
{return pigpio_command(pi, PI_CMD_WVTAT, 0, 0, 1);}
int wave_tx_busy(int pi)
{return pigpio_command(pi, PI_CMD_WVBSY, 0, 0, 1);}
@ -1394,6 +1516,76 @@ int bb_i2c_zip(
return bytes;
}
int bb_spi_open(
int pi,
unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK,
unsigned baud, unsigned spiFlags)
{
uint8_t buf[20];
gpioExtent_t ext[1];
/*
p1=CS
p2=0
p3=20
## extension ##
uint32_t MISO
uint32_t MOSI
uint32_t SCLK
uint32_t baud
uint32_t spiFlags
*/
ext[0].size = 20;
ext[0].ptr = &buf;
memcpy(buf + 0, &MISO, 4);
memcpy(buf + 4, &MOSI, 4);
memcpy(buf + 8, &SCLK, 4);
memcpy(buf + 12, &baud, 4);
memcpy(buf + 16, &spiFlags, 4);
return pigpio_command_ext
(pi, PI_CMD_BSPIO, CS, 0, 20, 1, ext, 1);
}
int bb_spi_close(int pi, unsigned CS)
{return pigpio_command(pi, PI_CMD_BSPIC, CS, 0, 1);}
int bb_spi_xfer(
int pi,
unsigned CS,
char *txBuf,
char *rxBuf,
unsigned count)
{
int bytes;
gpioExtent_t ext[1];
/*
p1=CS
p2=0
p3=count
## extension ##
char txBuf[count]
*/
ext[0].size = count;
ext[0].ptr = txBuf;
bytes = pigpio_command_ext
(pi, PI_CMD_BSPIX, CS, 0, count, 1, ext, 0);
if (bytes > 0)
{
bytes = recvMax(pi, rxBuf, count, bytes);
}
_pmu(pi);
return bytes;
}
int spi_open(int pi, unsigned channel, unsigned speed, uint32_t flags)
{
gpioExtent_t ext[1];
@ -1601,6 +1793,148 @@ int custom_2(int pi, unsigned arg1, char *argx, unsigned count,
return bytes;
}
int get_pad_strength(int pi, unsigned pad)
{return pigpio_command(pi, PI_CMD_PADG, pad, 0, 1);}
int set_pad_strength(int pi, unsigned pad, unsigned padStrength)
{return pigpio_command(pi, PI_CMD_PADS, pad, padStrength, 1);}
int shell_(int pi, char *scriptName, char *scriptString)
{
int ln, ls;
gpioExtent_t ext[2];
ln = strlen(scriptName);
ls = strlen(scriptString);
/*
p1=len(scriptName)
p2=0
p3=len(scriptName) + len(scriptString) + 1
## extension ##
char[]
*/
ext[0].size = ln + 1; /* include null byte */
ext[0].ptr = scriptName;
ext[1].size = ls;
ext[1].ptr = scriptString;
return pigpio_command_ext
(pi, PI_CMD_SHELL, ln, 0, ln+ls+1, 2, ext, 1);
}
int file_open(int pi, char *file, unsigned mode)
{
int len;
gpioExtent_t ext[1];
len = strlen(file);
/*
p1=mode
p2=0
p3=len
## extension ##
char file[len]
*/
ext[0].size = len;
ext[0].ptr = file;
return pigpio_command_ext
(pi, PI_CMD_FO, mode, 0, len, 1, ext, 1);
}
int file_close(int pi, unsigned handle)
{return pigpio_command(pi, PI_CMD_FC, handle, 0, 1);}
int file_write(int pi, unsigned handle, char *buf, unsigned count)
{
gpioExtent_t ext[1];
/*
p1=handle
p2=0
p3=count
## extension ##
char buf[count]
*/
ext[0].size = count;
ext[0].ptr = buf;
return pigpio_command_ext
(pi, PI_CMD_FW, handle, 0, count, 1, ext, 1);
}
int file_read(int pi, unsigned handle, char *buf, unsigned count)
{
int bytes;
bytes = pigpio_command
(pi, PI_CMD_FR, handle, count, 0);
if (bytes > 0)
{
bytes = recvMax(pi, buf, count, bytes);
}
_pmu(pi);
return bytes;
}
int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)
{
gpioExtent_t ext[1];
/*
p1=handle
p2=seekOffset
p3=4
## extension ##
uint32_t seekFrom
*/
ext[0].size = sizeof(uint32_t);
ext[0].ptr = &seekFrom;
return pigpio_command_ext
(pi, PI_CMD_FS, handle, seekOffset, 4, 1, ext, 1);
}
int file_list(int pi, char *fpat, char *buf, unsigned count)
{
int len;
int bytes;
gpioExtent_t ext[1];
len = strlen(fpat);
/*
p1=60000
p2=0
p3=len
## extension ##
char fpat[len]
*/
ext[0].size = len;
ext[0].ptr = fpat;
bytes = pigpio_command_ext(pi, PI_CMD_FL, 60000, 0, len, 1, ext, 0);
if (bytes > 0)
{
bytes = recvMax(pi, buf, count, bytes);
}
_pmu(pi);
return bytes;
}
int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)
{return intCallback(pi, user_gpio, edge, f, 0, 0);}
@ -1660,3 +1994,114 @@ int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)
return triggered;
}
int bsc_xfer(int pi, bsc_xfer_t *bscxfer)
{
int bytes;
int status;
gpioExtent_t ext[1];
/*
p1=control
p2=0
p3=len
## extension ##
char buf[len]
*/
ext[0].size = bscxfer->txCnt;
ext[0].ptr = bscxfer->txBuf;
bytes = pigpio_command_ext
(pi, PI_CMD_BSCX, bscxfer->control, 0, bscxfer->txCnt, 1, ext, 0);
if (bytes > 0)
{
recvMax(pi, &status, 4, 4);
status = ntohl(status);
bytes -= 4;
bytes = recvMax(pi, bscxfer->rxBuf, sizeof(bscxfer->rxBuf), bytes);
bscxfer->rxCnt = bytes;
}
else
{
status = bytes;
}
_pmu(pi);
return status;
}
int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)
{
int control = 0;
if (i2c_addr) control = (i2c_addr<<16) | 0x305;
bscxfer->control = control;
return bsc_xfer(pi, bscxfer);
}
int event_callback(int pi, unsigned event, evtCBFunc_t f)
{return intEventCallback(pi, event, f, 0, 0);}
int event_callback_ex(
int pi, unsigned event, evtCBFuncEx_t f, void *user)
{return intEventCallback(pi, event, f, user, 1);}
int event_callback_cancel(unsigned id)
{
evtCallback_t *ep;
int pi;
ep = geCallBackFirst;
while (ep)
{
if (ep->id == id)
{
pi = ep->pi;
if (ep->prev) {ep->prev->next = ep->next;}
else {geCallBackFirst = ep->next;}
if (ep->next) {ep->next->prev = ep->prev;}
else {geCallBackLast = ep->prev;}
free(ep);
findEventBits(pi);
return 0;
}
ep = ep->next;
}
return pigif_callback_not_found;
}
int wait_for_event(int pi, unsigned event, double timeout)
{
int triggered = 0;
int id;
double due;
if ((pi < 0) || (pi >= MAX_PI) || !gPiInUse[pi])
return pigif_unconnected_pi;
if (timeout <= 0.0) return 0;
due = time_time() + timeout;
id = event_callback_ex(pi, event, _ewfe, &triggered);
while (!triggered && (time_time() < due)) time_sleep(0.05);
event_callback_cancel(id);
return triggered;
}
int event_trigger(int pi, unsigned event)
{return pigpio_command(pi, PI_CMD_EVM, event, 0, 1);}

File diff suppressed because it is too large Load Diff

1701
pigs.1

File diff suppressed because it is too large Load Diff

53
pigs.c
View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
This version is for pigpio version 34+
This version is for pigpio version 56+
*/
#include <stdio.h>
@ -48,8 +48,8 @@ This program provides a socket interface to some of
the commands available from pigpio.
*/
char command_buf[8192];
char response_buf[8192];
char command_buf[CMD_MAX_EXTENSION];
char response_buf[CMD_MAX_EXTENSION];
int printFlags = 0;
@ -171,7 +171,10 @@ void print_result(int sock, int rv, cmdCmd_t cmd)
printf("%s", cmdUsage);
break;
case 6: /* BI2CZ CF2 I2CPK I2CRD I2CRI I2CRK I2CZ SERR SLR SPIX SPIR */
case 6: /*
BI2CZ CF2 FL FR I2CPK I2CRD I2CRI I2CRK
I2CZ SERR SLR SPIX SPIR
*/
printf("%d", r);
if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
if (r > 0)
@ -186,7 +189,8 @@ void print_result(int sock, int rv, cmdCmd_t cmd)
else if (printFlags & PRINT_ASCII)
{
if ((ch > 31) && (ch < 127)) printf("%c", ch);
if (isprint(ch) || (ch == '\n') || (ch == '\r'))
printf("%c", ch);
else printf("\\x%02hhx", ch);
}
else printf(" %hhu", response_buf[i]);
@ -212,6 +216,41 @@ void print_result(int sock, int rv, cmdCmd_t cmd)
}
printf("\n");
break;
case 8: /*
BSCX
*/
if (r < 0)
{
printf("%d", r);
fatal("ERROR: %s", cmdErrStr(r));
}
p = (uint32_t *)response_buf;
printf("%d %d", r-3, p[0]);
if (r > 4)
{
if (printFlags == PRINT_ASCII) printf(" ");
for (i=4; i<r; i++)
{
ch = response_buf[i];
if (printFlags & PRINT_HEX) printf(" %hhx", ch);
else if (printFlags & PRINT_ASCII)
{
if (isprint(ch) || (ch == '\n') || (ch == '\r'))
printf("%c", ch);
else printf("\\x%02hhx", ch);
}
else printf(" %hhu", response_buf[i]);
}
}
printf("\n");
break;
}
}
@ -220,7 +259,11 @@ void get_extensions(int sock, int command, int res)
switch (command)
{
case PI_CMD_BI2CZ:
case PI_CMD_BSCX:
case PI_CMD_BSPIX:
case PI_CMD_CF2:
case PI_CMD_FL:
case PI_CMD_FR:
case PI_CMD_I2CPK:
case PI_CMD_I2CRD:
case PI_CMD_I2CRI:

View File

@ -3,7 +3,7 @@
from distutils.core import setup
setup(name='pigpio',
version='1.27',
version='1.34',
author='joan',
author_email='joan@abyz.co.uk',
maintainer='joan',

30
util/Findpigpio.cmake Normal file
View File

@ -0,0 +1,30 @@
################################################################################
### Find the pigpio shared libraries.
################################################################################
# Find the path to the pigpio includes.
find_path(pigpio_INCLUDE_DIR
NAMES pigpio.h pigpiod_if.h pigpiod_if2.h
HINTS /usr/local/include)
# Find the pigpio libraries.
find_library(pigpio_LIBRARY
NAMES libpigpio.so
HINTS /usr/local/lib)
find_library(pigpiod_if_LIBRARY
NAMES libpigpiod_if.so
HINTS /usr/local/lib)
find_library(pigpiod_if2_LIBRARY
NAMES libpigpiod_if2.so
HINTS /usr/local/lib)
# Set the pigpio variables to plural form to make them accessible for
# the paramount cmake modules.
set(pigpio_INCLUDE_DIRS ${pigpio_INCLUDE_DIR})
set(pigpio_INCLUDES ${pigpio_INCLUDE_DIR})
# Handle REQUIRED, QUIET, and version arguments
# and set the <packagename>_FOUND variable.
find_package_handle_standard_args(pigpio
DEFAULT_MSG
pigpio_INCLUDE_DIR pigpio_LIBRARY pigpiod_if_LIBRARY pigpiod_if2_LIBRARY)

31
util/pigpiod Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: pigpiod
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: pigpio daemon
# Description: pigpio daemon required to control GPIO pins via pigpio $
### END INIT INFO
# Actions
case "$1" in
start)
pigpiod
;;
stop)
pkill pigpiod
;;
restart)
pkill pigpiod
pigpiod
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
exit 0

31
util/readme.md Normal file
View File

@ -0,0 +1,31 @@
This folder provides utility files for the pigpio library.
### pigpiod
`pigpiod` is a script that allows to run pigpiod as a Linux service with root privileges.
The advantage of running pigpiod as a service is that pigpiod can be automatically launched on system startup.
To automatically start pigpiod as a service, do the following:
+ Copy `pigpiod` from this directory to `/etc/init.d/`.
+ Make it executable:
```
sudo chmod +x /etc/init.d/pigpiod
```
+ Tell update-rc.d to automatically start the pigpiod service on system startup:
```
sudo update-rc.d pigpiod defaults
```
+ Now, you can start, stop, and restart pigpiod using
```
sudo service pigpiod start
sudo service pigpiod stop
sudo service pigpiod restart
```
### Findpigpio.cmake
`Findpigpio.cmake` is a script used by CMake to find out where the pigpio header and library files are located.

View File

@ -1,5 +1,5 @@
/*
gcc -o x_pigpio x_pigpio.c -lpigpio -lrt -lpthread
gcc -Wall -pthread -o x_pigpio x_pigpio.c -lpigpio
sudo ./x_pigpio
*** WARNING ************************************************
@ -45,7 +45,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc)
void t0()
{
printf("Version.\n");
printf("\nTesting pigpio C I/F\n");
printf("pigpio version %d.\n", gpioVersion());
@ -392,7 +392,8 @@ To the lascivious pleasing of a lute.\n\
wid = gpioWaveCreate();
e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT);
CHECK(5, 3, e, 9, 0, "wave tx repeat");
if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat");
else CHECK(5, 3, e, 19, 0, "wave tx repeat");
oc = t5_count;
time_sleep(5);
@ -413,7 +414,8 @@ To the lascivious pleasing of a lute.\n\
wid = gpioWaveCreate();
e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
CHECK(5, 8, e, 6811, 0, "wave tx start");
if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start");
else CHECK(5, 8, e, 7116, 0, "wave tx start");
CHECK(5, 9, 0, 0, 0, "NOT APPLICABLE");
@ -447,10 +449,12 @@ To the lascivious pleasing of a lute.\n\
CHECK(5, 18, c, 12000, 0, "wave get max pulses");
c = gpioWaveGetCbs();
CHECK(5, 19, c, 6810, 0, "wave get cbs");
if (e < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs");
else CHECK(5, 19, c, 7115, 0, "wave get cbs");
c = gpioWaveGetHighCbs();
CHECK(5, 20, c, 6810, 0, "wave get high cbs");
if (e < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs");
else CHECK(5, 20, c, 7115, 0, "wave get high cbs");
c = gpioWaveGetMaxCbs();
CHECK(5, 21, c, 25016, 0, "wave get max cbs");

View File

@ -45,14 +45,14 @@ def CHECK(t, st, got, expect, pc, desc):
def t0():
print("Version.")
print("\nTesting pigpio Python module {}".format(pigpio.VERSION))
print("Python {}".format(sys.version.replace("\n", " ")))
print("pigpio version {}.".format(pi.get_pigpio_version()))
print("Hardware revision {}.".format(pi.get_hardware_revision()))
print("Python version {}.".format(sys.version.replace("\n", " ")))
def t1():
print("Mode/PUD/read/write tests.")
@ -361,7 +361,10 @@ To the lascivious pleasing of a lute.
wid = pi.wave_create()
e = pi.wave_send_repeat(wid)
CHECK(5, 3, e, 9, 0, "wave send repeat")
if e < 14:
CHECK(5, 3, e, 9, 0, "wave send repeat")
else:
CHECK(5, 3, e, 19, 0, "wave send repeat")
oc = t5_count
time.sleep(5)
@ -380,7 +383,10 @@ To the lascivious pleasing of a lute.
wid = pi.wave_create()
e = pi.wave_send_once(wid)
CHECK(5, 8, e, 6811, 0, "wave send once")
if e < 6964:
CHECK(5, 8, e, 6811, 0, "wave send once")
else:
CHECK(5, 8, e, 7116, 0, "wave send once")
oc = t5_count
time.sleep(3)
@ -417,7 +423,10 @@ To the lascivious pleasing of a lute.
CHECK(5, 18, c, 12000, 0, "wave get max pulses")
c = pi.wave_get_cbs()
CHECK(5, 19, c, 6810, 0, "wave get cbs")
if c < 6963:
CHECK(5, 19, c, 6810, 0, "wave get cbs")
else:
CHECK(5, 19, c, 7115, 0, "wave get cbs")
CHECK(5, 20, 0, 0, 0, "NOT APPLICABLE")
@ -434,7 +443,10 @@ To the lascivious pleasing of a lute.
CHECK(5, 24, w1, 0, 0, "wave create")
e = pi.wave_send_repeat(w1)
CHECK(5, 25, e, 9, 0, "wave send repeat")
if e < 14:
CHECK(5, 25, e, 9, 0, "wave send repeat")
else:
CHECK(5, 25, e, 19, 0, "wave send repeat")
oc = t5_count
time.sleep(5)
@ -451,7 +463,10 @@ To the lascivious pleasing of a lute.
CHECK(5, 29, w2, 1, 0, "wave create")
e = pi.wave_send_once(w2)
CHECK(5, 30, e, 6811, 0, "wave send once")
if e < 6964:
CHECK(5, 30, e, 6811, 0, "wave send once")
else:
CHECK(5, 30, e, 7116, 0, "wave send once")
oc = t5_count
time.sleep(3)

View File

@ -1,5 +1,5 @@
/*
gcc -o x_pigpiod_if x_pigpiod_if.c -lpigpiod_if -lrt -lpthread
gcc -Wall -pthread -o x_pigpiod_if x_pigpiod_if.c -lpigpiod_if
./x_pigpiod_if
*** WARNING ************************************************
@ -42,7 +42,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc)
void t0()
{
printf("Version.\n");
printf("\nTesting pigpiod C I/F 1\n");
printf("pigpio version %d.\n", get_pigpio_version());
@ -360,7 +360,8 @@ To the lascivious pleasing of a lute.\n\
wid = wave_create();
e = wave_send_repeat(wid);
CHECK(5, 3, e, 9, 0, "wave tx repeat");
if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat");
else CHECK(5, 3, e, 19, 0, "wave tx repeat");
oc = t5_count;
time_sleep(5.05);
@ -379,7 +380,8 @@ To the lascivious pleasing of a lute.\n\
wid = wave_create();
e = wave_send_once(wid);
CHECK(5, 8, e, 6811, 0, "wave tx start");
if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start");
else CHECK(5, 8, e, 7116, 0, "wave tx start");
oc = t5_count;
time_sleep(3);
@ -419,10 +421,12 @@ To the lascivious pleasing of a lute.\n\
CHECK(5, 18, c, 12000, 0, "wave get max pulses");
c = wave_get_cbs();
CHECK(5, 19, c, 6810, 0, "wave get cbs");
if (c < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs");
else CHECK(5, 19, c, 7115, 0, "wave get cbs");
c = wave_get_high_cbs();
CHECK(5, 20, c, 6810, 0, "wave get high cbs");
if (c < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs");
else CHECK(5, 20, c, 7115, 0, "wave get high cbs");
c = wave_get_max_cbs();
CHECK(5, 21, c, 25016, 0, "wave get max cbs");

View File

@ -1,5 +1,5 @@
/*
gcc -o x_pigpiod_if2 x_pigpiod_if2.c -lpigpiod_if2 -lpthread
gcc -Wall -pthread -o x_pigpiod_if2 x_pigpiod_if2.c -lpigpiod_if2
./x_pigpiod_if2
*** WARNING ************************************************
@ -42,7 +42,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc)
void t0(int pi)
{
printf("Version.\n");
printf("\nTesting pigpiod C I/F 2\n");
printf("pigpio version %d.\n", get_pigpio_version(pi));
@ -364,7 +364,8 @@ To the lascivious pleasing of a lute.\n\
wid = wave_create(pi);
e = wave_send_repeat(pi, wid);
CHECK(5, 3, e, 9, 0, "wave tx repeat");
if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat");
else CHECK(5, 3, e, 19, 0, "wave tx repeat");
oc = t5_count;
time_sleep(5.05);
@ -383,7 +384,8 @@ To the lascivious pleasing of a lute.\n\
wid = wave_create(pi);
e = wave_send_once(pi, wid);
CHECK(5, 8, e, 6811, 0, "wave tx start");
if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start");
else CHECK(5, 8, e, 7116, 0, "wave tx start");
oc = t5_count;
time_sleep(3);
@ -423,10 +425,12 @@ To the lascivious pleasing of a lute.\n\
CHECK(5, 18, c, 12000, 0, "wave get max pulses");
c = wave_get_cbs(pi);
CHECK(5, 19, c, 6810, 0, "wave get cbs");
if (c < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs");
else CHECK(5, 19, c, 7115, 0, "wave get cbs");
c = wave_get_high_cbs(pi);
CHECK(5, 20, c, 6810, 0, "wave get high cbs");
if (c < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs");
else CHECK(5, 20, c, 7115, 0, "wave get high cbs");
c = wave_get_max_cbs(pi);
CHECK(5, 21, c, 25016, 0, "wave get max cbs");

24
x_pigs
View File

@ -19,7 +19,8 @@ GPIO=25
# of tests indicate a problem.
#
echo "Testing pigs I/F"
echo
echo "Testing pigpio pigs"
s=$(pigs pigpv)
echo "pigpio version $s"
@ -49,7 +50,7 @@ s=$(pigs bs2 0)
if [[ $s = "" ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi
s=$(pigs h)
if [[ ${#s} = 4544 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi
if [[ ${#s} = 5384 ]]; 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
@ -250,8 +251,13 @@ s=$(pigs wvag 16 0 5000000 0 16 5000000)
if [[ $s = 310 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi
w=$(pigs wvcre)
if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($s)"; fi
s=$(pigs wvtx $w)
if [[ $s = 621 ]]; then echo "WVTX ok"; else echo "WVTX fail ($s)"; fi
if [[ ($s = 621) || ($s = 1137) ]]
then echo "WVTX ok"
else echo "WVTX fail ($s)"
fi
s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi
sleep 1
@ -262,7 +268,11 @@ if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
s=$(pigs wvbsy)
if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi
s=$(pigs wvtxr $w)
if [[ $s = 621 ]]; then echo "WVTXR ok"; else echo "WVTXR fail ($s)"; fi
if [[ ($s = 621) || ($s = 1137) ]]
then echo "WVTXR ok"
else echo "WVTXR fail ($s)"
fi
s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi
s=$(pigs wvhlt)
@ -271,7 +281,11 @@ s=$(pigs wvbsy)
if [[ $s = 0 ]]; then echo "WVBSY-e ok"; else echo "WVBSY-e fail ($s)"; fi
s=$(pigs wvsc 0)
if [[ $s = 620 ]]; then echo "WVSC-a ok"; else echo "WVSC-a fail ($s)"; fi
if [[ ($s = 620) || ($s = 933) ]]
then echo "WVSC-a ok"
else echo "WVSC-a fail ($s)"
fi
s=$(pigs wvsc 1)
if [[ $s -ge 620 ]]; then echo "WVSC-b ok"; else echo "WVSC-b fail ($s)"; fi
s=$(pigs wvsc 2)

28
x_pipe
View File

@ -18,7 +18,8 @@ GPIO=25
# of tests indicate a problem.
#
echo "Testing pipe I/F"
echo
echo "Testing pigpio pipe I/F"
echo "pigpv" >/dev/pigpio
read -t 1 s </dev/pigout
@ -57,7 +58,7 @@ if [[ $s = 0 ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi
echo "h" >/dev/pigpio
read -t 1 s </dev/pigout
read -t 1 s </dev/pigout
if [[ $s = "BC1 bits Clear gpios in bank 1" ]]
if [[ $s = "BC1 bits Clear GPIO in bank 1" ]]
then echo "HELP-a ok"
else echo "HELP-a fail ($s)"
fi
@ -65,7 +66,7 @@ read -t 1 -N 9000 </dev/pigout # dump rest of help
echo "help" >/dev/pigpio
read -t 1 s </dev/pigout
read -t 1 s </dev/pigout
if [[ $s = "BC1 bits Clear gpios in bank 1" ]]
if [[ $s = "BC1 bits Clear GPIO in bank 1" ]]
then echo "HELP-b ok"
else echo "HELP-b fail ($s)"
fi
@ -347,7 +348,12 @@ read -t 1 w </dev/pigout
if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($s)"; fi
echo "wvtx $w" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 433 ]]; then echo "WVTX ok"; else echo "WVTX fail ($s)"; fi
if [[ ($s = 433) || ($s = 977) ]]
then echo "WVTX ok"
else echo "WVTX fail ($s)"
fi
echo "wvbsy" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi
@ -363,7 +369,12 @@ read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi
echo "wvtxr $w" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 433 ]]; then echo "WVTXR ok"; else echo "WVTXR fail ($s)"; fi
if [[ ($s = 433) || ($s = 977) ]]
then echo "WVTXR ok"
else echo "WVTXR fail ($s)"
fi
echo "wvbsy" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi
@ -376,7 +387,12 @@ if [[ $s = 0 ]]; then echo "WVBSY-e ok"; else echo "WVBSY-e fail ($s)"; fi
echo "wvsc 0" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 432 ]]; then echo "WVSC-a ok"; else echo "WVSC-a fail ($s)"; fi
if [[ ($s = 432) || ($s = 743) ]]
then echo "WVSC-a ok"
else echo "WVSC-a fail ($s)"
fi
echo "wvsc 1" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s -ge 432 ]]; then echo "WVSC-b ok"; else echo "WVSC-b fail ($s)"; fi