PIR Library  2
 All Classes Files Functions Variables Typedefs Macros Pages
Classes | Macros | Typedefs | Functions
pirlib2.h File Reference
#include "pirlib2_global.h"

Go to the source code of this file.

Classes

struct  PIR_Settings
 the Settings structure. More...
 

Macros

#define PIR_ARRIVED_STATUS   1
 
#define PIR_REMOVED_STATUS   2
 
#define PIR_BUTTON_IDLE   0
 
#define PIR_BUTTON_DOWN   1
 
#define PIR_BUTTON_REPEAT   2
 
#define PIR_BUTTON_UP   3
 
#define PIR_PIR_1   1
 
#define PIR_PIR_4   4
 

Typedefs

typedef void(* fStatusCB )(const char *serial, unsigned char status, void *userData)
 Callback called when the status of the PIR-1 driver is affected. More...
 
typedef void(* fIrReceivedCB )(const char *serial, const unsigned int *pulses, unsigned int pulseCount, void *userData)
 Called when an IR signal is received in non-learn mode. More...
 
typedef void(* fIrSentCB )(const char *serial, unsigned char status, void *userData)
 fIrSentCB is called when an IR code was sent. More...
 
typedef void(* fIrRawLearnCB )(const char *serial, unsigned int modulation, const unsigned int *pulses, unsigned int pulseCount, void *userData)
 fIrRawLearnCB is called when an IR code is received in LEARN mode. More...
 
typedef void(* fButtonCB )(const char *serial, int button1, int button2, int button3, int button4, void *userData)
 fButtonCB is called on a button event. More...
 

Functions

PIRLIB2SHARED_EXPORT int pir_open (PIR_Settings *settings)
 Opens the PIR Library. This must be called only once. More...
 
PIRLIB2SHARED_EXPORT int pir_close ()
 Close the library. More...
 
PIRLIB2SHARED_EXPORT int pir_sendCCF (const char *serial, const char *ccf, int bitmask, unsigned char repeats)
 Transmit a CCF code. More...
 
PIRLIB2SHARED_EXPORT unsigned int pir_list1 (char *buffer, unsigned int size)
 Get a comma separated list of PIR-1 serial numbers. More...
 
PIRLIB2SHARED_EXPORT unsigned int pir_list4 (char *buffer, unsigned int size)
 Get a comma separated list of PIR-4 serial numbers. More...
 
PIRLIB2SHARED_EXPORT int pir_version (const char *serial)
 Returns the firmware version of the attached PIR. More...
 
PIRLIB2SHARED_EXPORT int pir_blink (const char *serial, unsigned char count)
 Blinks the LED on the attached PIR-1. More...
 
PIRLIB2SHARED_EXPORT int pir_type (const char *serial)
 Returns the type. More...
 
PIRLIB2SHARED_EXPORT int pir_detect ()
 Looks for attached PIR-1 or PIR-4 devices. This library runs this code on startup but after that the calling code is responsible for periodically running this. More...
 
PIRLIB2SHARED_EXPORT int pir_learn (const char *serial)
 starts learn mode More...
 
PIRLIB2SHARED_EXPORT int pir_cancelLearn (const char *serial)
 starts learn mode More...
 

Detailed Description

Main C interface of the library.

Macro Definition Documentation

#define PIR_ARRIVED_STATUS   1

PIR-1 or PIR-4 has arrived

#define PIR_BUTTON_DOWN   1

Button is being pressed

#define PIR_BUTTON_IDLE   0

Idle Button

#define PIR_BUTTON_REPEAT   2

Button is held down

#define PIR_BUTTON_UP   3

Button was released

#define PIR_PIR_1   1

PIR-1

#define PIR_PIR_4   4

PIR-4

#define PIR_REMOVED_STATUS   2

PIR-1 or PIR-4 was removed

Typedef Documentation

fButtonCB

fButtonCB is called on a button event.

Parameters
serialserial number of PIR
button1current event number, PIR_BUTTON_DOWN, PIR_BUTTON_IDLE, PIR_BUTTON_REPEAT or PIR_BUTTON_UP
button1current event number, PIR_BUTTON_DOWN, PIR_BUTTON_IDLE, PIR_BUTTON_REPEAT or PIR_BUTTON_UP
button2current event number, PIR_BUTTON_DOWN, PIR_BUTTON_IDLE, PIR_BUTTON_REPEAT or PIR_BUTTON_UP
button3current event number, PIR_BUTTON_DOWN, PIR_BUTTON_IDLE, PIR_BUTTON_REPEAT or PIR_BUTTON_UP
button4current event number, PIR_BUTTON_DOWN, PIR_BUTTON_IDLE, PIR_BUTTON_REPEAT or PIR_BUTTON_UP
userDatauserData element from PIR_Settings
fIrRawLearnCB

fIrRawLearnCB is called when an IR code is received in LEARN mode.

Parameters
serialserial number of PIR
modulationis the modulation frequency of the signal.
pulsesis the array that holds the pulse lenghts
pulseCountis the number of elements in the buffer.
userDatauserData element from PIR_Settings
fIrReceivedCB

Called when an IR signal is received in non-learn mode.

fIrReceivedCB is called when an IR code is received. Note that the received code is NOT an CCF code and must be compared 'fuzzy'.

Parameters
serialserial number of PIR
pulsespulses is a array of pulse lenghts.
pulseCountpulseCount is the number of elements in the pulses array.
userDatauserData element from PIR_Settings
fIrSentCB

fIrSentCB is called when an IR code was sent.

Parameters
serialserial number of PIR
status,0= OK otherwise error.
userDatauserData element from PIR_Settings
fStatusCB

Callback called when the status of the PIR-1 driver is affected.

For example when a new PIR-1 arrives.

PIR_ARRIVED_STATUS if a new PIR-1 arrives. PIR_REMOVED_STATUS if a PIR-1 is removed.

Parameters
serialserial number of PIR
statusPIR_ARRIVED_STATUS or PIR_REMOVED_STATUS
userDatauserData element from PIR_Settings

Function Documentation

PIRLIB2SHARED_EXPORT int pir_blink ( const char *  serial,
unsigned char  count 
)

Blinks the LED on the attached PIR-1.

Parameters
serialserial number of the PIR-1 to query.
countthe number of times to blink.
Returns
0 on success
< 0 on error
PIRLIB2SHARED_EXPORT int pir_cancelLearn ( const char *  serial)

starts learn mode

Parameters
serialnumber of PIR-1 to stop learning.
Returns
0 on success
< 0 on error
PIRLIB2SHARED_EXPORT int pir_close ( )

Close the library.

Returns
0 on success.
PIRLIB2SHARED_EXPORT int pir_detect ( )

Looks for attached PIR-1 or PIR-4 devices. This library runs this code on startup but after that the calling code is responsible for periodically running this.

Returns
0 on success
< 0 on error
PIRLIB2SHARED_EXPORT int pir_learn ( const char *  serial)

starts learn mode

Parameters
serialserial number of PIR-1 to use for learning.
Returns
0 on success
< 0 on error
PIRLIB2SHARED_EXPORT unsigned int pir_list1 ( char *  buffer,
unsigned int  size 
)

Get a comma separated list of PIR-1 serial numbers.

Parameters
bufferallocated by caller
sizesize of buffer
Returns
the number of characters required in the buffer to hold the full string. If this number is larger then you have passed in size adjust your buffer and call again.
PIRLIB2SHARED_EXPORT unsigned int pir_list4 ( char *  buffer,
unsigned int  size 
)

Get a comma separated list of PIR-4 serial numbers.

Parameters
bufferallocated by caller
sizesize of buffer
Returns
the number of characters required in the buffer to hold the full string. If this number is larger then you have passed in size adjust your buffer and call again.
PIRLIB2SHARED_EXPORT int pir_open ( PIR_Settings settings)

Opens the PIR Library. This must be called only once.

Parameters
settingsPIR_Settings structure.
Returns
0 on success.
< 0 on error.

The PIR_Settings struct contents is copied so there is no need to keep the object around after pir_open

Example

This example opens the library without any callbacks registered.

memset(&s, 0, sizeof(PIR_Settings));
s.size = sizeof( PIR_Settings );
PIRLIB2SHARED_EXPORT int pir_sendCCF ( const char *  serial,
const char *  ccf,
int  bitmask,
unsigned char  repeats 
)

Transmit a CCF code.

CCF codes are the IR codes formatted according to the Pronto CCF format. This library only supports CCF-RAW codes.

Multiple code can be sent in quick succesion without waiting for fIrSentCB callback. Internally the library will queue the CCF codes.

Parameters
serialthe serial number of the PIR to use for sending or 0 ( or "" ) for all attached PIRs.
ccfPronto CCF string.
bitmaskcombination of bits 1 = back of PIR, 2 = front panel for pir-1
bitmask= 1, 2, 4 or 8 respectively for ports 1,2,3 or 4 on PIR-4
repeats= number of times to repeat the ir signal.
Returns
0 = success
< 0 = error
PIRLIB2SHARED_EXPORT int pir_type ( const char *  serial)

Returns the type.

Parameters
serialserial number of the PIR-1 to query.
Returns
PIR_PIR_1 or PIR_PIR_4 on success
< 0 on error
PIRLIB2SHARED_EXPORT int pir_version ( const char *  serial)

Returns the firmware version of the attached PIR.

Parameters
serialserial number of the PIR-1 to query.
Returns
version of firmware on success (>0)
< 0 on error.