Open Lighting Architecture  0.9.4
 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 
21 #ifndef PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_
22 #define PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_
23 
24 #include "ola/DmxBuffer.h"
25 #include "ola/thread/Thread.h"
26 
27 namespace ola {
28 namespace plugin {
29 namespace ftdidmx {
30 
32  public:
33  FtdiDmxThread(FtdiWidget *widget, unsigned int frequency);
34  ~FtdiDmxThread();
35 
36  bool Stop();
37  void *Run();
38  bool WriteDMX(const DmxBuffer &buffer);
39 
40  private:
41  enum TimerGranularity { UNKNOWN, GOOD, BAD };
42 
43  TimerGranularity m_granularity;
44  FtdiWidget *m_widget;
45  bool m_term;
46  unsigned int m_frequency;
47  DmxBuffer m_buffer;
48  ola::thread::Mutex m_term_mutex;
49  ola::thread::Mutex m_buffer_mutex;
50 
51  void CheckTimeGranularity();
52 
53  static const uint32_t DMX_MAB = 16;
54  static const uint32_t DMX_BREAK = 110;
55  static const uint32_t BAD_GRANULARITY_LIMIT = 3;
56 };
57 } // namespace ftdidmx
58 } // namespace plugin
59 } // namespace ola
60 #endif // PLUGINS_FTDIDMX_FTDIDMXTHREAD_H_