PIR Library  2
 All Classes Files Functions Variables Typedefs Macros Pages
pir.h
1 /*
2 
3 PIR-1/PIR-4 Driver v2
4 
5 Copyright (c) 2014, Promixis, LLC
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or
9 without modification, are permitted provided that the
10 following conditions are met:
11 
12 1. Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the following
14 disclaimer.
15 
16 2. Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials
19 provided with the distribution.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 
36 */
37 
38 #ifndef PIR_H
39 #define PIR_H
40 
41 #include <list>
42 #include <functional>
43 
44 #include "ipir.h"
45 #include "hidapi.h"
46 #include "pirlib2.h"
47 #include "iparser.h"
48 #include "irsend.h"
49 #include "boolsig.h"
50 
51 
52 extern "C" {
53 #include "pt.h"
54 }
55 
56 
57 class PIR : public IPIR
58 {
59 public:
60  typedef std::function< void( const std::string &serial ) > PIRClosedCallback;
61 
62  PIR( const std::string & serial, unsigned int version, IPIR::Type type, const std::string & path, PIR_Settings * settings, PIRClosedCallback closed );
63  // calling the destructor on PIR will _NOT_ trigger the closedCallback
64  ~PIR();
65 
66  std::string serial() const;
67  unsigned int version() const;
68  std::string path() const;
69 
70  bool sendCCF(const std::string ccf, unsigned char bitmask, unsigned char repeats);
71  bool blink(unsigned char count);
72  bool learn();
73  bool cancelLearn();
74 
75  IPIR::Type type() const;
76  void waitForStartup();
77 
78 
79 private:
80  std::string m_Serial;
81  unsigned int m_Version;
82  IPIR::Type m_Type;
83  std::string m_Path;
84  PIR_Settings * m_Settings;
85  PIRClosedCallback m_ClosedCallback;
86  hid_device * m_Device;
87  pthread_t m_Thread;
88  pthread_mutex_t m_Mutex;
89  pthread_mutex_t m_FunctionQueueMutex;
90  bool m_ExitThread;
91  bool m_IrSending;
92  BoolSig m_StartupSignal;
93  IParserPtr m_CurrentParser;
94  IParserPtr m_SendIRParser;
95  IParserPtr m_UnknownParser;
96  IParserPtr m_ReceiveParser;
97  IParserPtr m_ButtonParser;
98  IParserPtr m_IRLearnParser;
99 
100  typedef std::function<void()> QueuedFunction;
101  std::list<QueuedFunction> m_QueuedFunctions;
102  std::list<IRSendPtr> m_QueuedIrSignals;
103 
104  static void *_proc( void * attr );
105  void proc();
106 
107  void startCCFSend(const IRSend *send);
108  void queue( QueuedFunction f );
109  void irSendingDone();
110  size_t functionQueueSize();
111 
112 };
113 typedef std::shared_ptr<PIR> PIRPtr;
114 
115 #endif // PIR_H
116 
virtual bool blink(unsigned char count)=0
blinks the LED on the PIR-1
virtual bool sendCCF(const std::string ccf, unsigned char bitmask, unsigned char repeats)=0
sends CCF code.
The PIR interface class.
Definition: ipir.h:47
virtual unsigned int version() const =0
Returns the firmware version number.
virtual std::string serial() const =0
Returns the serial number.
virtual bool learn()=0
starts learn mode on a PIR-1
virtual Type type() const =0
returns the Type of the PIR
the Settings structure.
Definition: pirlib2.h:334
virtual bool cancelLearn()=0
ends learn mode on a PIR-1