PIR Library  2
 All Classes Files Functions Variables Typedefs Macros Pages
PIRLIB2

Introduction

This is the MIT licensed open source library for the Promixis PIR-1 and PIR-4. This library has been tested on Windows and Linux. It supports sending IR codes, receiving IR signals and learning IR signals.

Windows Notes

On Windows compilation requires hid.lib, a x86 and x64 version of this library can be found in buildExtras, place them in the appropriate spot when building the Qt version.

The precompiled version of pirlib2_example.exe requires the Visual Studio 2010 redistributables.

Windows x86: http://www.microsoft.com/en-us/download/details.aspx?id=5555

Windows x64: http://www.microsoft.com/en-us/download/details.aspx?id=14632

Linux Notes

On Linux the udev daemon typically sets the access permissions of USB-HID devices to 600 for user root. This means that regular users are not able to access the devices. This library accesses the PIR-1 and PIR-4 through /dev/hidraw* and thus we need udev to adjust permission on this.

Easiest way to do this is by creating a file called

/etc/udev/rules.d/99-usb-pir.rules

inside that file add

SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="413f", MODE="0666"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="4155", MODE="0666"

Then reload the rules with

udevadm control --reload-rules

Last step is to now unplug and replug the PIR-1 / PIR-4 so it can get the new permissions.

C API

The C api can be found here pirlib2.h

C++ API

The C++ api can be found here Manager

Example

#include "pirlib2.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void printUsage()
{
printf("PIR-1 / PIR-4 Library Example.\n");
printf("Copyright (c) 2014 Promixis, LLC\n\n");
printf("pir usage:\n");
printf("pir send PIR_SERIAL_OR_ALL CCF BITMASK REPEATS\n");
printf("pir blink PIR_SERIAL_OR_ALL\n");
printf("pir list\n");
printf("\nExample send from any attached PIR-1 or PIR-4:\n");
printf("./pir_example send all \"0000 006E 0000 0022 0156 00A9 0014 0014 0014 0040 0014 0040 0014 0040 0014 0014 0014 0040 0014 0040 0014 0014 0014 0040 0014 0014 0014 0014 0014 0014 0014 0040 0014 0014 0014 0014 0014 0040 0014 0040 0014 0014 0014 0040 0014 0040 0014 0040 0014 0014 0014 0014 0014 0014 0014 0014 0014 0040 0014 0014 0014 0014 0014 0014 0014 0040 0014 0040 0014 0040 0014 05EF\" 1 2\n\n");
}
int main(int argc, char ** argv)
{
if ( argc < 2 )
{
printUsage();
return 0;
}
memset(&s,0,sizeof(PIR_Settings));
s.size = sizeof(PIR_Settings);
if ( pir_open(&s) != 0 )
{
printUsage();
printf("Error Opening HID layer.");
return -1;
}
bool ok = false;
int res = -1;
if ( strcmp(argv[1], "send" ) == 0 && argc == 6 )
{
const char * serial = argv[2];
const char * ccf = argv[3];
int bitmask = atoi( argv[4]);
int repeats = atoi( argv[5]);
if ( strcmp(serial, "all") == 0 )
{
serial = "";
}
res = pir_sendCCF(serial, ccf, bitmask, repeats);
ok = true;
}
if ( strcmp(argv[1], "blink") == 0 && argc == 3 )
{
const char * serial = argv[2];
if ( strcmp(serial, "all") == 0 )
{
printf("blink does not support \"all\"\n");
}
else
{
res = pir_blink(serial,5);
ok = true;
}
}
if ( strcmp(argv[1], "list") == 0 && argc == 2 )
{
char buffer[1024];
pir_list1(buffer, 1024);
printf("PIR-1: %s\n", buffer);
pir_list4(buffer, 1024);
printf("PIR-4: %s\n", buffer);
ok = true;
res = 0;
}
if ( !ok )
{
printUsage();
}
return res;
}

License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.