Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FtdiDmxThread.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * FtdiDmxThread.h
17  * The FTDI usb chipset DMX plugin for ola
18  * Copyright (C) 2011 Rui Barreiros
19  *
20  * Additional modifications to enable support for multiple outputs and
21  * additional device ids did change the original structure.
22  *
23  * by E.S. Rosenberg a.k.a. Keeper of the Keys 5774/2014
24  */
25 
26 #ifndef PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_
27 #define PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_
28 
29 #include "ola/DmxBuffer.h"
30 #include "ola/thread/Thread.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace ftdidmx {
35 
37  public:
38  FtdiDmxThread(FtdiInterface *interface, unsigned int frequency);
39  ~FtdiDmxThread();
40 
41  bool Stop();
42  void *Run();
43  bool WriteDMX(const DmxBuffer &buffer);
44 
45  private:
46  enum TimerGranularity { UNKNOWN, GOOD, BAD };
47 
48  TimerGranularity m_granularity;
49  FtdiInterface *m_interface;
50  bool m_term;
51  unsigned int m_frequency;
52  DmxBuffer m_buffer;
53  ola::thread::Mutex m_term_mutex;
54  ola::thread::Mutex m_buffer_mutex;
55 
56  void CheckTimeGranularity();
57 
58  static const uint32_t DMX_MAB = 16;
59  static const uint32_t DMX_BREAK = 110;
60  static const uint32_t BAD_GRANULARITY_LIMIT = 3;
61 };
62 } // namespace ftdidmx
63 } // namespace plugin
64 } // namespace ola
65 #endif // PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_